Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created November 4, 2010 02:01
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 ShimmerFairy/662027 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/662027 to your computer and use it in GitHub Desktop.
modified bin/tardis file
#! /usr/bin/env perl6
use v6;
use Tardis;
use Yapsi;
my $program;
if @*ARGS == 2 && @*ARGS[0] eq '-e' {
$program = @*ARGS[1];
}
elsif @*ARGS == 1 {
$program = slurp @*ARGS[0];
}
else {
die "Usage: `$*PROGRAM_NAME <file>` or `$*PROGRAM_NAME -e '<program>'`";
}
my $origprogram = $program; # in case we need the original copy later
my @ticks;
run-program();
sub run-program() {
my Yapsi::Compiler $c .= new;
my Tardis::Debugger $d .= new;
try {
say "# Compiling...";
my @sic = $c.compile($program);
warn $_ for $c.warnings;
say "# Running...";
$d.run(@sic);
}
say $! if $!;
@ticks = $d.ticks;
unless @ticks {
say "No ticks registered. Quitting.";
exit;
}
}
my $current-tick = 0;
say "# Finished. Ticks: 0..", @ticks.end;
while defined(my $cmd = prompt "TICK $current-tick/{@ticks.end}> ") {
given $cmd {
when /^ \s* $/ { }
when 'look' { look() }
when 'step' { step() }
when 'n' { step() }
when /^go\s+(\d+)$/ { go(+$0) }
when /^rewrite\s+(.+)$/ { rewrite(~$0) }
when 'help' { help() }
when 'quit' { quit() }
when 'q' { quit() }
when 'exit' { quit() }
when 'debug' { debug() }
default { say "Sorry, unrecognized command." }
}
}
# this just dresses up @ticks[$current-tick] and prints to STDOUT
sub look() {
my $tick = @ticks[$current-tick];
say $tick.fmt("%s = %s", "\n");
}
sub step() {
if $current-tick == @ticks.end {
say 'Can not go beyond last tick.';
return;
}
++$current-tick;
look();
}
# RAKUDO: Should really be typed 'Int'.
multi sub go(Num $tick where { $tick > @ticks.end }) {
say 'Can not go beyond last tick.';
}
multi sub go(Num $tick) {
$current-tick = $tick;
look();
}
sub rewrite(Str $line is copy) {
if $line.split('')[*-1] == ';' {
$line.chop;
}
if $current-tick == 0 {
say 'You cannot rewrite tick 0; this is the "before execution" tick.';
}
my @proglines = $program.split(';');
@proglines[$current-tick - 1] = $line;
$program = @proglines.join(';');
say "Rewrite of time successful. Realigning the rest of the program...";
run-program();
say "No paradoxes occurred. You may continue."
}
sub help() {
say "Tardis debugging commands:
look View the state of all variables in the program.
step Goes to the next tick in the program, then `look's.
go N Goes to tick N in the program, then `look's.
help Display this help message.
quit
exit
q exit Tardis.";
}
sub quit() {
exit;
}
sub debug() {
say $program.perl;
say @ticks.perl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment