subroutinecall_builtinrecursiveprivate
recursive subroutine call_builtin(c, name, args, v)
A builtin function: defined, dict, len, list, range, reversed, str, zip.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| name | character(len=*) | in | the function | |
| args | type(value_t) | in | dimension(:) | the arguments |
| v | type(value_t) | out | the result |
Calls
Source
Show the code
recursive subroutine call_builtin(c, name, args, v)
type(fypp_t), intent(inout) :: c !! the state
character(len=*), intent(in) :: name !! the function
type(value_t), intent(in) :: args(:) !! the arguments
type(value_t), intent(out) :: v !! the result
type(value_t), allocatable :: list(:)
type(buffer_t) :: b
character(len=:), allocatable :: text
logical :: found
type(value_t) :: unused
integer :: k, j, n, id
select case (name)
case ('defined')
id = find_name(c, args(1)%text)
found = .false.
if (id > 0) call lookup(c, id, unused, found)
call make_bool(found, v)
case ('len')
if (args(1)%kind == V_STR) then
call make_int(len(args(1)%text), v)
else
call items_of(c, args(1), list)
if (.not. allocated(c%error)) call make_int(size(list), v)
end if
case ('list')
v%kind = V_LIST
call items_of(c, args(1), v%items)
case ('reversed')
call items_of(c, args(1), list)
if (allocated(c%error)) return
v%kind = V_LIST
call copy_items(list(size(list):1:-1), v%items)
case ('str')
call write_value(args(1), .false., b)
call take(b, text)
call make_string(text, v)
case ('range')
call make_range(c, args, v)
case ('zip')
call make_zip(c, args, v)
case ('dict')
if (args(1)%kind == V_DICT) then
v = args(1)
return
end if
call items_of(c, args(1), list)
if (allocated(c%error)) return
v%kind = V_DICT
n = size(list)
allocate (v%items(2*n))
do k = 1, n
do j = 1, 2
v%items(2*(k - 1) + j) = list(k)%items(j)
end do
end do
case default
call fail(c, 'the function '//name//' is not supported')
end select
end subroutine call_builtin