Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/boblio-max/origin/llms.txt

Use this file to discover all available pages before exploring further.

Every syntactic construct in the Origin language is represented as a Python object that inherits from ASTNode. These objects are produced by parser.Parser and consumed by interpreter.Interpreter. The node classes themselves are intentionally thin — they carry only the data fields the interpreter needs, with no evaluation logic of their own. All node classes are defined in classes.py and re-exported via from classes import * in both the parser and interpreter.
Every node class inherits from ASTNode and therefore carries a line attribute. The parser sets this attribute to the 1-based source line number of the first token that triggered the node. The interpreter uses it to inject globals()['_origin_runtime_line'] = N markers into the emitted Python source, enabling accurate runtime error reporting.

Base Class

class ASTNode:
    def __init__(self, line=None):
        self.line = line   # int | None — set by Parser._set_line()
All other node classes call super().__init__() without arguments, leaving line as None until the parser assigns it.

Program and Block Nodes

These two nodes form the structural skeleton of every parsed Origin program.

ProgramNode(statements)

The root of every AST. Returned by Parser.program().
FieldTypeDescription
statementslist[ASTNode]Top-level statements in document order

BlockNode(statements)

A { … } block body. Returned by Parser.block() and stored in the body fields of control-flow and definition nodes.
FieldTypeDescription
statementslist[ASTNode]Statements inside the braces

Literal Nodes

NumberNode(value, type)

An integer or float literal.
FieldTypeValues
valueint | floatThe parsed numeric value
typestr"int" or "float"

StringNode(value, type)

A string literal with its quotes stripped.
FieldTypeValues
valuestrContent without surrounding quotes
typestrAlways "str"

BoolNode(value)

A boolean literal (true or false in Origin source).
FieldTypeValues
valueboolTrue or False
typestrAlways "bool" (set in __init__)

NoneNode()

The none literal. Carries type = "none" and no other fields.

PassNode()

The pass statement. No fields; generates "pass" in Python.

Variable and Assignment Nodes

VarNode(name, type=None)

A reference to a named variable.
FieldTypeDescription
namestrVariable identifier
typestr | NoneStatically known type, if any

AssignNode(name, value, type=None)

A let declaration or a bare name = value assignment.
FieldTypeDescription
namestrTarget variable name
valueASTNodeRight-hand side expression
typestr | NoneDeclared type annotation (e.g. "int")

ConstAssignNode(name, value)

A const declaration. The interpreter records the name in CONST_VARS and rejects any later AssignNode targeting the same name.
FieldTypeDescription
namestrConstant name
valueASTNodeInitializer expression

CompoundAssignNode(name, op, value)

A compound assignment (+=, -=, *=, /=, %=, **=, //=, &=, |=).
FieldTypeDescription
namestrTarget variable name
opstrThe compound operator string, e.g. "+="
valueASTNodeRight-hand side expression

Expression Nodes

BinOpNode(left, op, right)

A binary operation. The + operator receives special treatment in the interpreter (smart string concatenation).
FieldTypeDescription
leftASTNodeLeft operand
opstrOperator: +, -, *, /, //, %, **, ==, !=, <, >, <=, >=, …
rightASTNodeRight operand

UnaryOpNode(op, node)

A unary operation.
FieldTypeDescription
opstrOperator: -, not, !, ++, --
nodeASTNodeThe operand

LogicOpNode(left, op, right)

A logical operation. The interpreter maps &&and and ||or.
FieldTypeDescription
leftASTNodeLeft operand
opstr"and", "or", "&&", "||"
rightASTNodeRight operand

SpecialOpNode(left, op, right)

A special-operator expression (??, ->, =>, <=>, ::).
FieldTypeDescription
leftASTNodeLeft operand
opstrThe special operator string
rightASTNodeRight operand

Control Flow Nodes

IfNode(condition, then_body, elif_nodes, else_body)

An if / elif / else construct.
FieldTypeDescription
conditionASTNodeBoolean-valued expression
then_bodyBlockNodeThe if branch body
elif_nodeslist[ElifNode]Zero or more elif branches
else_bodyBlockNode | NoneThe else branch body, or None

ElifNode(condition, then_body)

A single elif branch, stored inside IfNode.elif_nodes.
FieldTypeDescription
conditionASTNodeBoolean-valued expression
then_bodyBlockNodeThe elif branch body

WhileNode(condition, body)

A while loop.
FieldTypeDescription
conditionASTNodeLoop continuation condition
bodyBlockNodeLoop body

ForNode(var_name, iterable, body)

A for var in iterable { } loop.
FieldTypeDescription
var_namestrLoop variable name
iterableASTNodeThe sequence to iterate
bodyBlockNodeLoop body

TryNode(try_body, except_body, else_body)

A try / except / else construct. Each except block is parsed into its own BlockNode and appended to except_body; the interpreter emits a bare except Exception: for each one.
FieldTypeDescription
try_bodyBlockNodeThe guarded block
except_bodylist[BlockNode]One entry per except clause
else_bodyBlockNode | NoneThe else clause, or None

Function and Class Nodes

FuncNode(name, params, body)

A def function definition.
FieldTypeDescription
namestrFunction name
paramslist[str]Parameter names in declaration order
bodyBlockNodeFunction body

ClassNode(name, fields, body)

A class definition. Fields become __init__ parameters (all defaulting to None).
FieldTypeDescription
namestrClass name
fieldslist[str]Instance field names
bodyBlockNodeAdditional methods and statements

CallNode(callee, args)

A function or method call.
FieldTypeDescription
calleeASTNodeThe callable (VarNode, AttributeNode, etc.)
argslist[ASTNode]Positional arguments

ReturnNode(value)

A return statement.
FieldTypeDescription
valueASTNodeThe returned expression

YieldNode(value)

A yield expression (generator support).
FieldTypeDescription
valueASTNodeThe yielded expression

BreakNode

A bare break statement. No fields.

ContinueNode

A bare continue statement. No fields.

Data Structure Nodes

ListNode(elements)

A list literal [e1, e2, ...].
FieldTypeDescription
elementslist[ASTNode]Element expressions

TupleNode(elements)

A tuple literal (e1, e2, ...). Produced by a parenthesized comma-separated list.
FieldTypeDescription
elementslist[ASTNode]Element expressions

DictNode(elements)

A dictionary literal {k1: v1, k2: v2, ...}.
FieldTypeDescription
elementsdict[ASTNode, ASTNode]Key-value pairs (both sides are AST nodes)

IndexNode(collection, index)

A subscript read collection[index].
FieldTypeDescription
collectionASTNodeThe subscriptable object
indexASTNodeThe subscript expression

IndexAssignNode(collection, index, value)

A subscript write collection[index] = value.
FieldTypeDescription
collectionASTNodeThe subscriptable object
indexASTNodeThe subscript expression
valueASTNodeThe value to store

ListCallNode(list_node, pos)

A call[list, pos] expression — syntactic sugar for list element access.
FieldTypeDescription
list_nodeASTNodeThe list expression
posASTNodeThe position expression

Object Access Nodes

AttributeNode(obj, attr)

An attribute read obj.attr.
FieldTypeDescription
objASTNodeThe object expression
attrstrAttribute name

AttributeAssignNode(obj, attr, value)

An attribute write obj.attr = value.
FieldTypeDescription
objASTNodeThe object expression
attrstrAttribute name
valueASTNodeThe value to assign

I/O Nodes

PrintNode(expr)

A print statement.
FieldTypeDescription
exprASTNodeThe expression to print

InputNode(prompt=None)

A user input call.
FieldTypeDescription
promptStringNode | NoneOptional prompt string

OpenNode(name, path, type)

A file-open operation.
FieldTypeDescription
namestrVariable name to bind the file handle
pathASTNodePath expression
typestrOpen mode (e.g. "r", "w")

Math Built-In Nodes

SqrtNode(value)

sqrt(value) — maps to math.sqrt(...).
FieldTypeDescription
valueASTNodeThe radicand

RandNumNode(start, end)

rand_num(start, end) — maps to random.randint(start, end).
FieldTypeDescription
startASTNodeLower bound (inclusive)
endASTNodeUpper bound (inclusive)

LenNode(value)

len(value) — maps to Python’s built-in len.
FieldTypeDescription
valueASTNodeThe collection

RangeNode(start, end)

range(start, end) — maps to Python’s built-in range.
FieldTypeDescription
startASTNodeStart of the range (inclusive)
endASTNodeEnd of the range (exclusive)

CastNode(cast_type, value)

An explicit type cast — int(v), str(v), float(v), bool(v).
FieldTypeDescription
cast_typestrTarget type name: "int", "str", "float", "bool"
valueASTNodeThe expression to cast
typestrSame as cast_type (for get_type inference)

Hardware Nodes

SetNode(name, num, type_, params)

A hardware state assignment (set pin, set servo).
FieldTypeDescription
namestrDevice type: "pin", "servo", etc.
numASTNodeChannel or pin number expression
type_str | NoneSub-type, e.g. "angle" for a servo
paramsASTNodeValue to set

HardwarePrimitiveNode(namespace, method, args)

A protocol primitive call: i2c.read(...), spi.write(...), uart.send(...).
FieldTypeDescription
namespacestrProtocol name: "i2c", "spi", or "uart"
methodstrMethod name, e.g. "read" or "write"
argslist[ASTNode]Call arguments
The interpreter emits _execute_{namespace}_{method}(args), which the runtime resolves to one of the hardware helper functions injected into runtime_globals.

Module Nodes

ImportNode(name)

An import name statement.
FieldTypeDescription
namestrModule name
If name is in Interpreter.original_imports (currently {"calc": "/lib/calc.or"}), the .or library is inlined at codegen time rather than emitting a Python import.

ImportFromNode(name, library)

A from library import name statement.
FieldTypeDescription
namestrThe symbol to import
libstrThe source library

ImportAsNode(name, alias)

An import name as alias statement.
FieldTypeDescription
namestrModule name
aliasstrLocal alias

Execution Nodes

PyNode(code)

A py { ... } raw Python block. The code field holds the verbatim Python source text extracted from between the braces. The interpreter emits it without any transformation.
FieldTypeDescription
codestrRaw Python source

ExecNode(code)

An exec "string" statement. At codegen time the interpreter writes the string to a temporary file and runs it via runner.py in a subprocess.
FieldTypeDescription
codestrOrigin source code to execute

ParallelNode(body, threads)

A parallel { ... } or parallel(N) { ... } block.
FieldTypeDescription
bodyBlockNodeThe statements to parallelize
threadsintFixed thread count (0 = one thread per statement)

Experimental Bytecode Path

The bComp.py module contains a Compiler class and an OpCode enum that target a custom stack-based virtual machine (VM). The Compiler.compile(node) method accepts the same AST node classes described above and emits integer opcodes into self.bytecode, with literal values stored in self.constants. This path supports most of the same node types as the interpreter, including FuncNode (with jump patching), ForNode (with GET_ITER / FOR_ITER), WhileNode, BreakNode, and ContinueNode.
The bytecode compiler and VM are experimental and are not invoked by the default runner.py. They exist as a foundation for a future native execution mode and are not feature-complete relative to the interpreter backend.

Build docs developers (and LLMs) love