Astreum

Language Reference

Concise reference for grammar, operators, module loading, CLI flags, and naming rules.

Grammar

program     ::= expr
expr        ::= symbol | bytes | int | float | string | list
list        ::= "(" {expr} ")"
quote       ::= "'" expr

module      ::= "(" {definition} ")"
definition  ::= "(" expr expr ("def" | "import") ")"

symbol      ::= non-whitespace, non-paren token
bytes       ::= "0x" hex-digits
int         ::= decimal integer literal
float       ::= decimal floating-point literal
string      ::= double-quoted text
comment     ::= ";" to end of line | "#;" expr

Evaluation is postfix: the last symbol in a list drives dispatch.

Operators

Operator names in the machine evaluator.

Arithmetic

NameStack effectDescription
+b a -> sumInt/Int -> Int, Float/Float -> Float, mixed Int/Float -> Float
-b a -> diffSame type rules as +
*b a -> productSame type rules as +
/b a -> quotientInt/Int uses integer division, Float/Float uses float division
%b a -> remainderInt only
sqrta -> sqrtFloat only

Bitwise

NameStack effectDescription
&b a -> a & bBitwise AND on Bytes
|b a -> a | bBitwise OR on Bytes
^b a -> a ^ bBitwise XOR on Bytes
~a -> ~aBitwise NOT on Bytes

Shifts and rotates

NameStack effectDescription
<<value shifts -> resultLogical left shift on Bytes
>>>value shifts -> resultLogical right shift on Bytes
>>value shifts -> resultArithmetic right shift on Bytes
rolvalue shifts -> resultRotate left on Bytes
rorvalue shifts -> resultRotate right on Bytes

Stack operations

NameStack effectDescription
dropa ->Discard top of stack
dupa -> a aDuplicate top of stack
swapb a -> a bSwap top two items
dipv (expr) -> ... vRemove v, evaluate expr, push v back

Expression construction

NameStack effectDescription
linkhead tail -> Link(head, tail)Build a Link pair
headlink -> headExtract head (NIL if missing)
taillink -> tailExtract tail (NIL if missing)
is_atomexpr -> 1|01 if the value is not a Link, else 0
is_eqb a -> 1|0Deep structural equality
evalexpr -> evaluatedRe-enter evaluator on the value
quotea -> (' a)Wrap a value in a quotation
symbola -> symbol|NILConvert Bytes, String, Int, or Float to Symbol
stra -> string|NILConvert any atom to String
floata -> float|NILConvert Int, Bytes, String, or Symbol to Float
inta -> int|NILConvert Bytes, String, Symbol, or Float to Int
bytesa -> bytes|NILConvert Int, Float, String, or Symbol to Bytes
refhash -> expr|NILResolve a 32-byte hash via content lookup
loadhash -> full_expr|NILDeep-resolve a hash recursively

Control flow and definition

NameStack effectDescription
fnargN ... arg1 params body -> resultBind arguments in a child environment with lexical parentage
lambdaargN ... arg1 params body -> resultSame as fn but with no parent environment
ifcond then else -> resultEvaluate the condition quotation, then select a branch by truthiness
defname value ->Bind value under name in env.def_target, write-once per target

Actors

NameStack effectDescription
spawnbody name -> name|NILSpawn actor thread running body in a child environment
sendtarget msg ->Send msg to target's mailbox
receivetarget -> msg|NILBlock until a message arrives

Special form

quote is handled inline in the evaluator loop, not dispatched as an operator. The ' symbol at the head of a list behaves the same way.

Module system

  • Module files use .aex by convention. Each file is a parenthesized sequence of definitions.
  • Each definition must be a 3-element form: (value name def) or (prefix path import).
  • def stores the raw expression under the name with no runtime evaluation at load time.
  • import accepts a filesystem path that may be absolute or relative to the importing file's directory.
  • Reference imports use (prefix (0x... ref) import) to load from atom storage by content hash.
  • Imported symbols are qualified under the given prefix, and intra-module references are rewritten to fully qualified names.
  • Circular imports are rejected via an active-stack guard.

CLI flags

FlagDescription
--tuiLaunch the interactive TUI
--headlessRun startup actions without TUI
--evalEnter evaluation mode
--script <path>Load a module file; entry defaults to main
--expr "<expr>"Evaluate a postfix expression
--apiEnable the HTTP API server
--api-port <n>HTTP API port
--api-host <addr>HTTP API bind address
--node-default-seed <s>Override the node default seed

Use --eval with at least one of --script or --expr.

Reserved words and naming rules

  • All operator names are reserved.
  • quote is also reserved as a special form.
  • Module keywords def, import, and ref are reserved.
  • Names are UTF-8 symbols, optionally dot-qualified, such as math.sum.
  • Unbound symbols silently push NIL.
  • Integers in source become Expr.Int literals, not Expr.Bytes.
  • Line comments start with ; and run to end of line. Block comments use #;.