(* Aji text AIR, format version 0. Normative together with docs/spec/07-air.md §8 and docs/spec/07a-air-instructions.md. Lexical conventions ------------------- - A comment starts with ";" and runs to the end of the line. - Line breaks are significant: each header line, declaration header, block label and instruction ends with NL. Line breaks inside "(" ")", "[" "]" and "{" "}" are ignored. - Spaces and tabs separate tokens and are otherwise insignificant. - Opcodes are written as one dotted word, e.g. "add.checked.u64". Name spaces ----------- - "%name" SSA value, scoped to its function. - "@name" function, type or block label. Functions and types share the 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. *) 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 *) declaration = type_decl | function ; type_decl = "type" global "=" ( struct_type | enum_type ) NL ; struct_type = "struct" "{" [ field { "," field } [ "," ] ] "}" ; field = ident ":" type ; enum_type = "enum" "{" variant { "," variant } [ "," ] "}" ; variant = ident [ "(" [ type { "," type } ] ")" ] ; function = "fn" global "(" [ param_list ] ")" "->" type NL "effects" "[" [ path_list ] "]" NL block { block } ; param_list = param { "," param } ; param = local ":" type ; block = ident [ "(" [ param_list ] ")" ] ":" NL { instruction NL } ; (* The first block is the entry block and takes no parameters. *) instruction = [ local "=" ] operation ; operation = "const." int_type int_lit | "const.bool" ( "true" | "false" ) | "copy" local | arith_op local "," local | "assert" local | "cast." cast_mode "." int_type local | "struct.make" global "(" [ local_list ] ")" | "struct.get" global "." ident "," local | "enum.make" global "." ident "(" [ local_list ] ")" | "call" global "(" [ local_list ] ")" | terminator ; arith_op = ( "add" | "sub" | "mul" ) "." ( "checked" | "wrap" ) "." int_type | ( "div" | "rem" ) ".checked." int_type | ( "and" | "or" | "xor" ) "." ( int_type | "bool" ) | ( "shl" | "shr" ) "." int_type | ( "eq" | "ne" ) "." ( int_type | "bool" ) | ( "lt" | "le" | "gt" | "ge" ) "." int_type ; 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 ] | "ret" [ local ] | "trap" ; enum_arm = ident "->" global ; (* target block receives the variant payload as parameters *) target = global "(" [ local_list ] ")" ; type = int_type | "bool" | "void" | "never" | global ; 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. *) local_list = local { "," local } ; path_list = path { "," path } ; path = ident { "." ident } ; local = "%" name_char { name_char } ; global = "@" ident ; (* no dots inside a global name *) ident = ( letter | "_" ) { name_char } ; name_char = letter | digit | "_" ; int_lit = [ "-" ] ( dec_digits | "0x" hex_digits | "0b" bin_digits ) ; (* "_" may separate digits; it carries no meaning. *) version_lit = digit { digit } "." digit { digit } ;