-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestgen.py
More file actions
77 lines (69 loc) · 1.47 KB
/
testgen.py
File metadata and controls
77 lines (69 loc) · 1.47 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from gen import geneval,genfn
import sys
from stmt import expr,stmt
from disasm import disasm2,disasm
import itertools
try:
batched=itertools.batched
except AttributeError:
def batched(l,count):
it=iter(l)
while True:
line=()
for i in range(count):
try:
line=line+(next(it),)
except StopIteration:
break
else:
yield line
continue
yield line
break
def parseexpr(s):
return next(iter(expr(s)))[0]
def parsestmt(s):
return next(iter(stmt(s)))[0]
def hexlen(n,l):
return hex(n)[2:].rjust(l,'0')
def hexformat(s):
step=8
lines=[]
for i,parts in enumerate(batched(s,step)):
line=hexlen(i*step,8)
for n in parts:
line+=' '
line+=hexlen(n,2)
lines.append(line)
return '\n'.join(lines)
def testexpr(code):
print('code')
print(code)
insts=geneval(parseexpr(code),{})
print('compiled')
print(hexformat(insts))
print('asm')
#print(disasm(insts))
#print('asm2')
print(disasm2(insts))
def teststmt(code):
print('code')
print(code)
insts=genfn(parsestmt(code),{})
print('compiled')
print(hexformat(insts))
print('asm')
#print(disasm(insts))
#print('asm2')
print(disasm2(insts))
testexpr('9')
testexpr('9+6')
#testexpr('+9')
testexpr('9?5:7?6:3')
#teststmt('9?5:7?6:3')
teststmt('fn a(a) a=1')
teststmt('fn a(a,b) a=1')
teststmt('fn a(a,b) b=1')
teststmt('fn a(a,b) def b=1')
teststmt('fn a(a,b){def b=1 a=b}')
teststmt('fn a(a,b){def b=1 a=b(b)}')