Skip to content

Commit

Permalink
Callable role becomes parametric (like role Callable[::T = Object] { }).
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 3, 2009
1 parent 4a7fe22 commit 903a782
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions src/classes/Callable.pir
Expand Up @@ -6,13 +6,58 @@ src/classes/Callable.pir - Callable Role

=head1 DESCRIPTION

This implements the parametric role Callable[::T = Object].

=cut

.namespace []
.namespace ['Callable[T]']

.sub '_callable_role_body'
.param pmc type :optional

# Capture type.
if null type goto no_type
type = type.'WHAT'()
goto type_done
no_type:
type = get_hll_global 'Object'
type_done:
.lex 'T', type

# Create role.
.local pmc metarole
metarole = "!meta_create"("role", "Callable[T]", 0)
.create_parametric_role(metarole)
.end
.sub '' :load :init :outer('_callable_role_body')
.local pmc block, signature
block = get_hll_global ['Callable[T]'], '_callable_role_body'
signature = new ["Signature"]
setprop block, "$!signature", signature
signature."!add_param"("T", 1 :named("optional"))
"!ADDTOROLE"(block)
.end

.sub 'returns' :method :outer('_callable_role_body')
$P0 = find_lex 'T'
.return ($P0)
.end
.sub '' :load :init :outer('_callable_role_body')
.local pmc block, signature
block = get_hll_global ['Callable[T]'], 'returns'
signature = new ["Signature"]
setprop block, "$!signature", signature
.end

.sub '' :anon :load :init
.local pmc callable
callable = '!keyword_role'('Callable')
.sub 'of' :method :outer('_callable_role_body')
$P0 = find_lex 'T'
.return ($P0)
.end
.sub '' :load :init :outer('_callable_role_body')
.local pmc block, signature
block = get_hll_global ['Callable[T]'], 'of'
signature = new ["Signature"]
setprop block, "$!signature", signature
.end

# Local Variables:
Expand Down

0 comments on commit 903a782

Please sign in to comment.