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
|
* Base type for all runtime exceptions
|
||||||
*/
|
*/
|
||||||
public abstract class OwnLangRuntimeException extends RuntimeException {
|
public class OwnLangRuntimeException extends RuntimeException {
|
||||||
|
|
||||||
public OwnLangRuntimeException() {
|
public OwnLangRuntimeException() {
|
||||||
super();
|
super();
|
||||||
@ -12,4 +12,8 @@ public abstract class OwnLangRuntimeException extends RuntimeException {
|
|||||||
public OwnLangRuntimeException(String message) {
|
public OwnLangRuntimeException(String message) {
|
||||||
super(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) {
|
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() {
|
public static synchronized void exit() {
|
||||||
@ -25,10 +25,10 @@ public final class CallStack {
|
|||||||
return calls;
|
return calls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record CallInfo(String name, Function function) {
|
public record CallInfo(String name, String function) {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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;
|
package com.annimon.ownlang.parser.ast;
|
||||||
|
|
||||||
import com.annimon.ownlang.exceptions.ArgumentsMismatchException;
|
import com.annimon.ownlang.exceptions.*;
|
||||||
import com.annimon.ownlang.exceptions.TypeException;
|
|
||||||
import com.annimon.ownlang.exceptions.VariableDoesNotExistsException;
|
|
||||||
import com.annimon.ownlang.exceptions.UnknownFunctionException;
|
|
||||||
import com.annimon.ownlang.lib.*;
|
import com.annimon.ownlang.lib.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -42,13 +39,9 @@ public final class FunctionalExpression extends InterruptableNode implements Exp
|
|||||||
}
|
}
|
||||||
final Function f = consumeFunction(functionExpr);
|
final Function f = consumeFunction(functionExpr);
|
||||||
CallStack.enter(functionExpr.toString(), f);
|
CallStack.enter(functionExpr.toString(), f);
|
||||||
try {
|
final Value result = f.execute(values);
|
||||||
final Value result = f.execute(values);
|
CallStack.exit();
|
||||||
CallStack.exit();
|
return result;
|
||||||
return result;
|
|
||||||
} catch (ArgumentsMismatchException | TypeException | VariableDoesNotExistsException ex) {
|
|
||||||
throw new RuntimeException(ex.getMessage() + " in function " + functionExpr, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Function consumeFunction(Expression expr) {
|
private Function consumeFunction(Expression expr) {
|
||||||
|
Loading…
Reference in New Issue
Block a user