Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a basic REPL

  • Loading branch information...
commit 14fa691f56c522536056c0ab65ff437e9bb4b723 1 parent 97dea43
@tadzik tadzik authored
Showing with 26 additions and 25 deletions.
  1. +26 −25 bin/yapsi
View
51 bin/yapsi
@@ -5,13 +5,31 @@ use Yapsi;
my @TARGETS = <run future sic>;
+sub run-code($target, $program) {
+ try {
+ my @output;
+ given Yapsi::Compiler.new {
+ @output = $target eq 'future'
+ ?? .to-future($program)
+ !! .compile($program);
+ warn $_ for .warnings;
+ }
+
+ if $target eq 'run' {
+ my Yapsi::Runtime $runtime .= new;
+ $runtime.run(@output);
+ }
+ else {
+ .say for @output;
+ }
+ }
+ say $! if $!;
+}
+
if @*ARGS && @*ARGS[0] eq '--version' {
my $revision = qx[git describe];
say "This is Yapsi, revision $revision";
shift @*ARGS;
- unless @*ARGS {
- push @*ARGS, '-e', '';
- }
}
my $target = 'run';
@@ -22,32 +40,15 @@ if @*ARGS && @*ARGS[0] ~~ /'--target='(\w+)/ {
shift @*ARGS;
}
-my $program;
if @*ARGS == 2 && @*ARGS[0] eq '-e' {
- $program = @*ARGS[1];
+ run-code $target, @*ARGS[1];
}
elsif @*ARGS == 1 {
- $program = slurp @*ARGS[0];
+ run-code $target, slurp(@*ARGS[0]);
+}
+elsif @*ARGS == 0 {
+ while prompt("yapsi> ") -> $code { run-code($target, $code) };
}
else {
die "Usage: `$*PROGRAM_NAME <file>` or `$*PROGRAM_NAME -e '<program>'`";
}
-
-try {
- my @output;
- given Yapsi::Compiler.new {
- @output = $target eq 'future'
- ?? .to-future($program)
- !! .compile($program);
- warn $_ for .warnings;
- }
-
- if $target eq 'run' {
- my Yapsi::Runtime $runtime .= new;
- $runtime.run(@output);
- }
- else {
- .say for @output;
- }
-}
-say $! if $!;
Please sign in to comment.
Something went wrong with that request. Please try again.