Пример #1
0
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]
Пример #2
0
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]
Пример #3
0
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"]
Пример #4
0
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"]
Пример #5
0
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]
Пример #6
0
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
Пример #7
0
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"]
Пример #8
0
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]
Пример #9
0
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"]
Пример #10
0
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"']
Пример #11
0
def test_1():
    assert code_scan('(1 (2) 3)') == ['(', '1', '(', '2', ')', '3', ')']
Пример #12
0
def test_0():
    symbol_vect = code_scan(string)
    sexp_vect = parse_sexp_vect(symbol_vect)
    for sexp in sexp_vect:
        sexp_print(sexp)
        newline()