This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba31cee
commit 69b970f
Showing
5 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Define a simple node type called `Item` | ||
node Item { | ||
has value: int = 0; | ||
} | ||
|
||
# Define an edge type called `Link` | ||
edge Link {} | ||
|
||
# Define the `bar` walker | ||
walker bar_walk { | ||
has count: int = 0; | ||
|
||
# Start walking from the root node or an Item node | ||
can start with `root | Item entry { | ||
here ++> Item(); | ||
if self.count < 5 { | ||
visit [-->]; | ||
} else { | ||
"Created 5 items." |> print; | ||
disengage; | ||
} | ||
} | ||
|
||
# Walk over Item nodes and update their values | ||
can walk with Item entry { | ||
here.value = self.count; | ||
f"Item value: {here.value}" |> print; | ||
self.count += 1; | ||
visit [-->] else { | ||
"Finished walking over all items." |> print; | ||
disengage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import:py from jaclang.plugin.feature {JacFeature as Jac} | ||
import:jac from bar {bar_walk} | ||
import:py from time {sleep} | ||
|
||
|
||
can update_bar_walker { | ||
new_behavior = ''' | ||
# New behavior added during runtime | ||
can end with `root exit { | ||
"bar_walk has been updated with new behavior!" |> print; | ||
disengage; | ||
} | ||
} | ||
'''; | ||
bar_file_path = '/home/ubuntu/jaclang/jaclang/tests/fixtures/walker_reload/bar.jac'; | ||
with open(bar_file_path, 'r') as bar_file{ | ||
original_content = bar_file.read(); | ||
} | ||
|
||
with open(bar_file_path, 'r+') as bar_file { # Specify the correct path to bar.jac | ||
content = bar_file.read(); | ||
|
||
# Replace the last occurrence of "}" with the new behavior | ||
last_brace_index = content.rfind('}'); | ||
if last_brace_index != -1{ | ||
updated_content = content[:last_brace_index] + new_behavior; | ||
bar_file.seek(0); | ||
bar_file.write(updated_content); | ||
bar_file.truncate(); | ||
} | ||
} | ||
"Updated bar.jac with new behavior." |> print; | ||
|
||
(bar_walk_new,)=Jac.context().jac_machine.update_walker("bar", items={'bar_walk': None}); | ||
"Running bar_walk after update..." |> print; | ||
root spawn bar_walk_new(); | ||
print(f"bar_walk: {bar_walk_new.__dict__}"); | ||
with open(bar_file_path, 'w') as bar_file{ | ||
bar_file.write(original_content); | ||
} | ||
} | ||
|
||
# Initialize the walker | ||
can initial_run { | ||
root spawn bar_walk(); | ||
print(f"bar_walk: {bar_walk.__dict__}"); | ||
|
||
} | ||
|
||
# Define the entry point to run the test | ||
with entry { | ||
initial_run(); | ||
|
||
# Update the walker | ||
update_bar_walker(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters