From 81662aa56b8ad2fa397b1d3e9dd3bb398c7d1798 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 Jun 2024 16:01:46 +0100 Subject: print -> puts --- com.c | 8 ++++---- dis.c | 2 +- tests/fizzbuzz.bth | 2 +- tests/vars.bth | 8 ++++---- vm.c | 2 +- vm.h | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/com.c b/com.c index 93b0b59..6ffd7c2 100644 --- a/com.c +++ b/com.c @@ -53,10 +53,10 @@ static void compile_node(State *S, Chunk *ch, AstNode a) { char *name = l.vals[0].as.str; - if (0 == strcmp(name, "print")) { - CK(l.len == 2, "print requires exactly 1 argument"); + if (0 == strcmp(name, "puts")) { + CK(l.len == 2, "puts requires exactly 1 argument"); compile_node(S, ch, l.vals[1]); - chunk_wbc(S, ch, OP_PRINT); + chunk_wbc(S, ch, OP_PUTS); } else if (0 == strcmp(name, "set")) { CK(l.len == 3, "set requires exactly 2 arguments"); AstNode ident = l.vals[1]; @@ -174,7 +174,7 @@ int main(int argc, char **argv) { AstNode an = read(); compile_node(S, &ch, an); - chunk_wbc(S, &ch, OP_PRINT); + chunk_wbc(S, &ch, OP_PUTS); chunk_wbc(S, &ch, OP_RET); return runvm(S); diff --git a/dis.c b/dis.c index 5c22cc2..de1e3ae 100644 --- a/dis.c +++ b/dis.c @@ -66,7 +66,7 @@ void disasm_chunk(Chunk *ch) { #define SIMPLE_INSTR(opcode, str) \ case opcode: puts(str); break; SIMPLE_INSTR(OP_RET, "ret") - SIMPLE_INSTR(OP_PRINT, "print") + SIMPLE_INSTR(OP_PUTS, "puts") SIMPLE_INSTR(OP_DROP, "drop") SIMPLE_INSTR(OP_ADD, "add") SIMPLE_INSTR(OP_SUB, "sub") diff --git a/tests/fizzbuzz.bth b/tests/fizzbuzz.bth index e70c2c1..82e80cf 100644 --- a/tests/fizzbuzz.bth +++ b/tests/fizzbuzz.bth @@ -1,7 +1,7 @@ (do (set n 1) (while (< n 30) - (print + (puts (if (= 0 (% n 5)) (if (= 0 (% n 3)) "fizzbuzz" "buzz") (if (= 0 (% n 3)) "fizz" n))) diff --git a/tests/vars.bth b/tests/vars.bth index 7799acf..a524ae6 100644 --- a/tests/vars.bth +++ b/tests/vars.bth @@ -2,8 +2,8 @@ (set a 5) (set b 10) (set thethe 1234) - (print (+ a b)) - (print (- thethe a)) - (print (+ (set a 90) b)) - (print a) + (puts (+ a b)) + (puts (- thethe a)) + (puts (+ (set a 90) b)) + (puts a) nil) diff --git a/vm.c b/vm.c index 667ceed..eac0033 100644 --- a/vm.c +++ b/vm.c @@ -85,7 +85,7 @@ int runvm(State *S) { // printf(")\n"); break; } - case OP_PRINT: + case OP_PUTS: println_val(PEEK()); break; case OP_DROP: diff --git a/vm.h b/vm.h index 609ed2c..8fa72a1 100644 --- a/vm.h +++ b/vm.h @@ -38,7 +38,7 @@ Thread thread_new(State *S); typedef enum { OP_RET, OP_LOADK, - OP_PRINT, + OP_PUTS, OP_ADD, OP_SUB, -- cgit v1.2.3