-
-
Save zoffixznet/9479d47c86fb3934f84f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Inline::Brainfuck::Actions { | |
use Term::termios; | |
has Buf $!stack = Buf.new: 0; | |
has Int $!pointer = 0; | |
has Bool $.debug = False; | |
has $!saved-term-settings; | |
submethod BUILD { | |
$!saved-term-settings = Term::termios.new(fd => 1).getattr; | |
given Term::termios.new(fd => 1).getattr { | |
.makeraw; | |
.setattr(:DRAIN); | |
} | |
} | |
END { $!saved-term-settings.setattr(:DRAIN); } | |
method next ($) { | |
$!pointer++; | |
$!stack.append: 0 if $!stack.elems < $!pointer; | |
} | |
method prev ($) { | |
$!pointer--; | |
die "Cannot have a negative cell pointer\n" if $pointer < 0; | |
} | |
method inc ($) { $!stack[$!pointer]++ } | |
method dec ($) { $!stack[$!pointer]-- } | |
method out ($) { print $!stack[$!pointer] } | |
method in ($) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment