Compiler Progress!

A short post showing off named arguments in my compiler

Posted Dec 03 2024

Written Oct 19 2022


Originally posted on Cohost.

Here's the main result of what I've been working on! (Apart from some use-after-frees and allocator bugs :P)

Function calls with named arguments!
Lace code
Main ::= function do
	Standard_Out : File_Descriptor := 1

	Write (
		File    => Standard_Out,
		Message => "Hello world!\n",
	)
end

File_Descriptor ::= range 0 .. 2^64 - 1
Byte            ::= mod 2^8
Index           ::= range 1 .. 2^64 - 1
Byte_String     ::= array [Index range <>] of Byte

Write ::= function (
	File    : File_Descriptor,
	Message : access Byte_String,
) do
	@​inline "rax" := 1
	@​inline "rdi" := File
	@​inline "rsi" := Message ['first]'access
	@​inline "rdx" := Message'length
	@​inline "Syscall"
end

This is usually one of my favorite features of any programming language that has it so I definitely planned to have this in for a while.

This brings the parsing of aggregates and function arguments much closer together, thus simplifying my parser a bit.

(aggregate syntax)
Lace code
Foo : Some_Aggregate_Type := {
	Bar => "Baz"
}