mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Call stack memory optimization
This commit is contained in:
parent
3e01978f22
commit
8a4dcde2a1
@ -3,7 +3,7 @@ package com.annimon.ownlang.exceptions;
|
||||
/**
|
||||
* Base type for all runtime exceptions
|
||||
*/
|
||||
public abstract class OwnLangRuntimeException extends RuntimeException {
|
||||
public class OwnLangRuntimeException extends RuntimeException {
|
||||
|
||||
public OwnLangRuntimeException() {
|
||||
super();
|
||||
@ -12,4 +12,8 @@ public abstract class OwnLangRuntimeException extends RuntimeException {
|
||||
public OwnLangRuntimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public OwnLangRuntimeException(String message, Throwable ex) {
|
||||
super(message, ex);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ public final class CallStack {
|
||||
}
|
||||
|
||||
public static synchronized void enter(String name, Function function) {
|
||||
calls.push(new CallInfo(name, function));
|
||||
calls.push(new CallInfo(name, function.toString()));
|
||||
}
|
||||
|
||||
public static synchronized void exit() {
|
||||
@ -25,10 +25,10 @@ public final class CallStack {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public record CallInfo(String name, Function function) {
|
||||
public record CallInfo(String name, String function) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s: %s", name, function.toString().trim());
|
||||
return String.format("%s: %s", name, function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.annimon.ownlang.parser.ast;
|
||||
|
||||
import com.annimon.ownlang.exceptions.ArgumentsMismatchException;
|
||||
import com.annimon.ownlang.exceptions.TypeException;
|
||||
import com.annimon.ownlang.exceptions.VariableDoesNotExistsException;
|
||||
import com.annimon.ownlang.exceptions.UnknownFunctionException;
|
||||
import com.annimon.ownlang.exceptions.*;
|
||||
import com.annimon.ownlang.lib.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -42,13 +39,9 @@ public final class FunctionalExpression extends InterruptableNode implements Exp
|
||||
}
|
||||
final Function f = consumeFunction(functionExpr);
|
||||
CallStack.enter(functionExpr.toString(), f);
|
||||
try {
|
||||
final Value result = f.execute(values);
|
||||
CallStack.exit();
|
||||
return result;
|
||||
} catch (ArgumentsMismatchException | TypeException | VariableDoesNotExistsException ex) {
|
||||
throw new RuntimeException(ex.getMessage() + " in function " + functionExpr, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Function consumeFunction(Expression expr) {
|
||||
|
Loading…
Reference in New Issue
Block a user