| | @@ -9,7 +9,7 @@ |
| 9 | 9 | This report defines the language. It is short on purpose. Whatever it |
| 10 | 10 | doesn't allow, raz doesn't have. |
| 11 | 11 | |
| 12 | | -This is version 2026-10.11 of the report; section 12 says what each |
| 12 | +This is version 2026-10.12 of the report; section 12 says what each |
| 13 | 13 | version changed. It is a thaw the owner chose, for a language anyone |
| 14 | 14 | can build again, and it breaks programs written for 2026-10.10. |
| 15 | 15 | The compiler follows version 2026-10.10 until it is brought to this |
| | @@ -964,7 +964,7 @@ |
| 964 | 964 | ``` |
| 965 | 965 | ProcDeclaration = "proc" IdentDef Signature ";" |
| 966 | 966 | ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ] |
| 967 | | - | "code" Expr { "," Expr } ) . |
| 967 | + | "code" { [ ident ":" ] [ Instruction ] ";" } "end" [ ident ] ) . |
| 968 | 968 | LocalDeclaration = "const" { ident [ ":" Type ] "=" Expr ";" } |
| 969 | 969 | | "type" { ident "=" Type ";" } |
| 970 | 970 | | "var" { ident { "," ident } ":" Type ";" } . |
| | @@ -1017,25 +1017,34 @@ |
| 1017 | 1017 | |
| 1018 | 1018 | Procedures don't nest. |
| 1019 | 1019 | |
| 1020 | | -**Code procedures.** A procedure whose body is `code` and a list of |
| 1021 | | -constant bytes is machine code, written by hand: |
| 1020 | +**Code procedures.** A procedure whose body is `code` is machine code, |
| 1021 | +written by hand in the target's assembly language (appendix A): one |
| 1022 | +instruction to each `;`, and labels for jumps, up to `end`: |
| 1022 | 1023 | |
| 1023 | 1024 | ``` |
| 1024 | 1025 | proc rdtsc*: U64; |
| 1025 | | -code 0FH, 31H, (* rdtsc *) |
| 1026 | | - 48H, 0C1H, 0E2H, 20H, (* shl rdx, 32 *) |
| 1027 | | - 48H, 09H, 0D0H, (* or rax, rdx *) |
| 1028 | | - 0C3H; (* ret *) |
| 1026 | +code |
| 1027 | + rdtsc; |
| 1028 | + shl rdx, 32; |
| 1029 | + or rax, rdx; |
| 1030 | + ret; |
| 1031 | +end rdtsc; |
| 1029 | 1032 | ``` |
| 1030 | 1033 | |
| 1034 | +A label, `name:`, names the place of the instruction after it, within |
| 1035 | +the procedure. A constant of the module may stand wherever a number |
| 1036 | +does. Any bytes may be written with `db`, as in `db 0FH, 31H;`, for an |
| 1037 | +instruction the assembler doesn't know. |
| 1038 | + |
| 1031 | 1039 | It is called like any procedure, with the System V convention: integer |
| 1032 | 1040 | and pointer arguments arrive in `rdi`, `rsi`, `rdx`, `rcx`, `r8` and |
| 1033 | 1041 | `r9`, `F32` and `F64` ones in `xmm0` to `xmm7`, and the result goes in |
| 1034 | 1042 | `rax` (and `rdx` for a second) or `xmm0`. Its parameters and results |
| 1035 | 1043 | are therefore of the types C can take (section 9), at most six integer |
| 1036 | | -and eight real parameters, and at most two results. The bytes are the whole |
| 1037 | | -procedure, `ret` included; they must keep `rbx`, `rbp`, `rsp` and `r12` |
| 1038 | | -to `r15` as they found them. The compiler doesn't look inside them. |
| 1044 | +and eight real parameters, and at most two results. The instructions |
| 1045 | +are the whole procedure, `ret` included; they must keep `rbx`, `rbp`, |
| 1046 | +`rsp` and `r12` to `r15` as they found them. The compiler doesn't look |
| 1047 | +past what they say. |
| 1039 | 1048 | |
| 1040 | 1049 | ## 9. Calling C |
| 1041 | 1050 | |
| | @@ -1725,6 +1734,8 @@ |
| 1725 | 1734 | 11). An array constant has a type and is used as a variable that |
| 1726 | 1735 | can't be changed; `+` joins string constants (section 4). `match` |
| 1727 | 1736 | takes an integer, with constants and ranges as labels (7.4). |
| 1737 | +- **2026-10.12.** A code procedure is written in the target's assembly |
| 1738 | + language, not as bytes (section 8; appendix A). |
| 1728 | 1739 | |
| 1729 | 1740 | ## Appendix A. What an implementation chooses |
| 1730 | 1741 | |
| | @@ -1753,10 +1764,17 @@ |
| 1753 | 1764 | several results, and how its frame is laid out, are the |
| 1754 | 1765 | implementation's. |
| 1755 | 1766 | - **What is the target's.** Code procedures (section 8) hold the |
| 1756 | | - target's machine code, and exist only where the implementation says |
| 1757 | | - so; `SYSCALL` exists only on Linux targets (section 6.8). A record's |
| 1767 | + target's machine code, written in its assembly language, and exist |
| 1768 | + only where the implementation says so; `SYSCALL` exists only on Linux targets (section 6.8). A record's |
| 1758 | 1769 | layout is the target's C layout (section 5.5), and the order of a |
| 1759 | 1770 | value's bytes is the target's (little-endian on x86-64). |
| 1771 | +- **The assembly language.** How a code procedure's instructions are |
| 1772 | + written (section 8). On x86-64 it is Intel's syntax, as NASM writes |
| 1773 | + it: the destination first; registers by name (`rax`, `eax`, `al`, |
| 1774 | + `xmm0`); memory as `[base + index * scale + disp]`, with `byte`, |
| 1775 | + `word`, `dword` or `qword` before it where no register says the |
| 1776 | + size; `lock` before an instruction. Which instructions it knows is |
| 1777 | + the implementation's; `db` gives any others. |
| 1760 | 1778 | - **Sizes in the library.** How many bytes `Out` keeps before it |
| 1761 | 1779 | writes them, `Sys.outSize` (section 11): 4 KB on Linux, fewer on a |
| 1762 | 1780 | small machine. |
| | @@ -1866,7 +1884,7 @@ |
| 1866 | 1884 | |
| 1867 | 1885 | ProcDeclaration = "proc" IdentDef Signature ";" |
| 1868 | 1886 | ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ] |
| 1869 | | - | "code" Expr { "," Expr } ) . |
| 1887 | + | "code" { [ ident ":" ] [ Instruction ] ";" } "end" [ ident ] ) . |
| 1870 | 1888 | LocalDeclaration = "const" { ident [ ":" Type ] "=" Expr ";" } |
| 1871 | 1889 | | "type" { ident "=" Type ";" } |
| 1872 | 1890 | | "var" { ident { "," ident } ":" Type ";" } . |
| | @@ -1882,4 +1900,5 @@ |
| 1882 | 1900 | but `"` and `\`, in a character any but `'` and `\`. A procedure |
| 1883 | 1901 | argument of a generic module (section 3) is written as a `QualIdent`, |
| 1884 | 1902 | which is a `Type` here. `...` comes last in a `Signature`, and only in |
| 1885 | | -an `extern`. |
| 1903 | +an `extern`. An `Instruction` is written in the target's assembly |
| 1904 | +language (appendix A). |