Skip to content

Commit

Permalink
Start to store the default value as a closure inside the signature ob…
Browse files Browse the repository at this point in the history
…ject. Also stub in space for sub-signatures - we don't support them just yet, but it'll be ready for when we do. Also fix a typo that caused constraints introspection to be broken.
  • Loading branch information
jnthn committed Oct 10, 2009
1 parent 1b83557 commit bd7966f
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/binder/sigguts.h
Expand Up @@ -22,6 +22,7 @@ typedef struct llsig_element {
PMC *nominal_type; /* The nominal type of the parameter. */
PMC *post_constraints; /* Junction of any extra constraints. */
PMC *sub_signature; /* Any nested signature. */
PMC *default_closure; /* The default value closure. */
} llsig_element;


Expand Down
6 changes: 3 additions & 3 deletions src/builtins/any-list.pir
Expand Up @@ -56,7 +56,7 @@ Return a List with the keys of the invocant.
signature = allocate_signature 1
null $P1
$I0 = SIG_ELEM_MULTI_INVOCANT + SIG_ELEM_SLURPY_POS
set_signature_elem signature, 0, "@values", $I0, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "@values", $I0, $P1, $P1, $P1, $P1, $P1, $P1
setprop block, "$!signature", signature
'!TOPERL6MULTISUB'(block)
.end
Expand All @@ -76,7 +76,7 @@ Return a List with the keys of the invocant.
setprop block, "$!signature", signature
$P0 = get_hll_global 'Any'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end

=item sort()
Expand Down Expand Up @@ -197,7 +197,7 @@ Return values of the list
signature = allocate_signature 1
null $P1
$I0 = SIG_ELEM_MULTI_INVOCANT + SIG_ELEM_SLURPY_POS
set_signature_elem signature, 0, "@values", $I0, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "@values", $I0, $P1, $P1, $P1, $P1, $P1, $P1
setprop block, "$!signature", signature
'!TOPERL6MULTISUB'(block)
.end
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/control.pir
Expand Up @@ -597,7 +597,7 @@ of a hack.
.local pmc names
.local string name
.local int flags, slurpy
get_signature_elem signature, cur_param, name, flags, $P0, $P1, names, $P2
get_signature_elem signature, cur_param, name, flags, $P0, $P1, names, $P2, $P3, $P4

# XXX We'll skip slurpies for now.
slurpy = flags & SIG_ELEM_SLURPY
Expand Down
16 changes: 8 additions & 8 deletions src/classes/Array.pir
Expand Up @@ -48,8 +48,8 @@ Return true if the elements at C<indices> have been assigned to.
setprop block, "$!signature", signature
null $P1
$P0 = get_hll_global 'Array'
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "@indices", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "@indices", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -101,7 +101,7 @@ Remove the last item from the array and return it.
setprop block, "$!signature", signature
$P0 = get_hll_global 'Array'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -138,8 +138,8 @@ Add C<args> to the end of the Array.
setprop block, "$!signature", signature
null $P1
$P0 = get_hll_global 'Array'
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "@items", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "@items", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -167,7 +167,7 @@ Shift the first item off the array and return it.
setprop block, "$!signature", signature
$P0 = get_hll_global 'Array'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -203,8 +203,8 @@ Adds C<args> to the beginning of the Array.
setprop block, "$!signature", signature
null $P1
$P0 = get_hll_global 'Array'
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "@items", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "@items", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1, $P1, $P1
.end

=item values()
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Associative.pir
Expand Up @@ -38,7 +38,7 @@ src/classes/Associative.pir - Associative Role
signature = allocate_signature 1
setprop block, "$!signature", signature
null $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
"!ADDTOROLE"(block)
.end

Expand Down
2 changes: 1 addition & 1 deletion src/classes/Callable.pir
Expand Up @@ -42,7 +42,7 @@ This implements the parametric role Callable[::T = Object].
signature = allocate_signature 1
setprop block, "$!signature", signature
null $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
"!ADDTOROLE"(block)
.end

Expand Down
20 changes: 10 additions & 10 deletions src/classes/Hash.pir
Expand Up @@ -37,8 +37,8 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "$topic", 0, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "$topic", 0, $P1, $P1, $P1, $P1, $P1, $P1
.end


Expand All @@ -56,8 +56,8 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "$key", 0, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "$key", 0, $P1, $P1, $P1, $P1, $P1, $P1
.end

.namespace ['Perl6Hash']
Expand Down Expand Up @@ -86,8 +86,8 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "@keys", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "@keys", SIG_ELEM_SLURPY_POS, $P1, $P1, $P1, $P1, $P1, $P1
.end

.namespace ['Perl6Hash']
Expand All @@ -104,8 +104,8 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "$key", 0, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "$key", 0, $P1, $P1, $P1, $P1, $P1, $P1
.end

.namespace ['Perl6Hash']
Expand All @@ -120,7 +120,7 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end

.namespace ['Perl6Hash']
Expand All @@ -135,7 +135,7 @@ src/classes/Hash.pir - Perl 6 Hash class and related functions
setprop block, "$!signature", signature
$P0 = get_hll_global 'Hash'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end

=back
Expand Down
2 changes: 1 addition & 1 deletion src/classes/List.pir
Expand Up @@ -273,7 +273,7 @@ Return the number of elements in the list.
setprop block, "$!signature", signature
$P0 = get_hll_global 'List'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
'!TOPERL6MULTISUB'(block)
.end
Expand Down
18 changes: 9 additions & 9 deletions src/classes/Mapping.pir
Expand Up @@ -79,9 +79,9 @@ every pair, joined by newlines or an explicitly given separator.
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 1, "$format", SIG_ELEM_MULTI_INVOCANT, $P1, $P1, $P1, $P1
set_signature_elem signature, 2, "$sep", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 1, "$format", SIG_ELEM_MULTI_INVOCANT, $P1, $P1, $P1, $P1, $P1, $P1
set_signature_elem signature, 2, "$sep", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
'!TOPERL6MULTISUB'(block)
.end

Expand Down Expand Up @@ -121,7 +121,7 @@ every pair, joined by newlines or an explicitly given separator.
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
'!TOPERL6MULTISUB'(block)
.end

Expand Down Expand Up @@ -160,7 +160,7 @@ Returns keys of hash as a List
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -202,7 +202,7 @@ Returns elements of hash as array of C<Pair(key, value)>
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -234,7 +234,7 @@ Returns elements of hash as array of C<Pairs>
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
'!TOPERL6MULTISUB'(block)
.end

Expand Down Expand Up @@ -275,7 +275,7 @@ Returns elements of hash as array of C<Pairs>
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end


Expand Down Expand Up @@ -314,7 +314,7 @@ Returns values of hash as a List
setprop block, "$!signature", signature
$P0 = get_hll_global 'Mapping'
null $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1
set_signature_elem signature, 0, "self", SIG_ELEM_INVOCANT_AND_MULTI_INVOCANT, $P0, $P1, $P1, $P1, $P1, $P1
.end

=back
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Positional.pir
Expand Up @@ -38,7 +38,7 @@ src/classes/Positional.pir - Positional Role
signature = allocate_signature 1
setprop block, "$!signature", signature
null $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
"!ADDTOROLE"(block)
.end

Expand Down
18 changes: 13 additions & 5 deletions src/classes/Signature.pir
Expand Up @@ -54,10 +54,10 @@ Returns a C<List> of C<Parameter> descriptors.
unless cur_param < count goto param_done

# Get all curent parameter info.
.local pmc nom_type, cons_type, names, type_captures
.local pmc nom_type, cons_type, names, type_captures, default, sub_sig
.local int flags, optional, invocant, multi_invocant, slurpy, rw, ref, copy, named
.local string name
get_signature_elem signature, cur_param, name, flags, nom_type, cons_type, names, type_captures
get_signature_elem signature, cur_param, name, flags, nom_type, cons_type, names, type_captures, default, sub_sig
optional = flags & SIG_ELEM_IS_OPTIONAL
invocant = flags & SIG_ELEM_INVOCANT
multi_invocant = flags & SIG_ELEM_MULTI_INVOCANT
Expand Down Expand Up @@ -92,8 +92,16 @@ Returns a C<List> of C<Parameter> descriptors.
type_captures = 'list'()
type_captures_done:

# Create parameter instance. XXX Missing $.default, $.signature
$P0 = parameter.'new'('name'=>name, 'type'=>nom_type, 'constraint'=>cons_type, 'optional'=>optional, 'slurpy'=>slurpy, 'invocant'=>invocant, 'multi_invocant'=>multi_invocant, 'rw'=>rw, 'ref'=>ref, 'copy'=>copy, 'named'=>named, 'named_names'=>names, 'type_captures'=>type_captures)
# Make sure default and sub-signature are non-null.
unless null default goto default_done
default = 'undef'()
default_done:
unless null sub_sig goto sub_sig_done
sub_sig = 'undef'()
sub_sig_done:

# Create parameter instance.
$P0 = parameter.'new'('name'=>name, 'type'=>nom_type, 'constraints'=>cons_type, 'optional'=>optional, 'slurpy'=>slurpy, 'invocant'=>invocant, 'multi_invocant'=>multi_invocant, 'rw'=>rw, 'ref'=>ref, 'copy'=>copy, 'named'=>named, 'named_names'=>names, 'type_captures'=>type_captures, 'default'=>default, 'signature'=>sub_sig)
push result, $P0
goto param_loop
param_done:
Expand Down Expand Up @@ -135,7 +143,7 @@ of the overall signature binding refactor.
.local pmc nom_type, cons_type
.local int flags, optional
.local string name
get_signature_elem callersig, cur_param, name, flags, nom_type, cons_type, $P0, $P1
get_signature_elem callersig, cur_param, name, flags, nom_type, cons_type, $P0, $P1, $P2, $P3
optional = flags & SIG_ELEM_IS_OPTIONAL

# Skip invocant.
Expand Down
52 changes: 30 additions & 22 deletions src/ops/perl6.ops
Expand Up @@ -442,22 +442,24 @@ inline op get_signature_size(out INT, in PMC) :base_core {

/*

=item set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PMC, inout PMC, inout PMC, inout PMC)
=item set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PMC, inout PMC, inout PMC, inout PMC, inout PMC)

Takes $1 (a P6LowLevelSig) and sets the contents of the signature element with
index $2 as follows:

$3 = lexical name to bind to
$4 = flags
$5 = main (nominal) type
$6 = constraint type or junction of constraint types; null if none
$7 = array of names for a named parameter (non-null PMC for named slurpy)
$8 = array of type captures
$3 = lexical name to bind to
$4 = flags
$5 = main (nominal) type
$6 = constraint type or junction of constraint types; null if none
$7 = array of names for a named parameter
$8 = array of type captures
$9 = default value closure
$10 = nested signature

=cut

*/
inline op set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PMC, inout PMC, inout PMC) :base_core {
inline op set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PMC, inout PMC, inout PMC, inout PMC, inout PMC) :base_core {
if (!lls_id)
lls_id = pmc_type(interp, string_from_literal(interp, "P6LowLevelSig"));
if ($1->vtable->base_type == lls_id) {
Expand All @@ -475,6 +477,8 @@ inline op set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PM
element->post_constraints = $6;
element->named_names = $7;
element->type_captures = $8;
element->default_closure = $9;
element->sub_signature = $10;

/* Also need to do fixups on the nominal type. */
if (!PMC_IS_NULL($5)) {
Expand Down Expand Up @@ -512,22 +516,24 @@ inline op set_signature_elem(in PMC, in INT, in STR, in INT, inout PMC, inout PM

/*

=item get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC, out PMC, out PMC, out PMC)
=item get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC, out PMC, out PMC, out PMC, out PMC, out PMC)

Takes $1 (a P6LowLevelSig) and sets the registers with the contents of the
signature element with index $2 as follows:

$3 = lexical name to bind to
$4 = flags
$5 = main (nominal) type
$6 = constraint type or junction of constraint types; null if none
$7 = array of names for a named parameter (non-null PMC for named slurpy)
$8 = array of type captures
$3 = lexical name to bind to
$4 = flags
$5 = main (nominal) type
$6 = constraint type or junction of constraint types; null if none
$7 = array of names for a named parameter
$8 = array of type captures
$9 = default value closure
$10 = nested signature

=cut

*/
inline op get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC, out PMC, out PMC) :base_core {
inline op get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC, out PMC, out PMC, out PMC, out PMC) :base_core {
if (!lls_id)
lls_id = pmc_type(interp, string_from_literal(interp, "P6LowLevelSig"));
if ($1->vtable->base_type == lls_id) {
Expand All @@ -539,12 +545,14 @@ inline op get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC,
GETATTR_P6LowLevelSig_num_elements(interp, $1, num_elements);
if ($2 < num_elements) {
struct llsig_element *element = elements[$2];
$3 = element->variable_name;
$4 = element->flags;
$5 = element->nominal_type;
$6 = element->post_constraints;
$7 = element->named_names;
$8 = element->type_captures;
$3 = element->variable_name;
$4 = element->flags;
$5 = element->nominal_type;
$6 = element->post_constraints;
$7 = element->named_names;
$8 = element->type_captures;
$9 = element->default_closure;
$10 = element->sub_signature;
goto NEXT();
}
else {
Expand Down

0 comments on commit bd7966f

Please sign in to comment.