Skip to content

Commit 41f5916

Browse files
committed
Bugfixes. Z3_string is now SML string.
1 parent 52369f0 commit 41f5916

File tree

3 files changed

+145
-138
lines changed

3 files changed

+145
-138
lines changed

src/ext/makesml/makesml.ml

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ let typtbl = H.create 117
99
let _ =
1010
H.add typtbl "int" "int";
1111
H.add typtbl "void" "unit";
12-
H.add typtbl "float" "double";
12+
H.add typtbl "float" "real";
13+
H.add typtbl "Z3_string" "string";
1314
H.add typtbl "ptr" "MLton.Pointer.t"
1415

1516
type varinfo = {mltyp : string; args : string}
@@ -18,9 +19,9 @@ let vartbl = H.create 1009
1819

1920
let mkFunTy (argTy,resTy) = argTy ^ " -> " ^ resTy
2021

21-
let mkTupleTy tys = "("^(match tys with
22-
| [] -> ""
23-
| x::xs -> List.fold_left (fun acc ty ->
22+
let mkTupleTy tys = match tys with
23+
| [] -> H.find typtbl "void"
24+
| x::xs -> "("^(List.fold_left (fun acc ty ->
2425
acc^" * "^ty) x xs)^")"
2526

2627
let rec maptype typ = match typ with
@@ -43,12 +44,16 @@ let rec maptype typ = match typ with
4344
| TComp _ | TEnum _ | TBuiltin_va_list _ ->
4445
(E.log "Unknown type : %a\n" d_type typ; "Tunknown")
4546

47+
let sanitize name = match name with
48+
| "val" | "ref" | "let" | "in" | "end" | "fun" -> name^"'"
49+
| _ -> name
50+
4651
let mapargs typ = match typ with
4752
| TFun (_,None,_,_) -> "()"
4853
| TFun (_,Some argTys,_,_) -> "("^(match argTys with
4954
[] -> ""
5055
| (x,_,_)::xs -> List.fold_left (fun acc (a,b,c) ->
51-
acc^","^a) x xs)^")"
56+
acc^","^(sanitize a)) (sanitize x) xs)^")"
5257

5358
let globalFolder x glob = match glob with
5459
| GVarDecl ({vname=vname;vtype=vtype},_) ->
@@ -94,10 +99,12 @@ let makeStructDoc () =
9499
then myconcat [text ("type "^mlTy^" = MLton.Pointer.t");
95100
line; doc]
96101
else doc) typtbl nil in
102+
let handl = text "val hndl = DynLink.dlopen
103+
(\"libz3.dylib\", DynLink.RTLD_LAZY);" in
97104
let fundecs = H.fold (fun name {mltyp=typ;args=args} doc ->
98105
myconcat [doc;line;instantiateFunDec (name,args,typ)])
99106
vartbl nil in
100-
let decs = myconcat [typedecs; line; fundecs] in
107+
let decs = myconcat [typedecs; line; handl; line; fundecs] in
101108
let footer = text "end" in
102109
let doc = myconcat [header; indent 2 decs; footer] in
103110
let outf = open_out "z3_ffi.sml" in

0 commit comments

Comments
 (0)