Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created January 24, 2016 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/9479d47c86fb3934f84f to your computer and use it in GitHub Desktop.
Save zoffixznet/9479d47c86fb3934f84f to your computer and use it in GitHub Desktop.
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