-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
33 lines (26 loc) · 889 Bytes
/
commands.py
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
# commands.py
import stapel_types
class Cmd:
def __init__(self, token):
raise NotImplementedError, "abstract class"
# pushing a value is the default for most word types.
def execute(self, interpreter):
interpreter.push(self.data)
class CmdInteger(Cmd):
def __init__(self, token):
self.data = int(token)
class CmdName(Cmd):
def __init__(self, token):
self.data = token # store as-is
def execute(self, interpreter):
value = interpreter.namespace[self.data]
if isinstance(value, stapel_types.Word):
value(interpreter)
else:
interpreter.push(value)
class CmdSymbol(Cmd):
def __init__(self, token):
self.data = token[1:] # strip the leading ':'
def execute(self, interpreter):
s = stapel_types.Symbol(self.data)
interpreter.push(s)