mattwparas / steel

An embedded scheme interpreter in Rust
Apache License 2.0
1.07k stars 50 forks source link

Successful redefinition of functions is inconsistent. #104

Closed kidrigger closed 8 months ago

kidrigger commented 9 months ago

Affected target

steel-interpreter REPL

Problem

Redefinition of any Steel function, or standard functions such as Ok->value replaces the function definition. Redefining + or * does nothing.

Expected Behavior

Either:

  1. Error thrown when disallowed redefinition
  2. Allow redefinition
mattwparas commented 9 months ago

good catch! Looks like its a bug with my constant evaluation pass missing redefinitions:

See this interaction in the REPL with the generated bytecode printing after the expression:

λ > (define + -)
0    SDEF : 0
1    PUSH : 186
2    EDEF : 0
3    BIND : 984 ;; + should be bound to - now, but at index 984
4    VOID : 0
5    POPPURE : 0
λ > (+ 10 20) ;; Constant evaluation isn't seeing the + redefinition
0    PUSHCONST : 378
1    POPPURE : 0
=> 30
λ > (+ (begin (#%black-box) 10) 20) ;; Forcing the constant evaluation to ignore this by adding #%black-box, it sees it
0    CALLGLOBAL : 0
1    Arity : 268
2    POPSINGLE : 0
3    PUSHCONST : 376
4    PUSHCONST : 377
5    CALLGLOBAL : 2
6    Arity : 984
7    POPPURE : 0
=> -10
mattwparas commented 9 months ago

At the repl, the expected behavior here should be that this is completely legal and works as expected. So I'll do some investigating

mattwparas commented 8 months ago

This looks to be resolved, thanks again for the report!