TritonVM / tasm-lang

Writing tasm with Rust syntax
15 stars 2 forks source link

Add support for constants #39

Open Sword-Smith opened 10 months ago

Sword-Smith commented 10 months ago

Goal: To be allowed to write this

const MEMORY_ADDRESS: u64 = 100;
let memory_address = BFieldElement::new(MEMORY_ADDRESS);

instead of that:

let memory_address = BFieldElement::new(100);

We can probably use a similar technique to what we did with the struct definitions: Add a literal variant "Unresolved" which must then be matched with the content of the associated constant declarations an appropriate place in the compiler pipeline, probably in types.rs where we are doing this match for structs.

Just like DataType has a method for resolve_type that takes the declared structs and maps any unresolved type to one of those, so too could resolve_literal map unresolved literals to those from a constant list stored in the type checkers CheckState struct.