@@ -190,6 +190,8 @@ def parse_proc_head():
190190 return op
191191
192192def parse_struct () -> Op | list [Op ] | None :
193+ is_unpack = State .is_unpack
194+ State .is_unpack = False
193195 first_token = next (State .tokens )
194196 parent = None
195197 if first_token [0 ].startswith ("(" ) and first_token [0 ].endswith (")" ):
@@ -249,8 +251,9 @@ def parse_struct() -> Op | list[Op] | None:
249251 if field_type != - 1 :
250252 State .loc = f"{ State .filename } :{ current_token [1 ]} "
251253 State .throw_error ("field name was not defined" )
252-
254+ State . is_unpack = is_unpack
253255 struct = Struct (name [0 ], fields , struct_types , parent , defaults )
256+ State .is_unpack = False
254257 if parent is not None :
255258 parent .children .append (struct )
256259 State .structures [name [0 ]] = struct
@@ -281,13 +284,13 @@ def parse_struct() -> Op | list[Op] | None:
281284 State .throw_error ("field name was not defined" )
282285
283286 if not started_proc :
287+ State .is_unpack = is_unpack
284288 struct = Struct (name [0 ], fields , struct_types , parent , defaults )
289+ State .is_unpack = False
285290 if parent is not None :
286291 parent .children .append (struct )
287292 State .structures [name [0 ]] = struct
288293
289- State .is_unpack = False
290-
291294 return ops
292295
293296def parse_dot (token : str , allow_var : bool = False , auto_ptr : bool = False ) -> list [Op ]:
@@ -345,7 +348,6 @@ def lex_token(token: str) -> Op | None | list:
345348
346349 elif token == "end" :
347350 if len (State .block_stack ) <= 0 :
348- State .loc = f"{ State .filename } :{ State .loc } "
349351 State .throw_error ("block for end not found" )
350352 block = State .block_stack .pop ()
351353 if block .type == BlockType .BIND :
@@ -418,9 +420,9 @@ def lex_token(token: str) -> Op | None | list:
418420 State .throw_error ("variable can't be initialized with non-int value" )
419421 value = evaluate_block (name [1 ], "variable value" )
420422 return [
421- Op (OpType .PUSH_INT , value , f" { State .filename } : { State . loc } " ),
422- Op (OpType .PUSH_VAR if State .current_proc is None else OpType .PUSH_LOCAL_VAR , name [0 ], f" { State .filename } : { State . loc } " ),
423- Op (OpType .OPERATOR , Operator .STORE , f" { State .filename } : { State . loc } " )
423+ Op (OpType .PUSH_INT , value , State .loc ),
424+ Op (OpType .PUSH_VAR if State .current_proc is None else OpType .PUSH_LOCAL_VAR , name [0 ], State .loc ),
425+ Op (OpType .OPERATOR , Operator .STORE , State .loc )
424426 ]
425427 else :
426428 State .tokens_queue .append (next_token )
@@ -583,7 +585,7 @@ def lex_token(token: str) -> Op | None | list:
583585 elif token .startswith ("!." ):
584586 return [
585587 * parse_dot (token [2 :], auto_ptr = True ),
586- Op (OpType .OPERATOR , Operator .STORE , f" { State .filename } : { State . loc } " )
588+ Op (OpType .OPERATOR , Operator .STORE , State .loc )
587589 ]
588590
589591 elif token .startswith ("!" ):
@@ -593,7 +595,7 @@ def lex_token(token: str) -> Op | None | list:
593595 else :
594596 return [
595597 * parse_dot (token [1 :], allow_var = True , auto_ptr = True ),
596- Op (OpType .OPERATOR , Operator .STORE , f" { State .filename } : { State . loc } " )
598+ Op (OpType .OPERATOR , Operator .STORE , State .loc )
597599 ]
598600
599601 elif token .startswith ("*" ) and token [1 :] in State .procs :
@@ -647,7 +649,7 @@ def parse_until_end() -> list[Op]:
647649 for token , loc in State .tokens :
648650 if token == "end" and len (State .block_stack ) - 1 == initial_blocks :
649651 end = True
650- State .loc = loc
652+ State .loc = f" { State . filename } : { loc } "
651653 op = lex_token (token )
652654 if isinstance (op , list ):
653655 ops .extend (op )
@@ -669,7 +671,7 @@ def parse_to_ops(program: str) -> list:
669671 ops = []
670672
671673 for token , loc in State .tokens :
672- State .loc = loc
674+ State .loc = f" { State . filename } : { loc } "
673675 op = lex_token (token )
674676 if isinstance (op , list ):
675677 ops .extend (op )
0 commit comments