Execute Brain****/Raku: Difference between revisions
Content added Content deleted
No edit summary |
(constructor can't initialize a private variable for some reason) |
||
Line 1: | Line 1: | ||
<lang perl6>class BFInterpreter { |
<lang perl6>class BFInterpreter { |
||
has @ |
has @.code; |
||
has @!mem; |
has @!mem; |
||
has @!loop_stack; |
has @!loop_stack; |
||
Line 14: | Line 14: | ||
$!c = 0; |
$!c = 0; |
||
$!m = 0; |
$!m = 0; |
||
while $!c < @ |
while $!c < @.code { |
||
given @ |
given @.code[$!c] { |
||
when '>' { $!m++ } |
when '>' { $!m++ } |
||
when '<' { $!m-- } |
when '<' { $!m-- } |
||
Line 41: | Line 41: | ||
while $depth { |
while $depth { |
||
$!c++; |
$!c++; |
||
die "unbalanced code" if $!c >= @ |
die "unbalanced code" if $!c >= @.code.elems; |
||
$depth++ if @ |
$depth++ if @.code[$!c] eq '['; |
||
$depth-- if @ |
$depth-- if @.code[$!c] eq ']'; |
||
} |
} |
||
} |
} |