@@ -87,8 +87,8 @@ def set_global(self, symbol):
8787
8888class Assembler :
8989
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 {})
9292 opcodes .symbols = self .symbols # XXX dirty hack
9393
9494 def init (self , a_pass ):
@@ -223,7 +223,7 @@ def d_align(self, align=4, fill=None):
223223 self .fill (self .section , amount , fill )
224224
225225 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 ))
227227 self .symbols .set_sym (symbol , ABS , None , value )
228228
229229 def d_global (self , symbol ):
@@ -265,6 +265,12 @@ def assembler_pass(self, lines):
265265 # machine instruction
266266 func = getattr (opcodes , 'i_' + opcode .lower (), None )
267267 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.
268274 instruction = 0 if self .a_pass == 1 else func (* args )
269275 self .append_section (instruction .to_bytes (4 , 'little' ), TEXT )
270276 continue
0 commit comments