Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 251 additions & 48 deletions src/codegen.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ mod tests {

#[test]
fn test_float_literal_decimal() {
let mut lexer = Lexer::new("X = 3.14159");
let mut lexer = Lexer::new("X = 1.23456");
let tokens = lexer.tokenize().unwrap();
assert_eq!(tokens[2], Token::Float(3.14159));
assert_eq!(tokens[2], Token::Float(1.23456));
}

#[test]
Expand Down Expand Up @@ -783,13 +783,13 @@ mod tests {

#[test]
fn test_function_call() {
let mut lexer = Lexer::new("X = SIN(3.14) + COS(0)");
let mut lexer = Lexer::new("X = SIN(1.23) + COS(0)");
let tokens = lexer.tokenize().unwrap();
assert_eq!(tokens[0], Token::Ident("X".to_string()));
assert_eq!(tokens[1], Token::Eq);
assert_eq!(tokens[2], Token::Ident("SIN".to_string()));
assert_eq!(tokens[3], Token::LParen);
assert_eq!(tokens[4], Token::Float(3.14));
assert_eq!(tokens[4], Token::Float(1.23));
assert_eq!(tokens[5], Token::RParen);
assert_eq!(tokens[6], Token::Plus);
assert_eq!(tokens[7], Token::Ident("COS".to_string()));
Expand Down
1 change: 1 addition & 0 deletions src/runtime/sysv/data_defs.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ _chr_buf: .skip 2
_str_buf: .skip 64
_rng_state: .quad 0x12345678DEADBEEF
_cls_seq: .asciz "\033[2J\033[H"
_gosub_overflow_msg: .asciz "Error: GOSUB stack overflow\n"
19 changes: 19 additions & 0 deletions src/runtime/sysv/print.s
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,22 @@ _rt_print_float:
.Lprint_float_done:
leave
ret

# ------------------------------------------------------------------------------
# _rt_gosub_overflow - Handle GOSUB stack overflow error
# ------------------------------------------------------------------------------
# Called when the GOSUB return stack is exhausted. Prints an error message
# and terminates the program with exit code 1.
#
# Arguments: none
# Returns: never (calls exit)
# ------------------------------------------------------------------------------
.globl _rt_gosub_overflow
_rt_gosub_overflow:
push rbp
mov rbp, rsp
lea rdi, [rip + _gosub_overflow_msg]
xor eax, eax
call {libc}printf
mov edi, 1 # exit code 1
call {libc}exit
4 changes: 4 additions & 0 deletions src/runtime/win64-native/data_defs.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
_fmt_int: .asciz "%lld"
_fmt_float: .asciz "%g"

# Error messages
_gosub_overflow_msg: .ascii "Error: GOSUB stack overflow\r\n"
.equ _gosub_overflow_msg_len, 30

30 changes: 30 additions & 0 deletions src/runtime/win64-native/print.s
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,33 @@ _rt_print_float:

leave
ret

# ------------------------------------------------------------------------------
# _rt_gosub_overflow - Handle GOSUB stack overflow error
# ------------------------------------------------------------------------------
# Called when the GOSUB return stack is exhausted. Prints an error message
# and terminates the program with exit code 1.
#
# Arguments: none
# Returns: never (calls ExitProcess)
# ------------------------------------------------------------------------------
.globl _rt_gosub_overflow
_rt_gosub_overflow:
push rbp
mov rbp, rsp
sub rsp, 48

# Get stdout handle
lea rax, [rip + _stdout_handle]
mov rcx, [rax]

# WriteFile(handle, message, length, &bytesWritten, NULL)
lea rdx, [rip + _gosub_overflow_msg]
mov r8, _gosub_overflow_msg_len
lea r9, [rip + _bytes_written]
mov QWORD PTR [rsp + 32], 0
call WriteFile

# ExitProcess(1)
mov ecx, 1
call ExitProcess
Loading