Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference rules for addresses #778

Merged
merged 17 commits into from
Feb 17, 2020
Merged
Changes from 1 commit
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
34 changes: 27 additions & 7 deletions src/base/JSON.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,22 @@ let build_prim_lit_exn t v =
let exn () =
mk_invalid_json ("Invalid " ^ pp_typ t ^ " value " ^ v ^ " in JSON")
in
let build_prim_literal_of_type t v =
match build_prim_literal t v with
| Some v' -> v'
| None -> raise (exn ())
in
match t with
| PrimType pt -> (
match build_prim_literal pt v with
| Some v' -> v'
| None -> raise (exn ()) )
| _ -> raise (exn ())
| PrimType pt ->
build_prim_literal_of_type pt v
| Address _ ->
build_prim_literal_of_type (Bystrx_typ 20) v
| MapType _
| FunType _
| ADT _
| TypeVar _
| PolyFun _
| Unit -> raise (exn ())

(****************************************************************)
(* JSON parsing *)
Expand Down Expand Up @@ -213,10 +223,20 @@ and json_to_lit t v =
| ADT (name, tlist) ->
let vl = read_adt_json (get_id name) v tlist in
vl
| _ ->
| PrimType _
| Address _ ->
let tv = build_prim_lit_exn t (to_string_exn v) in
tv

| FunType _
| TypeVar _
| PolyFun _
| Unit ->
let exn () =
mk_invalid_json ("Invalid type " ^ pp_typ t ^ " in JSON")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we now name this function json_to_lit_exn (conforming to the other functions above that have _exn to mark that they throw exceptions).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

in
raise (exn ())


let jobj_to_statevar json =
let n = member_exn "vname" json |> to_string_exn in
let tstring = member_exn "type" json |> to_string_exn in
Expand Down