changes for reading input files
authorjzhou <jzhou>
Thu, 10 May 2012 03:51:35 +0000 (03:51 +0000)
committerjzhou <jzhou>
Thu, 10 May 2012 03:51:35 +0000 (03:51 +0000)
Robust/src/ClassLibrary/MGC/Scanner.java
Robust/src/Runtime/bamboo/multicoreruntime.c

index 31b4567e77b2d0a06eabac317961214eb7150c89..f4fba9b149489d518a81935944439a1ed2f57d9f 100644 (file)
@@ -1,6 +1,7 @@
 public class Scanner implements Iterator {\r
   private String sourcename;\r
   private int currentpos;\r
+  private int filearray;\r
 \r
   public Scanner (final String source) {\r
     this.sourcename = source;\r
@@ -10,13 +11,7 @@ public class Scanner implements Iterator {
   public void close () {\r
   }\r
 \r
-  public double nextDouble () {\r
-      return Double.parseDouble(new String(next()));\r
-  }\r
+  public native double nextDouble ();\r
 \r
-  public int nextInt () {\r
-      return Integer.parseInt(new String(next()));\r
-  }\r
-  \r
-  private native char[] next();\r
+  public native int nextInt ();\r
 }\r
index 57c971af4d1506f33e9b5ee0514499d70791ec4d..bed80cf40a50b49fd462a29a29000cded452cf55 100644 (file)
@@ -429,23 +429,94 @@ void CALL01(___System______printString____L___String___, struct ___String___ * _
 }
 #endif
 
-#ifdef D___Scanner______next____ 
-struct ArrayObject * CALL01(___Scanner______next____, struct ___Scanner___ * ___this___) {
+#ifdef D___Scanner______nextInt____ 
+int CALL01(___Scanner______nextInt____, struct ___Scanner___ * ___this___) {
   int pos = VAR(___this___)->___currentpos___;
-#if defined(MULTICORE_GC)||defined(PMC_GC)
-  struct ArrayObject * result= allocate_newarray(NULL, CHARARRAYTYPE, 10);
-#else
-  struct ArrayObject * result=allocate_newarray(CHARARRAYTYPE, 10);
-#endif
   int i = 0;
-  while(true) { //(VAR(___this___)->___sourcename___[pos]==' ')||(VAR(___this___)->___sourcename___[pos]=='\n')){
+  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
+  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
          pos++;
   }
+  int value = 0;
+  bool isNeg=false;
+  int radix = 10;
+
+  if (filearray[pos]=='-') {
+         isNeg=true;
+      pos++;
+  }
+  bool cont=true;
   do {
-         ((short *)(((char *)&result->___length___)+sizeof(int)))[i++]='\0';//(short)VAR(___this___)->___sourcename___[pos++]; // TODO
-  }while(true);//(VAR(___this___)->___sourcename___[pos]!=' ')&&(VAR(___this___)->___sourcename___[pos]!='\n'));
+         unsigned char b=filearray[pos];
+      int val;
+      if (b>='0'&&b<='9')
+        val=b-'0';
+      else if (b>='a'&&b<='z')
+        val=10+b-'a';
+      else if (b>='A'&&b<='Z')
+        val=10+b-'A';
+      else {
+        cont=false;
+      }
+      if (cont) {
+        if (val>=radix)
+          printf("Error in Scanner.nextInt(): val >= radix");
+        value=value*radix+val;
+               pos++;
+      }
+  }while(cont);
+  if (isNeg)
+         value=-value;
+
+  VAR(___this___)->___currentpos___ = pos;
+  return value;
+}
+#endif
+
+#ifdef D___Scanner______nextDouble____ 
+double CALL01(___Scanner______nextDouble____, struct ___Scanner___ * ___this___) {
+  int pos = VAR(___this___)->___currentpos___;
+  int i = 0;
+  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
+  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
+         pos++;
+  }
+  double value = 0.0;
+  bool isNeg=false;
+  int radix = 10;
+
+  if (filearray[pos]=='-') {
+         isNeg=true;
+      pos++;
+  } else if(filearray[pos]=='+') {
+         pos++;
+  }
+  bool cont=true;
+  // TODO
+  /*do {
+         unsigned char b=filearray[pos];
+      int val;
+      if (b>='0'&&b<='9')
+        val=b-'0';
+      else if (b>='a'&&b<='z')
+        val=10+b-'a';
+      else if (b>='A'&&b<='Z')
+        val=10+b-'A';
+      else {
+        cont=false;
+      }
+      if (cont) {
+        if (val>=radix)
+          System.error();
+        value=value*radix+val;
+               pos++;
+      }
+  }while(cont)*/
+  if (isNeg)
+         value=-value;
+
   VAR(___this___)->___currentpos___ = pos;
-  return result;
+  return value;
 }
 #endif