Skip to content

Initial interpreter structure - #49

Open
Haibib wants to merge 3 commits into
mainfrom
fix-interpreter
Open

Initial interpreter structure#49
Haibib wants to merge 3 commits into
mainfrom
fix-interpreter

Conversation

@Haibib

@Haibib Haibib commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Description

  • Refactor to use Interpreter with the new grammar.

Future Work

  • Add tests for language interpretation.
  • Separate pre-processor.
  • Lift Interpreter to run in user space.
  • Implement more language features.

Comment thread fix/src/main.rs
Comment on lines 21 to +28
Some("eval") => {
let filename = argv.get(2).expect("fix eval: expected a command file");
eval_file(filename);
}
Some(other) => panic!("fix: unknown command '{other}' (expected: init | eval <file>)"),
None => panic!("fix: expected a command (init | eval <file>)"),
Some("interpret") => {
let filename = argv.get(2).expect("fix interpret: expected a program file");
interpret_file(filename);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between eval and interpret? I don't think we should keep both syntaxes around if that's what the distinction here is—maintaining one text format is enough work. If this is just for development until the new syntax is complete that's fine, just make it clear in the code that the old syntax must be deleted once the new one is finished (and maybe call them eval and eval-v2 or something so they're clearly a lineage, not a branching choice).

Comment thread fix/src/interpreter/interpreter.rs Outdated
Comment on lines +27 to +30
Statement::Assign { name, expr } => {
let handle = self.interpret(&expr);
self.context.insert(name, handle);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our new version isn't going to have statements at all, right? In Scheme (approximately) everything is an expression.

R ::= &B | &T Ref
O ::= B | T | R Data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this grammar were actually used directly by the code, rather than being a documentation file that will inevitably get out of date. Some Rust parsing crates support this, I'm not sure of any of them work in no_std but it's possible. I know chumsky supports no_std but it uses parser combinators instead of an external BNF grammar.

Also I'm not sure handles should be a thing at this level? This seems more like you're using it to mean "any value", which is semantically different than a "handle"; Handles are a concrete 32-byte in-memory "pointer" in the implementation, while values are abstract objects in Fix. (although the meaning of "value" vs. "object" vs. "expression" vs. whatever else has changed a lot over time...)

@SaibililaA
SaibililaA force-pushed the fix-interpreter branch 2 times, most recently from f21c878 to a98500a Compare August 6, 2026 01:36

@Akshay-Srivatsan Akshay-Srivatsan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but I think our addblob example should stay simple/straightforward and the other features should be delegated to a specific demo (or a folder of example programs).

Comment thread addblob.fix Outdated
Comment on lines +1 to +2
(let ((add @"./target/x86_64-unknown-none/addblob"))
!*(add *(add ^&2 3) 1)) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is a good way of showing off the different features... maybe our primary example shouldn't be doing this in such a complicated way. Could you split this into an addblob.fix which just does *(add *(add 2 3) 1) and a separate (commented, if we have a way of doing that?) demo.fix that demonstrates the different features?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added some tests and a small demo.fix. Do you think it is ready to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants