summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-26 14:48:27 +0100
committerubq323 <ubq323@ubq323.website>2024-06-26 14:48:27 +0100
commit517e9fe048844533d927c4e3b6d021f82ccea984 (patch)
tree5629a6d2e43201c14a8d43d652751ff8a987eefb
parenta8519434f058d0ab60bf7f90acc61997cb982cfa (diff)
remove OP_PUTS and OP_PRINT, use say and write functions instead
-rw-r--r--com.c6
-rw-r--r--dis.c2
-rw-r--r--tests/fizzbuzz.bth2
-rw-r--r--tests/four.bth2
-rw-r--r--tests/func1.bth2
-rw-r--r--tests/func2.bth6
-rw-r--r--tests/func3.bth4
-rw-r--r--tests/func4.bth2
-rw-r--r--tests/mandel.bth4
-rw-r--r--tests/mandel_local.bth4
-rw-r--r--tests/multi.bth4
-rw-r--r--tests/vars.bth8
-rw-r--r--tests/vars1.bth2
-rw-r--r--tests/vars2.bth2
-rw-r--r--tests/vars3.bth2
-rw-r--r--tests/vars4.bth8
-rw-r--r--vm.c6
-rw-r--r--vm.h2
18 files changed, 27 insertions, 41 deletions
diff --git a/com.c b/com.c
index fcb4fdf..0ae79f6 100644
--- a/com.c
+++ b/com.c
@@ -39,8 +39,6 @@ static int stack_effect_of(Op opcode) {
case OP_TRUE:
case OP_FALSE:
return 1;
- case OP_PUTS:
- case OP_PRINT:
case OP_SKIP:
case OP_REDO:
case OP_SETGLOBAL:
@@ -111,7 +109,7 @@ static size_t compile_constant(Compiler *C, Val v) {
static void compile_call_instr(Compiler *C, uint8_t len) {
compile_opcode(C, OP_CALL);
compile_byte(C, len);
- C->stack_cur -= len;
+ C->stack_cur -= len - 1;
}
static void compile_endscope_instr(Compiler *C, uint8_t nlocals) {
@@ -337,8 +335,6 @@ typedef struct {
} BuiltinForm;
static BuiltinForm builtin_forms[] = {
- { "puts", 1, false, single_form, OP_PUTS },
- { "print", 1, false, single_form, OP_PRINT },
{ "set", 2, false, set_form, 0 },
{ "do", 1, true, do_form, 0 },
{ "if", 3, false, if_form, 0 },
diff --git a/dis.c b/dis.c
index 193f410..9220b75 100644
--- a/dis.c
+++ b/dis.c
@@ -89,8 +89,6 @@ static size_t disasm_instr_h(Chunk *ch, size_t ip, int depth) {
#define SIMPLE_INSTR(opcode, str) \
case opcode: puts(str); break;
SIMPLE_INSTR(OP_RET, "ret")
- SIMPLE_INSTR(OP_PUTS, "puts")
- SIMPLE_INSTR(OP_PRINT, "print")
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 42c1760..2837b55 100644
--- a/tests/fizzbuzz.bth
+++ b/tests/fizzbuzz.bth
@@ -1,6 +1,6 @@
(set n 1)
(while (< n 30)
- (puts
+ (say
(if (= 0 (% n 5))
(if (= 0 (% n 3)) "fizzbuzz" "buzz")
(if (= 0 (% n 3)) "fizz" n)))
diff --git a/tests/four.bth b/tests/four.bth
index c44e487..c4df4e1 100644
--- a/tests/four.bth
+++ b/tests/four.bth
@@ -1 +1 @@
-(puts (+ 2 2))
+(say (+ 2 2))
diff --git a/tests/func1.bth b/tests/func1.bth
index 1f175ab..a71d160 100644
--- a/tests/func1.bth
+++ b/tests/func1.bth
@@ -1,2 +1,2 @@
(set f (fn (_) 42))
-(puts (f 0))
+(say (f 0))
diff --git a/tests/func2.bth b/tests/func2.bth
index ee995fa..e57bc27 100644
--- a/tests/func2.bth
+++ b/tests/func2.bth
@@ -1,5 +1,5 @@
(set f1 (fn (a) (* a a)))
(set f2 (fn (a b) (+ a b)))
-(puts (f1 6))
-(puts (f2 20 40))
-(puts (f1 (f2 2 1)))
+(say (f1 6))
+(say (f2 20 40))
+(say (f1 (f2 2 1)))
diff --git a/tests/func3.bth b/tests/func3.bth
index 050a9bc..9c0ceeb 100644
--- a/tests/func3.bth
+++ b/tests/func3.bth
@@ -3,5 +3,5 @@
(let (a 3
g (fn (y) (+ y 7)))
(* (g a) (g x)))))
-(puts (f1 6 6))
-(puts (f2 7))
+(say (f1 6 6))
+(say (f2 7))
diff --git a/tests/func4.bth b/tests/func4.bth
index fca67b1..efd2b71 100644
--- a/tests/func4.bth
+++ b/tests/func4.bth
@@ -1,5 +1,5 @@
(set f1 (fn (x) (+ x 10)))
(set f2 (fn (x) (* x 10)))
-(set g (fn (f x) (puts (f x)) (puts (f x))))
+(set g (fn (f x) (say (f x)) (say (f x))))
(g f1 26)
(g f2 6)
diff --git a/tests/mandel.bth b/tests/mandel.bth
index 54a1b4d..e75d694 100644
--- a/tests/mandel.bth
+++ b/tests/mandel.bth
@@ -14,7 +14,7 @@
(set zim nzim)
(set mag (+ (* zre zre) (* zim zim)))
(set i (if (< mag 4) (+ i 1) 999)))
- (print (if (< mag 4) "#" "."))
+ (write (if (< mag 4) "#" "."))
(set pxx (+ pxx 1)))
- (puts "")
+ (say "")
(set pxy (+ pxy 1)))
diff --git a/tests/mandel_local.bth b/tests/mandel_local.bth
index f2a1213..2cfa814 100644
--- a/tests/mandel_local.bth
+++ b/tests/mandel_local.bth
@@ -17,7 +17,7 @@
(set zim nzim)
(set mag (+ (* zre zre) (* zim zim)))
(set i (if (< mag 4) (+ i 1) 999)))
- (print (if (< mag 4) "#" "."))
+ (write (if (< mag 4) "#" "."))
(set pxx (+ pxx 1)))))
- (puts "")
+ (say "")
(set pxy (+ pxy 1))))
diff --git a/tests/multi.bth b/tests/multi.bth
index 49691ce..c2ff8cf 100644
--- a/tests/multi.bth
+++ b/tests/multi.bth
@@ -1,3 +1,3 @@
-(puts "hello")
-(puts "world")
+(say "hello")
+(say "world")
nil
diff --git a/tests/vars.bth b/tests/vars.bth
index 54555ad..423dde6 100644
--- a/tests/vars.bth
+++ b/tests/vars.bth
@@ -1,8 +1,8 @@
(set a 5)
(set b 10)
(set thethe 1234)
-(puts (+ a b))
-(puts (- thethe a))
-(puts (+ (set a 90) b))
-(puts a)
+(say (+ a b))
+(say (- thethe a))
+(say (+ (set a 90) b))
+(say a)
nil
diff --git a/tests/vars1.bth b/tests/vars1.bth
index 7c0e264..24a3f2b 100644
--- a/tests/vars1.bth
+++ b/tests/vars1.bth
@@ -1,2 +1,2 @@
-(puts (+ 2 (let (a 10)
+(say (+ 2 (let (a 10)
(* a a))))
diff --git a/tests/vars2.bth b/tests/vars2.bth
index cc4952e..4e49fb4 100644
--- a/tests/vars2.bth
+++ b/tests/vars2.bth
@@ -1,4 +1,4 @@
-(puts (+ 2 (* 6 (let (a 10
+(say (+ 2 (* 6 (let (a 10
b 20
c 30)
(* b b)))))
diff --git a/tests/vars3.bth b/tests/vars3.bth
index cfc4560..149e694 100644
--- a/tests/vars3.bth
+++ b/tests/vars3.bth
@@ -1,5 +1,5 @@
(set x 1)
(set y 10)
-(puts (let (x 2)
+(say (let (x 2)
(let (y 20)
(+ x y))))
diff --git a/tests/vars4.bth b/tests/vars4.bth
index a535d54..30f75d3 100644
--- a/tests/vars4.bth
+++ b/tests/vars4.bth
@@ -1,7 +1,7 @@
(set x 100)
-(puts x)
+(say x)
(let (x 20)
- (puts x)
+ (say x)
(set x 30)
- (puts x))
-(puts x)
+ (say x))
+(say x)
diff --git a/vm.c b/vm.c
index 34660de..b8fcbd6 100644
--- a/vm.c
+++ b/vm.c
@@ -65,12 +65,6 @@ int runvm(State *S) {
// printf(")\n");
break;
}
- case OP_PUTS:
- println_val(PEEK());
- break;
- case OP_PRINT:
- print_val(PEEK());
- break;
case OP_DROP:
--th->sp;
break;
diff --git a/vm.h b/vm.h
index d9fcb50..4af6300 100644
--- a/vm.h
+++ b/vm.h
@@ -32,8 +32,6 @@ Thread thread_new(State *S);
typedef enum {
OP_RET,
OP_LOADK,
- OP_PUTS,
- OP_PRINT,
OP_ADD,
OP_SUB,