diff --git a/changes/01-feature/1375-literal-arrays.md b/changes/01-feature/1375-literal-arrays.md index 5ac7cb3073..f300d7cec2 100644 --- a/changes/01-feature/1375-literal-arrays.md +++ b/changes/01-feature/1375-literal-arrays.md @@ -1,3 +1,4 @@ - Byte arrays can occur as literal values as string constants (`"abcd"`) or as a sequence of expressions (e.g., `{ 1, 2, 3 }`) - ([PR 1375](https://github.com/jasmin-lang/jasmin/pull/1375)). + ([PR 1375](https://github.com/jasmin-lang/jasmin/pull/1375), + [PR 1376](https://github.com/jasmin-lang/jasmin/pull/1376)). diff --git a/compiler/src/dune b/compiler/src/dune index cde421d19b..fb94b0812d 100644 --- a/compiler/src/dune +++ b/compiler/src/dune @@ -4,7 +4,7 @@ (modules lexer)) (menhir - (flags "--table" "--explain" "--inspection") + (flags "--table" "--explain" "--inspection" "--strict") (modules parser)) (rule diff --git a/compiler/src/functionAnnotations.ml b/compiler/src/functionAnnotations.ml index e3fcfeee51..5028028269 100644 --- a/compiler/src/functionAnnotations.ml +++ b/compiler/src/functionAnnotations.ml @@ -22,6 +22,7 @@ and pattri_to_simple_attribute (pattri: Syntax.psimple_attribute) : Annotations. | PEVar id -> Aid (L.unloc id) | PEInt ir -> Aint (Syntax.parse_int ir) | PEOp1 (`Neg None, {L.pl_desc = PEInt ir}) -> Aint (Z.neg (Syntax.parse_int ir)) + | PEstring s -> Astring s | _ -> hierror ~kind:"syntax" ~loc:(Lone (L.loc e)) "complex expressions not allowed in annotations" diff --git a/compiler/src/parser.mly b/compiler/src/parser.mly index d370a6d269..77363f8c99 100644 --- a/compiler/src/parser.mly +++ b/compiler/src/parser.mly @@ -125,8 +125,7 @@ annotationlabel: | s=loc(STRING) { s } simple_attribute: - | e=pexpr { PAexpr e} - | s=STRING { PAstring s } + | e=pexpr_noarr { PAexpr e} | s=keyword { PAstring s } | ws=utype { PAws (fst ws) } @@ -267,7 +266,7 @@ arr_access: let s = if s = None then Warray_.AAscale else Warray_.AAdirect in s, i } -pexpr_r: +pexpr_noarr_r(parent): | v=var { PEVar v } @@ -286,34 +285,39 @@ pexpr_r: | ma=mem_access { PEFetch ma } -| ct=parens(svsize) LBRACKET es=rtuple1(pexpr) RBRACKET +| ct=parens(svsize) LBRACKET es=rtuple1(parent) RBRACKET { PEpack(ct,es) } | e = STRING { PEstring e } -| LBRACE es = rtuple1(pexpr) RBRACE { PEarray es } - -| ct=parens(cast) e=pexpr %prec BANG +| ct=parens(cast) e=parent %prec BANG { PEOp1 (`Cast(ct), e) } -| o=peop1 e=pexpr +| o=peop1 e=parent { PEOp1 (o, e) } -| e1=pexpr o=peop2 e2=pexpr +| e1=parent o=peop2 e2=parent { PEOp2 (o, (e1, e2)) } -| e=parens(pexpr) +| e=parens(parent) { PEParens e } -| f=var args=parens_tuple(pexpr) +| f=var args=parens_tuple(parent) { PECall (f, args) } -| f=prim args=parens_tuple(pexpr) +| f=prim args=parens_tuple(parent) { PEPrim (f, args) } -| e1=pexpr QUESTIONMARK e2=pexpr COLON e3=pexpr +| e1=parent QUESTIONMARK e2=parent COLON e3=parent { PEIf(e1, e2, e3) } +pexpr_noarr: +| e=loc(pexpr_noarr_r(pexpr_noarr)) { e } + +pexpr_r: +| e = pexpr_noarr_r(pexpr) { e } +| LBRACE es = rtuple1(pexpr) RBRACE { PEarray es } + pexpr: | e=loc(pexpr_r) { e } diff --git a/compiler/tests/exec/dune b/compiler/tests/exec/dune index 8c2809b7da..13c68f029b 100644 --- a/compiler/tests/exec/dune +++ b/compiler/tests/exec/dune @@ -15,6 +15,7 @@ vpsxldq.jazz ../success/x86-64/vpsxldq.jazz sem_unit.jazz ../success/x86-64/test_global_string_literal.jazz + ../success/common/literal-arrays.jazz wide_rotation.jazz ) (names diff --git a/compiler/tests/success/common/annotations.jazz b/compiler/tests/success/common/annotations.jazz index e21d654e17..90f6e8353b 100644 --- a/compiler/tests/success/common/annotations.jazz +++ b/compiler/tests/success/common/annotations.jazz @@ -5,3 +5,6 @@ multiline annotation with tabs and \" special {| |} characters "] export fn noop() {} + +#[array = {a, b}, struct = {y = 0, z}, other_struct = { p, q = 1}] +export fn dummy() {}