-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed build script * Supporting MetaModelica assignment semantics
- Loading branch information
Showing
5 changed files
with
65 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Setfield | ||
""" | ||
Helper function for the assignmacro, see @assign | ||
We have one case where we assign a immutable structure to an immutable structure or something to a primitive variable. | ||
If it is not a primitive we assign to a subcomponent of that structure. We then clone the structure with that particular field changed. | ||
""" | ||
function assignFunc(expr) | ||
res = if @capture(expr, lhs_._= rhs_) | ||
if !isprimitivetype(typeof(lhs)) | ||
Setfield.setmacro(identity, expr, overwrite=true) | ||
else | ||
quote | ||
$(esc(expr)) | ||
end | ||
end | ||
else | ||
quote | ||
$(esc(expr)) | ||
end | ||
end | ||
return res | ||
end | ||
|
||
""" | ||
This macro reimplements the MetaModelica assignment semantics using | ||
setfield to assign to variables. | ||
For assignments using primitives, the regular Julia assignment is generated. | ||
For cases where deeply nested immutable structures are manipulated we use setfield | ||
E.g.: | ||
a.b.c = 5 | ||
Where a is a nested immutable struct | ||
""" | ||
macro assign(expr) | ||
assignFunc(expr) | ||
end |
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