Skip to content

Commit

Permalink
Implement ~ with many arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 28, 2010
1 parent f506534 commit 4563a6c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
16 changes: 11 additions & 5 deletions CORE.setting
Expand Up @@ -223,11 +223,17 @@ my class Bool is Enum {
constant True = Q:CgOp { (box Bool (bool 1)) };
constant False = Q:CgOp { (box Bool (bool 0)) };
# ought to take a slurpy
sub infix:<~>($l,$r) { Q:CgOp {
(box Str (rawscall String.Concat
(unbox String (fetch (methodcall (scopedlex $l) Str)))
(unbox String (fetch (methodcall (scopedlex $r) Str)))))
# taking a slurpy is wrong for this due to flattening. I'm not sure what is
# right, maybe **@foo
sub infix:<~> { Q:CgOp {
(letn buf (rawnew System.Text.StringBuilder)
i (int 0)
max (getfield Length (getfield pos (callframe)))
[whileloop 0 0 (< (l i) (l max)) (prog
[rawcall (l buf) Append
(unbox String (@ (methodcall (pos (l i)) Str)))]
[l i (+ (l i) (int 1))])]
[box Str (rawcall (l buf) ToString)])
} }
sub infix:<+>($l,$r) { Q:CgOp {
Expand Down
9 changes: 7 additions & 2 deletions CgOp.pm
Expand Up @@ -572,8 +572,13 @@ use warnings;
}

sub letn {
my ($name, $value, @stuff) = @_;
CgOp::Let->new(name => $name, zyg => [ $value, @stuff ]);
my (@stuff) = @_;
if (blessed($stuff[0])) {
@stuff;
} else {
my ($name, $value) = splice @stuff, 0, 2;
CgOp::Let->new(name => $name, zyg => [ $value, letn(@stuff) ]);
}
}

sub pos {
Expand Down
3 changes: 3 additions & 0 deletions CodeGen.pm
Expand Up @@ -47,6 +47,9 @@ use 5.010;
'String' =>
{ Length => [f => 'Int32'],
Substring => [m => 'String'] },
'System.Text.StringBuilder' =>
{ Append => [m => 'Void'],
ToString => [m => 'String'] },
'Frame' =>
{ pos => [f => 'LValue[]'],
caller => [f => 'Frame'],
Expand Down
3 changes: 2 additions & 1 deletion test.pl
Expand Up @@ -2,7 +2,7 @@

use Test;

plan 135;
plan 136;

ok 1, "one is true";
ok 2, "two is also true";
Expand Down Expand Up @@ -92,6 +92,7 @@

ok 12 eq "12", "eq stringifies";
ok ("a" ~ "b") eq "ab", "a + b = ab";
ok ("a" ~ "b" ~ "c") eq "abc", "a + b + c = abc";
ok (?1) eq "Bool::True", "True strings to Bool::True";
ok (?0) eq "Bool::False", "False strings to Bool::False";

Expand Down

0 comments on commit 4563a6c

Please sign in to comment.