88import pickle
99import shutil
1010import types
11- from typing import Optional
12- from uuid import UUID
11+ from typing import Any , Optional
1312
1413import jaclang .compiler .absyntree as ast
1514from jaclang import jac_import
1918from jaclang .compiler .passes .main .pyast_load_pass import PyastBuildPass
2019from jaclang .compiler .passes .main .schedules import py_code_gen_typed
2120from jaclang .compiler .passes .tool .schedules import format_pass
22- from jaclang .core .construct import Architype
21+ from jaclang .core .construct import ObjectAnchor
2322from jaclang .plugin .builtin import dotgen
2423from jaclang .plugin .feature import JacCmd as Cmd
2524from jaclang .plugin .feature import JacFeature as Jac
@@ -73,6 +72,7 @@ def run(
7372 cache : bool = True ,
7473 walker : str = "" ,
7574 node : str = "" ,
75+ root : str = "" ,
7676) -> None :
7777 """Run the specified .jac file."""
7878 # if no session specified, check if it was defined when starting the command shell
@@ -86,7 +86,7 @@ def run(
8686 else ""
8787 )
8888
89- Jac .context (). init_memory ( session )
89+ jctx = Jac .context (session , { "root" : root , "entry" : node } )
9090
9191 base , mod = os .path .split (filename )
9292 base = base if base else "./"
@@ -112,47 +112,35 @@ def run(
112112 print ("Not a .jac file." )
113113 return
114114
115- if not node or node == "root" :
116- entrypoint : Architype = Jac .get_root ()
117- else :
118- obj = Jac .context ().get_obj (UUID (node ))
119- if obj is None :
120- print (f"Entrypoint { node } not found." )
121- return
122- entrypoint = obj
123-
124115 # TODO: handle no override name
125116 if walker :
126117 walker_module = dict (inspect .getmembers (loaded_mod )).get (walker )
127- if walker_module :
128- Jac .spawn_call (entrypoint , walker_module ())
118+ if walker_module and ( architype := jctx . entry . architype ) :
119+ Jac .spawn_call (architype , walker_module ())
129120 else :
130121 print (f"Walker { walker } not found." )
131122
132- Jac . reset_context ()
123+ jctx . close ()
133124
134125
135126@cmd_registry .register
136- def get_object (id : str , session : str = "" ) -> dict :
127+ def get_object (id : str , session : str = "" ) -> dict [ str , Any ] :
137128 """Get the object with the specified id."""
138129 if session == "" :
139130 session = cmd_registry .args .session if "session" in cmd_registry .args else ""
140131
141- Jac .context (). init_memory (session )
132+ jctx = Jac .context (session )
142133
143134 if id == "root" :
144- id_uuid = UUID (int = 0 )
145- else :
146- id_uuid = UUID (id )
135+ return jctx .root .__dict__
147136
148- obj = Jac .context ().get_obj (id_uuid )
149- if obj is None :
150- print (f"Object with id { id } not found." )
151- Jac .reset_context ()
152- return {}
153- else :
154- Jac .reset_context ()
155- return obj .__getstate__ ()
137+ obj = {}
138+ if (of := ObjectAnchor .ref (id )) and (oa := of .sync ()):
139+ obj = oa .__dict__
140+
141+ jctx .close ()
142+
143+ return obj
156144
157145
158146@cmd_registry .register
0 commit comments