| Crates.io | walc_model |
| lib.rs | walc_model |
| version | 0.5.2 |
| created_at | 2024-03-24 13:18:09.428171+00 |
| updated_at | 2025-02-10 21:33:09.07419+00 |
| description | Interpreter for Walc programming language. |
| homepage | |
| repository | https://github.com/Willmo3/walc-model |
| max_upload_size | |
| id | 1184373 |
| size | 38,510 |
Walc-model is the core of the walc programming language.
Walc is designed as a modular language which supports frontends in multiple languages. A TypeScript web platform (https://github.com/Willmo3/webwalc.ts) and a Rust CLI frontend (https://github.com/Willmo3/walc-frontend) have been constructed.
To enable its modular design, Walc has been published as a crate, so that different frontends can pull it in as a dependency. https://crates.io/crates/walc_model
treewalk_interpreter::interpretThis function executes a program AST without converting to bytecode.
&ASTNode
bytecode_interpreter::interpretThis function executes a collection of Walc bytecode. Note that a standard AST must first be translated to bytecode.
&Vec<U8>
bytecode_generator::generateGiven an AST, returns a stream of Walc bytecode. This function is intended to serve as a reference for other implementations. In many cases, it will be ideal to write translation functions on the frontend -- for instance, in a WebAssembly environment, where data transports can dominate computation time, translating to bytecode before using walc-model may be ideal.
&ASTNode
bytecode_generate performs no checking on the validity of the AST.Note that other public fields exist, which may be viewed on the crates.io package explorer. This documentation merely serves to explain the key interface of walc-model.
start = add add = mult ((PLUS | MINUS) mult)* mult = exp ((STAR | SLASH) exp)* exp = [atom (DOUBLESTAR)] exp atom = LEFT_PARENS start RIGHT_PARENS | NUMBER_LITERAL
The Walc interpreter supports both AST and Bytecode formats for execution.
To bolster compatibility, Walc-model ASTs are serializable and deserializable. We have tested serialization under a json scheme.
left and right fields containing their subtrees.value field containing a decimal representation of the number they contain.3.1 - 2: {"Subtract":{"left":{"Number":{"value": 3.1}},"right":{"Number":{"value": 2}}}}
Early in Walc's development, Walc contained only the execution backend of the interpreter. This is based on the strategy planned for the Twoville language's Rust interpreter, which would maintain a JavaScript lexer and parser to ease direct manipulation of the AST. However, as it became clear that Walc might use static analysis passes in the "middle end," this clean decoupling began to vanish.
A key aspect of separating Walc's frontend from its backend was to allow bytecode to be transferred through WebAssembly's memory, rather than a larger tree-based representation. However, many static analyses (such as typechecking) require access to the tree representation. Therefore, extending Walc required taking one of three paths:
Option on devastated the extensibility of the Walc language. Option two tightly coupled the back and front end across a language boundary. Only option three remained.