-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtalogo-notes.txt
93 lines (77 loc) · 2.51 KB
/
talogo-notes.txt
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
generate_code(blk, blocks):
blk -- top block of the start stack (i.e., 'start' block)
blocks -- all blocks of the program ???
for every named stack:
stacks[stack_key] = _readline(_blocks_to_code(top block of that stack))
return _blocks_to_code('start' block)
_blocks_to_code(blk):
blk -- top block of a stack
return a list of tuples (primitive name or value of value block or '%nothing%', block number)
define scope by inserting '[', ']', etc.
run_blocks(code):
code -- output of generate_code(...)
_setup_cmd(code)
_setup_cmd(string):
string -- output of generate_code(...), not a str instance
hide the active turtle
step = _start_eval(_readline(string))
_readline(line):
line -- output of generate_code(...)
turn tuples (primitive name, block number) into tuples (symbol, block number)
turn stringified values back into values of the original type
turn '[', ']', etc. into embedded lists
return the list of all tuples in the original order
_start_eval(blklist):
show stop button
icall(evline, blklist)
hide stop button
re-enable hover help
evline(blklist):
iline = copy of blklist
arglist = None
while iline:
If the blocks are visible, highlight the current block.
In debugging modes, we pause between steps and show the turtle.
'Stand-alone' booleans are handled here. ???
Process the token and any arguments.
icall(_eval)
Time to unhighlight the current block.
set iline back to its original value
_eval():
token = iline.pop(0)
if token is a symbol:
We highlight blocks here in case an error occurs...
icall(_evalsym, token)
and unhighlight if everything was OK.
ireturn(iresult)
else:
ireturn(token)
_evalsym(token):
cfun = token
arglist = []
for repeat(token.nargs):
icall(_eval)
arglist.append(iresult)
if cfun.rprim:
if isinstance(cfun.fcn, list):
# embedded flow of blocks
icall(_ufuncall, cfun.fcn)
else:
icall(cfun.fcn, *arglist)
ireturn(None)
else:
ireturn(cfun.fcn(self, *arglist))
set cfun and arglist back to their original value
_ufuncall(body):
ijmp(evline, body)
icall(fcn, *args):
PUSH onto the istack
istack.append(step)
step = fcn(*(args))
ireturn(res):
POP from the istack
step = istack.pop()
iresult = res
ijmp(fcn, *args):
advance to next step without changing the istack
step = fcn(*(args))