checked in changes
authorbdemsky <bdemsky>
Sat, 29 Jul 2006 05:31:05 +0000 (05:31 +0000)
committerbdemsky <bdemsky>
Sat, 29 Jul 2006 05:31:05 +0000 (05:31 +0000)
Robust/src/ClassLibrary/String.java
Robust/src/ClassLibrary/System.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/ParseNode.java
Robust/src/IR/TypeUtil.java
Robust/src/Lex/Lexer.java
Robust/src/Main/Main.java
Robust/src/Parse/java14.cup
Robust/src/Runtime/runtime.c

index 8f448a7b9f2eb3d95af594a26fdbadde66d49c89..6752c7ecf055404ad017b3ae3e8e18feddeb27bc 100644 (file)
@@ -9,20 +9,30 @@ public class String {
        return o.toString();
     }
 
-    /*    public static String valueOf(int x) {
-         int length=0;
-         int tmp=x;
-         do {
-         tmp=tmp/10;
-         length=length+1;
-         } while(tmp!=0);
-         char chararray[]=new chararray[length];
-         do {
-         length--;
-         chararray[length]=x%10;
-         x=x/10;
-         } while (length!=0);
-         return new String(chararray);
-         }*/
-
+    public static String valueOf(int x) {
+       int length=0;
+       int tmp;
+       if (x<0)
+           tmp=-x;
+       else
+           tmp=x;
+       do {
+           tmp=tmp/10;
+           length=length+1;
+       } while(tmp!=0);
+       
+       char chararray[];
+       if (x<0)
+           chararray=new char[length+1];
+       else
+           chararray=new char[length];
+       if (x<0) {
+           chararray[0]='-';
+       }
+       do {
+           chararray[--length]=(char)(x%10+'0');
+           x=x/10;
+       } while (length!=0);
+       return new String(chararray);
+    }
 }
index 23e5295ea1420b33b66f7094ea3a5df238ddfa21..49b00937c5e2603a25d883fddea09487d7cbd84d 100644 (file)
@@ -1,9 +1,8 @@
 public class System {
-    /*    public static void printInt(int x) {
+    public static void printInt(int x) {
        String s=String.valueOf(x);
        printString(s);
-       }*/
+    }
 
     public static native void printString(String s);
-    public static native void printInt(int x);
 }
index ea8bd2f5f797e14868c20f4df875ffd53f1818ae..76e209f52a905365c707a29e9855d7e359008071 100644 (file)
@@ -648,6 +648,7 @@ public class BuildCode {
     private void generateFlatSetElementNode(FlatMethod fm, FlatSetElementNode fsen, PrintWriter output) {
        //TODO: need dynamic check to make sure this assignment is actually legal
        //Because Object[] could actually be something more specific...ie. Integer[]
+
        TypeDescriptor elementtype=fsen.getDst().getType().dereference();
        String type="";
 
@@ -711,6 +712,8 @@ public class BuildCode {
                output.println(generateTemp(fm, fln.getDst())+"=1;");
            else
                output.println(generateTemp(fm, fln.getDst())+"=0;");
+       } else if (fln.getType().isChar()) {
+           output.println(generateTemp(fm, fln.getDst())+"='"+fln.getValue()+"';");
        } else
            output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";");
     }
index be64f97a34e62fc28afb2e04a923950f0a0c7834..a5cfe5fa7bd9a5f450cf11cbd4926085007b74c9 100644 (file)
@@ -283,9 +283,10 @@ public class BuildFlat {
     }
 
     private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
-       // Two cases:
+       // Three cases:
        // left side is variable
        // left side is field
+       // left side is array
        
        Operation base=an.getOperation().getBaseOp();
        TempDescriptor src_tmp=TempDescriptor.tempFactory("src",an.getSrc().getType());
@@ -303,6 +304,7 @@ public class BuildFlat {
        }
        
        if (an.getDest().kind()==Kind.FieldAccessNode) {
+           //We are assigning an object field
            FieldAccessNode fan=(FieldAccessNode)an.getDest();
            ExpressionNode en=fan.getExpression();
            TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
@@ -310,8 +312,11 @@ public class BuildFlat {
            last.addNext(np_baseexp.getBegin());
            FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
            np_baseexp.getEnd().addNext(fsfn);
-           return new NodePair(np_src.getBegin(), fsfn);
+           FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+           fsfn.addNext(fon2);
+           return new NodePair(np_src.getBegin(), fon2);
        } else if (an.getDest().kind()==Kind.ArrayAccessNode) {
+           //We are assigning an array element
            ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
            ExpressionNode en=aan.getExpression();
            ExpressionNode enindex=aan.getIndex();
@@ -323,10 +328,14 @@ public class BuildFlat {
            np_baseexp.getEnd().addNext(np_indexexp.getBegin());
            FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
            np_indexexp.getEnd().addNext(fsen);
-           return new NodePair(np_src.getBegin(), fsen);
+           FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+           fsen.addNext(fon2);
+           return new NodePair(np_src.getBegin(), fon2);
        } else if (an.getDest().kind()==Kind.NameNode) {
+           //We could be assigning a field or variable
            NameNode nn=(NameNode)an.getDest();
            if (nn.getExpression()!=null) {
+               //It is a field
                FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
                ExpressionNode en=fan.getExpression();
                TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
@@ -334,16 +343,24 @@ public class BuildFlat {
                last.addNext(np_baseexp.getBegin());
                FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
                np_baseexp.getEnd().addNext(fsfn);
-               return new NodePair(np_src.getBegin(), fsfn);
+               FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+               fsfn.addNext(fon2);
+               return new NodePair(np_src.getBegin(), fon2);
            } else {
                if (nn.getField()!=null) {
+                   //It is a field
                    FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
                    last.addNext(fsfn);
-                   return new NodePair(np_src.getBegin(), fsfn);
+                   FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+                   fsfn.addNext(fon2);
+                   return new NodePair(np_src.getBegin(), fon2);
                } else {
+                   //It is a variable
                    FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
                    last.addNext(fon);
-                   return new NodePair(np_src.getBegin(),fon);
+                   FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+                   fon.addNext(fon2);
+                   return new NodePair(np_src.getBegin(),fon2);
                }
            }
        } 
@@ -376,10 +393,14 @@ public class BuildFlat {
            op.getOp()==Operation.PREDEC) {
            LiteralNode ln=new LiteralNode("int",new Integer(1));
            ln.setType(new TypeDescriptor(TypeDescriptor.INT));
-           AssignmentNode an=new AssignmentNode(on.getLeft(),ln,
-                              new AssignOperation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?AssignOperation.PLUSEQ:AssignOperation.MINUSEQ));
+           
+           AssignmentNode an=new AssignmentNode(on.getLeft(),
+                                                new OpNode(on.getLeft(),ln, 
+                                                           new Operation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?Operation.PLUS:Operation.MINUS))
+                                                );
            if (op.getOp()==Operation.POSTINC||
                op.getOp()==Operation.POSTDEC) {
+               //Can't do, this could have side effects
                NodePair left=flattenExpressionNode(on.getLeft(),out_temp);
                NodePair assign=flattenAssignmentNode(an,temp_left);
                left.getEnd().addNext(assign.getBegin());
index 6e29795869a20d02a0d9250f0a0ce4d5f0b44d95..e5292e64c756d895ba95d1ff186878a64a78c740 100644 (file)
@@ -176,6 +176,7 @@ public class BuildIR {
 
     private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
        ParseNode tn=pn.getChild("type");
+
        String type_st=tn.getTerminal();
        if(type_st.equals("byte")) {
            return state.getTypeDescriptor(TypeDescriptor.BYTE);
index 00858a6ffa95776ba568a05153fe01202d5da77b..e5e34d2183ddaf3a29a8ca7c0cd94753245a2790 100644 (file)
@@ -111,7 +111,7 @@ public class ParseNode implements Walkable {
     public ParseNode addChild( ParseNode child ) {
 
        if (child == null) {
-           throw new NullPointerException("Can't add null node to parse tree");
+           throw new NullPointerException("Can't add null node to parse tree: "+getLabel());
        }
 
        children.addElement (child);
index 5e12999aafbd4ee7b4d453361c25a4aabcc9a946..b0d584abab3fc2f838e3a378b51511ea70e7e847 100644 (file)
@@ -121,7 +121,14 @@ public class TypeUtil {
                return true;
            
            return false;
-       } else throw new Error();
+       } else if (possiblesuper.isPrimitive()&&(!possiblesuper.isArray())&&
+                  (cd2.isArray()||cd2.isPtr()))
+           return false;
+       else if (cd2.isPrimitive()&&(!cd2.isArray())&&
+                (possiblesuper.isArray()||possiblesuper.isPtr()))
+           return false;
+       else
+           throw new Error();
     }
 
 
index 1f8775d69a44e81dd9bd70003fec10eccc1ff8d7..456cd0d1bd28e5a4ea49d8e6a3e4d3c0cd51bb0f 100644 (file)
@@ -89,7 +89,7 @@ public class Lexer {
     } while (!(ie instanceof Token));
     endpos = lineL.head + line_pos - 1;
 
-    //System.out.println(ie.toString()); // uncomment to debug lexer.
+    // System.out.println(ie.toString()); // uncomment to debug lexer.
     java_cup.runtime.Symbol sym = ((Token)ie).token();
     // fix up left/right positions.
     sym.left = startpos; sym.right = endpos;
@@ -246,14 +246,15 @@ public class Lexer {
   static final String[] keywords = new String[] {
     "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
     "class", "const", "continue", "default", "do", "double", "else", "enum",
-    "extends", "final", "finally", "float", "for", "goto", "if", 
+    "extends", "final", "finally", 
+    "flag", //keyword for failure aware computation
+    "float", "for", "goto", "if", 
     "implements", "import", "instanceof", "int", "interface", "long", 
     "native", "new", "package", "private", "protected", "public", 
-    "return", "short", "static", "strictfp", "super", "switch",
-    "synchronized", "this", "throw", "throws", "transient", "try", "void",
-    "volatile", "while", 
-    //keywords for failure aware computation
-    "flag", "tag", "task", "taskexit"};
+    "return", "short", "static", "strictfp", "super", "switch", "synchronized",
+    "tag", "task", "taskexit", //keywords for failure aware computation
+    "this", "throw", "throws", "transient", "try", "void",
+    "volatile", "while"};
   Token getIdentifier() {
     // Get id string.
     StringBuffer sb = new StringBuffer().append(consume());
index 9f29ce67fbc9a5ab0b2c40b063e386b4b4d72ccf..da4c77bdb1b0f5406b8752410383a747bcc97870 100644 (file)
@@ -65,7 +65,7 @@ public class Main {
        Lex.Lexer l = new Lex.Lexer(fr);
        java_cup.runtime.lr_parser g;
        g = new Parse.Parser(l);
-       ParseNode p=(ParseNode) g.debug_parse().value;
+       ParseNode p=(ParseNode) g./*debug_*/parse().value;
        state.addParseNode(p);
        if (l.numErrors()!=0) {
            System.out.println("Error parsing Object.java");
index 6333defd77e80ee411561fcfedbdf521244c6aae..ec0ad3ede002818d9cd85092e99ce335515196fd 100644 (file)
@@ -446,13 +446,13 @@ array_type ::=    primitive_type:prim dims:dims {:
                ParseNode pn=(new ParseNode("type")).addChild("array");
                pn.addChild("basetype").addChild(prim);
                pn.addChild("dims").setLiteral(dims);
-               RESULT=pn;
+               RESULT=pn.getRoot();
        :}
        |       name:name dims:dims {: 
                ParseNode pn=(new ParseNode("type")).addChild("array");
                pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
                pn.addChild("dims").setLiteral(dims);
-               RESULT=pn;
+               RESULT=pn.getRoot();
        :}
        ;
 
@@ -946,7 +946,7 @@ statement_without_trailing_substatement ::=
        |       empty_statement:st {: RESULT=st; :}
        |       expression_statement:st {: RESULT=st; :}
 //     |       switch_statement
-       |       do_statement
+       |       do_statement:dos {:RESULT=dos; :}
        |       break_statement:st {: RESULT=st; :}
        |       continue_statement:st {: RESULT=st; :}
        |       return_statement:st {: RESULT=st; :}
@@ -1238,11 +1238,11 @@ dim_exprs ::=   dim_expr:exp {:
        ;
 dim_expr ::=   LBRACK expression:exp RBRACK {: RESULT=exp; :}
        ;
-dims_opt ::= {: RESULT=null; :}
+dims_opt ::= {: RESULT=new Integer(0); :}
        |       dims:dims {: RESULT = dims; :}
        ;
 
-dims ::=       LBRACK RBRACK {: RESULT=new Integer(0); :}
+dims ::=       LBRACK RBRACK {: RESULT=new Integer(1); :}
        |       dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
        ;
 
index bb933db3cf89a4361a8362f4ee0395741ef936f6..c70189cf51496ff112652f9d454a347ce32ff733 100644 (file)
@@ -12,9 +12,9 @@ int ___Object______hashcode____(struct ___Object___ * ___this___) {
   return (int) ___this___;
 }
 
-void ___System______printInt____I(int x) {
+/*void ___System______printInt____I(int x) {
   printf("%d",x);
-}
+  }*/
 
 void ___System______printString____L___String___(struct ___String___ * s) {
     struct ArrayObject * chararray=s->___string___;