@@ -87,8 +87,8 @@ def set_global(self, symbol):
87
87
88
88
class Assembler :
89
89
90
- def __init__ (self , symbols = None , bases = None , globls = None ):
91
- self .symbols = SymbolTable (symbols or {}, bases or {}, globls or {})
90
+ def __init__ (self , symbols = None , bases = None , globals = None ):
91
+ self .symbols = SymbolTable (symbols or {}, bases or {}, globals or {})
92
92
opcodes .symbols = self .symbols # XXX dirty hack
93
93
94
94
def init (self , a_pass ):
@@ -223,7 +223,7 @@ def d_align(self, align=4, fill=None):
223
223
self .fill (self .section , amount , fill )
224
224
225
225
def d_set (self , symbol , expr ):
226
- value = int (opcodes .eval_arg (expr )) # TODO: support more than just integers
226
+ value = int (opcodes .eval_arg (expr ))
227
227
self .symbols .set_sym (symbol , ABS , None , value )
228
228
229
229
def d_global (self , symbol ):
@@ -265,6 +265,12 @@ def assembler_pass(self, lines):
265
265
# machine instruction
266
266
func = getattr (opcodes , 'i_' + opcode .lower (), None )
267
267
if func is not None :
268
+ # during the first pass, symbols are not all known yet.
269
+ # so some expressions may not evaluate to something (yet).
270
+ # instruction building requires sane arguments however.
271
+ # since all instructions are 4 bytes long, we simply skip
272
+ # building instructions during pass 1, and append an "empty
273
+ # instruction" to the section to get the right section size.
268
274
instruction = 0 if self .a_pass == 1 else func (* args )
269
275
self .append_section (instruction .to_bytes (4 , 'little' ), TEXT )
270
276
continue
0 commit comments