Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Shallow_Micro_Rust/Micro_Rust_Shallow_Embedding.thy
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,22 @@ ML\<open>

(* Mimicking "instance {rec_name} :: (type, type, ...) localizable .." *)
fun instantiate_localizable_class rec_name (ctxt : Proof.context) =
let val typeargs = generic_type_arguments ctxt rec_name in
((Class.instance_arity_cmd ([rec_name], typeargs, @{class localizable})
let val typeargs = generic_type_arguments ctxt rec_name
val full_tyname = Proof_Context.read_type_name {proper = true, strict = false} ctxt rec_name
|> Term.dest_Type |> fst
in
((Class.instance_arity_cmd ([full_tyname], typeargs, @{class localizable})
#> Proof.global_default_proof
#> Proof_Context.theory_of)
|> Local_Theory.background_theory) ctxt
end
\<close>

ML\<open>
fun register_lens_with_micro_rust rec_name field =
notation_nano_rust "field" (lens_name rec_name field, field)
fun register_lens_with_micro_rust rec_name field lthy =
let val name = lens_name rec_name field
val full_name = Local_Theory.full_name lthy (Binding.name name)
in notation_nano_rust "field" (full_name, field) lthy end
fun register_lenses_with_micro_rust rec_name thy =
let val fields = get_fields rec_name thy in fold (register_lens_with_micro_rust rec_name) fields thy end

Expand Down
16 changes: 16 additions & 0 deletions Shallow_Micro_Rust/Micro_Rust_Shallow_Embedding_Tests.thy
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,22 @@ begin
value \<open>\<lbrakk> y.field3.field1 \<rbrakk>\<close>
end

subsubsection\<open>Declaring \<^verbatim>\<open>micro_rust_record\<close>s in locales\<close>
locale micro_rust_record_locale_test =
fixes answer :: \<open>64 word\<close>
assumes \<open>answer = 42\<close>
begin

datatype_record foobar =
field5 :: \<open>64 word\<close>
field6 :: \<open>64 word\<close>
micro_rust_record foobar

term \<open>\<lambda> x :: foobar. \<lbrakk> x.field5 + x.field6 \<rbrakk>\<close>
term \<open>\<lambda> x :: ('addr, 'fv, foobar) ref. \<lbrakk> *x.field5 + *x.field6 \<rbrakk>\<close>

end

subsubsection\<open>Field Assignment Through Lenses\<close>

context
Expand Down
Loading