-
Notifications
You must be signed in to change notification settings - Fork 0
/
subroutines.py
40 lines (33 loc) · 894 Bytes
/
subroutines.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
34
35
36
37
38
39
import settings as s
from constants import *
def handleSubroutine(subname):
s.callstack.append(s.point)
try:
s.point = s.sub[subname]
except KeyError:
print("Subroutine name does not exist", subname)
exit(1)
def handleInitSubroutine(code):
s.point += 1
# Just a marker
subDefinitionStack = ["s"]
while subDefinitionStack != []:
try:
l = code[s.point].strip()
except:
print("Unclosed subroutine!")
exit(1)
line = l.split()
ins = line[0]
if ins == subEnd:
subDefinitionStack.pop()
if ins == subInit:
subDefinitionStack.append("s")
s.point += 1
def handleEndSubroutine():
try:
sp = s.callstack.pop()
s.point = sp + 1
except:
print("Calling 'end' without a subroutine")
exit(1)