Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
(fix) catch conversion errors early for diagnostic
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed May 29, 2018
1 parent efc3438 commit 66ab835
Show file tree
Hide file tree
Showing 5 changed files with 4,876 additions and 4,866 deletions.
2 changes: 1 addition & 1 deletion examples/acceptance-of-delivery/request.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$class":"org.accordproject.acceptanceofdelivery.InspectDeliverable",
"deliverableReceivedAt": "17 May 2018 16:34:00 EST",
"deliverableReceivedAt": "27 May 2018 16:34:00 EST",
"inspectionPassed": true
}
28 changes: 14 additions & 14 deletions extraction/ergocoreJS.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ let json_of_error error =
end

let ergo_compile input =
let gconf =
begin try
global_config_of_json input
with exn ->
ergo_raise (ergo_system_error ("Couldn't load configuration: "^(Printexc.to_string exn)))
end
in
let j_s =
begin try
Js.to_string input##.ergo
with exn ->
ergo_raise (ergo_system_error ("[Compilation Error] Couldn't load contract: "^(Printexc.to_string exn)))
end
in
begin try
let gconf =
begin try
global_config_of_json input
with exn ->
ergo_raise (ergo_system_error ("Couldn't load configuration: "^(Printexc.to_string exn)))
end
in
let j_s =
begin try
Js.to_string input##.ergo
with exn ->
ergo_raise (ergo_system_error ("[Compilation Error] Couldn't load contract: "^(Printexc.to_string exn)))
end
in
let res = ErgoCompile.ergo_compile gconf j_s in
json_of_result res
with
Expand Down
22 changes: 15 additions & 7 deletions extraction/src/Util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ type dnrc_logger_token_type = string
(* Data type conversions between Coq and OCaml *)

let string_of_char_list l =
let b = Bytes.create (List.length l) in
let i = ref 0 in
List.iter (fun c -> Bytes.set b !i c; incr i) l;
Bytes.to_string b
begin try
let b = Bytes.create (List.length l) in
let i = ref 0 in
List.iter (fun c -> Bytes.set b !i c; incr i) l;
Bytes.to_string b
with
| exn -> raise (Failure ("Error in string_of_char_list: " ^ (Printexc.to_string exn)))
end

let char_list_of_string s =
let l = ref [] in
String.iter (fun c -> l := c :: !l) s;
List.rev !l
begin try
let rec exp i l =
if i < 0 then l else exp (i - 1) (s.[i] :: l) in
exp (String.length s - 1) []
with
| exn -> raise (Failure ("Error in char_list_of_string: " ^ (Printexc.to_string exn)))
end

let coq_Z_of_int i = i

Expand Down
4,703 changes: 2,352 additions & 2,351 deletions packages/ergo-cli/lib/ergoc-lib.js

Large diffs are not rendered by default.

4,987 changes: 2,494 additions & 2,493 deletions packages/ergo-compiler/lib/ergo-core.js

Large diffs are not rendered by default.

0 comments on commit 66ab835

Please sign in to comment.