-
Notifications
You must be signed in to change notification settings - Fork 166
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
Implemented basic classes #2775
Conversation
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.
I think this looks good to me!
Great job.
@Thirumalai-Shaktivel can you please also review this? If it looks good, go ahead and merge.
Added Assignment of StructConstructor and related test. Working on deepcopying objects:
Related issue : #2775 |
@@ -0,0 +1,44 @@ | |||
from lpython import i32 | |||
class Character: | |||
def __init__(self:"Character", name:str, health:i32, attack_power:i32): |
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.
Can we have __new__
here?
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.
The __init__
in LPython has a similar signature to the the __new__
in Cpython but it performs the functionality of the __init__
function. This doesn't control the memory allocation of the object.
Looks great, thank you. Are you planning to introduce |
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.
LGTM as well, thank you!
virtual void visit_init_body (const AST::FunctionDef_t &/*x*/) = 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.
If this is not used, you can remove this.
ASR::down_cast<ASR::Variable_t>(st)->m_type)->m_derived_type; | ||
std::string call_name = "__init__"; | ||
ASR::symbol_t* call_sym = get_struct_member(der, call_name, x.base.base.loc); | ||
tmp_vec.push_back(make_call_helper(al, call_sym, |
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 modifies the meaning of the code, I mean, we have to handle this in the ASR pass.
The generated ASR must be the same as the original source code.
This can be done in the upcoming PR.
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.
Example
x: test = test(1, 3)
The ASR should be generated as
x: test
x = test(1, 3) # StructConstructor
But, PR generates the following
x: test
x__init__(x, 1, 3) # SubroutineCall
Let's handle this in the ASR pass
I do plan on implementing the ClassVars but they are a lower priority right now. |
I'm merging this. |
Implemented self, member functions, and calling init.
@Thirumalai-Shaktivel @certik