Repository navigation
feat: numscript compiler, public compile/exec API and CLI - #200
Merged
Merged
Conversation
The numscript-to-IR compiler (internal/compiler) with its own bidirectional checker (internal/typecheck) and the shared builtin names (internal/builtins); the public API in numscript.go (Compile, VarsEncoder, NewVm, ExecVm, program/vars encode-decode, opt-in verification) and the CLI wiring. Cut from feat/vm's final tree state. Two cleanups called out in the series plan: internal/analysis' builtin name constants now alias internal/builtins instead of re-declaring the literals, and typecheck's package doc no longer claims analysis consumes it (analysis keeps its own unification-based checker).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 3 of the VM series, stacked on #199 (retargets to main when it merges). Cut from
feat/vm's final tree state by path checkout, like #199.What this adds
internal/compiler— lowers parsed numscript to the IR of feat: compiler and register VM #199: sources/destinations to funds-queue instruction sequences, allotments toAssertLeftover+ split, vars to typed registers with aVarsEncoderfor runtime bindings. Fixture-driven tests run the whole interpreter spec corpus through compiler+VM (scripts_test.go), with a blacklist for the one feature the compiler doesn't lower yet (asset scaling), plus a corpus-wide verifier pass.internal/typecheck— the compiler's checker: bidirectional base-type checking, fault-tolerant. Not a duplicate ofanalysis' checker, which is unification-based (asset-identity inference) and stays the LSP's.internal/builtins— the builtin name constants, now shared:analysis'Fn*constants alias these instead of re-declaring the literals (one of the two cleanups noted in the series plan; the other istypecheck's package doc, which wrongly claimedanalysisconsumes it).numscript.go):Compile/CompileWithFeatureFlags,CompiledProgramencode/decode,VarsEncoder/DecodeVars,NewVm/ExecVm, and opt-inVerifyCompiledProgram(WithVars)for bytecode from elsewhere.compiler-architecture.mddocuments the pipeline.internal/cmd.24 files, +6.9k/−20.
Semantics
The compiler+VM matches the tree-walking interpreter on the whole spec corpus, including the recent main-side decisions: a negative destination
maxclamps to zero (was a hard error in an earlier cut of this code; aligned after merging main intofeat/vm), and allotments past 100% next toremainingreject at run time (Op_AssertLeftover), which the interpreter now also does since #198.Verification
Root suite (incl. the full fixture corpus through compiler+VM),
internal/oracleandinternal/difftestmodules green; gofmt clean. Next in the series: the difftest VM leg, so generated programs run against oracle, interpreter and VM together.