Skip to content

Commit

Permalink
Perlito5 - misc/Java-Asm-Interpreter/MethodExecutorAsm new Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Aug 2, 2024
1 parent cca71fc commit 6597127
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions misc/Java-Asm-Interpreter/MethodExecutorAsm/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ public Runtime(String value) {
this.value = value;
}

public Runtime(Runtime value) {
this.type = Type.REFERENCE;
this.value = value;
}

public Runtime(Method value) {
this.type = Type.CODE;
this.value = value;
}

// Getters
public long getLong() {
switch (type) {
Expand Down Expand Up @@ -92,7 +82,7 @@ public boolean getBoolean() {
case INTEGER:
return (long) value != 0;
case DOUBLE:
return (long) ((double) value) != 0;
return (double) value != 0.0;
case STRING:
String s = (String) value;
return !s.equals("") && !s.equals("0");
Expand Down Expand Up @@ -134,9 +124,9 @@ public String toString() {
case STRING:
return (String) value;
case REFERENCE:
return "Reference to: " + value.toString();
return "CODE(" + value.toString() + ")";
case CODE:
return "Code Reference: " + value.toString();
return "REF(" + value.toString() + ")";
case UNDEF:
return "";
default:
Expand All @@ -148,7 +138,10 @@ public static Runtime make_sub(String className) throws Exception {
// finish setting up a CODE object
Class<?> clazz = Runtime.anonSubs.remove(className);
Method mm = clazz.getMethod("apply", Runtime.class, ContextType.class);
return new Runtime(mm);
Runtime r = new Runtime();
r.value = mm;
r.type = Type.CODE;
return r;
}

public Runtime apply(Runtime a, ContextType callContext) throws Exception {
Expand Down Expand Up @@ -201,7 +194,7 @@ public Runtime stringConcat(Runtime b) {
}

public Runtime unaryMinus() {
return new Runtime(new Runtime(0).subtract(this));
return new Runtime(0).subtract(this);
}

public Runtime add(Runtime arg2) {
Expand Down Expand Up @@ -334,8 +327,8 @@ private Runtime parseNumber() {
return new Runtime(parsedValue);
}
} catch (NumberFormatException e) {
// Return a Runtime object with a double value of 0.0 if parsing fails
return new Runtime(0.0);
// Return a Runtime object with value of 0 if parsing fails
return new Runtime(0);
}
}
}

0 comments on commit 6597127

Please sign in to comment.