-
Notifications
You must be signed in to change notification settings - Fork 164
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
backend code generation when python programm cotains class #2815
Comments
@ljq-0814 LPython translates the source code into an intermediary form called an Abstract Semantic Representation (ASR). This form contains all the information related to the code, including type semantics. It is done inside The above code gets translated to: (TranslationUnit
(SymbolTable
1
{
__main__:
(Module
(SymbolTable
2
{
student:
(Struct
(SymbolTable
3
{
__init__:
(Function
(SymbolTable
4
{
age:
(Variable
4
age
[]
In
()
()
Default
(Integer 4)
()
Source
Public
Required
.false.
),
name:
(Variable
4
name
[]
In
()
()
Default
(Character 1 -2 ())
()
Source
Public
Required
.false.
),
self:
(Variable
4
self
[]
InOut
()
()
Default
(StructType
[(Character 1 -2 ())
(Integer 4)]
[(FunctionType
[(Class
2 student
)
(Character 1 -2 ())
(Integer 4)]
()
Source
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
.false.
)]
.false.
2 student
)
()
Source
Public
Required
.false.
)
})
__init__
(FunctionType
[(Class
2 student
)
(Character 1 -2 ())
(Integer 4)]
()
Source
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
.false.
)
[]
[(Var 4 self)
(Var 4 name)
(Var 4 age)]
[(Assignment
(StructInstanceMember
(Var 4 self)
3 name
(Character 1 -2 ())
()
)
(Var 4 name)
()
)
(Assignment
(StructInstanceMember
(Var 4 self)
3 age
(Integer 4)
()
)
(Var 4 age)
()
)]
()
Public
.false.
.false.
()
),
age:
(Variable
3
age
[]
Local
()
()
Default
(Integer 4)
()
Source
Public
Required
.false.
),
name:
(Variable
3
name
[]
Local
()
()
Default
(Character 1 -2 ())
()
Source
Public
Required
.false.
)
})
student
[]
[name
age]
[__init__]
Source
Public
.false.
.false.
[(())
(())]
()
()
)
})
__main__
[]
.false.
.false.
),
main_program:
(Program
(SymbolTable
5
{
})
main_program
[]
[]
)
})
[]
) We then apply some optimization passes to this initial ASR. The final ASR is passed over to the backend for further translation. The backend translator #include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <lfortran_intrinsics.h>
struct dimension_descriptor
{
int32_t lower_bound, length, stride;
};
struct student {
char * name;
int32_t age;
};
// Implementations
int main(int argc, char* argv[])
{
_lpython_set_argv(argc, argv);
return 0;
} |
I have a question regarding the compilation of a Python program using LPython. If a Python program contains any class or a class like the following:
Does this imply that after compilation, the code can only generate C++ code, and not C code? I would appreciate an explanation of why that might be the case. Thank you!
The text was updated successfully, but these errors were encountered: