Wasm-DSL / spectec

Wasm SpecTec specification tools
https://wasm-dsl.github.io/spectec/
Other
27 stars 9 forks source link

Refactor numerics with higher-order functions #118

Closed rossberg closed 2 months ago

rossberg commented 3 months ago

There is a lot of code duplication in the numerics implementation. This PR simplifies that by factoring out much of the logic into higher-order functions. This is just a start, we can probably simplify further.

However, this is the first use of def's as parameters, which the interpreter does not support yet.

@ShinWonho, @f52985, this PR isn't high priority. Just putting it out there so that you can have a look in case you have spare cycles. :)

f52985 commented 2 months ago

Now the interpreter backends support the def parameter!

To keep it simple, instead of maintaining a new environment, it uses the original env that interpreter was using, where key is the concatenation of the prefix $ and the parameter name (i.e. "$f_"), and the value is the name of the original target function definition. (i.e. FnameV("fadd_"))

This is based on the assumption that the normal variables in SpecTec never starts with "$".

rossberg commented 2 months ago

Cool, thanks @f52985!