154 lines
4.0 KiB
Python
Executable File
154 lines
4.0 KiB
Python
Executable File
import sys
|
|
from pathlib import Path
|
|
|
|
import xic_breakpoint_shell
|
|
from xic_executor import run_xic
|
|
from xic_validator import validate_xic
|
|
from xic_visualizer import xic_visualizer
|
|
from xic_diagnostics import xic_diagnostics
|
|
from xic_profiler import xic_profiler
|
|
from xic_cache import xic_cache
|
|
|
|
|
|
class CommandRegistry:
|
|
def __init__(self):
|
|
self.commands = {}
|
|
|
|
def register(self, name, handler):
|
|
self.commands[name] = handler
|
|
|
|
def dispatch(self, cmd, args):
|
|
if cmd in self.commands:
|
|
return self.commands[cmd](args)
|
|
return False
|
|
|
|
|
|
class XICShell:
|
|
def __init__(self):
|
|
self.last_file = None
|
|
self.registry = CommandRegistry()
|
|
|
|
xic_breakpoint_shell.register_breakpoint_commands(self)
|
|
|
|
self.registry.register("run", self.cmd_run)
|
|
self.registry.register("inspect", self.cmd_inspect)
|
|
self.registry.register("vis", self.cmd_vis)
|
|
self.registry.register("profile", self.cmd_profile)
|
|
self.registry.register("cache", self.cmd_cache)
|
|
self.registry.register("clear", self.cmd_clear)
|
|
self.registry.register("reload", self.cmd_reload)
|
|
self.registry.register("help", self.cmd_help)
|
|
self.registry.register("exit", self.cmd_exit)
|
|
self.registry.register("quit", self.cmd_exit)
|
|
|
|
def start(self):
|
|
print("XIC Interactive Shell")
|
|
print("Type 'help' for commands.\n")
|
|
|
|
while True:
|
|
try:
|
|
line = input("xic> ").strip()
|
|
except EOFError:
|
|
print("")
|
|
break
|
|
|
|
if not line:
|
|
continue
|
|
|
|
parts = line.split()
|
|
cmd = parts[0]
|
|
args = parts[1:]
|
|
|
|
handled = self.registry.dispatch(cmd, args)
|
|
if not handled:
|
|
print(f"Unknown command: {cmd}")
|
|
|
|
def cmd_run(self, args):
|
|
if not args:
|
|
print("Usage: run <file.gx>")
|
|
return True
|
|
gx = Path(args[0])
|
|
self.last_file = gx
|
|
run_xic(str(gx))
|
|
return True
|
|
|
|
def cmd_inspect(self, args):
|
|
if not args:
|
|
print("Usage: inspect <file.gx>")
|
|
return True
|
|
gx = Path(args[0])
|
|
self.last_file = gx
|
|
manifest = validate_xic(str(gx))
|
|
print("[XIC] Manifest:")
|
|
for k, v in manifest.items():
|
|
print(f" {k}: {v}")
|
|
return True
|
|
|
|
def cmd_vis(self, args):
|
|
if not args:
|
|
print("Usage: vis <file.gx>")
|
|
return True
|
|
gx = Path(args[0])
|
|
self.last_file = gx
|
|
manifest = validate_xic(str(gx))
|
|
xic_visualizer.report(manifest)
|
|
return True
|
|
|
|
def cmd_profile(self, args):
|
|
if not args:
|
|
print("Usage: profile <file.gx>")
|
|
return True
|
|
gx = Path(args[0])
|
|
self.last_file = gx
|
|
xic_profiler.reset()
|
|
run_xic(str(gx))
|
|
xic_profiler.report()
|
|
return True
|
|
|
|
def cmd_cache(self, args=None):
|
|
print("[XIC] Cache State:")
|
|
for key in xic_cache.cache.keys():
|
|
print(f" {key}")
|
|
return True
|
|
|
|
def cmd_clear(self, args=None):
|
|
xic_cache.cache.clear()
|
|
print("[XIC] Cache cleared")
|
|
return True
|
|
|
|
def cmd_reload(self, args=None):
|
|
if not self.last_file:
|
|
print("No previous file to reload")
|
|
return True
|
|
run_xic(str(self.last_file))
|
|
return True
|
|
|
|
def cmd_help(self, args=None):
|
|
print("Commands:")
|
|
for name in sorted(self.registry.commands.keys()):
|
|
print(f" {name}")
|
|
return True
|
|
|
|
def cmd_exit(self, args=None):
|
|
sys.exit(0)
|
|
|
|
|
|
xic_shell = XICShell()
|
|
|
|
def xic_cli(argv):
|
|
if not argv:
|
|
xic_shell.start()
|
|
return True
|
|
cmd = argv[0]
|
|
args = argv[1:]
|
|
return xic_shell.registry.dispatch(cmd, args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) > 1:
|
|
cmd = sys.argv[1]
|
|
args = sys.argv[2:]
|
|
xic_shell.registry.dispatch(cmd, args)
|
|
else:
|
|
xic_shell.start()
|