paxdotdev / pax

User interface engine with an integrated vector design tool, built in Rust
https://www.pax.dev/
Apache License 2.0
466 stars 23 forks source link

Expression Interpreting #220

Closed warfaj closed 3 months ago

warfaj commented 3 months ago

In this PR we transition from compiling expressions to using an expression interpreter that lives in pax_lang::interpreter.

Changes included in this PR:

  1. Rewriting the deserializer to go from string -> PaxValue. It now only does a single parse and uses references all the way through. I've also moved it from pax-manifest -> pax-lang.
  2. Create an expression interpreter (pax-lang::interpreter). The main entry points here are parse_pax_expression which goes from a &str -> PaxExpression (AST) and compute_paxel which goes from a &str -> PaxValue. The interpreter has been brought to parity with the current system and contains unit tests for functionality.
  3. Rewrite the code-gen to use the interpreter rather than the v-table and then removed the vtable entirely.
  4. Updated the manifest to remove expression ids and compiling of expressions step.
  5. In order to support our current usage of functions, I have created 2 new macros that can be used in tandem to register helpers. These two macros are #[has_helpers] and #[helpers]. A struct can define helper functions by marking itself #[has_helpers] and creating an impl block with static functions marked #[helpers]. The need of the #[has_helpers] macro is to solve to macro coordination problem.

The examples are all running and pax-designer has been brought up to date.

A possible next step in this work could be to bring PaxValue & PaxExpression into the manifest as the underlying representation of ValueDefinitions rather than string. This would remove the need to parse completely from the runtime.