Skip to content

Commit

Permalink
+ bs: if & else
Browse files Browse the repository at this point in the history
+ llbs: not
@ fixed some bugs
  • Loading branch information
eXerigumo Clanjor (哆啦比猫) committed Sep 2, 2012
1 parent 9824739 commit 0ac8bf4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/bs/bs.pl
Expand Up @@ -589,15 +589,37 @@ sub do_gen_code
my $end = &alloc_func;

gen("go\t\t$while");
$fcurrent = $while;

$fcurrent = $while;
do_gen_code($p{cond});
gen("while\t$body, $end");
$var_offset--;
$fcurrent = $body;

$fcurrent = $body;
do_gen_code($p{body});
gen("go\t\t$while");

$fcurrent = $end;
last;
};

/^IF$/ and do {
my $then = &alloc_func;
my $else = &alloc_func if $p{else};
my $end = &alloc_func;

do_gen_code($p{cond});
gen("if\t$then, " . ($else ? "$else, " : "") . "$end");
$var_offset--;

$fcurrent = $then;
do_gen_code($p{then});

$else and do {
$fcurrent = $else;
do_gen_code($p{else});
};

$fcurrent = $end;
last;
};
Expand Down Expand Up @@ -771,7 +793,7 @@ sub find_var
return $id + $var_offset + 1;
};

($id) = grep { $var_name[$_] eq $name } 0 .. $#param_name;
($id) = grep { $var_name[$_] eq $name } 0 .. $#var_name;
defined $id and return $var_offset - $var_id[$id];

-1;
Expand Down
5 changes: 4 additions & 1 deletion src/bs/test.bs
Expand Up @@ -8,7 +8,10 @@ main()
n--;
}
"press <ENTER> to quit...";
putc(getc());

@ b = getc();
b -= 'x';
if (!b) "yes";
}

abc(x)
Expand Down
6 changes: 6 additions & 0 deletions src/llbs/llbs.pl
Expand Up @@ -187,6 +187,12 @@
last;
};

/^not$/ and do {
if (@p) { die "[$line_no] invalid parameter: @p\n"; }
print "\t[[-]>+<]+>[-<->]<\n";
last;
};

/^exit$/ and do {
print "\t>>>+<<<\n";
last;
Expand Down

0 comments on commit 0ac8bf4

Please sign in to comment.