Open ChrisIsKing opened 4 days ago
So for the dependency stuff @AshishMahendra I'm thinking we can do something like:
import:py from jaclang.runtimelib.machine {JacMachine}
# Dynamic node source code with Jac and Python module imports
node_source_code = """
node test_node {
has value:int;
can calculate_value with entry {
import:py random; # Python module
import:jac my_jac_module; # Jac module within current namespace
let random_value = random.randint(1, 100);
self.value = my_jac_module.add_value(self.value, random_value); # Using Jac module functionality
print("Calculated Value:", f'{self.value}');
}
}
"""
with entry {
# Specify allowed modules with flexibility for both Jac and Python
allowed_modules = {
'python': ['random', 'math'], # Python modules
'jac': ['my_jac_module', 'another_module'] # Jac modules (within the current namespace or globally)
}
# Dynamically define the node architype with module injection
JacMachine.get().create_architype_from_source(
node_source_code,
allowed_modules=allowed_modules
)
# Instantiate the dynamically created node
node_obj = JacMachine.get().spawn_node('test_node', {'value': 42})
node_obj.calculate_value()
}
The current JacMachine VM provides a robust framework for handling operations on loaded Jac programs, including listing and updating nodes, walkers, and other key components. For example:
To further enhance the flexibility of JacMachine, we propose an extension to allow for the dynamic creation of architypes (such as nodes and walkers) through direct source code input via the VM interface. This would allow developers to define new architypes at runtime without needing to predefine them in static code.
A desired interface for this feature might look like the following:
Considerations/Requirements: