@@ -69,13 +69,13 @@ def getvar(self, name: str, **kwargs) -> XTDatastore:
6969
7070 def execute (self , line : str , raise_error : bool = False ) -> Any :
7171 if self ._live and ((self .linetrk and self .linetrk [- 1 ][0 ] != "<stdin>" ) or not self .linetrk ):
72- self .linetrk .append ([ " <stdin>" , "<stdin>.global" , 0 , False , "<stdin>" ] )
72+ self .linetrk .append ({ "file" : " <stdin>" , "path" : " <stdin>" , "section" : "<stdin> .global" , "start" : 0 , "ended" : False , "as" : " <stdin>"} )
7373
7474 try :
7575 tokens = self .parseline (line )
7676 try :
7777 trkdata = self .linetrk [- 1 ]
78- prevline = self .sections [trkdata [1 ]]["lines" ][trkdata [2 ] - self .sections [trkdata [1 ]]["start" ] - 2 ]
78+ prevline = self .sections [trkdata ["section" ]]["lines" ][trkdata ["start" ] - self .sections [trkdata ["section" ]]["start" ] - 2 ]
7979 if prevline [- 2 :] in [" \\ " , ".." ]:
8080 return None
8181
@@ -89,16 +89,16 @@ def execute(self, line: str, raise_error: bool = False) -> Any:
8989 return self ._opmap [operator ](XTContext (self .memory , tokens [1 :]))
9090
9191 except Exception as e :
92- if raise_error :
92+ if raise_error or True :
9393 raise e
9494
9595 elif config .get ("quiet" , False ):
9696 return None
9797
9898 print ("Exception occured in x2 thread!" )
9999 for tracker in self .linetrk :
100- line = self .sections [tracker [1 ]]["lines" ][tracker [2 ] - self .sections [tracker [1 ]]["start" ] - 1 ].lstrip ()
101- print (f"{ tracker [0 ]} line { tracker [2 ]} , in { tracker [1 ].split ('.' )[1 ]} :\n > { line } " )
100+ line = self .sections [tracker ['section' ]]["lines" ][tracker ['start' ] - self .sections [tracker ['section' ]]["start" ] - 1 ].lstrip ()
101+ print (f"{ tracker ['file' ]} line { tracker ['start' ]} , in { tracker ['section' ].split ('.' )[1 ]} :\n > { line } " )
102102
103103 print (f"\n { type (e ).__name__ } : { e } " )
104104 if not self ._live :
@@ -170,17 +170,21 @@ def parseline(self, line: str, multiline_offset: int = 0) -> list:
170170
171171 return data ["line" ]
172172
173- def load_sections (self , code : str , filename : str , namespace : str = None , external : bool = False ) -> None :
173+ def load_sections (self , code : str , filepath : str , namespace : str = None , external : bool = False ) -> None :
174+ filename = filepath .replace ("\\ " , "/" ).split ("/" )[- 1 ]
174175 if not hasattr (self , "_entrypoint" ):
175176 self ._entrypoint = filename
176177
177- self .memory .vars ["file" ][filename ] = {}
178+ self .memory .vars ["file" ][filepath ] = {}
178179
179- fileid = (namespace or filename ).removesuffix (".xt" )
180+ fileid = (namespace or filepath . replace ( "/" , "." ) ).removesuffix (".xt" )
180181 dt = {
181182 "active" : "global" ,
182183 "code" : [],
183- "sections" : {f"{ fileid } .global" : {"lines" : [], "priv" : False , "file" : filename , "start" : 0 , "args" : [], "ret" : None , "as" : fileid }}
184+ "sections" : {f"{ fileid } .global" : {
185+ "lines" : [], "priv" : False , "file" : filename , "path" : filepath ,
186+ "start" : 0 , "args" : [], "ret" : None , "as" : fileid
187+ }}
184188 }
185189 for lno , line in enumerate (code .split ("\n " )):
186190 if line .strip ():
@@ -198,7 +202,7 @@ def load_sections(self, code: str, filename: str, namespace: str = None, externa
198202 dt ["sections" ][ns ]["lines" ] = dt ["code" ]
199203 dt ["sections" ][f"{ fileid } .{ sid } " ] = {
200204 "file" : filename , "start" : lno + 1 , "lines" : [], "priv" : priv ,
201- "args" : line .split (" " )[1 :], "ret" : None , "as" : fileid
205+ "args" : line .split (" " )[1 :], "ret" : None , "as" : fileid , "path" : filepath
202206 }
203207 dt ["code" ] = []
204208 dt ["active" ] = sid
@@ -215,7 +219,7 @@ def load_sections(self, code: str, filename: str, namespace: str = None, externa
215219 del self .sections [f"{ fileid } .global" ] # Save memory
216220
217221 def find_section (self , section : str ) -> Tuple [str , str ]:
218- current_file = (self .linetrk or [( self . _entrypoint ,)])[ - 1 ][- 1 ]. removesuffix (".xt" )
222+ current_file = (self .linetrk [ - 1 ]["path" ] if self . linetrk else self . _entrypoint ). removesuffix (".xt" ). replace ( "/" , ". " )
219223 if "." not in section :
220224 section = f"{ current_file } .{ section } "
221225
@@ -234,12 +238,12 @@ def run_section(self, section: str) -> Any:
234238 if section not in self .memory .vars ["local" ]:
235239 self .memory .vars ["local" ][section ] = {}
236240
237- self .linetrk .append ([ s ["file" ], section , s ["start" ], False , s ["as" ]] )
241+ self .linetrk .append ({ "file" : s ["file" ], "path" : s [ "path" ], " section" : section , "start" : s ["start" ], "ended" : False , "as" : s ["as" ]} )
238242 for line in s ["lines" ]:
239- self .linetrk [- 1 ][2 ] += 1
243+ self .linetrk [- 1 ]["start" ] += 1
240244 if line .strip () and line [:2 ] != "::" :
241245 self .execute (line )
242- if self .linetrk [- 1 ][3 ]:
246+ if self .linetrk [- 1 ]['ended' ]:
243247 break
244248
245249 del self .memory .vars ["local" ][section ]
@@ -292,5 +296,6 @@ def run_section(self, section: str) -> Any:
292296 print ("x2: failed to load file" )
293297 os ._exit (1 )
294298
295- inter .load_sections (code , file .replace ("\\ " , "/" ).split ("/" )[- 1 ])
296- [inter .run_section (s ) for s in ["global" , "main" ]]
299+ inter .load_sections (code , file )
300+ file = file .replace ("\\ " , "/" ).replace ("/" , "." ).removesuffix (".xt" )
301+ [inter .run_section (s ) for s in [f"{ file } .global" , f"{ file } .main" ]]
0 commit comments