Phase 6A: .aji layer 2 (structs, enums, exhaustive match)

Owner rules: struct/enum declarations in Rust form; one construction
form each (named struct literal, Enum::Variant); struct fields lowered
in declaration order, so field order in the source does not change the
AIR (golden test with two orders, one AIR); match over enums exhaustive
with no '_' (E7004 lists missing variants, E7006 for '_'), integer
match needs '_'; payload names scoped to their arm (enum.switch block
parameters); match as an expression with a merge block; arm-level
source map; no destructuring, guards or nested patterns. Type inference
limits written into spec 15 (one function, monomorphic, no search,
E7007). aji lower --stats: source/AIR size and expansion ratio.

Tests: 4 run (one shared golden), 7 rejects incl. verifier-caught E1003.
This commit is contained in:
dev committed 2026-10-05 11:31:56 +03:00
1 parent ba3e9b3719
commit 0fdd04179b
22 files changed
+702 -121

No files matched your search

+8 -6
View File
@@ -5,7 +5,7 @@
-------------------
- `//` starts a comment that runs to the end of the line.
- Whitespace and line breaks separate tokens and are otherwise insignificant.
- Keywords: module type struct enum fn effects trusted from let var zero
- Keywords: module struct enum fn effects trusted from let var zero
if else while for in loop break continue return trap match select
scope shield lock as cancelled ref mut move unchecked or and not
true false recv send.
@@ -16,10 +16,10 @@ module = "module" path { item } ;
item = type_decl | fn_decl ;
path = ident { "." ident } ;
type_decl = "type" ident "=" ( struct_body | enum_body ) ;
struct_body = "struct" "{" [ field { "," field } [ "," ] ] "}" ;
type_decl = struct_decl | enum_decl ;
struct_decl = "struct" ident "{" [ field { "," field } [ "," ] ] "}" ;
field = ident ":" type ;
enum_body = "enum" "{" [ variant { "," variant } [ "," ] ] "}" ;
enum_decl = "enum" ident "{" variant { "," variant } [ "," ] "}" ;
variant = ident [ "(" type { "," type } ")" ] ;
fn_decl = "fn" ident "(" [ param { "," param } ] ")" "->" type [ "from" ident ]
@@ -59,8 +59,9 @@ block_stmt = if_expr | match_expr | select_stmt | block
if_expr = "if" expr block [ "else" ( if_expr | block ) ] ;
match_expr = "match" expr "{" { arm } "}" ;
arm = pattern "=>" ( block | expr "," ) ;
pattern = "_" | int_lit
| ident [ "(" ident { "," ident } ")" ] ; (* variant or outcome: ok(n), closed, Shape.Rect(w, h) is written Rect(w, h) *)
pattern = "_" | int_lit (* integer matches only; `_` is required there *)
| ident "::" ident [ "(" ident { "," ident } ")" ] (* enum variant: Shape::Rect(w, h); no `_` in enum matches *)
| ident [ "(" ident { "," ident } ")" ] ; (* outcome of a fallible operation: ok(n), closed *)
select_stmt = "select" "{" { select_arm } "cancelled" [ "(" ident { "," ident } ")" ] "=>" ( block | expr "," ) "}" ;
select_arm = "recv" "(" ident ")" "{" { arm } "}"
@@ -83,6 +84,7 @@ postfix = primary { "." ident | "[" expr [ ".." expr ] "]" | call_args } ;
call_args = [ "<" type ">" ] "(" [ expr { "," expr } ] ")" ;
primary = int_lit | "true" | "false" | string
| ident [ "{" field_init { "," field_init } [ "," ] "}" ] (* struct literal *)
| ident "::" ident (* enum variant; applied by a call *)
| "[" expr ";" int_lit "]"
| "(" expr ")"
| if_expr | match_expr | block ;