Types and Values
Types and Values
Section titled “Types and Values”Literal values represent values directly present in source code.
Examples:
1233.14"hello"truefalsenullThese are represented by the Literal enum in the frontend.
At runtime, values are represented separately.
pub enum Value { Number(f64), String(String), Boolean(bool), Null,}For example:
let age = 23can become:
Value::Number(23.0)and:
let name = "Tanmoy"becomes:
Value::String("Tanmoy")Why separate AST literals from runtime values?
Section titled “Why separate AST literals from runtime values?”The AST describes the program. The runtime describes values while the program runs.
For example:
AST: Literal(Number(23))Runtime: Value::Number(23.0)This separation becomes increasingly important as the language grows.
Potential future runtime values include:
NumberStringBooleanNullArrayObjectFunctionNativeFunction