From ebc0b98929dde4f85488d9fc28afd6ac9555e530 Mon Sep 17 00:00:00 2001 From: Tj Campanella Date: Wed, 24 Apr 2024 22:23:10 -0400 Subject: [PATCH] Update error messages --- example-asm/digit | Bin 33464 -> 33480 bytes example-asm/digit.s | 23 +++++++++++++++++------ example-asm/test.txt | Bin 0 -> 25 bytes examples/stack.rorth | 2 ++ src/main.rs | 27 ++++++++------------------- 5 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 example-asm/test.txt diff --git a/example-asm/digit b/example-asm/digit index 700074948fca955d274741a8c16cf3c70ddd22a8..21174b5b05d1e3cfa3a3241f3a05bdeb85a6f745 100755 GIT binary patch delta 454 zcmdnd%5qJe?I14wfNaR3m5 z04o$T0crNhjZEPLFP|BJIQFl=Z6$~Q4JTykPyKHb8=-2IT5Wt9R$!=(v8 z%qYNcg#k!U_OLhOm;V8DZ^Q#2edYiE>6a(>+M6@p*nHG}wS(u4TA(dJAPdBNKu^K^ zrVQaTy@C4G0LoXehxpwJ#AgN)4iLWG*GXn_+2;XG# z&W3o=ywY5TywviX%)C^f6ckL>ZM0%lP+(%<0s2W@9~L5vDVgb+B@9gmYG&_anfH66 z^unEYJbf~yM5J?PmMdrGa(7$ F8~{{)gaiNp diff --git a/example-asm/digit.s b/example-asm/digit.s index 4a50d40..340a8cf 100644 --- a/example-asm/digit.s +++ b/example-asm/digit.s @@ -7,7 +7,7 @@ print: add x0, x0, num@PAGEOFF // Load value from the stack. - ldr x1, [sp], #64 + ldr x1, [sp], #16 // Convert number in x1 to its ASCII representation mov x2, #10 // Base 10 @@ -28,21 +28,32 @@ convert_loop: mov x1, x4 // Update x1 with quotient cmp x1, #0 // Check if quotient is zero - bne convert_loop // If not zero, continue loop + beq zero_done // If quotient is zero, terminate early + cmp x3, #0 // Check if index is zero + beq zero_done // If index is zero, terminate early + + b convert_loop // If not zero, continue loop + +zero_done: // Recompute the address of num adrp x4, num@PAGE add x4, x4, num@PAGEOFF - mov x1, x4 // Load the correct address into x1 + // Find the actual length of the converted number + mov x2, #20 // Length of num + sub x2, x2, x3 // Subtract remaining index from the total length + add x4, x4, x3 // Move the address forward by the remaining index + + mov x1, x4 // Load the correct address into x1 mov x0, #1 // 1 = StdOut - mov x2, #20 // Length of num mov x16, #4 // Unix write system call svc #0x80 // Call kernel to output the string // Print newline character + mov x0, #0 adrp x0, newline@PAGE add x0, x0, newline@PAGEOFF @@ -65,11 +76,11 @@ loop: _start: // push ldr x0, =34 - str x0, [sp, #-64]! + str x0, [sp, #-16]! // push ldr x0, =12345678912345678912 - str x0, [sp, #-64]! + str x0, [sp, #-16]! bl print diff --git a/example-asm/test.txt b/example-asm/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..5dc20852cceabf4a69fc9c34c49b526a8ad709c2 GIT binary patch literal 25 XcmZQDGBzA*j7_)zJQW0J literal 0 HcmV?d00001 diff --git a/examples/stack.rorth b/examples/stack.rorth index a7ac2cb..62726c2 100644 --- a/examples/stack.rorth +++ b/examples/stack.rorth @@ -22,3 +22,5 @@ 10 20 < print // prints 1 100 20 < print // prints 0 + +2 rot diff --git a/src/main.rs b/src/main.rs index f7ecd7a..7970461 100644 --- a/src/main.rs +++ b/src/main.rs @@ -312,7 +312,7 @@ fn simulate_program(program: &[Op]) { } ip += 1; } - OpKind::If => { + OpKind::If | OpKind::Do => { if let Some(a) = stack.pop() { if a == 1 { ip += 1; @@ -326,17 +326,6 @@ fn simulate_program(program: &[Op]) { OpKind::While => { ip += 1; } - OpKind::Do => { - if let Some(a) = stack.pop() { - if a == 1 { - ip += 1; - } else if let Some(ind) = op.value { - if let Ok(ind) = ind.try_into() { - ip = ind; - } - } - } - } OpKind::End => { if let Some(ind) = op.value { if let Ok(ind) = ind.try_into() { @@ -562,7 +551,7 @@ fn compile_program_darwin_arm64(program: &[Op], filename: &str) { fn main() { let args: Vec = env::args().collect(); if args.len() < 3 { - eprintln!("[ERROR] You have to pass in a mode and a file path."); + eprintln!("ERROR: You have to pass in a mode and a file path."); eprintln!("Usage: rorth [OPTIONS] [ARGS]"); eprintln!(" SUBCOMMAND:"); eprintln!(" sim Simulate the program"); @@ -583,7 +572,7 @@ fn main() { } else if &args[2] == "-s" { silence_flag = true; } else { - eprintln!("[ERROR] Unknown option: {}", &args[2]); + eprintln!("ERROR: Unknown option: {}", &args[2]); eprintln!("Usage: rorth [OPTIONS] [ARGS]"); eprintln!(" SUBCOMMAND:"); eprintln!(" sim Simulate the program"); @@ -598,7 +587,7 @@ fn main() { if args.len() > 4 { if &args[2] != "-r" && &args[2] != "-s" { - eprintln!("[ERROR] Unknown option: {}", &args[2]); + eprintln!("ERROR: Unknown option: {}", &args[2]); eprintln!("Usage: rorth [OPTIONS] [ARGS]"); eprintln!(" SUBCOMMAND:"); eprintln!(" sim Simulate the program"); @@ -610,7 +599,7 @@ fn main() { } if &args[3] != "-r" && &args[3] != "-s" { - eprintln!("[ERROR] Unknown option: {}", &args[3]); + eprintln!("ERROR: Unknown option: {}", &args[3]); eprintln!("Usage: rorth [OPTIONS] [ARGS]"); eprintln!(" SUBCOMMAND:"); eprintln!(" sim Simulate the program"); @@ -691,7 +680,7 @@ fn main() { } if let Some(err) = res.err() { - eprintln!("[ERROR] Failed to execute compiled program: {err}"); + eprintln!("ERROR: Failed to execute compiled program: {err}"); } } } @@ -699,11 +688,11 @@ fn main() { } } } else { - eprintln!("[ERROR] Unknown mode '{mode}'"); + eprintln!("ERROR: Unknown mode '{mode}'"); exit(1); } } else { - eprintln!("[ERROR] Cannot read file: {filename}"); + eprintln!("ERROR: Cannot read file: {filename}"); exit(1); } }