forked from zack-bitcoin/chalang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_chalang.erl
45 lines (42 loc) · 1.7 KB
/
test_chalang.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-module(test_chalang).
-export([test/0, test/1, run_script/3]).
-define(loc, "src/forth/").
run_script(X, Gas, Loc) ->
{ok, A} = file:read_file(Loc ++ X ++ ".fs"),
io:fwrite("run script "),
io:fwrite(X),
io:fwrite("\n"),
io:fwrite("\n"),
B = compiler_chalang:doit(<<A/binary, <<"\n test \n">>/binary>>),
chalang:test(B, Gas, Gas, Gas, Gas, []).
run_scripts([], _, _) -> ok;
run_scripts([H|T], Gas, Loc) ->
X = run_script(H, Gas, Loc),
{d, NewGas, [<<1:32>>],_,_,_,_,_,_,_,_,_} = X,
run_scripts(T, NewGas, Loc).
test() -> test(?loc).
test(Loc) ->
Scripts = ["function", "variable",
"macro", "case", "recursion", "map",
"math", "hashlock", "case2",
"case_binary"],
%"merge"],
Gas = 10000,
run_scripts(Scripts, Gas, Loc),
{ok, A} = file:read_file(Loc ++ "satoshi_dice.fs"),
B = compiler_chalang:doit(<<A/binary, <<"\n test1 \n">>/binary>>),
{d, _, Stack, _,_,_,_,_,_,_,_,_} = chalang:test(B, Gas, Gas, Gas, Gas, []),
[<<0:32>>,<<0:32>>,<<1:32>>] = Stack,
C = compiler_chalang:doit(<<A/binary, <<"\n test2 \n">>/binary>>),
{d, _, Stack2, _,_,_,_,_,_,_,_,_} = chalang:test(C, Gas, Gas, Gas, Gas, []),
[<<1000:32>>,<<0:32>>,<<2:32>>] = Stack2,
D = compiler_chalang:doit(<<A/binary, <<"\n test3 \n">>/binary>>),
{d, _, Stack3, _,_,_,_,_,_,_,_,_} = chalang:test(D, Gas, Gas, Gas, Gas, []),
[<<1000:32>>,<<1:32>>,<<2:32>>] = Stack3,
E = compiler_chalang:doit(<<A/binary, <<"\n test4 \n">>/binary>>),
{d, _, Stack4, _,_,_,_,_,_,_,_,_} = chalang:test(E, Gas, Gas, Gas, Gas, []),
[<<1000:32>>,<<0:32>>,<<3:32>>] = Stack4,
S = success,
S = compiler_lisp:test(),
S = compiler_lisp2:test(),
success.