From 1b0ed4d4dee8ebc84db93ccd518e9246d29b5607 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 9 Jan 2020 16:50:27 -0600 Subject: [PATCH] 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);