def test_5(): code = '''\ (+jojo t null 1 swap cons 2 swap cons cdr car) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_5', sexp_vect) vm = VM([], [RP(module.t)]) vm = vm.exe() assert vm.ds == [1]
def test_6(): code = '''\ (+jojo t :body! [:body [:body]]) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_6', sexp_vect) vm = VM([1], [RP(module.t)]) vm = vm.exe() assert vm.ds == [1, 1]
def test_3(): code = '''\ (+jojo t 1 2 eq? {"true"} {"false"} ifte) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_3', sexp_vect) vm = VM([], [RP(module.t)]) vm = vm.exe() assert vm.ds == ["false"]
def test_4(): code = '''\ (+jojo t (if [1 2 eq?] ["true"] ["false"])) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_4', sexp_vect) vm = VM([], [RP(module.t)]) vm = vm.exe() assert vm.ds == ["false"]
def test_1(): code = '''\ (+jojo six 1 2 add 3 add) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_1', sexp_vect) vm = VM([], [RP(module.six)]) vm = vm.exe() assert vm.ds == [6]
def test_2(): code = '''\ (import os) (+jojo times os .times) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_2', sexp_vect) vm = VM([], [RP(module.times)]) vm = vm.exe() assert type(vm.ds.pop()) == posix.times_result
def test_1(): code = '''\ (+jojo c :x! `(a (@ :x :x mul) b (@ :x :x mul) c)) (+jojo t 4 c list->vect vect-spread) ''' sexp_vect = jojo.parse_sexp_vect(jojo.code_scan(code)) module = jojo.compile_module(__name__ + 'test_1', sexp_vect) vm = jojo.VM([], [jojo.RP(module.t)]) vm = vm.exe() assert vm.ds == ["a", 16, "b", 16, "c"]
def test_1(): code = '''\ (+jojo c (list 1 2 add dup)) (+jojo t c list->vect vect-spread) ''' sexp_vect = jojo.parse_sexp_vect(jojo.code_scan(code)) module = jojo.compile_module(__name__ + 'test_1', sexp_vect) vm = jojo.VM([], [jojo.RP(module.t)]) vm = vm.exe() assert vm.ds == [3, 3]
def test_7(): code = '''\ (+jojo t '(a b (((c)))) dup car swap dup cdr car swap dup cdr cdr car car car car swap drop) ''' sexp_vect = parse_sexp_vect(code_scan(code)) module = compile_module(__name__ + 'test_7', sexp_vect) vm = VM([], [RP(module.t)]) vm = vm.exe() assert vm.ds == ["a", "b", "c"]
def test_0(): assert code_scan('123 123') == ['123', '123'] assert code_scan('123 "123"') == ['123', '"123"'] assert code_scan('123"123"') == ['123', '"123"'] assert code_scan('123" 123"') == ['123', '" 123"']
def test_1(): assert code_scan('(1 (2) 3)') == ['(', '1', '(', '2', ')', '3', ')']
def test_0(): symbol_vect = code_scan(string) sexp_vect = parse_sexp_vect(symbol_vect) for sexp in sexp_vect: sexp_print(sexp) newline()