Skip to content

Commit

Permalink
Merge pull request #42 from stefanhts/peter/tests
Browse files Browse the repository at this point in the history
Peter/tests
  • Loading branch information
peterpie123 authored May 13, 2022
2 parents 962cf10 + 3289729 commit 82e14fb
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 43 deletions.
20 changes: 10 additions & 10 deletions lang/compile.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))))))
68 changes: 35 additions & 33 deletions server/public/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -134,17 +136,17 @@ function unwrap(raw) {
case typesEnum.T_EMPTY:
return "'()"
case typesEnum.T_CONS:
return "#<cons>"
return "#\<cons\>"
case typesEnum.T_BOX:
return "#<box>"
return "#\<box\>"
case typesEnum.T_VECT:
return "#<vector>"
// return "'" + result_interior(raw) // TODO
return "#\<vector\>"
// return "'" + result_interior(raw) // TODO
case typesEnum.T_STR:
return "#<string>"
//return '"' + val_unwrap_str(raw) + '"' // TODO
return "#\<string\>"
//return '"' + val_unwrap_str(raw) + '"' // TODO
case typesEnum.T_PROC:
return "#<procedure>"
return "#\<procedure\>"
case typesEnum.T_INVALID:
return "internal error"
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = []
}
2 changes: 2 additions & 0 deletions tests/dodger/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(add1 #\a)
2 changes: 2 additions & 0 deletions tests/dodger/2.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(char? #\b)
2 changes: 2 additions & 0 deletions tests/dodger/3.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(char->integer #\a)
2 changes: 2 additions & 0 deletions tests/dodger/4.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(integer->char 97)
2 changes: 2 additions & 0 deletions tests/dupe/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(add1 #t)
2 changes: 2 additions & 0 deletions tests/evildoer/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(read-byte)
2 changes: 2 additions & 0 deletions tests/evildoer/2.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(write-byte 49)
2 changes: 2 additions & 0 deletions tests/evildoer/3.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(peek-byte)
2 changes: 2 additions & 0 deletions tests/extort/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(zero? #f)
2 changes: 2 additions & 0 deletions tests/hoax/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(make-vector 3 #t)
2 changes: 2 additions & 0 deletions tests/hoax/2.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
"abc"
2 changes: 2 additions & 0 deletions tests/hoax/3.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(vector-ref (make-vector 3 #t) 0)
2 changes: 2 additions & 0 deletions tests/hoax/4.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang wacket
(string-ref "abcd" 2)
4 changes: 4 additions & 0 deletions tests/hoax/5.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#lang wacket
(let ((v (make-vector 3 #t)))
(begin (vector-set! v 1 #f)
(vector-ref v 1)))
3 changes: 3 additions & 0 deletions tests/iniquity/1.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#lang wacket
(define (f x) (add1 x))
(f 1)
3 changes: 3 additions & 0 deletions tests/iniquity/2.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#lang wacket
(define (f x y) (+ x y))
(f 42 84)
4 changes: 4 additions & 0 deletions tests/iniquity/3.wkt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions tests/iniquity/4.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#lang wacket
(define (f x) (car x))
(f (cons 42 69))

0 comments on commit 82e14fb

Please sign in to comment.