2024-08-17 13:32:59 +02:00
|
|
|
type lox_value = String of string | Number of float | Bool of bool | Nil
|
|
|
|
|
[@@deriving show { with_path = false }]
|
|
|
|
|
|
|
|
|
|
let string_of_lox_value lox_value =
|
|
|
|
|
match lox_value with
|
|
|
|
|
| String s -> s
|
2024-08-26 01:57:08 +02:00
|
|
|
| Number x -> if Float.is_integer x then string_of_int (Int.of_float x) else string_of_float x
|
2024-08-17 13:32:59 +02:00
|
|
|
| Bool b -> string_of_bool b
|
|
|
|
|
| Nil -> "nil"
|
|
|
|
|
|
|
|
|
|
let type_string_of_lox_value lox_value =
|
|
|
|
|
match lox_value with
|
|
|
|
|
| String _ -> "String"
|
|
|
|
|
| Number _ -> "Number"
|
|
|
|
|
| Bool _ -> "Bool"
|
|
|
|
|
| Nil -> "Nil"
|
2024-08-26 17:26:59 +02:00
|
|
|
|
|
|
|
|
let lox_value_to_bool lox_value =
|
|
|
|
|
match lox_value with String _ -> true | Number _ -> true | Bool b -> b | Nil -> false
|