Skip to content

MOGWAI v8.4.0

Choose a tag to compare

@Sydney680928 Sydney680928 released this 27 Mar 14:26
· 247 commits to main since this release
29b047c

Added

  • !A sigil — direct evaluation of a variable's content
    A new prefix sigil ! can now be applied to any variable to immediately evaluate its content, without pushing the object onto the stack first.

    This completes the variable sigil set:

    Notation Behavior
    A Reads A and pushes its value onto the stack
    &A Reference to A for in-place mutation
    @A Statically resolved read (compile-time)
    !A Evaluates the content of A directly

    !A is universal — its effect depends on the type of the object stored in A:

    Type Effect of !A
    Block { } Executes the code
    Function « » Executes the function
    String "..." Interpolates embedded {! } blocks
    List ( ) Evaluates embedded blocks in elements
    Record [ ] Evaluates embedded blocks in fields
    Number, boolean… Silent no-op

    Examples:

    # block
    100 -> 'A'
    { A 10 * } -> 'B'
    !B    # → 1000
    
    # string interpolation
    "We are in { ! now ->date year: get }" -> 'C'
    !C    # → "We are in 2026"
    

    Containers are lazy. Everything inside a container is deferred until ! is applied — the container stores expressions, not values. This means !A on a composite object always evaluates with the current state of the program:

    10 -> 'A'
    { A 200 * } -> 'B'
    [ x: { A 10 * }
      y: "We are in { ! now ->date year: get }"
      z: !B ] -> 'R'
    
    !R       # → [ x: 100   y: "We are in 2026"   z: 2000 ]
    20 -> 'A'
    !R       # → [ x: 200   y: "We are in 2026"   z: 4000 ]
    

    Internally, !A sets the AutoEval flag on the object referenced by A and dispatches it directly — the object never lands on the stack as an intermediate value, making it slightly more efficient than the equivalent A eval sequence.

    For non-executable types (numbers, booleans, etc.), !A behaves identically to A — it is a silent no-op, no error is raised.

    The semantics of ! are consistent with its existing use inside containers ({ ! ... }, « ! ... », ( ! ... ), [ ! ... ]): it always means "resolve everything evaluable in this object", regardless of where it appears.

    Circular reference detection The runtime now detects circular references during evaluation and raises an error instead of looping indefinitely.

    When !A is called, the variable A is registered as being evaluated. If the evaluation chain reaches !A again before it completes, a circular reference error is returned immediately via EvalResult. The variable is released as soon as the evaluation completes, whether the result is a success or an error.

    { !B } -> 'A'
    { !A } -> 'B'
    !A    # → error: circular reference detected (A → B → A)
    

    The error includes the full chain of variable names involved in the cycle.

  • Added --> in-place pipeline operator: applies a sequence of transformations directly to a referenced variable — e.g. (->upper butfirst butlast) --> &A.

    • New private primitive PIPEREF to support -->: pushes the actual value of the variable (not a copy) onto a private stack, evaluates each item in the list, then discards the private stack.
    • PIPEREF is transactional: a snapshot is taken before the pipeline starts and restored automatically if any item raises an error.
    • Quotations are valid items in the pipeline list, enabling complex inline logic mid-pipeline.
    • Empty pipeline list is a no-op with immediate early exit.

Changed

  • AOT compatibility — The MOGWAI engine is now fully compatible with .NET Native AOT publishing. Removed all dynamic JSON serialization in favor of source-generated contexts, replaced reflection-based assembly access with static attribute reading, and suppressed plugin system warnings by design. No behavioral changes.

  • Performance improvement — Optimized the core execution loop in MOGCode.Execute(). Avoid unnecessary async state machine allocations on each iteration, and consolidated control flow flags into a single check. ~13% speedup measured on intensive benchmarks.