iota-compiler

raw JSON →
0.2.3 verified Fri May 01 auth: no javascript

Io-to-JavaScript source-to-source compiler, version 0.2.3. Originally written for CodeCombat's parser challenge, now used in CodeCombat via Aether. Compiles a minimal subset of Io (messages, objects, methods, prototype chain, infix operators) into JavaScript. Dependencies include Escodegen for code generation and Jison for parsing. The project is in early development; many core constructs and standard library features are missing. Differentiators: direct JavaScript interop, AST conforms to Mozilla Parser API, CLI and library usage.

error ReferenceError: _io is not defined
cause Missing runtime library when manually evaluating compiled JavaScript.
fix
Add const _io = require('iota-compiler').lib; before eval(iota.compile(code)).
error TypeError: iota.eval is not a function
cause Using older import style (e.g., `import * as iota from 'iota-compiler'`)
fix
Use default import: import iota from 'iota-compiler' or const iota = require('iota-compiler').
error SyntaxError: Unexpected token
cause Io code contains unsupported constructs like 'self' or first-class primitive methods.
fix
Review supported features; avoid using 'self' or unsupported operators.
gotcha Only a minimal subset of Io is implemented; many standard library methods and constructs are missing.
fix Check the 'Still to come' list in README; avoid using unsupported features.
gotcha The runtime library binding `_io` is required for manual eval; default export's `lib` property must be available.
fix Always include `var _io = iota.lib;` before calling `eval(iota.compile(code))`.
gotcha Options like `wrapWithFunction` and `useProxy` change the output format; default is standalone code that may pollute global scope.
fix Set `wrapWithFunction: true` to run within a function context, preventing global leaks.
npm install iota-compiler
yarn add iota-compiler
pnpm add iota-compiler

Shows basic usage of iota eval and compile with Io code to compute a greeting.

import iota from 'iota-compiler';

const ioCode = `
  greet := method(name,
    "Hello, " .. name
  )
  greet("World")
`;

// Evaluate with convenience method
const result = iota.eval(ioCode);
console.log(result); // Output: "Hello, World"

// Or compile and run manually
const compiled = iota.compile(ioCode);
eval(compiled);