Skip to content

Commit

Permalink
feat: add standard writing to syscalls
Browse files Browse the repository at this point in the history
nawetimebomb committed Sep 21, 2024
1 parent f3aac39 commit db3570a
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion compiler/frontend.go
Original file line number Diff line number Diff line change
@@ -434,6 +434,8 @@ func newSyscall(token Token) {
code.op = OP_SYSCALL
code.loc = token.loc

consume(TOKEN_PAREN_OPEN, MsgParseSyscallMissingOpenStmt)

for !check(TOKEN_PAREN_CLOSE) && !check(TOKEN_EOF) {
advance()
var arg DataType
@@ -453,7 +455,7 @@ func newSyscall(token Token) {
value = append(value, arg)
}
code.value = value
consume(TOKEN_PAREN_CLOSE, "TODO: handle error")
consume(TOKEN_PAREN_CLOSE, MsgParseSyscallMissingCloseStmt)
emit(code)
}

9 changes: 9 additions & 0 deletions compiler/msgs.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,15 @@ const (
"\t\tbind ( a b c )\n" +
"\t\t ^"

MsgParseSyscallMissingCloseStmt =
"missing ')'\n" +
"\t\tsyscall ( int int )\n" +
"\t\t ^"
MsgParseSyscallMissingOpenStmt =
"missing '('\n" +
"\t\tsyscall ( int int )\n" +
"\t\t ^"

MsgParseDoOrphanTokenFound =
"only use 'do' when starting a block statement\nE.g.:\n\tif [condition] do [...] else [...] .\n\t^^ ^^\n'do' can be used in other blocks like function and loops"

8 changes: 4 additions & 4 deletions libs/io.sk
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ fn clear (
fn eputs ptr (
dup strlen swap
STDERR LINUX_WRITE
syscall int ptr int int )
syscall ( int ptr int int )
)

fn error ptr (
@@ -93,13 +93,13 @@ fn error ptr (

fn exit int (
LINUX_EXIT
syscall int int )
syscall ( int int )
)

fn* print ptr (
dup strlen swap
STDOUT LINUX_WRITE
syscall int ptr int int )
syscall ( int ptr int int )
)

fn* print int (
@@ -131,5 +131,5 @@ fn* println bool (

fn read int ptr -> int (
STDIN LINUX_READ
syscall int ptr int int )
syscall ( int ptr int int )
)

0 comments on commit db3570a

Please sign in to comment.