Skip to content

Nan Adapter

Leon Matthes edited this page Dec 19, 2018 · 5 revisions

Creating and Running a Program

The Interpreter can be required in the following way:

var Interpreter = require('InterpreterNan');

To create a new Program object and run it, use:

var jsProgram = {/*This object contains the program definition*/};

var program = new Interpreter.Program(jsProgram);
program.run(1, 2, false); //The parameters to this function will be passed to the main function of the program

Program objects

An object that may be parameter for an Interpreter.Program construction must have the following attributes:

  • functions: must contain a Map from Number to function objects
  • start: must be a Number that is a valid key of the functions attribute

Function objects

An object inside a program objects function attribute must be an object with the following attributes:

  • inputs: An array of input datatype names
  • outputs: An array of output datatype names
  • variables: An array of variable declarations
  • blocks: A Map from Number to block objects
  • start: A Number that is a valid key of the blocks attribute
  • connections: An array of connections

Variable declarations

A variable declaration is an object with the following attributes:

  • ID: The variable identifier (must be of type string)
  • type: Refers to the datatype name of the variables type

block objects

A block object is an object that must contain at least one attribute:

  • type: The type of block as a string Depending on the type, additional attributes may have to be specified (see Block types)

Connections

A connection is an Object with the following attributes:

  • startBlock: Must be a valid key to the blocks attribute of a function
  • endBlock: Must be a valid key to the blocks attribute of a function
  • startPort: The index of the port in the startBlock
  • endPort: The index of the port in the endBlock

All connections must be between ports of the same type, or otherwise the typecheck will fail!

Error checking

The constructor of a Interpreter.Program might throw errors, in which case these error objects may contain a functionID and a blockID attribute, indicating where the error occured. If the function or block in question are not known, these values will have the javascript undefined value