clj_env
Clojerl compilation environment.
clj_env:env()
holds the information for the current compilation
environment. It is used by all the compilation stages: the
clj_reader
, the clj_analyzer
and the clj_emitter
.
- Local variables available in the current scope.
- Current location in the file or string being processed.
- Stack of expressions added by the
clj_analyzer
. - ... and more.
Summary
Types
- after_expr()
- binary_segment_expr()
- binding_expr()
- case_expr()
- catch_expr()
- constant_expr()
- context()
- def_expr()
- defprotocol_expr()
- deftype_expr()
- do_expr()
- env()
- erl_alias_expr()
- erl_binary_expr()
- erl_fun_expr()
- erl_list_expr()
- erl_map_expr()
- expr()
- extend_type_expr()
- fn_expr()
- fn_method_expr()
- if_expr()
- import_expr()
- invoke_expr()
- let_expr()
- letfn_expr()
- local_expr()
- loop_expr()
- loop_id()
- loop_type()
- map_expr()
- new_expr()
- on_load_expr()
- quote_expr()
- receive_expr()
- recur_expr()
- resolve_type_expr()
- set_expr()
- throw_expr()
- try_expr()
- tuple_expr()
- type_expr()
- var_expr()
- vector_expr()
- with_meta_expr()
Functions
-
add_locals_scope(Env)
Push a new local variables scope.
-
context(Env)
Returns the current type of context.
-
default()
Returns a default new environment.
-
exprs(X1)
Returns all the expressions on the stack, but in FIFO order.
-
get(Name, Env)
Equivalent to
get(Name, undefined, Env)
. -
get(Name, Default, X3)
Get a value stored in the environment or
Default
if not found. -
get_local(Sym, Env)
Returns the information for the local variable with the name
Sym
orundefined
if not found. -
get_locals(X1)
Returns all available local variables in the current scope.
-
last_exprs(N, Env)
Returns the last
N
expressions that where pushed to the stack. -
location(Env)
Returns the current location in the file or string.
-
pop(Env)
Pop the custom scope.
-
pop_expr(Env)
Pop a Clojerl expression from the stack.
-
push(Mapping, Env)
Push a custom
Mapping
into the custom scopeclj_scope
. -
push_expr(Expr, Env)
Push a Clojerl expression to the stack.
-
put(Name, Value, Env)
Put a value in the custom scope
clj_scope:put/3
. -
put_local(Sym, Local, Env)
Adds the expression for the local variable named
Sym
. -
put_locals(Locals, Env)
Adds the expression for multiple local variables.
-
remove_locals_scope(Env)
Pop a local variables scope.
-
restore_locals_scope(Env)
Restore the saved local variables to the current scope.
-
save_locals_scope(Env)
Saves the local variables in the current scope and empties the scope.
-
time(Env)
Returns the timing information stored by the compiler.
-
time(Key, Delta, Env)
Increase the time for
Key
byDelta
. -
update(Name, Value, Env)
Update a value in the custom scope
clj_scope:update/3
.
Types
after_expr()
-type after_expr() ::
#{op => 'after',
env => clj_env:env(),
form => any(),
tag => expr(),
timeout => expr(),
body => expr()}.
binary_segment_expr()
-type binary_segment_expr() ::
#{op => erl_list,
env => clj_env:env(),
form => any(),
tag => expr(),
value => expr(),
size => expr(),
unit => expr(),
type => expr(),
flags => expr()}.
binding_expr()
-type binding_expr() ::
#{op => binding,
env => clj_env:env(),
form => any(),
tag => expr(),
pattern => expr(),
'variadic?' => boolean(),
arg_id => integer(),
local => arg | loop | 'let'}.
case_expr()
-type case_expr() ::
#{op => 'case',
env => clj_env:env(),
form => any(),
tag => expr(),
test => expr(),
clauses => [{expr(), expr()}],
default => expr() | undefined}.
catch_expr()
-type catch_expr() ::
#{op => 'catch',
env => clj_env:env(),
form => any(),
tag => expr(),
class => expr(),
local => binding_expr(),
stacktrace => binding_expr() | undefined,
guard => expr(),
body => expr()}.
constant_expr()
-type constant_expr() ::
#{op => constant,
env => clj_env:env(),
form => any(),
tag => expr()}.
context()
-type context() :: expr | return | statement.
def_expr()
-type def_expr() ::
#{op => def,
env => clj_env:env(),
form => any(),
tag => expr(),
name => 'clojerl.Symbol':type(),
var => 'clojerl.Var':type(),
init => expr(),
dynamic => boolean()}.
defprotocol_expr()
-type defprotocol_expr() ::
#{op => defprotocol,
env => clj_env:env(),
form => any(),
tag => expr(),
methods_sigs => [any()]}.
deftype_expr()
-type deftype_expr() ::
#{op => deftype,
env => clj_env:env(),
form => any(),
tag => expr(),
name => 'clojerl.Symbol':type(),
type => 'erlang.Type':type(),
fields => [expr()],
protocols => [expr()],
methods => [expr()],
opts => [any()]}.
do_expr()
-type do_expr() ::
#{op => do,
env => clj_env:env(),
form => any(),
tag => expr(),
statements => [expr()],
ret => expr()}.
env()
-type env() ::
#{context => context(),
exprs => [expr()],
locals => clj_scope:scope(),
saved_locals => clj_scope:scope() | undefined,
mapping => clj_scope:scope()}.
erl_alias_expr()
-type erl_alias_expr() ::
#{op => erl_alias,
env => clj_env:env(),
form => any(),
tag => expr(),
variable => expr(),
pattern => expr()}.
erl_binary_expr()
-type erl_binary_expr() ::
#{op => erl_list,
env => clj_env:env(),
form => any(),
tag => expr(),
segments => [binary_segment_expr()]}.
erl_fun_expr()
-type erl_fun_expr() ::
#{op => erl_fun,
env => clj_env:env(),
form => any(),
tag => no_tag,
module => module(),
function => atom(),
arity => arity()}.
erl_list_expr()
-type erl_list_expr() ::
#{op => erl_list,
env => clj_env:env(),
form => any(),
tag => expr(),
items => [expr()],
tail => expr() | undefined}.
erl_map_expr()
-type erl_map_expr() ::
#{op => erl_map,
env => clj_env:env(),
form => any(),
tag => expr(),
keys => [expr()],
vals => [expr()],
pattern => boolean()}.
expr()
-type expr() ::
constant_expr() |
quote_expr() |
local_expr() |
binding_expr() |
fn_expr() |
fn_method_expr() |
do_expr() |
if_expr() |
let_expr() |
loop_expr() |
recur_expr() |
letfn_expr() |
case_expr() |
def_expr() |
import_expr() |
new_expr() |
deftype_expr() |
defprotocol_expr() |
extend_type_expr() |
invoke_expr() |
resolve_type_expr() |
throw_expr() |
try_expr() |
catch_expr() |
erl_fun_expr() |
var_expr() |
type_expr() |
with_meta_expr() |
erl_map_expr() |
erl_list_expr() |
erl_binary_expr() |
binary_segment_expr() |
tuple_expr() |
vector_expr() |
set_expr() |
map_expr() |
receive_expr() |
after_expr() |
erl_alias_expr() |
on_load_expr().
extend_type_expr()
-type extend_type_expr() ::
#{op => extend_type,
env => clj_env:env(),
form => any(),
tag => expr(),
type => expr(),
impls => #{expr() => [expr()]}}.
fn_expr()
-type fn_expr() ::
#{op => fn,
env => clj_env:env(),
form => any(),
tag => expr(),
'variadic?' => boolean(),
fixed_arities => [arity()],
min_fixed_arity => undefined | integer(),
max_fixed_arity => undefined | integer(),
variadic_arity => undefined | integer(),
'erlang-fn?' => boolean(),
methods => [expr()],
once => boolean(),
local => local_expr()}.
fn_method_expr()
-type fn_method_expr() ::
#{op => fn_method,
env => clj_env:env(),
form => any(),
tag => expr(),
loop_id => loop_id(),
loop_type => loop_type(),
'variadic?' => boolean(),
params => [expr()],
guard => expr(),
fixed_arity => integer(),
body => expr()}.
if_expr()
-type if_expr() ::
#{op => 'if',
env => clj_env:env(),
form => any(),
tag => expr(),
test => expr(),
then => expr(),
else => expr()}.
import_expr()
-type import_expr() ::
#{op => import,
env => clj_env:env(),
form => any(),
tag => expr(),
typename => binary()}.
invoke_expr()
-type invoke_expr() ::
#{op => invoke,
env => clj_env:env(),
form => any(),
tag => expr(),
f => expr(),
args => [expr()]}.
let_expr()
-type let_expr() ::
#{op => 'let',
env => clj_env:env(),
form => any(),
tag => expr(),
body => expr(),
bindings => [expr()]}.
letfn_expr()
-type letfn_expr() ::
#{op => letfn,
env => clj_env:env(),
form => any(),
tag => expr(),
vars => [local_expr()],
fns => [fn_expr()],
body => expr()}.
local_expr()
-type local_expr() ::
#{op => local,
env => clj_env:env(),
form => any(),
tag => expr(),
name => 'clojerl.Symbol':type(),
shadow => any(),
underscore => boolean(),
id => integer(),
binding => boolean()}.
loop_expr()
-type loop_expr() ::
#{op => loop,
env => clj_env:env(),
form => any(),
tag => expr(),
loop_id => loop_id(),
body => expr(),
bindings => [expr()]}.
loop_id()
-type loop_id() :: 'clojerl.Symbol':type().
loop_type()
-type loop_type() :: fn | fn_method | var | loop.
map_expr()
-type map_expr() ::
#{op => map,
env => clj_env:env(),
form => any(),
tag => expr(),
keys => [expr()],
vals => [expr()]}.
new_expr()
-type new_expr() ::
#{op => new,
env => clj_env:env(),
form => any(),
tag => expr(),
type => [expr()],
args => [expr()]}.
on_load_expr()
-type on_load_expr() ::
#{op => on_load,
env => clj_env:env(),
form => any(),
tag => expr(),
body => expr()}.
quote_expr()
-type quote_expr() ::
#{op => quote,
env => clj_env:env(),
expr => any(),
form => any(),
tag => expr()}.
receive_expr()
-type receive_expr() ::
#{op => 'receive',
env => clj_env:env(),
form => any(),
tag => expr(),
clauses => [expr()],
'after' => expr()}.
recur_expr()
-type recur_expr() ::
#{op => recur,
env => clj_env:env(),
form => any(),
tag => expr(),
exprs => [expr()],
loop_id => loop_id(),
loop_type => loop_type()}.
resolve_type_expr()
-type resolve_type_expr() ::
#{op => resolve_type,
env => clj_env:env(),
form => any(),
tag => expr(),
function => atom()}.
set_expr()
-type set_expr() ::
#{op => set,
env => clj_env:env(),
form => any(),
tag => expr(),
items => [expr()]}.
throw_expr()
-type throw_expr() ::
#{op => throw,
env => clj_env:env(),
form => any(),
tag => expr(),
exception => expr(),
stacktrace => expr()}.
try_expr()
-type try_expr() ::
#{op => 'try',
env => clj_env:env(),
form => any(),
tag => expr(),
body => expr(),
catches => [catch_expr()],
finally => expr()}.
tuple_expr()
-type tuple_expr() ::
#{op => tuple,
env => clj_env:env(),
form => any(),
tag => expr(),
items => [expr()]}.
type_expr()
-type type_expr() ::
#{op => type,
env => clj_env:env(),
form => any(),
tag => expr(),
type => 'clojerl.Symbol':type()}.
var_expr()
-type var_expr() ::
#{op => var,
env => clj_env:env(),
form => any(),
tag => expr(),
name => 'clojerl.Symbol':type(),
var => 'clojerl.Var':type(),
is_dynamic => boolean()}.
vector_expr()
-type vector_expr() ::
#{op => vector,
env => clj_env:env(),
form => any(),
tag => expr(),
items => [expr()]}.
with_meta_expr()
-type with_meta_expr() ::
#{op => with_meta,
env => clj_env:env(),
form => any(),
tag => expr(),
meta => expr(),
expr => expr()}.
Functions
add_locals_scope(Env)
-spec add_locals_scope(env()) -> env().
Push a new local variables scope.
A single local variable can be registered in the current scope by
using put_local/2
. It's possible to register multiple at the
same time through put_locals/2
.
remove_locals_scope/1
.
context(Env)
-spec context(env()) -> context().
Returns the current type of context.
default()
-spec default() -> env().
Returns a default new environment.
exprs(X1)
-spec exprs(env()) -> [any()].
Returns all the expressions on the stack, but in FIFO order.
get(Name, Env)
-spec get(atom(), env()) -> any().
Equivalent to get(Name, undefined, Env)
.
get(Name, Default, X3)
-spec get(atom(), any(), env()) -> any().
Get a value stored in the environment or Default
if not
found.
get_local(Sym, Env)
-spec get_local('clojerl.Symbol':type(), env()) -> expr().
Returns the information for the local variable with the name
Sym
or undefined
if not found.
get_locals(X1)
-spec get_locals(env()) -> [expr()].
Returns all available local variables in the current scope.
last_exprs(N, Env)
-spec last_exprs(integer(), env()) -> {Exprs :: [any()], Env :: env()}.
Returns the last N
expressions that where pushed to the
stack.
location(Env)
-spec location(env()) -> undefined | clj_reader:location().
Returns the current location in the file or string.
When the location is not available it returnsundefined
.
pop(Env)
-spec pop(env()) -> env().
Pop the custom scope.
pop_expr(Env)
-spec pop_expr(env()) -> {expr(), env()}.
Pop a Clojerl expression from the stack.
push(Mapping, Env)
-spec push(map(), env()) -> env().
Push a custom Mapping
into the custom scope clj_scope
.
push_expr(Expr, Env)
-spec push_expr(expr(), env()) -> env().
Push a Clojerl expression to the stack.
put(Name, Value, Env)
-spec put(any(), any(), env()) -> env().
Put a value in the custom scope clj_scope:put/3
.
put_local(Sym, Local, Env)
-spec put_local('clojerl.Symbol':type(), expr(), env()) -> env().
Adds the expression for the local variable named Sym
.
put_locals(Locals, Env)
-spec put_locals([expr()], env()) -> env().
Adds the expression for multiple local variables.
remove_locals_scope(Env)
-spec remove_locals_scope(env()) -> env().
Pop a local variables scope.
The scope can be popped usingremove_locals_scope/1
.
restore_locals_scope(Env)
-spec restore_locals_scope(env()) -> env().
Restore the saved local variables to the current scope.
Seesave_locals_scope/1
.
save_locals_scope(Env)
-spec save_locals_scope(env()) -> clj_scope:scope().
Saves the local variables in the current scope and empties the scope.
The saved local variables can be restored usingrestore_locals_scope/1
.
time(Env)
-spec time(env()) -> map().
Returns the timing information stored by the compiler.
Timing information is only stored and kept in the environment by the compiler when the user asks for a timed compilation.
time(Key, Delta, Env)
-spec time(any(), number(), env()) -> env().
Increase the time for Key
by Delta
.
update(Name, Value, Env)
-spec update(any(), any(), env()) -> env().
Update a value in the custom scope clj_scope:update/3
.