Login
7 branches 0 tags
Ben (X13/Arch) WIP: stackless 2218ce7 3 years ago 763 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 "#{##[]\n00090F10FF\n}" [string/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    [apply [environment*] [arr->bytecode-arr #[#$2 #$0 #$1]]]]
[test/add 127  [apply [environment*] [arr->bytecode-arr #[#$2 #$7F #$1]]]]
[test/add -1   [apply [environment*] [arr->bytecode-arr #[#$2 #$FF #$1]]]]
[test/add -128 [apply [environment*] [arr->bytecode-arr #[#$2 #$80 #$1]]]]
[test/add 5    [apply [environment*] [assemble [$push/int 3] [$push/int 2] [$add/int] [$ret]]]]
[test/add 3    [apply [environment*] [assemble [$push/int 3] [$ret]]]]
[test/add 0    [apply [environment*] [assemble [$push/int 0] [$ret]]]]
[test/add 10   [apply [environment* [def test-var 9]] [assemble [$push/val 'test-var] [$get] [$push/int 1] [$add/int] [$ret]]]]
[test/add -3   [apply [environment*] [assemble [$push/int -3] [$ret]]]]
[test/add -128 [apply [environment*] [assemble [$push/int -128] [$nop] [$ret]]]]
[test/add 127  [apply [environment*] [assemble [$push/int 127] [$ret]]]]
[test/add '[123 asd] [asmrun [$push/val '[123 asd]] [$ret]]]
[test/add 'test [asmrun [$push/val 'test] [$ret]]]
[test/add 2 [[asmrun [$push/val [fn [a] [+ 1 a]]] [$ret]] 1]]
[test/add '[test list] [let [[code [assemble [$push/val [list 'test 'list]] [$ret]]]]                   [apply [environment*] code]]]
[test/add '[test list] [let [[code [assemble [$push/val [list 'test 'list]] [$ret]]]] [garbage-collect] [apply [environment*] 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/val #t] [$jt :asd] [$push/int 99] [list :label :asd] [$ret]]]
[test/add 99 [asmrun [$nop] [$push/int 26] [$push/val #f] [$jt :asd] [$push/int 99] [list :label :asd] [$ret]]]
[test/add "#$0" [string/write [int->bytecode-op 0]]]
[test/add "#$9" [string/write [int->bytecode-op 9]]]
[test/add "#$F" [string/write [int->bytecode-op 15]]]
[test/add "#$10" [string/write [int->bytecode-op 16]]]
[test/add "#$FF" [string/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" [string/write #$]]
[test/add "#$9" [string/write #$9]]
[test/add "#$F" [string/write #$F]]
[test/add "#$10" [string/write #$10]]
[test/add "#$FF" [string/write #$FF]]
[test/add :read-error [try car [read/single "#$1FF"]]]
[test/add 55 [+ 1 [+ 2 [+ 3 [+ 4 [+ 5 [+ 6 [+ 7 [+ 8 [+ 9 10]]]]]]]]]]
[test/add "3.14159" [string/write [asmrun [$push/val 'π] [$get] [$ret]]]]
[test/add 2 [asmrun [$push/int 1] [$push/val 'tmp] [$def] [$let] [$push/int 2] [$push/val 'tmp] [$def] [$push/val 'tmp] [$get] [$ret]]]
[test/add 1 [asmrun [$push/int 1] [$push/val 'tmp] [$def] [$let] [$push/int 2] [$push/val 'tmp] [$def] [$closure/pop] [$push/val 'tmp] [$get] [$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 [apply [environment*] [apply assemble [list [$push/int 1] [$push/int 2] [$apply 2 cons] [$apply 1 car] [$ret]]]]]
[test/add 37 [asmrun [$push/val +] [$push/int 12] [$push/int 25] [$apply/dynamic 2] [$ret]]]
[test/add 3 [apply [environment*] [arr->bytecode-arr [apply array/new [flatten [list [$push/int 1] [$push/int 2] [$add/int] [$ret]]]]]]]
[test/add 3 [apply [environment*] #{020102020301}]]
[test/add "#{##[]\n020102020301\n}" [string/write #{020102020301}]]
[test/add 3 [apply [environment*] #{020102020301}]]
[test/add 3 [apply [environment*] #{##[1 2] 1A001A010301}]]
[test/add "#{##[1 2]\n1A001A010301\n}" [string/write #{##[1 2] 1A001A010301}]]
[test/add 3 [let [[tmp 3]] [apply [environment*] #{##[tmp] 1A000501} [current-closure]]]]
[test/add #$99 [let [[tmp 3]] [apply [environment*] #{##[#$99 tmp] 1A001A010801} [current-closure]] tmp]]
[test/add 'test [asmrun [$push/val 'test] [$ret]]]
[test/add #nil [asmrun [$push/nil] [$ret]]]
[test/add :invalid-bc-op [try car [asmrun [$push/val #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/val :a] [$push/val '[:b]] [$apply 2 cons] [$ret]]]
[test/add '[:a :b] [asmrun [$push/val :a] [$push/val '[:b]] [$cons] [$ret]]]
[test/add :a [asmrun [$push/val '[:a :b]] [$car] [$ret]]]
[test/add '[:b] [asmrun [$push/val '[:a :b]] [$cdr] [$ret]]]
[test/add :stack-underflow [try car [asmrun [$get] [$ret]]]]
[test/add :type-error [try car [asmrun [$push/val 123] [$get] [$ret]]]]
[test/add #t [try car [asmrun [$push/val 'otherwise] [$get] [$ret]]]]