P4-11: air-text.ebnf covers the syntax of Phases 2–4
Types cap<K>, resources, own/region, scope/task/shield, endpoints, mutex/guard, island/frozen/iref/arc and the built-in enums; productions for capability, heap, region, task, cancellation, channel, sync and graph instructions, with the named-edge terminator forms. Every opcode in the conformance corpus and in the spec contract tables has a production. AIR bundle +3.6 % (cl100k), recorded.
This commit is contained in:
1 parent
c699529fec
commit
3c5c129078
4 files changed
+122
-5
No files matched your search
@@ -9,6 +9,9 @@
|
||||
"[" "]" and "{" "}" are ignored.
|
||||
- Spaces and tabs separate tokens and are otherwise insignificant.
|
||||
- Opcodes are written as one dotted word, e.g. "add.checked.u64".
|
||||
- Every construct marked "(* feature f *)" requires f in the module's
|
||||
"features" header (E0006 otherwise); the feature table and dependency
|
||||
closure are in docs/reference/air-features.md.
|
||||
|
||||
Name spaces
|
||||
-----------
|
||||
@@ -17,7 +20,8 @@
|
||||
module scope; block labels are scoped to their function. A label
|
||||
reference appears only in branch targets, so it never clashes
|
||||
with a function name.
|
||||
- bare field names, variant names, module path segments, effect names.
|
||||
- bare field names, variant names, module path segments, effect names,
|
||||
capability kinds, intrinsic names, edge roles.
|
||||
*)
|
||||
|
||||
module = { NL } header { NL } { declaration { NL } } ;
|
||||
@@ -25,7 +29,7 @@ module = { NL } header { NL } { declaration { NL } } ;
|
||||
header = "module" path NL
|
||||
"air" int_lit NL (* AIR text format version; this file defines 0 *)
|
||||
"lang" version_lit NL (* Aji semantic version, e.g. 0.1 *)
|
||||
"features" "[" [ path_list ] "]" NL ; (* required feature names; empty in format 0 *)
|
||||
"features" "[" [ path_list ] "]" NL ; (* required features and their full dependency closure *)
|
||||
|
||||
declaration = type_decl | function ;
|
||||
|
||||
@@ -34,6 +38,8 @@ struct_type = "struct" "{" [ field { "," field } [ "," ] ] "}" ;
|
||||
field = ident ":" type ;
|
||||
enum_type = "enum" "{" variant { "," variant } [ "," ] "}" ;
|
||||
variant = ident [ "(" [ type { "," type } ] ")" ] ;
|
||||
(* Linear types as fields, payloads or elements need features
|
||||
that are reserved in format 0; see air-features.md. *)
|
||||
|
||||
function = "fn" global "(" [ param_list ] ")" "->" type [ "from" local ] NL (* from: feature ownership *)
|
||||
"effects" "[" [ path_list ] "]" NL
|
||||
@@ -60,8 +66,24 @@ operation = "const." int_type int_lit
|
||||
| "call" global "(" [ local_list ] ")"
|
||||
| ownership_op
|
||||
| arrays_op
|
||||
| capability_op
|
||||
| heap_op
|
||||
| region_op
|
||||
| task_op
|
||||
| cancellation_op
|
||||
| channel_op
|
||||
| sync_op
|
||||
| graph_op
|
||||
| terminator ;
|
||||
|
||||
(* Several instructions are terminators with named outgoing edges (spec 07a).
|
||||
Each edge names a block of the same function; the instruction's results
|
||||
arrive as that block's parameters, so an edge carries no arguments. *)
|
||||
edge = role "->" global ;
|
||||
role = "ok" | "err" | "closed" | "cancelled" | "pending" ;
|
||||
ok_err = "," "ok" "->" global "," "err" "->" global ;
|
||||
ok_cancelled = "," "ok" "->" global "," "cancelled" "->" global ;
|
||||
|
||||
(* Feature ownership (spec 07a). *)
|
||||
ownership_op = "local.alloc" type
|
||||
| "local.store" local "," local
|
||||
@@ -86,6 +108,69 @@ arrays_op = "array.splat" type local
|
||||
| "assume" local (* feature unsafe *)
|
||||
| "borrow.index.unchecked" local "," local ; (* feature unsafe *)
|
||||
|
||||
(* Feature capabilities (spec 05 §10–§12, reference/intrinsics.md). *)
|
||||
capability_op = "cap.narrow." ident local { "," local } ok_err (* terminator; form registered for the kind *)
|
||||
| "intrinsic" path "(" [ local_list ] ")" [ ok_err ] ; (* fallible intrinsics are terminators;
|
||||
resource intrinsics need feature resources *)
|
||||
|
||||
(* Feature heap (spec 03 §18–§19). *)
|
||||
heap_op = "own.new" local "," local ok_err (* terminator: value, cap<mem.alloc> *)
|
||||
| "own.array" local "," local "," local ok_err (* terminator: count, element, cap<mem.alloc> *)
|
||||
| "own.take" local
|
||||
| "own.free" local ;
|
||||
|
||||
(* Feature regions (spec 03 §20). *)
|
||||
region_op = "region.create" local ok_err (* terminator: cap<mem.alloc> *)
|
||||
| "region.new" local "," local ok_err (* terminator: region borrow, value *)
|
||||
| "region.array" local "," local "," local ok_err (* terminator: region borrow, count, element *)
|
||||
| "region.reset" local
|
||||
| "region.destroy" local ;
|
||||
|
||||
(* Feature tasks (spec 04 §33–§36). *)
|
||||
task_op = "task.scope.begin"
|
||||
| "task.spawn" local "," global "(" [ local_list ] ")"
|
||||
| "task.join" local
|
||||
| "task.cancel" local
|
||||
| "task.cancelled"
|
||||
| "task.scope.end" local ;
|
||||
|
||||
(* Feature cancellation (spec 04 §37). *)
|
||||
cancellation_op = "task.check_cancel" ok_cancelled (* terminator *)
|
||||
| "task.join.cancel" local ok_cancelled (* terminator *)
|
||||
| "task.shield.begin"
|
||||
| "task.shield.end" local ;
|
||||
|
||||
(* Feature channels (spec 04 §38–§39). *)
|
||||
channel_op = "channel.make" type "," local "," local ok_err (* terminator: element type, capacity, cap<mem.alloc> *)
|
||||
| "channel.sender.dup" local
|
||||
| "channel.send" local "," local "," "ok" "->" global "," "closed" "->" global "," "cancelled" "->" global
|
||||
| "channel.recv" local "," "ok" "->" global "," "closed" "->" global "," "cancelled" "->" global
|
||||
| "channel.close_sender" local
|
||||
| "channel.close_receiver" local "," "ok" "->" global "," "pending" "->" global
|
||||
| "select" select_arm { select_arm } "cancelled" "->" global ; (* terminator *)
|
||||
select_arm = "[" ( "recv" local | "send" local "," local )
|
||||
"," "ok" "->" global "," "closed" "->" global "]" "," ;
|
||||
(* send, recv and close_receiver are terminators *)
|
||||
|
||||
(* Feature sync (spec 04 §40–§41). *)
|
||||
sync_op = "mutex.make" local
|
||||
| "mutex.take" local
|
||||
| "mutex.lock" local ok_cancelled (* terminator *)
|
||||
| "mutex.borrow" local
|
||||
| "mutex.unlock" local ;
|
||||
|
||||
(* Features islands and arc (spec 03 §22–§24). *)
|
||||
graph_op = "island.create" local "," local ok_err (* terminator: root value, cap<mem.alloc> *)
|
||||
| "island.alloc" local "," local ok_err (* terminator: mut<island<T>>, value *)
|
||||
| ( "island.root" | "frozen.root" | "arc.root" ) local
|
||||
| ( "island.borrow" | "frozen.borrow" | "arc.borrow" ) local "," local (* owner borrow, iref *)
|
||||
| "island.freeze" local
|
||||
| "island.destroy" local
|
||||
| "frozen.release" local
|
||||
| "iref.eq" local "," local
|
||||
| "arc.new" local "," local ok_err (* feature arc; terminator: root value, cap<mem.alloc> *)
|
||||
| ( "arc.from_frozen" | "arc.clone" | "arc.release" ) local ; (* feature arc *)
|
||||
|
||||
arith_op = ( "add" | "sub" | "mul" ) "." ( "checked" | "wrap" ) "." int_type
|
||||
| ( "div" | "rem" ) ".checked." int_type
|
||||
| ( "and" | "or" | "xor" ) "." ( int_type | "bool" )
|
||||
@@ -98,7 +183,7 @@ cast_mode = "checked" | "wrap" | "widen" ;
|
||||
terminator = "br" target
|
||||
| "cbr" local "," target "," target
|
||||
| "switch." int_type local "," { int_lit "->" target "," } "default" "->" target
|
||||
| "enum.switch" global local "," enum_arm { "," enum_arm } [ "," "default" "->" target ]
|
||||
| "enum.switch" ( global | builtin_type ) local "," enum_arm { "," enum_arm } [ "," "default" "->" target ]
|
||||
| "ret" [ local ]
|
||||
| "trap" ;
|
||||
enum_arm = ident "->" global ; (* target block receives the variant payload as parameters *)
|
||||
@@ -107,7 +192,22 @@ target = global "(" [ local_list ] ")" ;
|
||||
type = int_type | "bool" | "void" | "never" | global
|
||||
| ( "local" | "ref" | "mut" ) "<" type ">" (* feature ownership *)
|
||||
| "array" "<" type "," int_lit ">" (* feature arrays; ";" starts a comment, so source syntax [T; N] is spelled array<T, N> *)
|
||||
| ( "slice" | "slice_mut" ) "<" type ">" ; (* feature arrays *)
|
||||
| ( "slice" | "slice_mut" ) "<" type ">" (* feature arrays *)
|
||||
| "cap" "<" path ">" (* feature capabilities; a capability kind, e.g. cap<fs.read> *)
|
||||
| "file" "<" ( "read" | "write" | "append" ) ">" (* feature resources *)
|
||||
| "listener" | "stream" (* feature resources *)
|
||||
| ( "own" | "own_array" ) "<" type ">" (* feature heap *)
|
||||
| "region" (* feature regions *)
|
||||
| "scope" | "task" "<" type ">" (* feature tasks *)
|
||||
| "shield" (* feature cancellation *)
|
||||
| ( "sender" | "receiver" ) "<" type ">" (* feature channels *)
|
||||
| ( "mutex" | "guard" ) "<" type ">" (* feature sync *)
|
||||
| ( "island" | "frozen" | "iref" ) "<" type ">" (* feature islands *)
|
||||
| "arc" "<" type ">" (* feature arc *)
|
||||
| builtin_type ;
|
||||
builtin_type = "cap_error" (* feature capabilities *)
|
||||
| "alloc_error" (* feature heap *)
|
||||
| "io_error" ; (* feature resources *)
|
||||
int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
||||
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ;
|
||||
(* "f32" and "f64" are reserved; see spec 07 §8.4. "byte" is not an AIR type: frontends lower it to u8. *)
|
||||
|
||||
Reference in new issue
Block a user