From 1b0ed4d4dee8ebc84db93ccd518e9246d29b5607 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 9 Jan 2020 16:50:27 -0600 Subject: [PATCH 1/2] Fix literal bytes --- src/passes/1-parser/cameligo/LexToken.mll | 2 +- src/passes/1-parser/pascaligo/LexToken.mll | 2 +- src/passes/1-parser/reasonligo/LexToken.mll | 2 +- src/passes/2-simplify/cameligo.ml | 2 +- src/passes/2-simplify/pascaligo.ml | 2 +- src/test/contracts/bytes_arithmetic.ligo | 2 +- src/test/contracts/bytes_arithmetic.mligo | 2 +- src/test/contracts/bytes_arithmetic.religo | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/passes/1-parser/cameligo/LexToken.mll b/src/passes/1-parser/cameligo/LexToken.mll index 5c8136624..5576d7c7b 100644 --- a/src/passes/1-parser/cameligo/LexToken.mll +++ b/src/passes/1-parser/cameligo/LexToken.mll @@ -378,7 +378,7 @@ let mk_string lexeme region = let mk_bytes lexeme region = let norm = Str.(global_replace (regexp "_") "" lexeme) in - let value = lexeme, Hex.of_string norm + let value = lexeme, `Hex norm in Bytes Region.{region; value} let mk_int lexeme region = diff --git a/src/passes/1-parser/pascaligo/LexToken.mll b/src/passes/1-parser/pascaligo/LexToken.mll index f1d219655..b721a7932 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mll +++ b/src/passes/1-parser/pascaligo/LexToken.mll @@ -443,7 +443,7 @@ let mk_string lexeme region = String Region.{region; value=lexeme} let mk_bytes lexeme region = let norm = Str.(global_replace (regexp "_") "" lexeme) in - let value = lexeme, Hex.of_string norm + let value = lexeme, `Hex norm in Bytes Region.{region; value} type int_err = Non_canonical_zero diff --git a/src/passes/1-parser/reasonligo/LexToken.mll b/src/passes/1-parser/reasonligo/LexToken.mll index 4bf6bd8d6..dd3272142 100644 --- a/src/passes/1-parser/reasonligo/LexToken.mll +++ b/src/passes/1-parser/reasonligo/LexToken.mll @@ -361,7 +361,7 @@ let mk_string lexeme region = String Region.{region; value=lexeme} let mk_bytes lexeme region = let norm = Str.(global_replace (regexp "_") "" lexeme) in - let value = lexeme, Hex.of_string norm + let value = lexeme, `Hex norm in Bytes Region.{region; value} let mk_int lexeme region = diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index ac71c4335..ba790e390 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -356,7 +356,7 @@ let rec simpl_expression : return @@ e_literal ~loc Literal_unit | EBytes x -> let (x , loc) = r_split x in - return @@ e_literal ~loc (Literal_bytes (Bytes.of_string @@ fst x)) + return @@ e_literal ~loc (Literal_bytes (Hex.to_bytes @@ snd x)) | ETuple tpl -> simpl_tuple_expression @@ (npseq_to_list tpl.value) | ERecord r -> let (r , loc) = r_split r in diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index bd6457c03..913e1bddc 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -326,7 +326,7 @@ let rec simpl_expression (t:Raw.expr) : expr result = return @@ e_literal ~loc Literal_unit | EBytes x -> let (x' , loc) = r_split x in - return @@ e_literal ~loc (Literal_bytes (Bytes.of_string @@ fst x')) + return @@ e_literal ~loc (Literal_bytes (Hex.to_bytes @@ snd x')) | ETuple tpl -> let (tpl' , loc) = r_split tpl in simpl_tuple_expression ~loc @@ npseq_to_list tpl'.inside diff --git a/src/test/contracts/bytes_arithmetic.ligo b/src/test/contracts/bytes_arithmetic.ligo index c03270a18..8b9251f93 100644 --- a/src/test/contracts/bytes_arithmetic.ligo +++ b/src/test/contracts/bytes_arithmetic.ligo @@ -1,5 +1,5 @@ function concat_op (const s : bytes) : bytes is - begin skip end with bytes_concat(s , ("7070" : bytes)) + begin skip end with bytes_concat(s , 0x7070) function slice_op (const s : bytes) : bytes is begin skip end with bytes_slice(1n , 2n , s) diff --git a/src/test/contracts/bytes_arithmetic.mligo b/src/test/contracts/bytes_arithmetic.mligo index b084181b1..4d71994a2 100644 --- a/src/test/contracts/bytes_arithmetic.mligo +++ b/src/test/contracts/bytes_arithmetic.mligo @@ -1,5 +1,5 @@ let concat_op (s : bytes) : bytes = - Bytes.concat s ("7070" : bytes) + Bytes.concat s 0x7070 let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s diff --git a/src/test/contracts/bytes_arithmetic.religo b/src/test/contracts/bytes_arithmetic.religo index 0c2bf9e12..c04599411 100644 --- a/src/test/contracts/bytes_arithmetic.religo +++ b/src/test/contracts/bytes_arithmetic.religo @@ -1,4 +1,4 @@ -let concat_op = (s: bytes): bytes => Bytes.concat(s, "7070": bytes); +let concat_op = (s: bytes): bytes => Bytes.concat(s, 0x7070); let slice_op = (s: bytes): bytes => Bytes.slice(1n, 2n, s); From 5cef850bdd59fa46482cbe2a0a3778d6e0fc0320 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 9 Jan 2020 16:51:23 -0600 Subject: [PATCH 2/2] Fix printing of bytes in parsers/lexers --- src/passes/1-parser/cameligo/LexToken.mll | 2 +- src/passes/1-parser/cameligo/ParserLog.ml | 4 ++-- src/passes/1-parser/pascaligo/LexToken.mll | 2 +- src/passes/1-parser/pascaligo/ParserLog.ml | 4 ++-- src/passes/1-parser/reasonligo/LexToken.mll | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/passes/1-parser/cameligo/LexToken.mll b/src/passes/1-parser/cameligo/LexToken.mll index 5576d7c7b..d989d1186 100644 --- a/src/passes/1-parser/cameligo/LexToken.mll +++ b/src/passes/1-parser/cameligo/LexToken.mll @@ -145,7 +145,7 @@ let proj_token = function | Bytes Region.{region; value = s,b} -> region, sprintf "Bytes (\"%s\", \"0x%s\")" - s (Hex.to_string b) + s (Hex.show b) | Begin region -> region, "Begin" | Else region -> region, "Else" | End region -> region, "End" diff --git a/src/passes/1-parser/cameligo/ParserLog.ml b/src/passes/1-parser/cameligo/ParserLog.ml index 18c29a7d7..79c8baf09 100644 --- a/src/passes/1-parser/cameligo/ParserLog.ml +++ b/src/passes/1-parser/cameligo/ParserLog.ml @@ -105,7 +105,7 @@ let print_bytes state {region; value} = let line = sprintf "%s: Bytes (\"%s\", \"0x%s\")\n" (compact state region) lexeme - (Hex.to_string abstract) + (Hex.show abstract) in Buffer.add_string state#buffer line let print_int state {region; value} = @@ -712,7 +712,7 @@ and pp_ne_injection : and pp_bytes state {value=lexeme,hex; region} = pp_loc_node (state#pad 2 0) lexeme region; - pp_node (state#pad 2 1) (Hex.to_string hex) + pp_node (state#pad 2 1) (Hex.show hex) and pp_int state {value=lexeme,z; region} = pp_loc_node (state#pad 2 0) lexeme region; diff --git a/src/passes/1-parser/pascaligo/LexToken.mll b/src/passes/1-parser/pascaligo/LexToken.mll index b721a7932..51009bb76 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mll +++ b/src/passes/1-parser/pascaligo/LexToken.mll @@ -126,7 +126,7 @@ let proj_token = function | Bytes Region.{region; value = s,b} -> region, sprintf "Bytes (\"%s\", \"0x%s\")" - s (Hex.to_string b) + s (Hex.show b) | Int Region.{region; value = s,n} -> region, sprintf "Int (\"%s\", %s)" s (Z.to_string n) diff --git a/src/passes/1-parser/pascaligo/ParserLog.ml b/src/passes/1-parser/pascaligo/ParserLog.ml index 5febaecd1..9b793a327 100644 --- a/src/passes/1-parser/pascaligo/ParserLog.ml +++ b/src/passes/1-parser/pascaligo/ParserLog.ml @@ -90,7 +90,7 @@ let print_bytes state {region; value} = let line = sprintf "%s: Bytes (\"%s\", \"0x%s\")\n" (compact state region) lexeme - (Hex.to_string abstract) + (Hex.show abstract) in Buffer.add_string state#buffer line let print_int state {region; value} = @@ -1093,7 +1093,7 @@ and pp_pattern state = function and pp_bytes state {value=lexeme,hex; region} = pp_loc_node (state#pad 2 0) lexeme region; - pp_node (state#pad 2 1) (Hex.to_string hex) + pp_node (state#pad 2 1) (Hex.show hex) and pp_int state {value=lexeme,z; region} = pp_loc_node (state#pad 2 0) lexeme region; diff --git a/src/passes/1-parser/reasonligo/LexToken.mll b/src/passes/1-parser/reasonligo/LexToken.mll index dd3272142..341dd8015 100644 --- a/src/passes/1-parser/reasonligo/LexToken.mll +++ b/src/passes/1-parser/reasonligo/LexToken.mll @@ -140,7 +140,7 @@ let proj_token = function | Bytes Region.{region; value = s,b} -> region, sprintf "Bytes (\"%s\", \"0x%s\")" - s (Hex.to_string b) + s (Hex.show b) | Else region -> region, "Else" | False region -> region, "False" | If region -> region, "If"