- scope s { … }: task.scope.begin, task.scope.end at every normal exit
(scope ends generalized: borrow.end or task.scope.end, innermost first)
- task.spawn(s, f, args): call-like; named linear values moved (E7003);
lent borrows are bound first (inline borrow E7006); scope operand E7005
- task.join/cancel/cancelled; task<T>, sender<T>, receiver<T>, scope types
- channels: make<T>, dup, send, recv, close_sender, close_receiver; send,
recv and close_receiver are outcome matches; endpoints by name, borrowed
for the operation and ended on every edge (written `mut tx`: E7006)
- outcome rebinding: a value coming back under the name of a variable of
its type becomes the variable's value (pending(r))
- joins carry live variables only (pruned SSA): a linear value consumed
before a join does not travel to it; ordered after-walk over the
enclosing statement or tail, sibling arms not counted
- parser: a keyword after `.` is a member name (task.cancelled)
- conformance equivalence ignores schedule.choices (quantum counts AIR
instructions)
- tests: 10 run tests with AIR equivalence (Phase 3 programs), 12 rejects
(E4301, E4101 x2, E4002, E2001, E3101, E3002, E7006 x2, E7003, E0006,
E7005); Quick Reference tasks/channels programs now pass
- spec 15 §4/§6/§7, grammar, quick reference, bundle notes, plan
102 lines
5.5 KiB
EBNF
102 lines
5.5 KiB
EBNF
(* Aji source language `.aji` 0.1 (Phase 6A). Normative together with
|
|
docs/spec/15-source-language.md. Decision record: RFC 0013.
|
|
|
|
Lexical conventions
|
|
-------------------
|
|
- `//` starts a comment that runs to the end of the line.
|
|
- Whitespace and line breaks separate tokens and are otherwise insignificant.
|
|
- 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.
|
|
- Every construct has one canonical spelling (spec 15 §1).
|
|
*)
|
|
|
|
module = "module" path { item } ;
|
|
item = type_decl | fn_decl ;
|
|
path = ident { "." ident } ;
|
|
|
|
type_decl = struct_decl | enum_decl ;
|
|
struct_decl = "struct" ident "{" [ field { "," field } [ "," ] ] "}" ;
|
|
field = ident ":" type ;
|
|
enum_decl = "enum" ident "{" variant { "," variant } [ "," ] "}" ;
|
|
variant = ident [ "(" type { "," type } ")" ] ;
|
|
|
|
fn_decl = "fn" ident "(" [ param { "," param } ] ")" "->" type [ "from" ident ]
|
|
"effects" "[" [ path { "," path } ] "]"
|
|
block ; (* `trusted` is reserved and rejected, E7006 *)
|
|
param = ident ":" type ;
|
|
|
|
type = int_type | "bool" | "void" | "never" | ident
|
|
| "[" type ";" int_lit "]"
|
|
| wrapper "<" type ">"
|
|
| "cap" "<" path ">"
|
|
| "file" "<" ( "read" | "write" | "append" ) ">" ;
|
|
(* `>>` closes two type arguments: mut<file<write>> *)
|
|
wrapper = "ref" | "mut" | "slice" | "slice_mut" | "own" | "own_array"
|
|
| "task" | "sender" | "receiver" | "mutex" ;
|
|
int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
|
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ;
|
|
(* `region`, `listener`, `stream`, `io_error`, `alloc_error`,
|
|
`cap_error` are built-in type names (ident). *)
|
|
(* A built-in operation is a call whose callee is a dotted path:
|
|
`own.new(v, mem)`, `region.new(arena, v)`, `cap.narrow.budget(c, n)`. *)
|
|
|
|
block = "{" { statement } [ expr ] "}" ; (* optional tail expression: the block's value *)
|
|
statement = "let" binding [ ":" type ] "=" expr ";"
|
|
| "var" ident ":" type "=" ( expr | "zero" ) ";"
|
|
| ( "ref" | "mut" ) [ "unchecked" ] ident "=" place ";" (* borrow binding *)
|
|
| place "=" expr ";"
|
|
| "break" ";" | "continue" ";" | "return" [ expr ] ";" | "trap" ";"
|
|
| expr ";"
|
|
| block_stmt ;
|
|
binding = ident | "(" ident "," ident ")" ; (* the pair form only for `split_at` *)
|
|
block_stmt = if_expr | match_expr | select_stmt | block
|
|
| "while" expr block
|
|
| "for" ident "in" expr ".." expr block
|
|
| "loop" block
|
|
| "scope" ident block
|
|
| "shield" block
|
|
| "lock" "ref" place "as" ident block "cancelled" block ;
|
|
|
|
if_expr = "if" expr block [ "else" ( if_expr | block ) ] ;
|
|
match_expr = "match" expr "{" { arm } "}" ;
|
|
arm = pattern "=>" ( block | expr "," ) ;
|
|
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 } "}"
|
|
| "send" "(" ident "," expr ")" "{" { arm } "}" ;
|
|
|
|
expr = or_expr ;
|
|
or_expr = and_expr { "or" ( and_expr | "trap" ) } ; (* `e or trap`: the only fallible shorthand *)
|
|
and_expr = cmp_expr { "and" cmp_expr } ;
|
|
cmp_expr = bit_expr [ ( "==" | "!=" | "<" | "<=" | ">" | ">=" ) bit_expr ] ;
|
|
bit_expr = shift_expr { ( "&" | "|" | "^" ) shift_expr } ;
|
|
shift_expr = add_expr { ( "<<" | ">>" ) add_expr } ;
|
|
add_expr = mul_expr { ( "+" | "-" | "+%" | "-%" ) mul_expr } ;
|
|
mul_expr = cast_expr { ( "*" | "/" | "%" | "*%" ) cast_expr } ;
|
|
cast_expr = unary { ( "as" | "as!" | "as%" ) type } ;
|
|
unary = ( "-" | "not" | "*" ) unary
|
|
| ( "ref" | "mut" ) [ "unchecked" ] place
|
|
| "move" ident
|
|
| postfix ;
|
|
postfix = primary { "." member | "[" expr [ ".." expr ] "]" | call_args } ;
|
|
member = ident | keyword ; (* after `.` a keyword is a name: task.cancelled *)
|
|
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 ;
|
|
field_init = ident ":" expr ;
|
|
place = ident { "." ident | "[" expr [ ".." expr ] "]" } | "*" unary ;
|
|
|
|
int_lit = digit { digit | "_" } [ int_type ] | "0x" hexdigit { hexdigit | "_" } [ int_type ] ;
|
|
string = 'b"' { char | escape } '"' ; (* byte string; escapes \n \r \t \0 \\ \" \xHH *)
|
|
ident = ( letter | "_" ) { letter | digit | "_" } ;
|
|
keyword = ? any keyword listed under Lexical conventions ? ;
|