Skip to content

Commit

Permalink
better encode/decode of builtin values
Browse files Browse the repository at this point in the history
  • Loading branch information
h0nzZik committed Apr 20, 2024
1 parent 63e2651 commit dd357ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion minuska-examples/theories/examples.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
From Coq.Logic Require Import ProofIrrelevance.

From stdpp Require Import countable.

From Minuska Require Import
prelude
Expand Down Expand Up @@ -31,6 +31,10 @@ Module two_counters.
#[local]
Instance Σ : StaticModel := default_model (default_builtin.β).

Set Printing Implicit.
Check @encode.
Compute (@encode (Term' (@symbol Σ) BuiltinValue.BuiltinValue0) _ (@Term'_countable (@symbol Σ) string_eq_dec string_countable BuiltinValue.BuiltinValue0 _ (@BuiltinValue.BuiltinValue0_countable (@symbol Σ) string_eq_dec string_countable)) (uglify' (t_term "ahoj" [t_over (BuiltinValue.bv_Z 3)]))).
Compute (@encode (@TermOver' (@symbol Σ) BuiltinValue.BuiltinValue0)) _ (@TermOver_count (@symbol Σ) BuiltinValue.BuiltinValue0 string_eq_dec _ string_countable (@BuiltinValue.BuiltinValue0_countable (@symbol Σ) string_eq_dec string_countable)) ((t_term "ahoj" [t_over (BuiltinValue.bv_Z 3)])).

Definition M : variable := "M".
Definition N : variable := "N".
Expand Down
2 changes: 1 addition & 1 deletion minuska/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let compile input_filename interpreter_name () =
let _ = run [
"cd "; mldir; "; ";
"env OCAMLPATH="; libdir; ":$OCAMLPATH ";
"ocamlfind ocamlopt -thread -package coq-minuska -package zarith -linkpkg -g -w -20 -w -26 -o ";
"ocamlfind ocamlopt -thread -package coq-minuska -package zarith -linkpkg -g -o ";
"interpreter.exe"; " "; (String.append mlfile "i"); " "; mlfile] in
let _ = run ["mv "; mldir; "/interpreter.exe"; " "; real_interpreter_name] in
let _ = input_filename in
Expand Down
8 changes: 5 additions & 3 deletions minuska/theories/builtins.v
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ Module default_builtin.
x y
.

Definition my_encode := ((@encode (@TermOver' (symbol) BuiltinValue.BuiltinValue0)) _ (@TermOver_count (symbol) BuiltinValue.BuiltinValue0 (@symbol_eqdec symbol symbols) _ (@symbol_countable symbol symbols) (@BuiltinValue.BuiltinValue0_countable (symbol) (@symbol_eqdec symbol symbols) (@symbol_countable symbol symbols)))).

#[local]
Instance β
: Builtin
Expand Down Expand Up @@ -382,7 +384,7 @@ Module default_builtin.
| b_map_hasKey =>
match v1 with
| t_over (bv_pmap m) =>
let p := encode (uglify' v2) in
let p := my_encode (v2) in
match m !! p with
| Some _ => (t_over (bv_bool true))
| None => (t_over (bv_bool false))
Expand All @@ -392,7 +394,7 @@ Module default_builtin.
| b_map_lookup =>
match v1 with
| t_over (bv_pmap m) =>
let p := encode (uglify' v2) in
let p := my_encode (v2) in
match m !! p with
| Some v => (prettify v)
| None => err
Expand Down Expand Up @@ -423,7 +425,7 @@ Module default_builtin.
| b_map_update =>
match v1 with
| t_over (bv_pmap m) =>
let p := encode (uglify' v2) in
let p := my_encode (v2) in
let m' := <[ p := (uglify' v3) ]>m in
t_over (bv_pmap m')
| _ => err
Expand Down

0 comments on commit dd357ba

Please sign in to comment.