An library converts orthogonal AST into SpiderMonkey AST.
AST for Patrisika is provided as JavaScript arraies. The following forms represents a node:
Represents a variable.
Represents a literal value.
Represents undefined
value.
Represents this
reference.
Represents argument list passed into the current function.
Defines an anonymous function.
Represents an array.
Represents an object.
Represents a membering operation, i.e. base[member]
.
Represents a conditional evaluation.
Represents a while loop evaluation. It returns the value of body
in the last evaluation.
Represents a sequencial evaluation. Returns the last item evaluated.
Return a value. Similar to JavaScript return
statement.
Represents a exception handling expression. Returns the value of block
normally, or the value of handler1
when a exception is thrown during evaluating block
.
Throws value as an exception.
Assign right
to variable or property node left
.
Once fn
is a valid node, it means a common function invocation.
Initiates an instance of constructor callee
, with args
as arguments.
Represents a ES6 yield
expression. Any functions directly containing such node will become a generator function described in ES6 specification.
Represents a beta redex which is similar to [['.lambda', [...params], body], ...args]
, used to implement semantics of let
in scheme.
- Unary operator
['.typeof', x]
:typeof
['!', x]
:!
['+', x]
:+
['-', x]
:-
- Binary and Logical operator
['+', x, y]
:+
(both numeric and string)['-', x, y]
:-
['*', x, y]
:*
['/', x, y]
:/
['%', x, y]
:%
['<', x, y]
:<
['>', x, y]
:>
['<=', x, y]
:<=
['>=', x, y]
:>=
['===', x, y]
:===
['!==', x, y]
:!==
['=~', x, y]
:==
['!~', x, y]
:!=
['.is', x, y]
:instanceof
['&&', x, y]
:&&
['||', x, y]
:||
Using Patrisika is pretty simple and straight forward:
// Note : global scopes must be provided. Undeclared variables in Patrisika
// are treated as local variables, instead of global.
var globalScope = new Patrisika.DefaultExterns;
globalScope.declare("globalVariable");
patrisika.compile(ast, globals);