Skip to content

Commit 8a4dcde

Browse files
committed
Call stack memory optimization
1 parent 3e01978 commit 8a4dcde

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

ownlang-core/src/main/java/com/annimon/ownlang/exceptions/OwnLangRuntimeException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Base type for all runtime exceptions
55
*/
6-
public abstract class OwnLangRuntimeException extends RuntimeException {
6+
public class OwnLangRuntimeException extends RuntimeException {
77

88
public OwnLangRuntimeException() {
99
super();
@@ -12,4 +12,8 @@ public OwnLangRuntimeException() {
1212
public OwnLangRuntimeException(String message) {
1313
super(message);
1414
}
15+
16+
public OwnLangRuntimeException(String message, Throwable ex) {
17+
super(message, ex);
18+
}
1519
}

ownlang-core/src/main/java/com/annimon/ownlang/lib/CallStack.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static synchronized void clear() {
1414
}
1515

1616
public static synchronized void enter(String name, Function function) {
17-
calls.push(new CallInfo(name, function));
17+
calls.push(new CallInfo(name, function.toString()));
1818
}
1919

2020
public static synchronized void exit() {
@@ -25,10 +25,10 @@ public static synchronized Deque<CallInfo> getCalls() {
2525
return calls;
2626
}
2727

28-
public record CallInfo(String name, Function function) {
28+
public record CallInfo(String name, String function) {
2929
@Override
3030
public String toString() {
31-
return String.format("%s: %s", name, function.toString().trim());
31+
return String.format("%s: %s", name, function);
3232
}
3333
}
3434
}

ownlang-parser/src/main/java/com/annimon/ownlang/parser/ast/FunctionalExpression.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.annimon.ownlang.parser.ast;
22

3-
import com.annimon.ownlang.exceptions.ArgumentsMismatchException;
4-
import com.annimon.ownlang.exceptions.TypeException;
5-
import com.annimon.ownlang.exceptions.VariableDoesNotExistsException;
6-
import com.annimon.ownlang.exceptions.UnknownFunctionException;
3+
import com.annimon.ownlang.exceptions.*;
74
import com.annimon.ownlang.lib.*;
85
import java.util.ArrayList;
96
import java.util.Iterator;
@@ -42,13 +39,9 @@ public Value eval() {
4239
}
4340
final Function f = consumeFunction(functionExpr);
4441
CallStack.enter(functionExpr.toString(), f);
45-
try {
46-
final Value result = f.execute(values);
47-
CallStack.exit();
48-
return result;
49-
} catch (ArgumentsMismatchException | TypeException | VariableDoesNotExistsException ex) {
50-
throw new RuntimeException(ex.getMessage() + " in function " + functionExpr, ex);
51-
}
42+
final Value result = f.execute(values);
43+
CallStack.exit();
44+
return result;
5245
}
5346

5447
private Function consumeFunction(Expression expr) {

0 commit comments

Comments
 (0)