Permalink
Browse files

Perlito5 - javascript: add "break"

  • Loading branch information...
1 parent badd074 commit c3e52c2bf25d5c1c6874d0da3e228d68ac00ca12 @fglock committed Apr 24, 2012
View
@@ -16,12 +16,13 @@ dev 2012-04-12
-- negative index in array
-- more file and process operations: chdir, unlink, close, exit
--- control functions: next, last, redo
+-- control functions: next, last, redo, break
-- more functions: rand
+-- "continue" blocks
- perl5 backend:
--- require v5.10 just in case, because we might use 'when'
+-- require v5.10
* Perlito6 (Perl 6 compiler):
View
@@ -42,7 +42,6 @@ TODO list for Perlito5
-- "given" statement not implemented
-- "default" statement not implemented
--- "break" not implemented
-- clean up:
the several "end_tables" in Expression.pm are duplicating the function of
@@ -122,7 +121,6 @@ TODO list for Perlito5
-- "given" statement not implemented
-- "default" statement not implemented
--- "break" not implemented
-- bug: some declarations are not "seen":
for ( my $i = 0; $i < 10 ; $i++ ) { print "$i\n" } # compiles to global $i
View
@@ -57,6 +57,9 @@ if (typeof p5pkg !== "object") {
this.type = type;
this.v = v;
this.toString = function(){
+ if (this.type == 'break') {
+ return 'Can\'t "break" outside a given block'
+ }
if (this.type == 'next' || this.type == 'last' || this.type == 'redo') {
if (this.v == "") { return 'Can\'t "' + this.type + '" outside a loop block' }
return 'Label not found for "' + this.type + ' ' + this.v + '"';
@@ -2864,6 +2867,13 @@ var p5100 = p5pkg['main'];
return(err);
}
}
+ }, 'break', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
+ var v_level = null;
+ (v_level = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
+ (p5pkg["Perlito5"]["v_THROW"] = (1));
+ return (p5context(['throw(new p5_error("break", ""))'], p5want));
}, 'next', function (List__, p5want) {
var v_self = null;
(v_self = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
@@ -886,6 +886,11 @@ do {{
}
};
('(' . $parameters->emit_javascript($level) . ' = ' . $arguments->emit_javascript(($level + 1)) . ')')
+}, 'break', sub {
+ ((my $self) = shift());
+ ((my $level) = shift());
+ ($Perlito5::THROW = 1);
+ 'throw(new p5_error("break", ""))'
}, 'next', sub {
((my $self) = shift());
((my $level) = shift());

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1380,6 +1380,12 @@ package Perlito5::AST::Apply;
},
+ 'break' => sub {
+ my $self = shift;
+ my $level = shift;
+ $Perlito5::THROW = 1;
+ 'throw(new p5_error("break", ""))'
+ },
'next' => sub {
my $self = shift;
my $level = shift;
@@ -63,6 +63,9 @@ if (typeof p5pkg !== "object") {
this.type = type;
this.v = v;
this.toString = function(){
+ if (this.type == 'break') {
+ return 'Can\'t "break" outside a given block'
+ }
if (this.type == 'next' || this.type == 'last' || this.type == 'redo') {
if (this.v == "") { return 'Can\'t "' + this.type + '" outside a loop block' }
return 'Label not found for "' + this.type + ' ' + this.v + '"';

0 comments on commit c3e52c2

Please sign in to comment.