๐ Interpreter Architecture
The W++ interpreter is a recursive AST-walker with dynamic scoping and async evaluation support.
๐ File: Interpreter.cs
Evaluate(Node)
โ Core dispatch function for interpreting AST nodesEvaluateBinary()
โ Handles binary math, logic, and comparisonsInjectBuiltins()
โ Registers built-in functions likehttp.get
andjson.parse
GetAllMethods()
โ Recursively resolves entity method inheritanceConvertJsonElement()
โ Converts rawJsonElement
into usable W++ types
Runtime Features:
- ๐ง Dynamic scope: every
Interpreter
instance can be nested - ๐พ Built-in runtime linker via
IRuntimeLinker
- โ๏ธ Entity + method resolution with support for
alters
anddisown
- ๐ Function and async function delegates (
FunctionObject
,AsyncFunctionObject
) - ๐ฅ Exception-based flow for
return
,break
,continue
๐งฌ JIT Compiler Overview
The W++ JIT compiler emits .NET IL from AST nodes using System.Reflection.Emit
. It's fully async-compatible and produces runtime DynamicMethod
s that return Task<object>
.
๐ File: JitCompiler.cs
Compile(Node)
โ Kicks off IL generation for a full ASTEmitNode(Node, ILGenerator...)
โ Central recursive emitter for every supported nodeFunctionObject
โ Wrapper for compiled lambdas with asyncInvoke()
AwaitTask()
โ Safely awaitsTask<object>
results
Supported Nodes:
BlockNode
,PrintNode
,AssignmentNode
,IdentifierNode
BinaryExpressionNode
,UnaryExpressionNode
WhileNode
,ForNode
,IfElseNode
,SwitchNode
ReturnNode
,ThrowNode
,TryCatchNode
LambdaNode
,CallNode
,BooleanNode
,StringNode
,NumberNode
Special Behaviors:
- ๐ง Variables declared with
DeclareLocal
and stored in a scoped map - ๐ฏ Jump labels for control flow (
break
,continue
,return
) - ๐ฅ Full async pipeline with
AwaitTask
instead of blocking .Result - ๐งช Each function/lambda gets a
DynamicMethod
and is stored in a shared_constants
pool