Add loop macro and a test
This commit is contained in:
parent
2e784310fb
commit
8bdc8232f9
2 changed files with 25 additions and 0 deletions
|
@ -977,6 +977,25 @@ sub macro_return {
|
|||
}
|
||||
$macros{'return'} = \¯o_return;
|
||||
|
||||
sub macro_loop {
|
||||
my $ts = shift;
|
||||
|
||||
my $inner = macro_progn($ts);
|
||||
|
||||
return create_block(
|
||||
"nil",
|
||||
sub {
|
||||
my $ctx = shift;
|
||||
|
||||
while (1)
|
||||
{
|
||||
$inner->($ctx);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
$macros{loop} = \¯o_loop;
|
||||
|
||||
sub compile {
|
||||
my ($term) = @_;
|
||||
my @tokens = tokenize($term);
|
||||
|
|
6
t/loop.t
Normal file
6
t/loop.t
Normal file
|
@ -0,0 +1,6 @@
|
|||
(expect "loop"
|
||||
(equal (let ((i 0))
|
||||
(loop (set i (+ i 1))
|
||||
(when (> i 3)
|
||||
(return i))))
|
||||
4))
|
Loading…
Reference in a new issue