The project is very much still in its infancy: only a minimal subset of Io is implemented. A number of core constructs and much of the standard library are not yet done.
Try it out here.
- messages, objects, methods
- prototype chain
- global and local contexts
- infix operators (supporting different precedence levels)
- assignment operator
- primitives: strings, numbers, boolean values,
- first-class primitive methods
- primitives: lists
- call introspection
- library methods
- prototype tree
- proper scope chain
- proper lazy argument evaluation
- defining operators of custom precedence
- defining assignment operators
The AST constructed by the parser complies with the Mozilla Parser API specification.
npm install [-g] iota-compiler
Installing globally gives you easy access to the command-line interface.
var iota = require'iota-compiler';var ioProgram = 'fact := method(n, if (n == 0, 1, n * fact (n - 1))); fact(5)';iotaevalioProgram;// => 120// Lower-level API:var _io = iotalib; // make runtime library availablevar result = evaliotacompileioProgram;_iounwrapIoValueresult;// => 120_iogetTypeOfresult;// => Number
A demo of Iota running in a web page may be found in
lib.js in your web page. Usage is the same as with node (complete with
require, courtesy of Browserify), except that the
_io binding isn't required.
You'll have to install Iota globally for this to work. Installing locally will place the executable at
wrapWithFunctionIf true, the compiled output will be wrapped in a function to facilitate interaction with the outside world. Defaults to
useProxyIf true, messages sent to
wrapWithFunction, so the wrapped function can be invoked with a dynamic
this. Defaults to
functionNameThe name given to the wrapper function if
wrapWithFunctionis true. You can also pass a string such as
obj.property, in which case the function will be bound to the corresponding property on the object in the current scope (this way you can
evalthe compiled code without the function being bound globally). Defaults to
selfThe name of object that the wrapper function is being invoked with. Defaults to
runtimeLibThe name of the runtime library binding that Iota will look for. Defaults to
Convenience method that evalutes a string of Io code, then unwraps and returns the result.
The simplest way is to use
iota.eval as shown above.
iota.compile gives a greater level of control, with provisions for wrapping the generated code in a function and executing it in the context of an arbitrary object. An example of the former:
var jsCode = iotacompileioCodewrapWithFunction: truefunctionName: 'ioFromJS';evaljsCode;ioFromJS;
eval will make a function named
ioFromJS available in the global scope (see the
functionName option if this is undesirable; more sophisticated sandboxing can also be used). It will implicitly return the value of the last Io statement.
An additional option,
useProxy, should be set:
var jsCode = iotacompileioCodewrapWithFunction: truefunctionName: 'jsFromIo'useProxy: true;evaljsCode;jsFromIocalla: 24601 return 'one day more';;
The function may then be invoked using
Lobby). Messages passed to them will be translated into property accesses or method invocations, and arguments will be relayed appropriately. The value of the last Io statement will be returned.