-
Notifications
You must be signed in to change notification settings - Fork 171
Move visit_Call in Common Visitor #2013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from lpython import dataclass, i32 | ||
from lpython import dataclass, i32, u16, f32 | ||
|
||
|
||
@dataclass | ||
|
@@ -7,6 +7,14 @@ class StringIO: | |
_0cursor : i32 = 10 | ||
_len : i32 = 1 | ||
|
||
@dataclass | ||
class StringIONew: | ||
_buf : str | ||
_0cursor : i32 = i32(142) | ||
_len : i32 = i32(2439) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR assigns this to the "value" member of Variable. I am not sure if our code assumes that this is a constant, so the backend doesn't even visit this variable and uses the value instead. If so, then this won't work, since any modifications to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a test for modifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is documentation for Variable:
So A separate question is if they are set, if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT: This does work on an assignment but makes things more complex as it requires more methods to be moved to CommonVisitor. Now, this problem gets trickier as Structs don't have a body, and, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing that we may do is add a field in the Struct to contain initializers for all it's variable members like the following: | StructType(symbol_table symtab, identifier name, identifier* dependencies,
identifier* members, abi abi, access access, bool is_packed, bool is_abstract,
- expr? alignment, symbol? parent)
+ expr* initializers, expr? alignment, symbol? parent) |
||
_var1 : u16 = u16(23) | ||
_var2 : f32 = f32(30.24) | ||
|
||
|
||
def test_issue_1928(): | ||
integer_asr : str = '(Integer 4 [])' | ||
|
@@ -47,4 +55,15 @@ def test_issue_1928(): | |
assert test_dude4._0cursor == 31 | ||
|
||
|
||
def test_issue_1981(): | ||
integer_asr : str = '(Integer 4 [])' | ||
test_dude : StringIONew = StringIONew(integer_asr) | ||
assert test_dude._buf == integer_asr | ||
assert test_dude._len == 2439 | ||
assert test_dude._0cursor == 142 | ||
assert test_dude._var1 == u16(23) | ||
assert abs(test_dude._var2 - f32(30.24)) < f32(1e-5) | ||
|
||
|
||
test_issue_1981() | ||
test_issue_1928() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is forced by moving
visit_Call
andvisit_List
into the common visitor. Both the originalmat: Mat = Mat([f64(0.0), f64(0.0)])
and the newmat: Mat = Mat(2.0)
is incorrect so I think it's fine for now. The proper fix is to usemat: Mat = Mat(empty((2, 2), dtype=float64))
.