Created
April 2, 2010 12:53
-
-
Save snarkyboojum/353097 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
From 8e0cc2e7104bebfa25bc89155267661ee3beea0e Mon Sep 17 00:00:00 2001 | |
From: snarkyboojum <snarkyboojum@gmail.com> | |
Date: Fri, 2 Apr 2010 23:49:54 +1100 | |
Subject: [PATCH] An attempt at making the 'say' op go through an object with a .say method | |
--- | |
lib/Yapsi.pm | 11 ++++++++++- | |
yapsi | 2 +- | |
2 files changed, 11 insertions(+), 2 deletions(-) | |
diff --git a/lib/Yapsi.pm b/lib/Yapsi.pm | |
index 2e4f37e..7db08d3 100644 | |
--- a/lib/Yapsi.pm | |
+++ b/lib/Yapsi.pm | |
@@ -201,7 +201,16 @@ class Yapsi::Compiler { | |
} | |
} | |
+class Yapsi::Runtime::IO { | |
+ method say($string) { | |
+ # TODO: how to make this use Perl 6's say? :) | |
+ print $string, "\n"; | |
+ } | |
+} | |
+ | |
class Yapsi::Runtime { | |
+ has Yapsi::Runtime::IO $!IO; | |
+ | |
method run(@sic) { | |
my @r; | |
my %pad; | |
@@ -243,7 +252,7 @@ class Yapsi::Runtime { | |
%pad{~$0} = { :type<immediate>, :value(+$1) }; | |
} | |
when /^ 'say $'(\d+) $/ { | |
- say @r[+$0] | |
+ $!IO.say( @r[+$0] ) | |
} | |
default { die "Couldn't handle instruction `$_`" } | |
} | |
diff --git a/yapsi b/yapsi | |
index e869e7d..f1d99d7 100755 | |
--- a/yapsi | |
+++ b/yapsi | |
@@ -16,7 +16,7 @@ else { | |
try { | |
my Yapsi::Compiler $compiler .= new; | |
- my Yapsi::Runtime $runtime .= new; | |
+ my Yapsi::Runtime $runtime .= new(IO => Yapsi::Runtime::IO.new); | |
my @sic = $compiler.compile($program); | |
$runtime.run(@sic); | |
-- | |
1.5.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment