MaddLang Gold Standard

This document specifies the gold profile, including source parsing, bytecode encoding, opcode tags, runtime flags, and file I/O behavior.

1. File Roles

2. Source Syntax

3. Type Names

Accepted lowercase source types are:

Semantic mapping:

4. Source Compilation Pipeline

  1. Normalize newlines to \n.
  2. Apply compile-time preprocessing directives.
  3. Parse blocks and top-level lines.
  4. Run type checking.
  5. Emit in-memory chunk bytecode.
  6. Optionally serialize to .mlb.

5. Compile-Time Directives

Directives are evaluated before normal parsing.

DirectiveMeaningNotes
$(name: value)Sets a compile-time variable.The stored value may itself reference other compile-time variables.
$(define: name = value)Defines an expanded alias.The right-hand side is recursively expanded before storage.
$(if expr)Begins compile-time conditional inclusion.Nested conditionals are supported.
$(else)Switches the active branch.Only valid inside an open $(if).
$(endif)Closes the conditional.Only valid inside an open $(if).

Condition operators supported by the compile-time evaluator:

6. Compiler Flags

The CLI seeds the compile-time environment before parsing.

FlagEffect
--std VALUESets compile-time STD to VALUE.
--define NAME=VALUESets a compile-time name/value binding.
--flag NAMESets NAME=true.
--flag NAME=VALUESets NAME to the explicit string value.

7. Bytecode File Format

All multibyte integers are little-endian. String lengths are encoded as u64 byte counts followed by raw UTF-8 bytes.

7.1 Program layout

magic[4] = "MLB1"
main_chunk
function_count: u64
repeat function_count times:
  name: string
  chunk
suite_count: u64
repeat suite_count times:
  name: string
  chunk

7.2 Chunk layout

constant_count: u64
repeat constant_count times:
  value
code_count: u64
repeat code_count times:
  opcode

7.3 Value encoding

TagNamePayload
0x00Nullnone
0x01Bool1 byte, 0x00 false or 0x01 true
0x02Number8-byte IEEE-754 f64 little-endian
0x03Stringu64 length + UTF-8 bytes
0x04Arrayu64 item count + recursively encoded values
0x05Refu64 length + UTF-8 reference name

7.4 Opcode encoding

The opcode tag is one byte, followed by the payload shown below.

TagOpcodePayloadMeaning
0x00LoadConstu64 const_indexPush constant at index.
0x01LoadVarstring variable nameLoad runtime variable value.
0x02DeclareVarstring name + string type_nameDeclare a typed runtime variable.
0x03StoreIndexstring name + u64 indexStore into array element.
0x04StoreVarstring nameStore into a variable.
0x05LoadArrayu64 count + encoded valuesPush array literal.
0x06Concatu64 countConcatenate stack values as strings.
0x07AddnoneAdd two numeric operands.
0x08SubnoneSubtract two numeric operands.
0x09MulnoneMultiply two numeric operands.
0x0ADivnoneDivide two numeric operands.
0x0BModnoneModulo two numeric operands.
0x0CNegnoneNegate the top numeric operand.
0x0DCallstring name + u64 argcInvoke builtin or chunk.
0x0EJumpu64 target_ipUnconditional branch.
0x0FJumpIfFalseu64 target_ipPop condition; branch if falsey.
0x10ReturnnoneReturn from current chunk.
0x11PopnoneDiscard top of stack.
0x12NoopnoneNo operation.

Exact byte tags are fixed and must remain stable for cross-platform .mlb compatibility.

8. Runtime Semantics

9. Expression Precedence

Expression parsing follows a C-like precedence hierarchy. Higher rows bind tighter.

LevelOperatorsAssociativityNotes
1parentheses ( ), indexing [ ]left-to-rightGrouping and indexed access are resolved first.
2unary -right-to-leftNegates a single numeric operand.
3*, /, %left-to-rightMultiplicative operators.
4+, -left-to-rightAdditive operators.
5comparisons and condition operatorsleft-to-rightHandled in conditional parsing, not general arithmetic.

10. File I/O Rules

11. Reference Model

12. Reference and Pointer Bridge

13. Function Parameters

14. Example

string name = "gold"
umax fh = open("./testfile.txt", "w")
write(fh, "hello\n")
close(fh)
print($name)

That program is valid in gold mode and invalid in silver mode if it attempts file I/O.

Silver is also the debugging-oriented interpreted profile, so gold authors should prefer fn over suite unless compatibility with older source matters.