Skip to content

Commit c3d440f

Browse files
committed
Bug fixes
1 parent a7d6d9f commit c3d440f

File tree

7 files changed

+161
-107
lines changed

7 files changed

+161
-107
lines changed

py/ec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from ec_program import Program
55
from ec_core import Core
6+
from ec_graphics import Graphics
67
from ec_p100 import P100
78

89
class EasyCoder:
@@ -17,7 +18,7 @@ def __init__(self):
1718
source = f.read()
1819
f.close()
1920

20-
Program(source, [Core, P100])
21+
Program(source, [Core, Graphics, P100])
2122

2223
if __name__ == '__main__':
2324
EasyCoder()

py/ec_compiler.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def __init__(self, program):
1717
self.warnings = []
1818
self.program.compiler = self
1919
self.addCommand = self.program.add
20-
20+
2121
def getPC(self):
2222
return len(self.program.code)
23-
23+
2424
def getIndex(self):
2525
return self.index
26-
26+
2727
# Move the index along
2828
def next(self):
2929
self.index += 1
@@ -33,47 +33,47 @@ def getToken(self):
3333
if self.index >= len(self.tokens):
3434
FatalError(self, 'Premature end of script')
3535
return self.tokens[self.index].token
36-
36+
3737
# Get the next token
3838
def nextToken(self):
3939
self.index += 1
4040
return self.getToken()
41-
41+
4242
def peek(self):
4343
try:
4444
return self.tokens[self.index + 1].token
4545
except:
4646
return None
47-
47+
4848
# Get a value
4949
def getValue(self):
5050
return self.value.compileValue()
51-
51+
5252
# Get the next value
5353
def nextValue(self):
5454
self.index += 1
5555
return self.value.compileValue()
56-
56+
5757
# Get a constant
5858
def getConstant(self, token):
5959
self.index += 1
6060
return self.value.compileConstant(token)
61-
61+
6262
# Get a condition
6363
def getCondition(self):
6464
return self.condition.compileCondition()
65-
65+
6666
# Get the next condition
6767
def nextCondition(self):
6868
self.index += 1
6969
return self.condition.compileCondition()
70-
70+
7171
def tokenIs(self, value):
7272
return self.getToken() == value
73-
73+
7474
def nextIs(self, value):
7575
return self.nextToken() == value
76-
76+
7777
def getCommandAt(self, pc):
7878
return self.program.code[pc]
7979

@@ -91,15 +91,15 @@ def nextIsSymbol(self):
9191

9292
def rewindTo(self, index):
9393
self.index = index
94-
94+
9595
def getLino(self):
9696
if self.index >= len(self.tokens):
9797
return 0
9898
return self.tokens[self.index].lino
99-
99+
100100
def warning(self, message):
101101
self.warnings.append(message)
102-
102+
103103
def showWarnings(self):
104104
for warning in self.warnings:
105105
print(f'Line {self.getLino() + 1}: {warning}')
@@ -112,20 +112,24 @@ def getSymbolRecord(self):
112112
symbolRecord['used'] = True
113113
return symbolRecord
114114
return None
115-
115+
116116
def compileLabel(self, command):
117117
return self.compileSymbol(command, self.getToken(), False)
118118

119119
def compileVariable(self, command, valueHolder=False):
120120
return self.compileSymbol(command, self.nextToken(), valueHolder)
121121

122122
def compileSymbol(self, command, name, valueHolder):
123-
if hasattr(self.symbols, name):
124-
FatalError(self, f'{self.code[self.pc].lino}: Duplicate symbol name "{name}"')
123+
try:
124+
v = self.symbols[name]
125+
except:
126+
v = None
127+
if v:
128+
FatalError(self, f'Duplicate symbol name "{name}"')
125129
return False
126130
self.symbols[name] = self.getPC()
127131
command['type'] = 'symbol'
128-
command['isValueHolder'] = valueHolder
132+
command['valueHolder'] = valueHolder
129133
command['name'] = name
130134
command['elements'] = 1
131135
command['index'] = 0
@@ -138,7 +142,7 @@ def compileSymbol(self, command, name, valueHolder):
138142
# Compile the current token
139143
def compileToken(self):
140144
token = self.getToken()
141-
# print(token)
145+
# print(f'Compile {token}')
142146
if not token:
143147
return False
144148
mark = self.getIndex()

0 commit comments

Comments
 (0)