Skip to content

Commit

Permalink
Implement excess argument detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 3, 2010
1 parent f7e8ef5 commit 0abde70
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/Kernel.cs
Expand Up @@ -652,6 +652,21 @@ public class Kernel {
NewROScalar(n));
}

public static Frame BindFail(Frame caller, string msg) {
// TODO: Junctional failover goes here, as does some multi stuff
return Die(caller, msg);
}

public static Frame CheckArgEnd(Frame caller, int i, string m) {
// TODO: checking for SigCheckOnly goes here
if (i == caller.pos.Length &&
(caller.named == null || caller.named.Count == 0)) {
return caller;
} else {
return BindFail(caller, m);
}
}

public static readonly DynMetaObject SubMO;
public static readonly DynMetaObject ScalarMO;
public static readonly DynMetaObject StashMO;
Expand Down
2 changes: 2 additions & 0 deletions src/CLRTypes.pm
Expand Up @@ -107,6 +107,8 @@ my %typedata = (
'Lexer.GetLexer' => [m => 'Lexer'],
'Kernel.SearchForHandler' => [c => 'Variable'],
'Kernel.Die' => [c => 'Variable'],
'Kernel.BindFail' => [c => 'Variable'],
'Kernel.CheckArgEnd' => [c => 'Void'],
'Kernel.CoTake' => [c => 'Variable'],
'Kernel.Take' => [c => 'Variable'],
'Kernel.GatherHelper' => [c => 'Frame'],
Expand Down
9 changes: 7 additions & 2 deletions src/Sig.pm
Expand Up @@ -32,6 +32,8 @@ use 5.010;
CgOp::rawcall($do, 'SetSlot', CgOp::clr_string('rest'),
CgOp::rawscall('Kernel.SlurpyHelper',
CgOp::callframe, CgOp::letvar('!ix'))),
CgOp::scopedlex('!ix', CgOp::getfield('Length',
CgOp::getfield('pos', CgOp::callframe))),
CgOp::newscalar($do))});
}

Expand All @@ -48,8 +50,9 @@ use 5.010;
return CgOp::scopedlex($self->type);
}
} else {
return CgOp::die("No value in " . $body->name .
" available for parameter " . $self->name);
return CgOp::rawscall('Kernel.BindFail', CgOp::clr_string(
"No value in " . $body->name . " available for parameter " .
$self->name));
}
}

Expand Down Expand Up @@ -163,6 +166,8 @@ use 5.010;
for (@{ $self->params }) {
push @p, $_->binder($body);
}
push @p, CgOp::rawscall('Kernel.CheckArgEnd', CgOp::letvar('!ix'),
CgOp::clr_string("Unexpectedly many arguments to " . $body->name));
CgOp::letn('!ix', CgOp::int(0), CgOp::prog(@p));
}

Expand Down

0 comments on commit 0abde70

Please sign in to comment.