Permalink
Browse files

Basic classes for IR

  • Loading branch information...
jonjlee committed Feb 28, 2012
1 parent 2a504d1 commit b69431fd8590350e96f33c88c0531b1c8946c172
View
@@ -1,3 +1,3 @@
-This project will contain implementations for the fjava language from [Jason Hickey's CS134b class](http://main.metaprl.org/jyh/classes/cs134/cs134b/2002/), a modified version of MiniJava from Andrew Appel's [Modern Compiler Implementation in Java](http://www.cs.princeton.edu/~appel/modern/java/). Differences include the removal declaration modifiers (public, static, etc.) and the addition of higher-order functions. See [lab #2](http://main.metaprl.org/jyh/classes/cs134/cs134b/2002/labs/lab2/lab2.pdf) for a complete list of differences between the languages.
+This project will contain implementations for the fjava language from [Jason Hickey's CS134b class](http://main.metaprl.org/jyh/classes/cs134/cs134b/2002/), a modified version of MiniJava from Andrew Appel's [Modern Compiler Implementation in Java](http://www.cs.princeton.edu/~appel/modern/java/). Differences include the removal declaration modifiers (public, static, etc.) and the addition of higher-order functions and a completely different IR. See [lab #2](http://main.metaprl.org/jyh/classes/cs134/cs134b/2002/labs/lab2/lab2.pdf) for a complete list of differences between the languages.
-Code will be written using TDD. CI can be found on [CloudBees](https://jlee.ci.cloudbees.com/job/appel-exercises/).
+CI can be found on [CloudBees](https://jlee.ci.cloudbees.com/job/appel-exercises/).
@@ -0,0 +1,7 @@
+package appel.ch07;
+
+public class AstIRTransform {
+ public static Exp transform() {
+ return null;
+ }
+}
@@ -0,0 +1,31 @@
+package appel.ch07;
+
+public abstract class Atom {
+ public static class Unit extends Atom {};
+ public static class Nil extends Atom {};
+
+ public static class Bool extends Atom {
+ final boolean v;
+ public Bool(boolean v) { this.v = v; }
+ };
+
+ public static class Char extends Atom {
+ final char v;
+ public Char(char v) { this.v = v; }
+ };
+
+ public static class Int extends Atom {
+ final int v;
+ public Int(int v) { this.v = v; }
+ };
+
+ public static class Float extends Atom {
+ final float v;
+ public Float(float v) { this.v = v; }
+ };
+
+ public static class Var extends Atom {
+ final Symbol.Var name;
+ public Var(Symbol.Var name) { this.name = name; }
+ };
+}
@@ -0,0 +1,24 @@
+package appel.ch07;
+
+public enum Binop {
+ // integers
+ AddIntOp,
+ SubIntOp,
+ MulIntOp,
+ DivIntOp,
+ RemIntOp,
+ AndIntOp,
+ OrIntOp,
+ LslIntOp, // Logical shift left <<
+ LsrIntOp, // Logical shift right >>
+ AsrIntOp, // Arithmetic shift right >>>
+ XorIntOp,
+
+ // floats
+ AddFloatOp,
+ SubFloatOp,
+ MulFloatOp,
+ DivFloatOp,
+ RemFloatOp
+
+}
@@ -0,0 +1,52 @@
+package appel.ch07;
+
+import java.util.Map;
+import appel.ch07.Symbol.Var;
+import util.Table;
+
+public class Env {
+
+ public static final Table<Symbol, Type> BaseTypes;
+ public static final Env Empty;
+
+ static {
+ BaseTypes = Table.<Symbol, Type> create()
+ .put(new Symbol.TypeVar("void", 0), Type.Unit)
+ .put(new Symbol.TypeVar("boolean", 0), Type.Bool)
+ .put(new Symbol.TypeVar("char", 0), Type.Char)
+ .put(new Symbol.TypeVar("int", 0), Type.Int)
+ .put(new Symbol.TypeVar("float", 0), Type.Float)
+ .put(new Symbol.TypeVar("String", 0), Type.String);
+
+ Empty = new Env(
+ Table.<Symbol, TypeDef> create(),
+ BaseTypes,
+ Table.<Symbol, Type> create(),
+ Table.<Symbol, Map<Var, Type>> create(),
+ null,
+ null,
+ null,
+ IRState.objectType);
+ }
+
+ public final Table<Symbol, TypeDef> types;
+ public final Table<Symbol, Type> base;
+ public final Table<Symbol, Type> vars;
+ public final Table<Symbol, Map<Symbol.Var, Type>> funs;
+ public final Type ret;
+ public final Map<Symbol.Var, TypeDef> cls;
+ public final Symbol.Var brk;
+ public final Type obj;
+ public Env(Table<Symbol, TypeDef> types, Table<Symbol, Type> base, Table<Symbol, Type> vars, Table<Symbol, Map<Var, Type>> funs,
+ Type ret, Map<Var, TypeDef> cls, Var brk, Type obj) {
+ this.types = types;
+ this.base = base;
+ this.vars = vars;
+ this.funs = funs;
+ this.ret = ret;
+ this.cls = cls;
+ this.brk = brk;
+ this.obj = obj;
+ }
+
+}
Oops, something went wrong.

0 comments on commit b69431f

Please sign in to comment.