Finalising functions

typechecking still buggy, but close enough cause i cant handle any more
typechecker dev

added:
 - Functions
 - Constants
 - Better file positions for error reporting
 - Better error reporting, with examples being drawn in term

-MC
This commit is contained in:
MCorange
2023-04-13 00:34:08 +03:00
parent 63636e1f83
commit 7e46c07cca
20 changed files with 744 additions and 430 deletions

View File

@@ -1 +1 @@
// todo: add some sort of macro
// todo: add some sort of macrow

View File

@@ -2,13 +2,12 @@ const NULL 0 end
const false 0 end
const true 1 end
fn div with int int returns int int divmod drop end
fn mod with int int returns int int divmod swap drop end
fn / with int int returns int int div end
fn % with int int returns int int mod end
fn div with int int returns int then divmod drop done
fn mod with int int returns int then divmod swap drop done
fn 2dup with any any returns any over over end
fn 2drop with any any returns any drop drop end
fn dup2 with any any returns any any any any then over over done
fn drop2 with any any returns void then drop drop done
const sizeof(u64) 8 end
const sizeof(u32) 4 end

View File

@@ -5,9 +5,9 @@
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @arg fd: Int - file descriptor
// @ret Int
fn write with int ptr int returns int do
fn write with int ptr int returns int then
SYS_write syscall3
end
done
// Write to a file descriptor using the SYS_write syscall
// args: [buff_size, buff_ptr, fd]
@@ -15,9 +15,9 @@ end
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @arg fd: Int - file descriptor
// @ret Int
fn read with int ptr int returns int do
fn read with int ptr int returns int then
SYS_read syscall3
end
done
// Print a string to STDOUT
@@ -25,18 +25,18 @@ end
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @ret NULL
fn puts with int ptr returns null do
fn puts with int ptr returns void then
STDOUT write drop
end
done
// Print a string to STDERR
// args: [str_size, str_ptr]
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @ret NULL
fn eputs with int ptr returns null do
fn eputs with int ptr returns void then
STDOUT write drop
end
done
// TODO: make putc and eputc after we make local mem
@@ -44,7 +44,7 @@ end
// args: [exit_code]
// @arg exit_code: Int
// @ret NULL/NEVER
fn exit with int returns null do
fn exit with int returns void then
SYS_exit syscall1 drop
end
done

View File

@@ -5,11 +5,11 @@
// @arg str_len: Int
// @arg str_ptr: Ptr
// @ret NULL/NEVER
fn assert with bool int ptr returns null do
fn assert with bool int ptr returns void then
rot
if else
"Assert failed: \"" eputs eputs
"\". Exiting!\n" eputs
1 exit
end
end
done