diff --git a/lang/compile.rkt b/lang/compile.rkt index 7a96bbc..a87be2f 100644 --- a/lang/compile.rkt +++ b/lang/compile.rkt @@ -224,10 +224,10 @@ (match p ['vector-set! (seq (SetLocal (Name secondary-pointer) e1) - (SetLocal (Name 'assert_scratch) (load-from-heap (GetLocal (Name secondary-pointer)) type-vect (Const 0))) + (SetLocal (Name assert_scratch) (load-from-heap (GetLocal (Name secondary-pointer)) type-vect (Const 0))) (WatIf (64->32 (And (32->64 (Ge (Sar e2 (Const int-shift)) (Const 0))) - (32->64 (Lt (Sar e2 (Const int-shift)) (GetLocal (Name 'assert_scratch)))))) + (32->64 (Lt (Sar e2 (Const int-shift)) (GetLocal (Name assert_scratch)))))) (seq (64->32 (Add (Xor (GetLocal (Name secondary-pointer)) (Const type-vect)) (Mul (Const 8) (Add (Const 1) (Sar e2 (Const int-shift)))))) @@ -264,10 +264,10 @@ ;; Gets by index in an array-type structure (vector or string currently). (define (compile-ref e1 e2 type) (seq - (SetLocal (Name 'assert_scratch) (load-from-heap e1 type (Const 0))) + (SetLocal (Name assert_scratch) (load-from-heap e1 type (Const 0))) (WatIf (64->32 (And (32->64 (Ge (Sar e2 (Const int-shift)) (Const 0))) - (32->64 (Lt (Sar e2 (Const int-shift)) (GetLocal (Name 'assert_scratch)))))) + (32->64 (Lt (Sar e2 (Const int-shift)) (GetLocal (Name assert_scratch)))))) (load-from-heap e1 type (Mul (Const 8) (Add (Const 1) (Sar e2 (Const int-shift))))) (err) @@ -456,19 +456,19 @@ (define (assert-codepoint arg) (seq (SetLocal (Name assert_scratch) arg) - (WatIf (Lt (GetLocal (Name assert_scratch)) (imm->bits 0)) + (WatIf (Lt (GetLocal (Name assert_scratch)) (Const (imm->bits 0))) (err) - (WatIf (Gt (GetLocal (Name assert_scratch)) (imm->bits 1114111)) + (WatIf (Gt (GetLocal (Name assert_scratch)) (Const (imm->bits 1114111))) (err) - (WatIf (And (Ge (GetLocal (Name assert_scratch)) (imm->bits 55295)) - (Le (GetLocal (Name assert_scratch)) (imm->bits 57344))) + (WatIf (64->32 (And (32->64 (Ge (GetLocal (Name assert_scratch)) (Const (imm->bits 55295)))) + (32->64 (Le (GetLocal (Name assert_scratch)) (Const (imm->bits 57344)))))) (err) (GetLocal (Name assert_scratch))))))) (define (assert-byte arg) (seq (SetLocal (Name assert_scratch) arg) - (WatIf (Lt (GetLocal (Name assert_scratch)) (imm->bits 0)) + (WatIf (Lt (GetLocal (Name assert_scratch)) (Const (imm->bits 0))) (err) - (WatIf (Gt (GetLocal (Name assert_scratch)) (imm->bits 255)) + (WatIf (Gt (GetLocal (Name assert_scratch)) (Const (imm->bits 255))) (err) (GetLocal (Name assert_scratch)))))) diff --git a/server/public/runtime.js b/server/public/runtime.js index 18b7929..41fa8db 100644 --- a/server/public/runtime.js +++ b/server/public/runtime.js @@ -33,8 +33,10 @@ let STDIN = [] let STDOUT = [] const output = document.getElementById("res") let result = "" -const importObject = { io: {read: readByte, write: writeByte, peek: peekByte}, - err: {error: error}}; +const importObject = { + io: { read: readByte, write: writeByte, peek: peekByte }, + err: { error: error } +}; function error() { output.innerHTML = output.innerHTML + "RUNTIME ERROR" @@ -134,17 +136,17 @@ function unwrap(raw) { case typesEnum.T_EMPTY: return "'()" case typesEnum.T_CONS: - return "#" + return "#\" case typesEnum.T_BOX: - return "#" + return "#\" case typesEnum.T_VECT: - return "#" - // return "'" + result_interior(raw) // TODO + return "#\" + // return "'" + result_interior(raw) // TODO case typesEnum.T_STR: - return "#" - //return '"' + val_unwrap_str(raw) + '"' // TODO + return "#\" + //return '"' + val_unwrap_str(raw) + '"' // TODO case typesEnum.T_PROC: - return "#" + return "#\" case typesEnum.T_INVALID: return "internal error" } @@ -200,11 +202,11 @@ function val_unwrap_char(raw) { } function val_unwrap_int(raw) { - return raw >> int_shift + return (raw >> int_shift) + "" } function val_unwrap_bool(raw) { - return raw === val_true + return (raw === val_true) + "" } function val_wrap_int(i) { @@ -227,33 +229,33 @@ function val_wrap_void() { return val_void } -function readByte(){ - console.log("reading byte!"); - if(STDIN.length < 1) { - return val_eof - } - return val_wrap_int(BigInt(STDIN.shift())) +function readByte() { + console.log("reading byte!"); + if (STDIN.length < 1) { + return val_eof + } + return val_wrap_int(BigInt(STDIN.shift())) } -function writeByte(byte){ - console.log("writing byte!"); - const unwrappedByte = val_unwrap_int(byte); - STDOUT.push(Number(unwrappedByte)) - return val_wrap_void(); +function writeByte(byte) { + console.log("writing byte!"); + const unwrappedByte = val_unwrap_int(byte); + STDOUT.push(Number(unwrappedByte)) + return val_wrap_void(); } -function peekByte(){ - console.log("peeking byte!"); - if(STDIN.length < 1) { - return val_eof - } - return val_wrap_int(BigInt(STDIN[0])) +function peekByte() { + console.log("peeking byte!"); + if (STDIN.length < 1) { + return val_eof + } + return val_wrap_int(BigInt(STDIN[0])) } function flushSTDOUT() { - console.log("STDOUT before Uint8 conversion: ", STDOUT); - STDOUT = Uint8Array.from(STDOUT); - console.log("STDOUT: ", STDOUT); - output.innerHTML = output.innerHTML + DECODER.decode(STDOUT); - STDOUT = [] + console.log("STDOUT before Uint8 conversion: ", STDOUT); + STDOUT = Uint8Array.from(STDOUT); + console.log("STDOUT: ", STDOUT); + output.innerHTML = output.innerHTML + DECODER.decode(STDOUT); + STDOUT = [] } \ No newline at end of file diff --git a/tests/dodger/1.wkt b/tests/dodger/1.wkt new file mode 100644 index 0000000..905efc8 --- /dev/null +++ b/tests/dodger/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(add1 #\a) \ No newline at end of file diff --git a/tests/dodger/2.wkt b/tests/dodger/2.wkt new file mode 100644 index 0000000..e4ab131 --- /dev/null +++ b/tests/dodger/2.wkt @@ -0,0 +1,2 @@ +#lang wacket +(char? #\b) \ No newline at end of file diff --git a/tests/dodger/3.wkt b/tests/dodger/3.wkt new file mode 100644 index 0000000..3697c8e --- /dev/null +++ b/tests/dodger/3.wkt @@ -0,0 +1,2 @@ +#lang wacket +(char->integer #\a) \ No newline at end of file diff --git a/tests/dodger/4.wkt b/tests/dodger/4.wkt new file mode 100644 index 0000000..9606ef5 --- /dev/null +++ b/tests/dodger/4.wkt @@ -0,0 +1,2 @@ +#lang wacket +(integer->char 97) \ No newline at end of file diff --git a/tests/dupe/1.wkt b/tests/dupe/1.wkt new file mode 100644 index 0000000..85b1385 --- /dev/null +++ b/tests/dupe/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(add1 #t) \ No newline at end of file diff --git a/tests/evildoer/1.wkt b/tests/evildoer/1.wkt new file mode 100644 index 0000000..de992cf --- /dev/null +++ b/tests/evildoer/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(read-byte) \ No newline at end of file diff --git a/tests/evildoer/2.wkt b/tests/evildoer/2.wkt new file mode 100644 index 0000000..757e92e --- /dev/null +++ b/tests/evildoer/2.wkt @@ -0,0 +1,2 @@ +#lang wacket +(write-byte 49) \ No newline at end of file diff --git a/tests/evildoer/3.wkt b/tests/evildoer/3.wkt new file mode 100644 index 0000000..d3c9bd0 --- /dev/null +++ b/tests/evildoer/3.wkt @@ -0,0 +1,2 @@ +#lang wacket +(peek-byte) \ No newline at end of file diff --git a/tests/extort/1.wkt b/tests/extort/1.wkt new file mode 100644 index 0000000..dc5f98e --- /dev/null +++ b/tests/extort/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(zero? #f) \ No newline at end of file diff --git a/tests/hoax/1.wkt b/tests/hoax/1.wkt new file mode 100644 index 0000000..4bc73a7 --- /dev/null +++ b/tests/hoax/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(make-vector 3 #t) \ No newline at end of file diff --git a/tests/hoax/2.wkt b/tests/hoax/2.wkt new file mode 100644 index 0000000..4ebd24a --- /dev/null +++ b/tests/hoax/2.wkt @@ -0,0 +1,2 @@ +#lang wacket +"abc" \ No newline at end of file diff --git a/tests/hoax/3.wkt b/tests/hoax/3.wkt new file mode 100644 index 0000000..0a67883 --- /dev/null +++ b/tests/hoax/3.wkt @@ -0,0 +1,2 @@ +#lang wacket +(vector-ref (make-vector 3 #t) 0) \ No newline at end of file diff --git a/tests/hoax/4.wkt b/tests/hoax/4.wkt new file mode 100644 index 0000000..72e904f --- /dev/null +++ b/tests/hoax/4.wkt @@ -0,0 +1,2 @@ +#lang wacket +(string-ref "abcd" 2) \ No newline at end of file diff --git a/tests/hoax/5.wkt b/tests/hoax/5.wkt new file mode 100644 index 0000000..1c0efde --- /dev/null +++ b/tests/hoax/5.wkt @@ -0,0 +1,4 @@ +#lang wacket +(let ((v (make-vector 3 #t))) + (begin (vector-set! v 1 #f) + (vector-ref v 1))) \ No newline at end of file diff --git a/tests/iniquity/1.wkt b/tests/iniquity/1.wkt new file mode 100644 index 0000000..b42d758 --- /dev/null +++ b/tests/iniquity/1.wkt @@ -0,0 +1,3 @@ +#lang wacket +(define (f x) (add1 x)) +(f 1) \ No newline at end of file diff --git a/tests/iniquity/2.wkt b/tests/iniquity/2.wkt new file mode 100644 index 0000000..5de11d2 --- /dev/null +++ b/tests/iniquity/2.wkt @@ -0,0 +1,3 @@ +#lang wacket +(define (f x y) (+ x y)) +(f 42 84) \ No newline at end of file diff --git a/tests/iniquity/3.wkt b/tests/iniquity/3.wkt new file mode 100644 index 0000000..5c05e86 --- /dev/null +++ b/tests/iniquity/3.wkt @@ -0,0 +1,4 @@ +#lang wacket +(define (f1 a b c) (+ (f2 a b) c)) +(define (f2 x y) (* x y)) +(f1 42 84 124) \ No newline at end of file diff --git a/tests/iniquity/4.wkt b/tests/iniquity/4.wkt new file mode 100644 index 0000000..b9a6d2d --- /dev/null +++ b/tests/iniquity/4.wkt @@ -0,0 +1,3 @@ +#lang wacket +(define (f x) (car x)) +(f (cons 42 69)) \ No newline at end of file