feat(cli): add minivm run <file> and REPL .load / .save#36
Merged
Conversation
Consolidate CLI code into a new `cli/` package tree so embedders can reuse the minivm command tree, and add a non-interactive entry point for executing assembly files plus REPL dot-commands for session persistence. - `cli.Root()` assembles the cobra tree; `cli.NewRunCommand(fs.FS)` loads a file via the standard io/fs.FS, parses it as a `Program.String()` dump, runs it, and prints the final stack. - `.load <file>` replaces REPL state with the parsed program; `.save <file>` writes the current program back. Save refuses host values since they have no textual form. - `cli/display` factors out stack/value formatting shared by `run` and the REPL. - `cli/fsx.WriteFS` extends `io/fs.FS` with `Create` for `.save`; read-only callers continue to use the standard interface. - `cmd/repl/` moves to `cli/repl/`; `cmd/minivm/main.go` shrinks to `cli.Root().Execute()`.
Drop the separate cli/fsx subpackage: WriteFS and OS() now live in cli/fs.go. cli/repl declares its own WriteFS interface on the consumer side (the only place that uses it) so the REPL package stays cycle-free when cli imports it. The REPL no longer carries a default filesystem; cli.Root injects cli.OS() at the entry point, and standalone repl.New disables .load/.save unless WithFS is supplied.
Drop the cli/repl subpackage: REPL, NewREPL, the helper formatters, and the load/save dot commands now live directly under cli. The dedicated repl.Option / repl.WithFS pair, which existed solely to avoid colliding with cli.Option / cli.WithFS across the package boundary, is replaced by NewREPL(in, out, fs WriteFS) — a single direct argument since fs was the only option. Pass nil to disable .load and .save when callers construct the REPL standalone; cli.Root keeps wiring cli.OS() in for the default minivm command.
Move the stack/value formatting helpers from cli/display into cli itself. With repl already collapsed in, display was the last nested subpackage; consolidating leaves cli flat. The helpers no longer need to be exported now that both callers live in the same package, so Stack/Value become unexported printStack/formatValue.
Owner
Author
PR Review — feat(cli): add
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
==========================================
+ Coverage 53.31% 53.55% +0.23%
==========================================
Files 53 57 +4
Lines 9710 9788 +78
==========================================
+ Hits 5177 5242 +65
- Misses 3919 3925 +6
- Partials 614 621 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Consolidate CLI code into a new
cli/package tree so embedders canreuse the minivm command tree, and add a non-interactive entry point
for executing assembly files plus REPL dot-commands for session
persistence.
cli.Root()assembles the cobra tree;cli.NewRunCommand(fs.FS)loads a file via the standard io/fs.FS, parses it as a
Program.String()dump, runs it, and prints the final stack..load <file>replaces REPL state with the parsed program;.save <file>writes the current program back. Save refuses hostvalues since they have no textual form.
cli/displayfactors out stack/value formatting shared byrunandthe REPL.
cli/fsx.WriteFSextendsio/fs.FSwithCreatefor.save;read-only callers continue to use the standard interface.
cmd/repl/moves tocli/repl/;cmd/minivm/main.goshrinks tocli.Root().Execute().