@@ -65,6 +65,7 @@ let stdlib =
65
65
(([" bytes" ]," from_uint128_be" ), ([Some (`Exact (tword128))], (fs1 (fun _aty -> bytes_t)), Ident. make " bytes_from_uint128_be" ));
66
66
(([" bytes" ]," to_uint64_le" ), ([Some (`Exact bytes_t)], (fs1 (fun _aty -> tword64)), Ident. make " bytes_to_uint64_le" ));
67
67
(([" bytes" ]," from_uint64_le" ), ([Some (`Exact (tword64))], (fs1 (fun _aty -> bytes_t)), Ident. make " bytes_from_uint64_le" ));
68
+ (([" bytes" ]," from_uint64_be" ), ([Some (`Exact (tword64))], (fs1 (fun _aty -> bytes_t)), Ident. make " bytes_from_uint64_be" ));
68
69
69
70
(* (([],"natmod"), ([Some (`Approx PInt); Some (`Approx PInt)], (fun [aty;bty] -> TInt (`Natm (EUInt Big_int.zero))), Ident.make "natmod"));*)
70
71
(([" natmod" ]," to_nat" ), ([Some (`Approx PInt )], (fs1 (fun _aty -> nat_t)), Ident. make " natmod_to_nat" ));
@@ -167,6 +168,7 @@ module Env : sig
167
168
module Procs : sig
168
169
val get : env -> symbol -> pdecl option
169
170
val bind : env -> symbol -> hotype list * type_ -> env * ident
171
+ val add : env -> pdecl -> env
170
172
end
171
173
end = struct
172
174
type tdecl = { tname : ident ; tdef : type_ ; }
@@ -372,6 +374,8 @@ end = struct
372
374
let decl = { pname = Ident. make f; psig = sig_; pret = ret } in
373
375
let env = { env with e_procs = Mstr. add f decl env.e_procs } in
374
376
(env, decl.pname)
377
+ let add (env : env ) (p : pdecl ) =
378
+ { env with e_procs = Mstr. add (Ast.Ident. to_string p.pname) p env.e_procs }
375
379
end
376
380
377
381
let empty =
@@ -1009,8 +1013,27 @@ and tt_module (env : env) (nm : pident list) =
1009
1013
in resolve (env, [] ) nm
1010
1014
1011
1015
(* -------------------------------------------------------------------- *)
1012
- and tt_import (env : env ) (_ : pimport ) =
1013
- env
1016
+ and tt_import (e : env ) (imp : pimport ) =
1017
+ let impmod, impdec = imp in
1018
+ let impmodpath, impmod2 = impmod in
1019
+ if (unloc impmod2) = " speclib" then
1020
+ e
1021
+ else (
1022
+ (* TODO: use path to read import *)
1023
+ let _ = (String. concat " " (List. map unloc impmodpath)) in
1024
+ let importeddeclarations = (List. map (fun x ->
1025
+ match x with | None -> " " | Some y -> unloc y) (Option. get impdec)) in
1026
+ let (pi : Env.env * Env.env Ast.program ) =
1027
+ let stream = Reader. from_file (Resource. getspec (unloc impmod2 ^ " .py" )) in
1028
+ let past = Reader. parse_spec stream in
1029
+ tt_program e past
1030
+ in
1031
+ let new_env, _ = pi in
1032
+ let newdecls = List. map (fun d ->
1033
+ Env.Procs. get new_env d) importeddeclarations in
1034
+ let newdecls = List. map Option. get newdecls in
1035
+ List. fold_left Env.Procs. add e newdecls
1036
+ )
1014
1037
1015
1038
(* -------------------------------------------------------------------- *)
1016
1039
and tt_tydecl (env : env ) ((x , ty ) : pident * pexpr ) : env * tydecl =
@@ -1054,7 +1077,7 @@ and tt_annotation (env : env) (att : pexpr) : ident * hoexpr list =
1054
1077
| PEVar ([] ,x ) when unloc x = " typechecked" ->
1055
1078
(Ident. make " typechecked" , [] )
1056
1079
| PECall (x , args ) when qunloc x = ([] ," contract3" ) || qunloc x = ([] ," contract" ) ->
1057
- let es, tys = List. split (List. map (tt_expr env) args) in
1080
+ let es, _ = List. split (List. map (tt_expr env) args) in
1058
1081
(Ident. make " contract3" , List. map (fun x -> `Expr x) es)
1059
1082
| _ ->
1060
1083
error ~loc: (loc att) env UnsupportedAnnotation
@@ -1124,7 +1147,7 @@ and tt_procdef (env : env) (pf : pprocdef) : env * env procdef =
1124
1147
in (env, aout)
1125
1148
1126
1149
(* -------------------------------------------------------------------- *)
1127
- let tt_topdecl1 (env : env ) = function
1150
+ and tt_topdecl1 (env : env ) = function
1128
1151
| PTImport info ->
1129
1152
(tt_import env info, [] )
1130
1153
@@ -1138,7 +1161,7 @@ let tt_topdecl1 (env : env) = function
1138
1161
let env, x = tt_vardecl env ((x, ty), e) in (env, [TD_VarDecl x])
1139
1162
1140
1163
(* -------------------------------------------------------------------- *)
1141
- let tt_intf1 (env : env ) = function
1164
+ and tt_intf1 (env : env ) = function
1142
1165
| IPTTypeAlias (x , ty ) ->
1143
1166
let env, _ = tt_tydecl env (x, ty) in env
1144
1167
@@ -1158,10 +1181,10 @@ let tt_intf1 (env : env) = function
1158
1181
else Env.Mod. bindnm env (nmunloc nm) senv
1159
1182
1160
1183
(* -------------------------------------------------------------------- *)
1161
- let tt_interface (env : env ) (i : pintf ) : env =
1184
+ and tt_interface (env : env ) (i : pintf ) : env =
1162
1185
List. fold_left tt_intf1 env i
1163
1186
1164
1187
(* -------------------------------------------------------------------- *)
1165
- let tt_program (env : env ) (p : pspec ) : env * env program =
1188
+ and tt_program (env : env ) (p : pspec ) : env * env program =
1166
1189
let env, prgm = List. fold_left_map tt_topdecl1 env p in
1167
1190
(env, List. flatten prgm)
0 commit comments