Skip to content

Commit

Permalink
Add concat command.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Nov 19, 2009
1 parent 3d62c11 commit 61e1695
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/PmTcl/Commands.pm
@@ -1,5 +1,13 @@
our sub puts($x) { pir::say($x); ''; } our sub puts($x) { pir::say($x); ''; }


our sub concat(*@args) {
my $result := @args ?? string_trim(@args.shift) !! '';
while @args {
$result := $result ~ ' ' ~ string_trim(@args.shift);
}
$result;
}

our sub expr(*@args) { our sub expr(*@args) {
my $parse := my $parse :=
PmTcl::Grammar.parse( PmTcl::Grammar.parse(
Expand All @@ -10,7 +18,6 @@ our sub expr(*@args) {
PAST::Compiler.eval(PAST::Block.new($parse.ast)); PAST::Compiler.eval(PAST::Block.new($parse.ast));
} }



our sub proc($name, $args, $body) { our sub proc($name, $args, $body) {
my $parse := my $parse :=
PmTcl::Grammar.parse( $body, :rule<body>, :actions(PmTcl::Actions) ); PmTcl::Grammar.parse( $body, :rule<body>, :actions(PmTcl::Actions) );
Expand All @@ -33,9 +40,30 @@ our sub proc($name, $args, $body) {
PAST::Compiler.compile($block); PAST::Compiler.compile($block);
} }



our sub set($varname, $value) { our sub set($varname, $value) {
our %VARS; our %VARS;
%VARS{$varname} := $value; %VARS{$varname} := $value;
$value; $value;
} }

our sub string_trim($string) {
Q:PIR {
.include 'cclass.pasm'
.local string str
$P0 = find_lex '$string'
str = $P0
.local int lpos, rpos
rpos = length str
lpos = find_not_cclass .CCLASS_WHITESPACE, str, 0, rpos
rtrim_loop:
unless rpos > lpos goto rtrim_done
dec rpos
$I0 = is_cclass .CCLASS_WHITESPACE, str, rpos
if $I0 goto rtrim_loop
rtrim_done:
inc rpos
$I0 = rpos - lpos
$S0 = substr str, lpos, $I0
%r = box $S0
};
}

0 comments on commit 61e1695

Please sign in to comment.