Skip to content

Commit

Permalink
Added runtime memory limit check
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Apr 16, 2024
1 parent ca61f8a commit bee9f81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ public Spin1Object compileObject(File rootFile, Node root) {
}
}

tree = buildFrom(objectCompiler);

errors = objectCompiler.hasErrors();

int stackRequired = 16;
if (objectCompiler.getScope().hasSymbol("_STACK")) {
stackRequired = objectCompiler.getScope().getLocalSymbol("_STACK").getNumber().intValue();
Expand All @@ -215,19 +219,15 @@ public Spin1Object compileObject(File rootFile, Node root) {
}

if (stackRequired > 0x2000) {
logMessage(new CompilerException(rootFile.getName(), "_STACK and _FREE must sum to under 8k longs."));
logMessage(new CompilerException(rootFile.getName(), "_STACK and _FREE must sum to under 8k longs.", null));
}
else {
int requiredSize = object.getSize() + object.getVarSize() + (stackRequired << 2);
if (requiredSize >= 0x8000) {
logMessage(new CompilerException(rootFile.getName(), "object exceeds runtime memory limit by " + ((requiredSize - 0x8000) >> 2) + " longs."));
logMessage(new CompilerException(rootFile.getName(), "program exceeds runtime memory limit by " + ((requiredSize - 0x8000) >> 2) + " longs.", null));
}
}

tree = buildFrom(objectCompiler);

errors = objectCompiler.hasErrors();

messages.addAll(objectCompiler.getMessages());
for (ObjectInfo info : childObjects) {
messages.addAll(info.compiler.getMessages());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Spin2Compiler extends Compiler {
protected Spin2Debug debug = new Spin2Debug();

protected Spin2Interpreter interpreter;
protected Spin2Debugger debugger;

protected List<ObjectInfo> childObjects = new ArrayList<>();

Expand Down Expand Up @@ -106,8 +107,8 @@ public Spin2Object compile(File rootFile, Node root) {
obj.setInterpreter(interpreter);
}

if (debugEnabled) {
obj.setDebugger(new Spin2Debugger());
if (debugger != null) {
obj.setDebugger(debugger);
}

return obj;
Expand Down Expand Up @@ -164,20 +165,28 @@ protected Spin2Object compileObject(File rootFile, Node root) {
}
}

int stackFree = 512 * 1024;

if (interpreter != null) {
interpreter.setVBase((interpreter.getPBase() + object.getSize()) | (objectCompiler.getObjectLinks().size() << 21));
interpreter.setDBase(interpreter.getPBase() + object.getSize() + object.getVarSize());
interpreter.setClearLongs(255 + ((object.getVarSize() + 3) / 4));
stackFree -= interpreter.getDBase();
}

if (debugEnabled) {
debugger = new Spin2Debugger();
Spin2Object debugObject = generateDebugData();
object.setDebugData(debugObject);
stackFree -= debugger.getSize() + debugObject.getSize();
}

tree = buildFrom(objectCompiler);

errors = objectCompiler.hasErrors();
if (stackFree < 0) {
logMessage(new CompilerException(rootFile.getName(), "program exceeds runtime memory limit by " + Math.abs(stackFree) + " longs.", null));
}

messages.addAll(objectCompiler.getMessages());
for (ObjectInfo info : childObjects) {
Expand Down

0 comments on commit bee9f81

Please sign in to comment.