Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed Dec 8, 2023
1 parent f0c0853 commit 86bfd63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/leekscript/compiler/JavaCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static AI compile(AIFile file, boolean useClassCache, boolean enableOpera
var ai = (AI) entry.clazz.getDeclaredConstructor().newInstance();
ai.setId(file.getId());
ai.setLinesFile(lines);
ai.increaseRAMDirect((int) (java.length() * 10));
return ai;
} catch (Exception e) {
throw new LeekScriptException(Error.CANNOT_LOAD_AI, e.getMessage());
Expand All @@ -92,6 +93,7 @@ public static AI compile(AIFile file, boolean useClassCache, boolean enableOpera
ai.setId(file.getId());
ai.setFile(file);
ai.setLinesFile(lines);
ai.increaseRAMDirect((int) (java.length() * 10));
return ai;
} catch (Exception e) {
throw new LeekScriptException(Error.CANNOT_LOAD_AI, e.getMessage());
Expand Down Expand Up @@ -204,6 +206,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
ai.setCompileTime(compile_time);
ai.setLoadTime(load_time);
ai.setLinesFile(lines);
ai.increaseRAMDirect((int) (java.length() * 10));

if (useClassCache) {
aiCache.put(file.getJavaClass(), new AIClassEntry(clazz, file.getTimestamp()));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/leekscript/runner/AI.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ public long getMaxRAM() {
return maxRAM;
}

public void setMaxRAM(int maxRAM) {
this.maxRAM = maxRAM;
}

public void setMaxOperations(int maxOperations) {
this.maxOperations = maxOperations;
}

public AILog getLogs() {
return logs;
}
Expand Down Expand Up @@ -390,6 +398,11 @@ public void resetCounter() {
mOperations = 0;
}


public void increaseRAMDirect(int ram) {
mRAM += ram;
}

public void increaseRAM(int ram) throws LeekRunException {
mRAM += ram;
if (mRAM > maxRAM) {
Expand Down

0 comments on commit 86bfd63

Please sign in to comment.