Ore A language and a compiler built from scratch.
The compiler
From source
to binary.
Ore turns source directly into machine code and writes the executable itself. In this example, the loop adds three integers and passes the total to Windows as the exit code.
#import[kernel32.dll][ExitProcess] EXIT(integer:u32 code) {
#contract[code <= 255]
}
{
integer[3] values = {2, 3, 4}
integer total = 0
loop (integer i = 1, i <= #count(values), i += 1) {
total += values[i]
}
EXIT(total)
}.\ore.exe sum.ore1031 8b 44 24 38 mov eax, [rsp + 0x38]
1035 41 ba 03 00 00 00 mov r10d, 3
103b 44 39 d0 cmp eax, r10d
103e 7f 28 jg 0x1068
1040 8b 44 24 30 mov eax, [rsp + 0x30]
1044 44 8b 54 24 38 mov r10d, [rsp + 0x38]
1049 46 8b 54 94 1c mov r10d, [rsp + 4*r10 + 0x1c]
104e 44 01 d0 add eax, r10dLearn
Start with
a program.
Read a complete file, then look up the pieces you want to understand.
Print a lineCall Windows through an import
The program gets a handle for standard output, writes seven bytes, and exits.
#import[kernel32.dll][GetStdHandle] pointer:64 STD_HANDLE(integer:i32 which) {
#contract[which == -11]
}
#import[kernel32.dll][WriteFile] WRITE(pointer:64 file, string:8 text, integer:u32 size, pointer:64 written, pointer:64 overlapped) {
#contract[size <= 7]
}
#import[kernel32.dll][ExitProcess] EXIT(integer:u32 code) {
#contract[code == 0]
}
{
integer:u32[1] written
WRITE(STD_HANDLE(-11), "Hello{{46}}{{10}}", 7, written, null)
EXIT(0)
}Sum an arrayStart at 1 and use the count as your bound
The array has three items. To change the number of items, update the declaration and initializer. The loop bound follows #count(values).
Read an errorFind the index the compiler can’t prove
Try indexing a three-item array with 4. Inspect the line the compiler points to, then bring the index back into range.
Reference
Look it up.
Declarations and memory access in Ore, alongside instructions from three target architectures.
Language
#import- Declare a function from an external library.
#contract- State a condition about a value.
#at- Access memory at an address.
Assembly
x86_64ADDadds a source operand to its destination.arm_64ADDadds two operands and writes a register.wasm_32i32.addadds two 32-bit stack values.
Project direction
Where Ore
goes next.
Keep the language small enough to read years later. Work out what the compiler can prove before a program runs. Make it easy to inspect the instructions and storage a build produces.