-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Restored TemplateBinOp * Updated tests * Renamed tests * Forgot to update reference tests * Got the interface working in requirement * Converted binop in template into the corresponding functions during template construction, add various checks for requirement's parameters * Removed TemplateBinOp * Modified the template example with + operator --------- Co-authored-by: Ondřej Čertík <ondrej@certik.us>
- Loading branch information
1 parent
5c741a6
commit 67c3a20
Showing
21 changed files
with
1,504 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module template_add_01b_m | ||
implicit none | ||
private | ||
public :: add_t | ||
|
||
requirement R(T, F) | ||
type :: T; end type | ||
interface operator (+) | ||
procedure F | ||
end interface | ||
function F(x, y) result(z) | ||
type(T), intent(in) :: x, y | ||
type(T) :: z | ||
end function | ||
end requirement | ||
|
||
template add_t(T, F) | ||
requires R(T, F) | ||
private | ||
public :: add_generic | ||
contains | ||
function add_generic(x, y) result(z) | ||
type(T), intent(in) :: x, y | ||
type(T) :: z | ||
!print*, "x, y, z, x+y+z =", x, y, z, x+y+z | ||
z = x + y | ||
end function | ||
function add_generic2(x, y, z) result(s) | ||
type(T), intent(in) :: x, y, z | ||
type(T) :: s | ||
s = x + y + z | ||
end function | ||
end template | ||
|
||
contains | ||
|
||
integer function func_arg_int(x, y) result(z) | ||
integer, intent(in) :: x, y | ||
z = x + y | ||
end function | ||
|
||
subroutine test_template() | ||
integer :: n1, n2 | ||
|
||
instantiate add_t(integer, func_arg_int), only: add_integer => add_generic, add_integer2 => add_generic2 | ||
n1 = add_integer(5, 9) | ||
n2 = add_integer2(5, 9, 10) | ||
print*, "The result is", n1 | ||
print*, "The result is", n2 | ||
end subroutine | ||
end module | ||
|
||
program template_add_01b | ||
use template_add_01b_m | ||
implicit none | ||
|
||
call test_template() | ||
|
||
end program |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module template_01_m | ||
implicit none | ||
private | ||
public :: op_t | ||
|
||
requirement semigroup(t) | ||
type, deferred :: t | ||
elemental function combine(x, y) result(combined) | ||
type(t), intent(in) :: x, y | ||
type(t) :: combined | ||
end function | ||
end requirement | ||
|
||
contains | ||
|
||
subroutine test_template() | ||
end subroutine | ||
|
||
end module | ||
|
||
program template_01 | ||
use template_01_m | ||
implicit none | ||
|
||
end program template_01 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module template_01_m | ||
implicit none | ||
private | ||
public :: op_t | ||
|
||
requirement semigroup(t, combine) | ||
type, deferred :: t | ||
end requirement | ||
|
||
contains | ||
|
||
subroutine test_template() | ||
end subroutine | ||
|
||
end module | ||
|
||
program template_01 | ||
use template_01_m | ||
implicit none | ||
|
||
end program template_01 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module template_01_m | ||
implicit none | ||
private | ||
public :: op_t | ||
|
||
requirement semigroup(t, combine) | ||
type, deferred :: t | ||
elemental function combine(x, y) result(combined) | ||
type(t), intent(in) :: x, y | ||
type(t) :: combined | ||
end function | ||
end requirement | ||
|
||
requirement extended_semigroup(t, combine, sconcat, stimes) | ||
requires semigroup(t, scombine) | ||
pure function sconcat(list) result(combined) | ||
type(t), intent(in) :: list(:) | ||
type(t) :: combined | ||
end function | ||
elemental function stimes(n, a) result(repeated) | ||
integer, intent(in) :: n | ||
type(t), intent(in) :: a | ||
type(t) :: repeated | ||
end function | ||
end requirement | ||
|
||
contains | ||
|
||
subroutine test_template() | ||
end subroutine | ||
|
||
end module | ||
|
||
program template_01 | ||
use template_01_m | ||
implicit none | ||
|
||
end program template_01 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module template_add_01b_m | ||
implicit none | ||
private | ||
public :: add_t | ||
|
||
requirement R(T, F) | ||
type :: T; end type | ||
function F(x, y) result(z) | ||
type(T), intent(in) :: x, y | ||
type(T) :: z | ||
end function | ||
end requirement | ||
|
||
template add_t(T, F) | ||
requires R(T, F) | ||
private | ||
public :: add_generic | ||
contains | ||
function add_generic(x, y) result(z) | ||
type(T), intent(in) :: x, y | ||
type(T) :: z | ||
z = x + y | ||
end function | ||
end template | ||
|
||
contains | ||
|
||
integer function func_arg_int(x, y) result(z) | ||
integer, intent(in) :: x, y | ||
z = x + y | ||
end function | ||
|
||
subroutine test_template() | ||
real :: a | ||
integer :: n, s | ||
|
||
instantiate add_t(integer, func_arg_int), only: add_integer => add_generic | ||
n = add_integer(5, 9) | ||
!s = add_integer2(5, 9, 10) | ||
print*, "The result is", n | ||
end subroutine | ||
end module | ||
|
||
program template_add_01b | ||
use template_add_01b_m | ||
implicit none | ||
|
||
call test_template() | ||
|
||
end program |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-template_add_01b-bd911f4", | ||
"cmd": "lfortran --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/../integration_tests/template_add_01b.f90", | ||
"infile_hash": "7aff73d0cb778ae2dcac14a95cf3bd54d165adc17b929d7f5197ed50", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "asr-template_add_01b-bd911f4.stdout", | ||
"stdout_hash": "a4bc452d7016e9611a6eee8d2bfdc2668be37d7ad4010f0dbbd1f71b", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
Oops, something went wrong.