Skip to content

Commit 533179a

Browse files
committed
Merge branch 'master' into debugger
2 parents 9337c0a + b846e13 commit 533179a

7 files changed

Lines changed: 78 additions & 10 deletions

File tree

src/main/java/com/laytonsmith/core/Script.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,28 @@ private static Mixed evalLoop(EvalStack stack, Mixed lastResult, boolean hasResu
661661
return pauseResult;
662662
}
663663
}
664+
frame.setKeepIVariable(false);
665+
result = ((FlowFunction<Object>) frame.getFlowFunction()).childCompleted(
666+
t, frame.getFunctionState(), lastResult, frame.getEnv());
667+
hasResult = false;
668+
} else {
669+
throw ConfigRuntimeException.CreateUncatchableException(
670+
"Flow function in invalid state for " + data.val(), data.getTarget());
671+
}
672+
673+
frame.setFunctionState(result.getState());
674+
StepAction action = result.getAction();
675+
if(action instanceof StepAction.Evaluate e) {
676+
frame.setKeepIVariable(e.keepIVariable());
677+
Environment evalEnv = e.getEnv() != null ? e.getEnv() : frame.getEnv();
678+
stack.push(new StackFrame(e.getNode(), evalEnv, null, null));
679+
} else if(action instanceof StepAction.Complete c) {
680+
lastResult = c.getResult();
681+
hasResult = true;
682+
cleanupAndPop(stack, frame);
683+
} else if(action instanceof StepAction.FlowControl fc) {
684+
pendingFlowControl = fc;
685+
cleanupAndPop(stack, frame);
664686
}
665687
continue;
666688
}
@@ -771,6 +793,33 @@ private static Mixed debugPause(DebugContext debugCtx, EvalStack stack,
771793
debugCtx.getListener().onPaused(snapshot);
772794
return DEBUGGER_PAUSED;
773795
}
796+
797+
return lastResult;
798+
}
799+
800+
/**
801+
* Calls {@link FlowFunction#cleanup} if the frame has a FlowFunction that has begun,
802+
* then pops the frame from the stack.
803+
*/
804+
@SuppressWarnings("unchecked")
805+
private static void cleanupAndPop(EvalStack stack, StackFrame frame) {
806+
if(frame.hasFlowFunction() && frame.hasBegun()) {
807+
((FlowFunction<Object>) frame.getFlowFunction()).cleanup(
808+
frame.getNode().getTarget(), frame.getFunctionState(), frame.getEnv());
809+
}
810+
stack.pop();
811+
}
812+
813+
/**
814+
* Given the parse tree and environment, executes the tree.
815+
*
816+
* @param c
817+
* @param env
818+
* @return
819+
* @throws CancelCommandException
820+
*/
821+
public Mixed eval(ParseTree c, final Environment env) throws CancelCommandException {
822+
return iterativeEval(c, env);
774823
}
775824

776825
/**

src/main/java/com/laytonsmith/core/StackFrame.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class StackFrame {
2929
private final Environment env;
3030
private final Function function;
3131
private final FlowFunction<?> flowFunction;
32-
private List<Mixed> args;
32+
private final List<Mixed> args;
3333
private int childIndex;
3434
private boolean begun;
3535
private Object functionState;
@@ -48,6 +48,7 @@ public StackFrame(ParseTree node, Environment env, Function function, FlowFuncti
4848
this.env = env;
4949
this.function = function;
5050
this.flowFunction = flowFunction;
51+
this.args = new ArrayList<>();
5152
this.childIndex = 0;
5253
this.begun = false;
5354
this.functionState = null;
@@ -157,19 +158,13 @@ public ParseTree nextChild() {
157158
* Adds an evaluated child result to the args list (for simple mode).
158159
*/
159160
public void addArg(Mixed result) {
160-
if(args == null) {
161-
args = new ArrayList<>();
162-
}
163161
args.add(result);
164162
}
165163

166164
/**
167165
* Returns the accumulated evaluated arguments (for simple mode).
168166
*/
169167
public Mixed[] getArgs() {
170-
if(args == null) {
171-
return new Mixed[0];
172-
}
173168
return args.toArray(new Mixed[0]);
174169
}
175170

src/main/java/com/laytonsmith/core/constructs/CClosure.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ public synchronized Environment getEnv() {
275275
* @throws CancelCommandException
276276
* @deprecated Use {@link #executeCallable(Environment, Target, Mixed...)} instead, which
277277
* provides the caller's environment and target for proper error reporting.
278+
* Functions that call closures should also consider extending {@link CallbackYield}
279+
* instead of calling this directly, which re-enters eval() and defeats the iterative interpreter.
278280
*/
279281
@Deprecated
280282
public Mixed executeCallable(Mixed... values) {
@@ -311,7 +313,10 @@ public Mixed executeCallable(Mixed... values) {
311313
* @return The return value of the closure, or VOID if nothing was returned
312314
* @throws ConfigRuntimeException If any call inside the closure causes a CRE
313315
* @throws CancelCommandException If die() is called within the closure
316+
* @deprecated Functions that call closures should extend {@link CallbackYield}
317+
* instead of calling this directly, which re-enters eval() and defeats the iterative interpreter.
314318
*/
319+
@Deprecated
315320
@Override
316321
public Mixed executeCallable(Environment env, Target t, Mixed... values)
317322
throws ConfigRuntimeException, CancelCommandException {

src/main/java/com/laytonsmith/core/environments/GlobalEnv.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ public List<Iterator> GetArrayAccessIteratorsFor(ArrayAccess array) {
399399
*/
400400
public StackTraceManager GetStackTraceManager() {
401401
Thread currentThread = Thread.currentThread();
402-
if(this.stackTraceManager == null
403-
|| currentThread != this.stackTraceManagerThread) {
402+
if(this.stackTraceManager == null || currentThread != this.stackTraceManagerThread) {
404403
this.stackTraceManager = new StackTraceManager(this);
405404
this.stackTraceManagerThread = currentThread;
406405
}

src/main/java/com/laytonsmith/core/natives/interfaces/Callable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public interface Callable extends Mixed {
3636
* @return The return value of the callable, or VOID if nothing was returned
3737
* @throws ConfigRuntimeException If any call inside the callable causes a CRE
3838
* @throws CancelCommandException If die() is called within the callable
39+
* @deprecated Functions that call closures should extend {@link CallbackYield}
40+
* instead of calling this directly, which re-enters eval() and defeats the iterative interpreter.
3941
*/
42+
@Deprecated
4043
Mixed executeCallable(Environment env, Target t, Mixed... values)
4144
throws ConfigRuntimeException, CancelCommandException;
4245

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.laytonsmith.tools.debugger;
2+
3+
/**
4+
* Specifies the security mode for the DAP debug server.
5+
*/
6+
public enum DebugSecurity {
7+
/**
8+
* No authentication. Suitable for localhost-only debugging.
9+
*/
10+
NONE,
11+
12+
/**
13+
* SSH-style keypair authentication with TLS transport encryption.
14+
* Required for remote debugging.
15+
*/
16+
KEYPAIR
17+
}

src/main/resources/docs/LLVM_Development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,4 @@ Now %1 is a pointer to memory, which contains the value 0. To get 0 back, we hav
329329
for the various IR commands. Note that this is not necessarily the authoritative source though, reverse engineering \
330330
clang output is.
331331
* [https://borretti.me/article/compiling-llvm-ir-binary Compiling hand written LLVM, for test purposes.]
332-
* [https://mapping-high-level-constructs-to-llvm-ir.readthedocs.io/en/latest/README.html Guide for mapping high level language concepts to LLVM.]
332+
* [https://mapping-high-level-constructs-to-llvm-ir.readthedocs.io/en/latest/ Guide for mapping high level language concepts to LLVM.]

0 commit comments

Comments
 (0)