| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
ReoScript is an ECMAScript-like script language interpreter for .NET applications, allowing host applications to embed scripting and to expose .NET classes/objects/events directly to scripts. It is a tree-walking interpreter built on an ANTLR 3 grammar — there is no bytecode/JIT stage.
The library targets .NET 10 and is cross-platform (no System.Windows.Forms dependency in the core). Build with dotnet build.
Source/ReoScript.sln contains three migrated projects:
| Project | Target | Purpose |
|---|---|---|
| Source/ReoScript/ | net10.0 (library) | The interpreter library (unvell.ReoScript.dll). Root namespace unvell.ReoScript. |
| Source/ReoScriptRunner/ | net10.0 (exe) | Command-line runner that executes .reo files. |
| Source/TestCase/ | net10.0 (xUnit) | Test suite — xUnit adapter over XML-defined language tests + C# CLR-interop tests. |
Not yet migrated (still targeting .NET Framework 3.5, excluded from solution):
| Project | Purpose |
|---|---|
| Source/ReoScriptEditor/ | WinForms script editor (FastColoredTextBox-based). Needs net10.0-windows. |
| Source/ReoScriptExtensions/ | Optional extensions (File I/O, Graphics). Needs System.Drawing / net10.0-windows. |
Sample integrations live under Samples/ with their own ReoScriptSamples.sln.
# Build everything:
dotnet build Source/ReoScript.sln
# Release build:
dotnet build Source/ReoScript.sln -c ReleaseThe project has zero external dependencies beyond the .NET SDK (xUnit is restored via NuGet for tests only).
Tests use xUnit with a thin adapter (Source/TestCase/XmlTestAdapter.cs) that loads the existing XML test suites as [Theory] test data.
# Run all tests:
dotnet test Source/ReoScript.sln
# Run with verbose output:
dotnet test Source/TestCase/TestCase.csproj -v normal
# Filter by test name (xUnit filter):
dotnet test Source/TestCase/TestCase.csproj --filter "DisplayName~closure"Three test suites run:
Note: 070-001 setInterval is a known flaky test (timing-dependent busy-wait).
ScriptContext represents an execution scope; SRM exposes Run, CalcExpression, and CreateContext for host integration.
Closures use lexical scoping. Each FunctionObject has a CapturedScope field set once at creation time (not at call time). This means escaped closures, independent closure instances, and mutable shared state all work correctly, matching JavaScript's closure behavior.
Source/ReoScript/Core/ organizes individual node/statement classes:
Source/ReoScript/AnonymousFunctionDefineNode.cs lives at the project root for historical reasons. When adding new node types, prefer the Core/ layout over adding to the root.
A JIT compiler prototype exists under Source/ReoScript/Compiler/. It uses System.Reflection.Emit to generate IL from the SyntaxNode AST, with automatic fallback to tree-walking for unsupported node types. The AST is designed with JIT in mind — SyntaxNode is a public typed base class supporting the Visitor pattern for future compilation backends.
Condition expressions (if, while, for, ? :, &&, ||, !) use truthy/falsy conversion:
&& and || return the actual value (short-circuit), enabling patterns like var x = obj || "default".
ScriptRunningMachine.MaxIterationsPerLoop (default: 10,000,000) limits iterations per for/while loop. Exceeding the limit throws ScriptExecutionTimeoutException. Set to 0 to disable. This prevents user scripts from freezing the host application.
ErrorObject includes FilePath, Line, and CharIndex. GetFullErrorInfo() produces formatted output like demo.reo:3:5 - error message with a full call stack. Scripts can access error.file, error.line, error.message, and error.stack.
Script exceptions in CLR event handlers and async callbacks (setTimeout/setInterval) are caught and routed to the ScriptRunningMachine.ScriptError event instead of crashing the host. Subscribe to ScriptError to log or display errors.
importModule("path/to/file.reo") loads a script file in an isolated scope and returns a module object. Module-level functions and variables become properties of the returned object. Results are cached (each file executes at most once). Closures inside the module correctly resolve module-level variables.
var anim = importModule("animation/animate.xb");
anim.fadeIn(element);The traditional import "file.reo" (which executes in global scope) remains available for backward compatibility. From C# host code, use srm.ImportModuleFile(fullPath).
.reo is the canonical script extension (changed from .rs in v1.3.1, see Source/ChangeLog.txt).
| Back | FazBrowse Home | New Git URL |