Permalink
Browse files

Add the simplest possible &open

  • Loading branch information...
1 parent 63f4e9a commit 14c7d073bb1edd8df267607a96d94b108e9d7729 @sorear committed Dec 27, 2010
Showing with 28 additions and 0 deletions.
  1. +23 −0 lib/CLRBackend.cs
  2. +4 −0 lib/CORE.setting
  3. +1 −0 src/CgOp.pm
View
@@ -1918,6 +1918,21 @@ class ClrNewIntArray : ClrOp {
}
}
+ class ClrWiden : ClrOp {
+ readonly ClrOp z;
+ public ClrWiden(Type to, ClrOp z) {
+ TypeCheck(z.Returns, to);
+ Returns = to;
+ this.z = z;
+ this.Constant = z.Constant;
+ }
+ public override void ListCases(CgContext cx) { z.ListCases(cx); }
+ public override ClrOp Sink() { return z.Sink(); }
+ public override void CodeGen(CgContext cx) {
+ z.CodeGen(cx);
+ }
+ }
+
// CpsOps are rather higher level, and can support operations that
// both return to the trampoline and return a value.
@@ -2304,6 +2319,10 @@ class CpsOp {
return NewArray(Tokens.String, tmp);
}
}
+
+ public static CpsOp Widen(Type to, CpsOp z) {
+ return new CpsOp(z.stmts, new ClrWiden(to, z.head));
+ }
}
class CpsBuilder {
@@ -2953,6 +2972,10 @@ class NamProcessor {
thandlers["treader_slurp"] = Methody(null, typeof(TextReader).GetMethod("ReadToEnd"));
thandlers["treader_getline"] = Methody(null, typeof(TextReader).GetMethod("ReadLine"));
thandlers["treader_stdin"] = Methody(null, typeof(Kernel).GetMethod("OpenStdin"));
+ ConstructorInfo treader_open = typeof(StreamReader).GetConstructor(new Type[1] { Tokens.String });
+ thandlers["treader_open"] = delegate(CpsOp[] z) {
+ return CpsOp.Widen(typeof(TextReader),
+ CpsOp.ConstructorCall(treader_open, z)); };
foreach (KeyValuePair<string, Func<CpsOp[], CpsOp>> kv
in thandlers) {
View
@@ -35,6 +35,10 @@ my class TextReader is IO {
}
}
+sub open($filename) {
+ Q:CgOp { (box TextReader (treader_open (obj_getstr {$filename}))) }
+}
+
$PROCESS::IN ::= Q:CgOp { (box TextReader (treader_stdin)) };
@PROCESS::ARGS ::= [ unitem(Q:CgOp { (box Parcel (getargv)) }) ];
View
@@ -72,6 +72,7 @@ BEGIN {
vvarlist_shift, vvarlist_sort, vvarlist_to_fvarlist,
vvarlist_unshift, vvarlist_unshiftn, whileloop,
get_lexer, run_protoregex, label_table, mrl_count, mrl_index,
+ treader_open,
>;
my $code;

0 comments on commit 14c7d07

Please sign in to comment.