Upgrade.
This commit is contained in:
parent
388bf28102
commit
c8fe57191c
@ -45,8 +45,150 @@ public class Benchmark {
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int arraySum(int size) {
|
||||||
|
int[] arr = new int[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
arr[i] = i;
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (int ii = 0; ii < size; ii++) {
|
||||||
|
sum = sum + arr[ii];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int arrayReverse(int size) {
|
||||||
|
int[] arr = new int[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
arr[i] = i;
|
||||||
|
}
|
||||||
|
for (int ii = 0; ii < size / 2; ii++) {
|
||||||
|
int temp = arr[ii];
|
||||||
|
arr[ii] = arr[size - 1 - ii];
|
||||||
|
arr[size - 1 - ii] = temp;
|
||||||
|
}
|
||||||
|
return arr[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int nestedLoops(int n) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
for (int j = 0; j < n; j++) {
|
||||||
|
sum = sum + i + j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int factorial(int n) {
|
||||||
|
if (n <= 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return n * factorial(n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ackermann(int m, int n) {
|
||||||
|
if (m == 0) {
|
||||||
|
return n + 1;
|
||||||
|
}
|
||||||
|
if (n == 0) {
|
||||||
|
return ackermann(m - 1, 1);
|
||||||
|
}
|
||||||
|
return ackermann(m - 1, ackermann(m, n - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int identity(int x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int methodCallOverhead(int iterations) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
sum = sum + identity(i);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long arithmeticOps(int iterations) {
|
||||||
|
long result = 0L;
|
||||||
|
for (int i = 1; i < iterations; i++) {
|
||||||
|
result = result + i * 2 - i / 2 + i % 7;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int conditionalBranching(int iterations) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
sum = sum + i;
|
||||||
|
} else {
|
||||||
|
sum = sum - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int complexConditions(int iterations) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
if (i % 3 == 0 && i % 5 == 0) {
|
||||||
|
count = count + 1;
|
||||||
|
} else if (i % 3 == 0) {
|
||||||
|
count = count + 2;
|
||||||
|
} else if (i % 5 == 0) {
|
||||||
|
count = count + 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int matrixMultiply(int size) {
|
||||||
|
int[][] a = new int[size][size];
|
||||||
|
int[][] b = new int[size][size];
|
||||||
|
int[][] c = new int[size][size];
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
for (int j = 0; j < size; j++) {
|
||||||
|
a[i][j] = i + j;
|
||||||
|
b[i][j] = i - j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int ii = 0; ii < size; ii++) {
|
||||||
|
for (int jj = 0; jj < size; jj++) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int kk = 0; kk < size; kk++) {
|
||||||
|
sum = sum + a[ii][kk] * b[kk][jj];
|
||||||
|
}
|
||||||
|
c[ii][jj] = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int bubbleSort(int size) {
|
||||||
|
int[] arr = new int[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
arr[i] = size - i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int ii = 0; ii < size - 1; ii++) {
|
||||||
|
for (int jj = 0; jj < size - ii - 1; jj++) {
|
||||||
|
if (arr[jj] > arr[jj + 1]) {
|
||||||
|
int temp = arr[jj];
|
||||||
|
arr[jj] = arr[jj + 1];
|
||||||
|
arr[jj + 1] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr[0];
|
||||||
|
}
|
||||||
|
|
||||||
public static int main() {
|
public static int main() {
|
||||||
System.out.println("=== Rava Benchmark Suite ===");
|
System.out.println("=== Rava Comprehensive Benchmark Suite ===");
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
int fib30 = fibonacci(30);
|
int fib30 = fibonacci(30);
|
||||||
@ -88,6 +230,116 @@ public class Benchmark {
|
|||||||
System.out.print(sumTime);
|
System.out.print(sumTime);
|
||||||
System.out.println(" ms");
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int arrSum = arraySum(1000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long arrSumTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Array sum (1M elements) = ");
|
||||||
|
System.out.println(arrSum);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(arrSumTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int arrRev = arrayReverse(1000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long arrRevTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Array reverse (1M elements) = ");
|
||||||
|
System.out.println(arrRev);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(arrRevTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int nested = nestedLoops(1000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long nestedTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Nested loops (1000x1000) = ");
|
||||||
|
System.out.println(nested);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(nestedTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int fact = factorial(15);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long factTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Factorial(15) recursive = ");
|
||||||
|
System.out.println(fact);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(factTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int ack = ackermann(3, 6);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long ackTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Ackermann(3, 6) = ");
|
||||||
|
System.out.println(ack);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(ackTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int methodCall = methodCallOverhead(10000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long methodCallTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Method calls (10M) = ");
|
||||||
|
System.out.println(methodCall);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(methodCallTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
long arith = arithmeticOps(10000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long arithTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Arithmetic ops (10M) = ");
|
||||||
|
System.out.println(arith);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(arithTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int cond = conditionalBranching(10000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long condTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Conditional branches (10M) = ");
|
||||||
|
System.out.println(cond);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(condTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int complex = complexConditions(10000000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long complexTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Complex conditions (10M) = ");
|
||||||
|
System.out.println(complex);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(complexTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int matrix = matrixMultiply(50);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long matrixTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Matrix multiply (50x50) = ");
|
||||||
|
System.out.println(matrix);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(matrixTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
|
start = System.nanoTime();
|
||||||
|
int bubble = bubbleSort(5000);
|
||||||
|
end = System.nanoTime();
|
||||||
|
long bubbleTime = (end - start) / 1000000;
|
||||||
|
System.out.print("Bubble sort (5000 elements) = ");
|
||||||
|
System.out.println(bubble);
|
||||||
|
System.out.print("Time: ");
|
||||||
|
System.out.print(bubbleTime);
|
||||||
|
System.out.println(" ms");
|
||||||
|
|
||||||
System.out.println("=== Benchmark Complete ===");
|
System.out.println("=== Benchmark Complete ===");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,8 +34,110 @@ def sum_loop(iterations):
|
|||||||
total += i
|
total += i
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
def array_sum(size):
|
||||||
|
arr = [0] * size
|
||||||
|
for i in range(size):
|
||||||
|
arr[i] = i
|
||||||
|
total = 0
|
||||||
|
for i in range(size):
|
||||||
|
total += arr[i]
|
||||||
|
return total
|
||||||
|
|
||||||
|
def array_reverse(size):
|
||||||
|
arr = [0] * size
|
||||||
|
for i in range(size):
|
||||||
|
arr[i] = i
|
||||||
|
for i in range(size // 2):
|
||||||
|
arr[i], arr[size - 1 - i] = arr[size - 1 - i], arr[i]
|
||||||
|
return arr[0]
|
||||||
|
|
||||||
|
def nested_loops(n):
|
||||||
|
total = 0
|
||||||
|
for i in range(n):
|
||||||
|
for j in range(n):
|
||||||
|
total += i + j
|
||||||
|
return total
|
||||||
|
|
||||||
|
def factorial(n):
|
||||||
|
if n <= 1:
|
||||||
|
return 1
|
||||||
|
return n * factorial(n - 1)
|
||||||
|
|
||||||
|
def ackermann(m, n):
|
||||||
|
if m == 0:
|
||||||
|
return n + 1
|
||||||
|
if n == 0:
|
||||||
|
return ackermann(m - 1, 1)
|
||||||
|
return ackermann(m - 1, ackermann(m, n - 1))
|
||||||
|
|
||||||
|
def method_call_overhead(iterations):
|
||||||
|
total = 0
|
||||||
|
for i in range(iterations):
|
||||||
|
total += identity(i)
|
||||||
|
return total
|
||||||
|
|
||||||
|
def identity(x):
|
||||||
|
return x
|
||||||
|
|
||||||
|
def arithmetic_ops(iterations):
|
||||||
|
result = 0
|
||||||
|
for i in range(1, iterations):
|
||||||
|
result += i * 2 - i // 2 + i % 7
|
||||||
|
return result
|
||||||
|
|
||||||
|
def conditional_branching(iterations):
|
||||||
|
total = 0
|
||||||
|
for i in range(iterations):
|
||||||
|
if i % 2 == 0:
|
||||||
|
total += i
|
||||||
|
else:
|
||||||
|
total -= i
|
||||||
|
return total
|
||||||
|
|
||||||
|
def complex_conditions(iterations):
|
||||||
|
count = 0
|
||||||
|
for i in range(iterations):
|
||||||
|
if i % 3 == 0 and i % 5 == 0:
|
||||||
|
count += 1
|
||||||
|
elif i % 3 == 0:
|
||||||
|
count += 2
|
||||||
|
elif i % 5 == 0:
|
||||||
|
count += 3
|
||||||
|
return count
|
||||||
|
|
||||||
|
def matrix_multiply(size):
|
||||||
|
a = [[0] * size for _ in range(size)]
|
||||||
|
b = [[0] * size for _ in range(size)]
|
||||||
|
c = [[0] * size for _ in range(size)]
|
||||||
|
|
||||||
|
for i in range(size):
|
||||||
|
for j in range(size):
|
||||||
|
a[i][j] = i + j
|
||||||
|
b[i][j] = i - j
|
||||||
|
|
||||||
|
for i in range(size):
|
||||||
|
for j in range(size):
|
||||||
|
total = 0
|
||||||
|
for k in range(size):
|
||||||
|
total += a[i][k] * b[k][j]
|
||||||
|
c[i][j] = total
|
||||||
|
|
||||||
|
return c[0][0]
|
||||||
|
|
||||||
|
def bubble_sort(size):
|
||||||
|
arr = [0] * size
|
||||||
|
for i in range(size):
|
||||||
|
arr[i] = size - i
|
||||||
|
|
||||||
|
for i in range(size - 1):
|
||||||
|
for j in range(size - i - 1):
|
||||||
|
if arr[j] > arr[j + 1]:
|
||||||
|
arr[j], arr[j + 1] = arr[j + 1], arr[j]
|
||||||
|
|
||||||
|
return arr[0]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("=== Python Benchmark Suite ===")
|
print("=== Python Comprehensive Benchmark Suite ===")
|
||||||
|
|
||||||
start = time.perf_counter_ns()
|
start = time.perf_counter_ns()
|
||||||
fib30 = fibonacci(30)
|
fib30 = fibonacci(30)
|
||||||
@ -65,6 +167,83 @@ def main():
|
|||||||
print(f"Sum 0..10000000 = {sum_result}")
|
print(f"Sum 0..10000000 = {sum_result}")
|
||||||
print(f"Time: {sum_time} ms")
|
print(f"Time: {sum_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
arr_sum = array_sum(1000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
arr_sum_time = (end - start) // 1000000
|
||||||
|
print(f"Array sum (1M elements) = {arr_sum}")
|
||||||
|
print(f"Time: {arr_sum_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
arr_rev = array_reverse(1000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
arr_rev_time = (end - start) // 1000000
|
||||||
|
print(f"Array reverse (1M elements) = {arr_rev}")
|
||||||
|
print(f"Time: {arr_rev_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
nested = nested_loops(1000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
nested_time = (end - start) // 1000000
|
||||||
|
print(f"Nested loops (1000x1000) = {nested}")
|
||||||
|
print(f"Time: {nested_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
fact = factorial(15)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
fact_time = (end - start) // 1000000
|
||||||
|
print(f"Factorial(15) recursive = {fact}")
|
||||||
|
print(f"Time: {fact_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
ack = ackermann(3, 6)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
ack_time = (end - start) // 1000000
|
||||||
|
print(f"Ackermann(3, 6) = {ack}")
|
||||||
|
print(f"Time: {ack_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
method_call = method_call_overhead(10000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
method_call_time = (end - start) // 1000000
|
||||||
|
print(f"Method calls (10M) = {method_call}")
|
||||||
|
print(f"Time: {method_call_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
arith = arithmetic_ops(10000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
arith_time = (end - start) // 1000000
|
||||||
|
print(f"Arithmetic ops (10M) = {arith}")
|
||||||
|
print(f"Time: {arith_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
cond = conditional_branching(10000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
cond_time = (end - start) // 1000000
|
||||||
|
print(f"Conditional branches (10M) = {cond}")
|
||||||
|
print(f"Time: {cond_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
complex = complex_conditions(10000000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
complex_time = (end - start) // 1000000
|
||||||
|
print(f"Complex conditions (10M) = {complex}")
|
||||||
|
print(f"Time: {complex_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
matrix = matrix_multiply(50)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
matrix_time = (end - start) // 1000000
|
||||||
|
print(f"Matrix multiply (50x50) = {matrix}")
|
||||||
|
print(f"Time: {matrix_time} ms")
|
||||||
|
|
||||||
|
start = time.perf_counter_ns()
|
||||||
|
bubble = bubble_sort(5000)
|
||||||
|
end = time.perf_counter_ns()
|
||||||
|
bubble_time = (end - start) // 1000000
|
||||||
|
print(f"Bubble sort (5000 elements) = {bubble}")
|
||||||
|
print(f"Time: {bubble_time} ms")
|
||||||
|
|
||||||
print("=== Benchmark Complete ===")
|
print("=== Benchmark Complete ===")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
6
ir/ir.c
6
ir/ir.c
@ -221,6 +221,7 @@ static const char* _rava_opcode_name(RavaOpCode_e opcode) {
|
|||||||
case RAVA_OP_LABEL: return "LABEL";
|
case RAVA_OP_LABEL: return "LABEL";
|
||||||
case RAVA_OP_CALL: return "CALL";
|
case RAVA_OP_CALL: return "CALL";
|
||||||
case RAVA_OP_CALL_STATIC: return "CALL_STATIC";
|
case RAVA_OP_CALL_STATIC: return "CALL_STATIC";
|
||||||
|
case RAVA_OP_CALL_RECURSIVE: return "CALL_RECURSIVE";
|
||||||
case RAVA_OP_RETURN: return "RETURN";
|
case RAVA_OP_RETURN: return "RETURN";
|
||||||
case RAVA_OP_RETURN_VOID: return "RETURN_VOID";
|
case RAVA_OP_RETURN_VOID: return "RETURN_VOID";
|
||||||
case RAVA_OP_NEW: return "NEW";
|
case RAVA_OP_NEW: return "NEW";
|
||||||
@ -274,6 +275,11 @@ void rava_ir_print(RavaProgram_t *program) {
|
|||||||
instr->operand.call.class_name,
|
instr->operand.call.class_name,
|
||||||
instr->operand.call.method_name);
|
instr->operand.call.method_name);
|
||||||
break;
|
break;
|
||||||
|
case RAVA_OP_CALL_RECURSIVE:
|
||||||
|
printf(" %s.%s (recursive)",
|
||||||
|
instr->operand.call.class_name,
|
||||||
|
instr->operand.call.method_name);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
2
ir/ir.h
2
ir/ir.h
@ -53,6 +53,7 @@ typedef enum {
|
|||||||
|
|
||||||
RAVA_OP_CALL,
|
RAVA_OP_CALL,
|
||||||
RAVA_OP_CALL_STATIC,
|
RAVA_OP_CALL_STATIC,
|
||||||
|
RAVA_OP_CALL_RECURSIVE,
|
||||||
RAVA_OP_CALL_VIRTUAL,
|
RAVA_OP_CALL_VIRTUAL,
|
||||||
RAVA_OP_CALL_SUPER,
|
RAVA_OP_CALL_SUPER,
|
||||||
RAVA_OP_CALL_NATIVE,
|
RAVA_OP_CALL_NATIVE,
|
||||||
@ -139,6 +140,7 @@ typedef union {
|
|||||||
char *class_name;
|
char *class_name;
|
||||||
char *method_name;
|
char *method_name;
|
||||||
int arg_count;
|
int arg_count;
|
||||||
|
void *cached_method;
|
||||||
} call;
|
} call;
|
||||||
struct {
|
struct {
|
||||||
char *class_name;
|
char *class_name;
|
||||||
|
|||||||
@ -747,8 +747,13 @@ static void _rava_ir_gen_expression(RavaIRGenerator_t *gen, RavaASTNode_t *expr)
|
|||||||
}
|
}
|
||||||
instr.opcode = RAVA_OP_CALL_STATIC;
|
instr.opcode = RAVA_OP_CALL_STATIC;
|
||||||
if (expr->data.call.callee->type == RAVA_AST_IDENTIFIER_EXPR) {
|
if (expr->data.call.callee->type == RAVA_AST_IDENTIFIER_EXPR) {
|
||||||
|
const char *method_name = expr->data.call.callee->data.identifier.name;
|
||||||
|
if (gen->current_method && strcmp(gen->current_method->name, method_name) == 0) {
|
||||||
|
instr.opcode = RAVA_OP_CALL_RECURSIVE;
|
||||||
|
instr.operand.call.cached_method = (void*)gen->current_method;
|
||||||
|
}
|
||||||
instr.operand.call.class_name = strdup(gen->current_class->name);
|
instr.operand.call.class_name = strdup(gen->current_class->name);
|
||||||
instr.operand.call.method_name = strdup(expr->data.call.callee->data.identifier.name);
|
instr.operand.call.method_name = strdup(method_name);
|
||||||
instr.operand.call.arg_count = expr->data.call.arguments_count;
|
instr.operand.call.arg_count = expr->data.call.arguments_count;
|
||||||
}
|
}
|
||||||
_rava_ir_emit(gen, instr);
|
_rava_ir_emit(gen, instr);
|
||||||
|
|||||||
@ -1784,7 +1784,7 @@ static bool _rava_vm_execute_fast(RavaVM_t *vm, RavaCallFrame_t *frame) {
|
|||||||
&&op_and, &&op_or, &&op_xor, &&op_not, &&op_bitnot, &&op_shl, &&op_shr, &&op_ushr,
|
&&op_and, &&op_or, &&op_xor, &&op_not, &&op_bitnot, &&op_shl, &&op_shr, &&op_ushr,
|
||||||
&&op_eq, &&op_ne, &&op_lt, &&op_le, &&op_gt, &&op_ge,
|
&&op_eq, &&op_ne, &&op_lt, &&op_le, &&op_gt, &&op_ge,
|
||||||
&&op_jump, &&op_jump_if_true, &&op_jump_if_false, &&op_label,
|
&&op_jump, &&op_jump_if_true, &&op_jump_if_false, &&op_label,
|
||||||
&&op_call, &&op_call_static, &&op_call_virtual, &&op_call_super, &&op_call_native,
|
&&op_call, &&op_call_static, &&op_call_recursive, &&op_call_virtual, &&op_call_super, &&op_call_native,
|
||||||
&&op_return, &&op_return_void,
|
&&op_return, &&op_return_void,
|
||||||
&&op_new, &&op_new_array, &&op_new_array_of_arrays, &&op_array_length, &&op_get_field, &&op_put_field,
|
&&op_new, &&op_new_array, &&op_new_array_of_arrays, &&op_array_length, &&op_get_field, &&op_put_field,
|
||||||
&&op_cast, &&op_instanceof,
|
&&op_cast, &&op_instanceof,
|
||||||
@ -2249,6 +2249,29 @@ op_call_static: {
|
|||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
op_call_recursive: {
|
||||||
|
frame->pc = pc;
|
||||||
|
RavaMethod_t *target_method = (RavaMethod_t*)instr->operand.call.cached_method;
|
||||||
|
if (UNLIKELY(!target_method)) {
|
||||||
|
target_method = frame->method;
|
||||||
|
instr->operand.call.cached_method = target_method;
|
||||||
|
}
|
||||||
|
RavaCallFrame_t *new_frame = rava_call_frame_create(target_method);
|
||||||
|
for (int i = instr->operand.call.arg_count - 1; i >= 0; i--) {
|
||||||
|
new_frame->locals[i] = STACK_POP(stack);
|
||||||
|
}
|
||||||
|
rava_call_stack_push(vm->call_stack, new_frame);
|
||||||
|
if (!_rava_vm_execute_fast(vm, new_frame)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (!rava_stack_is_empty(new_frame->operand_stack)) {
|
||||||
|
STACK_PUSH(stack, rava_stack_pop(new_frame->operand_stack));
|
||||||
|
}
|
||||||
|
rava_call_stack_pop(vm->call_stack);
|
||||||
|
rava_call_frame_destroy(new_frame);
|
||||||
|
DISPATCH();
|
||||||
|
}
|
||||||
|
|
||||||
op_call_virtual: {
|
op_call_virtual: {
|
||||||
frame->pc = pc;
|
frame->pc = pc;
|
||||||
RavaValue_t this_val = stack->values[stack->top - instr->operand.call.arg_count - 1];
|
RavaValue_t this_val = stack->values[stack->top - instr->operand.call.arg_count - 1];
|
||||||
@ -3039,7 +3062,7 @@ static bool _rava_vm_execute_ultrafast(RavaVM_t *vm, RavaMethod_t *entry_method)
|
|||||||
&&uf_and, &&uf_or, &&uf_xor, &&uf_not, &&uf_bitnot, &&uf_shl, &&uf_shr, &&uf_ushr,
|
&&uf_and, &&uf_or, &&uf_xor, &&uf_not, &&uf_bitnot, &&uf_shl, &&uf_shr, &&uf_ushr,
|
||||||
&&uf_eq, &&uf_ne, &&uf_lt, &&uf_le, &&uf_gt, &&uf_ge,
|
&&uf_eq, &&uf_ne, &&uf_lt, &&uf_le, &&uf_gt, &&uf_ge,
|
||||||
&&uf_jump, &&uf_jump_if_true, &&uf_jump_if_false, &&uf_label,
|
&&uf_jump, &&uf_jump_if_true, &&uf_jump_if_false, &&uf_label,
|
||||||
&&uf_call, &&uf_call_static, &&uf_call_virtual, &&uf_call_super, &&uf_call_native,
|
&&uf_call, &&uf_call_static, &&uf_call_recursive, &&uf_call_virtual, &&uf_call_super, &&uf_call_native,
|
||||||
&&uf_return, &&uf_return_void,
|
&&uf_return, &&uf_return_void,
|
||||||
&&uf_new, &&uf_new_array, &&uf_new_array_of_arrays, &&uf_array_length, &&uf_get_field, &&uf_put_field,
|
&&uf_new, &&uf_new_array, &&uf_new_array_of_arrays, &&uf_array_length, &&uf_get_field, &&uf_put_field,
|
||||||
&&uf_cast, &&uf_instanceof,
|
&&uf_cast, &&uf_instanceof,
|
||||||
@ -3373,6 +3396,36 @@ uf_call_static: {
|
|||||||
UF_DISPATCH();
|
UF_DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uf_call_recursive: {
|
||||||
|
RavaMethod_t *target = (RavaMethod_t*)instr->operand.call.cached_method;
|
||||||
|
if (UNLIKELY(!target)) {
|
||||||
|
target = frame->method;
|
||||||
|
instr->operand.call.cached_method = target;
|
||||||
|
}
|
||||||
|
if (!target->label_table) {
|
||||||
|
rava_optimize_superinstructions(target);
|
||||||
|
target->label_table = rava_labeltable_create(target->instructions);
|
||||||
|
}
|
||||||
|
RavaNanboxValue_t args[16];
|
||||||
|
for (int i = instr->operand.call.arg_count - 1; i >= 0; i--) {
|
||||||
|
args[i] = UF_POP();
|
||||||
|
}
|
||||||
|
frame->pc = pc;
|
||||||
|
FastFrame_t *new_frame = rava_fastframe_push(target, target->local_count);
|
||||||
|
if (!new_frame) {
|
||||||
|
vm->had_error = true;
|
||||||
|
goto uf_done;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < instr->operand.call.arg_count; i++) {
|
||||||
|
new_frame->locals[i] = args[i];
|
||||||
|
}
|
||||||
|
frame = new_frame;
|
||||||
|
instructions = target->instructions->instructions;
|
||||||
|
instr_count = target->instructions->count;
|
||||||
|
pc = 0;
|
||||||
|
UF_DISPATCH();
|
||||||
|
}
|
||||||
|
|
||||||
uf_call_virtual: {
|
uf_call_virtual: {
|
||||||
int arg_count = instr->operand.call.arg_count;
|
int arg_count = instr->operand.call.arg_count;
|
||||||
RavaNanboxValue_t args[16];
|
RavaNanboxValue_t args[16];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user