EExpr
From Erights
(Difference between revisions)
m |
|||
Line 5: | Line 5: | ||
{{instance msgdoc|compile|1|env :Scope|CompiledE}} | {{instance msgdoc|compile|1|env :Scope|CompiledE}} | ||
- | Compile the expression to an internal form ( | + | Compile the expression to an internal form (currently transformed E, but could be Java bytecode). The result is a Thunk which can be invoked to evaluate the code in the given environment. |
+ | |||
+ | The CompiledE is also useful if you want to debug the optimiser: | ||
+ | |||
+ | ? def expr := e`def double (x) { return 2*x }` | ||
+ | # value: e`def double { | ||
+ | # | ||
+ | # method run(x) { | ||
+ | # escape __return { | ||
+ | # __return.run(2.multiply(x)) | ||
+ | # null | ||
+ | # } | ||
+ | # } | ||
+ | # }` | ||
+ | |||
+ | ? expr.compile(safeScope) | ||
+ | # value: compiled-e`def double { | ||
+ | # | ||
+ | # method run(x) { | ||
+ | # 2.multiply(x) | ||
+ | # } | ||
+ | # }` | ||
{{instance msgdoc|eval|1|env :Scope|any}} | {{instance msgdoc|eval|1|env :Scope|any}} | ||
Convenience method to compile and evaluate the expression in one go. | Convenience method to compile and evaluate the expression in one go. |
Latest revision as of 14:44, 9 June 2010
A parsed Kernel-E expression.
Protocol
compile/1
- Signature: compile(env :Scope) :CompiledE
Compile the expression to an internal form (currently transformed E, but could be Java bytecode). The result is a Thunk which can be invoked to evaluate the code in the given environment.
The CompiledE is also useful if you want to debug the optimiser:
? def expr := e`def double (x) { return 2*x }` # value: e`def double { # # method run(x) { # escape __return { # __return.run(2.multiply(x)) # null # } # } # }` ? expr.compile(safeScope) # value: compiled-e`def double { # # method run(x) { # 2.multiply(x) # } # }`
eval/1
- Signature: eval(env :Scope) :any
Convenience method to compile and evaluate the expression in one go.