Skip to content

Commit

Permalink
VM/native: primitive strings can be included in values
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Jan 7, 2025
1 parent 003b300 commit eb6d27f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kernel/nativelambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type lambda = Nativevalues.t Genlambda.lambda

let is_value lc =
match lc with
| Lval _ | Lint _ | Luint _ | Lfloat _ -> true
| Lval _ | Lint _ | Luint _ | Lfloat _ | Lstring _ -> true
| _ -> false

let get_value lc =
Expand All @@ -30,6 +30,7 @@ let get_value lc =
| Lint tag -> Nativevalues.mk_int tag
| Luint i -> Nativevalues.mk_uint i
| Lfloat f -> Nativevalues.mk_float f
| Lstring s -> Nativevalues.mk_string s
| _ -> raise Not_found

let as_value tag args =
Expand Down
4 changes: 3 additions & 1 deletion kernel/vmlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let get_lval (_, v) = v

let is_value lc =
match lc with
| Lval _ | Lint _ | Luint _ | Lfloat _ -> true
| Lval _ | Lint _ | Luint _ | Lfloat _ | Lstring _ -> true
| _ -> false

let get_value lc =
Expand All @@ -25,6 +25,7 @@ let get_value lc =
| Lval (_, v) -> v
| Lint i -> val_of_int i
| Lfloat f -> val_of_float f
| Lstring s -> val_of_string s
| _ -> assert false

let hash_block tag args =
Expand All @@ -34,6 +35,7 @@ let hash_block tag args =
| Luint i -> Uint63.hash i
| Lint i -> Hashtbl.hash (i : int)
| Lfloat f -> Float64.hash f
| Lstring s -> Pstring.hash s
| Lval (h, _) -> h
| _ -> assert false
in
Expand Down
4 changes: 4 additions & 0 deletions kernel/vmvalues.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ let rec eq_structured_values v1 v2 =
then Int64.equal (Obj.magic v1 : int64) (Obj.magic v2 : int64)
else if Int.equal t1 Obj.double_tag
then Float64.(equal (of_float (Obj.magic v1)) (of_float (Obj.magic v2)))
else if Int.equal t1 Obj.string_tag
then String.equal (Obj.magic v1) (Obj.magic v2)
else begin
assert (t1 <= Obj.last_non_constant_constructor_tag &&
t2 <= Obj.last_non_constant_constructor_tag);
Expand Down Expand Up @@ -434,6 +436,8 @@ let val_of_uint i = (Obj.magic i : structured_values)

let val_of_float f = (Obj.magic f : structured_values)

let val_of_string s = (Obj.magic s : structured_values)

let atom_of_proj kn v =
let r = Obj.new_block proj_tag 2 in
Obj.set_field r 0 (Obj.repr kn);
Expand Down
1 change: 1 addition & 0 deletions kernel/vmvalues.mli
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ val val_of_int : int -> structured_values
val val_of_block : tag -> structured_values array -> structured_values
val val_of_uint : Uint63.t -> structured_values
val val_of_float : Float64.t -> structured_values
val val_of_string : Pstring.t -> structured_values

external val_of_annot_switch : annot_switch -> values = "%identity"

Expand Down

0 comments on commit eb6d27f

Please sign in to comment.