Login
7 branches 0 tags
Ben (X13/Arch) WIP a25bc3e 3 years ago 651 Commits
nujel / testsuite / bytecode.nuj
[test/add #x0 [bytecode-op->int #$0]]
[test/add #x9 [bytecode-op->int #$9]]
[test/add #xF [bytecode-op->int #$F]]
[test/add #x10 [bytecode-op->int #$10]]
[test/add #xFF [bytecode-op->int #$FF]]
[test/add :type-error [try car [bytecode-op->int]]]
[test/add :type-error [try car [bytecode-op->int 12]]]
[test/add :bytecode-op [type-of #$10]]
[test/add :bytecode-op [type-of [int->bytecode-op 255]]]
[test/add "#{\n00\n09o 3856\nFF\n}" [str/write [arr->bytecode-arr #[#$0 #$9 #$F #$10 #$FF]]]]
[test/add :bytecode-array [type-of [arr->bytecode-arr #[#$0 #$9 #$F #$10 #$FF]]]]
[test/add #$0 [array/ref [bytecode-arr->arr [arr->bytecode-arr #[#$0 #$9 #$F #$10 #$FF]]] 0]]
[test/add 0    [bytecode-eval [arr->bytecode-arr #[#$2 #$0 #$1]]]]
[test/add 127  [bytecode-eval [arr->bytecode-arr #[#$2 #$7F #$1]]]]
[test/add -1   [bytecode-eval [arr->bytecode-arr #[#$2 #$FF #$1]]]]
[test/add -128 [bytecode-eval [arr->bytecode-arr #[#$2 #$80 #$1]]]]
[test/add 5    [bytecode-eval [assemble [$push/int 3] [$push/int 2] [$add/int] [$ret]]]]
[test/add 3    [bytecode-eval [assemble [$push/int 3] [$ret]]]]
[test/add 0    [bytecode-eval [assemble [$push/int 0] [$ret]]]]
[test/add 10   [bytecode-eval [assemble [$get 'test-var] [$push/int 1] [$add/int] [$ret]] [ω [def test-var 9]]]]
[test/add -3   [bytecode-eval [assemble [$push/int -3] [$ret]]]]
[test/add -128 [bytecode-eval [assemble [$push/int -128] [$nop] [$ret]]]]
[test/add 127  [bytecode-eval [assemble [$push/int 127] [$ret]]]]
[test/add #t   [int? [val->index "asd"]]]
[test/add "asd" [index->val [val->index "asd"]]]
[test/add '[123 asd] [index->val [val->index '[123 asd]]]]
[test/add '[123 asd] [asmrun [$push/lval '[123 asd]] [$ret]]]
[test/add 'test [asmrun [$push/symbol 'test] [$ret]]]
[test/add 2 [[asmrun [$push/lval [fn [a] [+ 1 a]]] [$ret]] 1]]
[test/add '[test list] [let [[code [assemble [$push/lval [list 'test 'list]] [$ret]]]]                   [bytecode-eval code]]]
[test/add '[test list] [let [[code [assemble [$push/lval [list 'test 'list]] [$ret]]]] [garbage-collect] [bytecode-eval code]]]
[test/add 5 [asmrun [$push/int 2] [$push/int 3] [$apply 2 add/int] [$ret]]]
[test/add 4 [asmrun [$push/int 2] [$dup] [$apply 2 add/int] [$ret]]]
[test/add 26 [asmrun [$nop] [$push/int 26] [$jmp :asd] [$push/int 99] [list :label :asd] [$ret]]]
[test/add 26 [asmrun [$nop] [$push/int 26] [$push/lval #t] [$jt :asd] [$push/int 99] [list :label :asd] [$ret]]]
[test/add 99 [asmrun [$nop] [$push/int 26] [$push/lval #f] [$jt :asd] [$push/int 99] [list :label :asd] [$ret]]]
[test/add "#$0" [str/write [int->bytecode-op 0]]]
[test/add "#$9" [str/write [int->bytecode-op 9]]]
[test/add "#$F" [str/write [int->bytecode-op 15]]]
[test/add "#$10" [str/write [int->bytecode-op 16]]]
[test/add "#$FF" [str/write [int->bytecode-op 255]]]
[test/add :invalid-bc-op [try car [int->bytecode-op -129]]]
[test/add :invalid-bc-op [try car [int->bytecode-op 256]]]
[test/add "#$0" [str/write #$]]
[test/add "#$9" [str/write #$9]]
[test/add "#$F" [str/write #$F]]
[test/add "#$10" [str/write #$10]]
[test/add "#$FF" [str/write #$FF]]
[test/add :read-error [try car [read/single "#$1FF"]]]
[test/add #t [int? [sym->index 'asd]]]
[test/add 'asd [index->sym [sym->index 'asd]]]
[test/add 55 [+ 1 [+ 2 [+ 3 [+ 4 [+ 5 [+ 6 [+ 7 [+ 8 [+ 9 10]]]]]]]]]]
[test/add "3.14159" [str/write [asmrun [$get 'π] [$ret]]]]
[test/add 2 [asmrun [$push/int 1] [$def 'tmp] [$let] [$push/int 2] [$def 'tmp] [$get 'tmp] [$ret]]]
[test/add 1 [asmrun [$push/int 1] [$def 'tmp] [$let] [$push/int 2] [$def 'tmp] [$closure/pop] [$get 'tmp] [$ret]]]
[test/add :asd [try [fn [a] [car a]] [throw '[:asd "Test"]] :error]]
[test/add :asd [try car [throw '[:asd "Test"]] :error]]
[test/add 3 [asmrun [$jmp :start] [list :label :ret] [$push/int 3] [$ret] [list :label :start] [$push/int 2] [$jmp :ret] [$ret]]]
[test/add 5 [asmrun [$jmp :start] [list :label :func] [$push/int 2] [$add/int] [$ret] [list :label :start] [$push/int 3] [$jmp :func]]]
[test/add '[1 . 2] [asmrun [$push/int 1] [$push/int 2] [$apply 2 cons] [$ret]]]
[test/add 1 [asmrun [$push/int 1] [$push/int 2] [$apply 2 cons] [$apply 1 car] [$ret]]]
[test/add 1 [bytecode-eval [apply assemble [list [$push/int 1] [$push/int 2] [$apply 2 cons] [$apply 1 car] [$ret]]]]]
[test/add 37 [asmrun [$push/lval +] [$push/int 12] [$push/int 25] [$apply/dynamic 2] [$ret]]]
[test/add 3 [bytecode-eval [arr->bytecode-arr [apply array/new [flatten [list [$push/int 1] [$push/int 2] [$add/int] [$ret]]]]]]]
[test/add 3 [bytecode-eval #{020102020301}]]
[test/add "#{\n02i 1\n02i 2\n03\n01\n}" [str/write #{020102020301}]]
[test/add "#{\n02i 1\n02i 2\n03\n01\n}" [str/write #{02i 1 02i 2 0301}]]
[test/add 3 [bytecode-eval #{02i 1 02i 2 0301}]]
[test/add 3 [bytecode-eval #{05v 1 05v 2 0301}]]
[test/add "#{\n05v 1\n05v 2\n03\n01\n}" [str/write #{05v 1 05v 2 0301}]]
[test/add 3 [let [[tmp 3]] [bytecode-eval #{10s tmp 01}]]]
[test/add #$99 [let [[tmp 3]] [bytecode-eval #{05v #$99 0Fs tmp 01}] tmp]]
[test/add "#{\n05v #$99\n0Fs tmp\n01\n}" [str/write #{05v #$99 0Fs tmp 01}]]
[test/add 'test [asmrun [$push/symbol 'test] [$ret]]]
[test/add #nil [asmrun [$push/nil] [$ret]]]
[test/add :invalid-bc-op [try car [asmrun [$push/lval #nil] [$ret]]]]
[test/add 4 [def min* [fn [a b] [if [< a b] a b]]] [+ [min* 1 3] [min* 10 3]]]
[test/add :vm-error [try car [apply return '[:test]]]]
[test/add 1 [[fn [] [return 1] 3]]]
[test/add '[:a :b] [asmrun [$push/lval :a] [$push/lval '[:b]] [$apply 2 cons] [$ret]]]
[test/add '[:a :b] [asmrun [$push/lval :a] [$push/lval '[:b]] [$cons] [$ret]]]
[test/add :a [asmrun [$push/lval '[:a :b]] [$car] [$ret]]]
[test/add '[:b] [asmrun [$push/lval '[:a :b]] [$cdr] [$ret]]]