--- /dev/null
+public class Integer {
+ private int value;
+
+ public Integer(int value) {
+ this.value=value;
+ }
+
+ public Integer(String str) {
+ value=Integer.parseInt(str, 10);
+ }
+
+ public int intValue() {
+ return value;
+ }
+
+ public static int parseInt(String str) {
+ return Integer.parseInt(str, 10);
+ }
+
+ public static int parseInt(String str, int radix) {
+ int value=0;
+ boolean isNeg=false;
+ int start=0;
+ byte[] chars=str.getBytes();
+ if (chars[0]=='-') {
+ isNeg=true;
+ start=1;
+ }
+ for(int i=start;i<str.length();i++) {
+ byte b=chars[i];
+ 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';
+ if (val>=radix)
+ System.error();
+ value=value*radix+val;
+ }
+ if (isNeg)
+ value=-value;
+ return value;
+ }
+
+ public String toString() {
+ return String.valueOf(value);
+ }
+
+ public int hashCode() {
+ return value;
+ }
+}
return value[i+offset];
}
+ public String toString() {
+ return this;
+ }
+
public static String valueOf(Object o) {
return o.toString();
}
}
public static native void printString(String s);
+
+ public static void error() {
+ System.printString("Error");
+ }
}
throw new Error("Illegal return appears in Task: "+d.getSymbol());
MethodDescriptor md=(MethodDescriptor)d;
if (rn.getReturnExpression()!=null)
- if (md.getReturnType().isVoid())
+ if (md.getReturnType()==null)
+ throw new Error("Constructor can't return something.");
+ else if (md.getReturnType().isVoid())
throw new Error(md+" is void");
else
checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
readSourceFile(state, ClassLibraryPrefix+"Object.java");
readSourceFile(state, ClassLibraryPrefix+"System.java");
readSourceFile(state, ClassLibraryPrefix+"String.java");
+ readSourceFile(state, ClassLibraryPrefix+"Integer.java");
readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java");
readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java");
readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
dotest WriteFile WriteFile.java
dotest ReadFile ReadFile.java
dotest FileLength FileLength.java
+dotest IntegerTest IntegerTest.java
\ No newline at end of file
--- /dev/null
+public class IntegerTest {
+ public static void main(String[] str) {
+ Integer i=new Integer("312");
+ System.printString(i.toString());
+ System.printString("\n");
+ System.printInt(Integer.parseInt("-34"));
+ System.printString("\n");
+ }
+
+
+}