Skip to content

Types and Values

Literal values represent values directly present in source code.

Examples:

123
3.14
"hello"
true
false
null

These 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 = 23

can 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:

Number
String
Boolean
Null
Array
Object
Function
NativeFunction