-
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
Conversation
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 comment
The 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 _len
will be lost.
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.
Let's add a test for modifying _len
.
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.
Here is documentation for Variable:
`symbolic_value` the optional symbolic expression to initialize the variable
(e.g. `2+3+4+x`), this value must be compile time, but it is not necessarily a
constant (e.g., can contain binary operations, other variables, etc.)
`value` the optional constant expression holding the compile time value
(e.g. `5`, or `5.5`), it is a compile time constant.
So value
and symbolic_value
must be compile time constants. So let's require that for now as well in LPython.
A separate question is if they are set, if the Variable
itself has to be a constant or not. I would say if it has to be a constant, then it should have a type Const. Otherwise it can change, which means value
is the initial value, but the runtime value can change.
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.
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 AnnAssign
which is an Assignment to the struct variables isn't possible with the current design.
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.
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)
TODO:
|
# But since lpython ignores empty, the following is just a workaround. | ||
# Follow the discussions here: https://github.com/lcompilers/lpython/issues/1809 | ||
mat: Mat = Mat(2.0) | ||
vec: Vec = Vec(2.0) |
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
and visit_List
into the common visitor. Both the original mat: Mat = Mat([f64(0.0), f64(0.0)])
and the new mat: Mat = Mat(2.0)
is incorrect so I think it's fine for now. The proper fix is to use mat: Mat = Mat(empty((2, 2), dtype=float64))
.
TODO:
|
I think The |
Otherwise I think this is fine. |
This is not required as #2056 is merged. |
Fixes #1981