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
Showing
5 changed files
with
68 additions
and
12 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
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,45 @@ | ||
""" | ||
@proceses | ||
Create a process from a function. | ||
Note: the first arg to the function being passed must be an AbstractClock | ||
""" | ||
macro process(id, expr) | ||
expr.head != :call && error("Expression is not a function call.") | ||
f = expr.args[1] #extract function passed | ||
c = expr.args[2] #first function arg must be an AbstractClock | ||
args = expr.args[3:end] #extract other function args | ||
p = :(Prc($id, $f, $(args...))) #create Prc struct | ||
esc(:(process!($c,$p))) #execute process! | ||
end | ||
|
||
""" | ||
@event | ||
Schedule an event. | ||
Note: if 3 arguments are passed after the function being called, | ||
the third one is assumed to be the keyword argument `n`. | ||
""" | ||
macro event(expr, args...) | ||
expr.head != :call && error("Expression is not a function call.") | ||
f = expr.args[1] #extract function passed | ||
c = expr.args[2] #first function arg must be an AbstractClock | ||
fargs = expr.args[2:end] #extract other function args | ||
ex = :(fun($f, $(fargs...))) #create Action | ||
if length(args) <= 2 | ||
esc(:(event!($c, $ex, $(args...)))) #execute event! | ||
else | ||
esc(:(event!($c, $ex, $(args[1:2]...), n = $args[end]))) #execute event! | ||
end | ||
end | ||
|
||
""" | ||
@run! | ||
Run a simulation for a given duration. | ||
""" | ||
macro run!(clk, duration) | ||
return esc(:(run!($clk, $duration))) | ||
end |