-
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
Parameterised init and methods #2761
Closed
Closed
Conversation
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
We need to translate to the following: ! Fortran code after applying the pass: implied_do_loops
module __main__
implicit none
type :: coord
integer(4) :: x
integer(4) :: y
end type coord
contains
subroutine __init__(self, x, y)
class(coord), intent(inout) :: self
integer, intent(in) :: x, y
self%x = x
self%y = y
end subroutine
subroutine __main__global_stmts()
type(coord) :: p1
! p1 = coord(6, 4)
call __init__(p1, 6, 4)
p1%x = 10
print *, p1%x
print *, p1%y
end subroutine __main__global_stmts
end module __main__
program main_program
use __main__, only: __main__global_stmts
implicit none
call __main__global_stmts()
end program main_program |
Passing the argument: class test:
def __init__(self: "coord"):
self.x = 3
self.y = 4
t: test = test()
t.x = 10
print(t.x)
print(t.y) Fortran ! Fortran code after applying the pass: implied_do_loops
module __main__
implicit none
type :: coord
integer(4) :: x
integer(4) :: y
end type coord
contains
subroutine __init__(self, x, y)
class(coord), intent(inout) :: self
integer, intent(in) :: x, y
self%x = x
self%y = y
end subroutine
subroutine __main__global_stmts()
type(coord) :: p1
! p1 = coord(3, 4)
call p1%__init__(3, 4)
p1%x = 10
print *, p1%x
print *, p1%y
end subroutine __main__global_stmts
end module __main__
program main_program
use __main__, only: __main__global_stmts
implicit none
call __main__global_stmts()
end program main_program |
Simple fortran example, check the ASR: module mod
type :: t
contains
procedure :: f
end type
contains
subroutine f(self)
class(t), intent(inout):: self
end subroutine
end module
program expr2
use mod
implicit none
type(t) :: t_
call t_%f()
end program |
How to handle: from lpython import i32,i64,f32
class coord:
# ClassType(coord)
def __init__(self: "coord"):
self.x: i32 = 3
self.y: i32 = 4
p1: coord = coord()
# p1: coord
# ExternalSymbol p1_init => __init__
# p1_init(p1)
p1.x = 10
print(p1.x)
print(p1.y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enabled generation of parameterised init and methods in the ASR. Adding self after symtab visit in each function symtabs so as to have the correct type of the class.
TODO:
@certik @Thirumalai-Shaktivel