forked from entropy-cloud/nop-entropy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将IEvalScope上线程不安全的函数移动到EvalRuntime类中,确保IServiceContext以及IServiceConte…
…xt.getEvalScope()都是线程安全的对象。逻辑流编配时会出现并发执行Xpl模板的情况,需要确保不会出现并发冲突
- Loading branch information
1 parent
6b2c109
commit fb048c1
Showing
185 changed files
with
1,438 additions
and
1,132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
nop-core/src/main/java/io/nop/core/lang/eval/EvalRuntime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package io.nop.core.lang.eval; | ||
|
||
import io.nop.api.core.util.IVariableScope; | ||
import io.nop.api.core.util.SourceLocation; | ||
|
||
public class EvalRuntime implements IVariableScope { | ||
private final IEvalScope scope; | ||
private ExitMode exitMode; | ||
private EvalFrame currentFrame; | ||
private IEvalOutput out = DisabledEvalOutput.INSTANCE; | ||
|
||
public EvalRuntime(IEvalScope scope) { | ||
this.scope = scope; | ||
} | ||
|
||
public EvalRuntime(IEvalScope scope, IEvalOutput out) { | ||
this(scope); | ||
this.out = out; | ||
} | ||
|
||
public EvalRuntime(IEvalScope scope, EvalFrame frame) { | ||
this(scope); | ||
this.currentFrame = frame; | ||
} | ||
|
||
public IEvalScope getScope() { | ||
return scope; | ||
} | ||
|
||
public ExitMode getExitMode() { | ||
return exitMode; | ||
} | ||
|
||
public void setExitMode(ExitMode exitMode) { | ||
this.exitMode = exitMode; | ||
} | ||
|
||
public IEvalOutput getOut() { | ||
return out; | ||
} | ||
|
||
public void setOut(IEvalOutput out) { | ||
this.out = out; | ||
} | ||
|
||
public EvalFrame getCurrentFrame() { | ||
return currentFrame; | ||
} | ||
|
||
public EvalFrame getFrame(int frameIndex) { | ||
if (frameIndex <= 0) | ||
return getCurrentFrame(); | ||
|
||
EvalFrame frame = getCurrentFrame(); | ||
for (int i = 0; i < frameIndex; i++) { | ||
frame = frame.getParentFrame(); | ||
if (frame == null) | ||
return null; | ||
} | ||
return frame; | ||
} | ||
|
||
public void pushFrame(EvalFrame frame) { | ||
this.currentFrame = frame; | ||
} | ||
|
||
public void popFrame() { | ||
if (currentFrame != null) | ||
currentFrame = currentFrame.getParentFrame(); | ||
} | ||
|
||
@Override | ||
public Object getValueByPropPath(String propPath) { | ||
return scope.getValueByPropPath(propPath); | ||
} | ||
|
||
public Object getValue(String name) { | ||
return scope.getValue(name); | ||
} | ||
|
||
public boolean containsValue(String name) { | ||
return scope.containsValue(name); | ||
} | ||
|
||
public Object getLocalValue(String name) { | ||
return scope.getLocalValue(name); | ||
} | ||
|
||
public void setLocalValue(String name, Object value) { | ||
scope.setLocalValue(name, value); | ||
} | ||
|
||
public void setLocalValue(SourceLocation loc, String name, Object value) { | ||
scope.setLocalValue(loc, name, value); | ||
} | ||
|
||
public EvalRuntime getRuntimeForFrame(int frameIndex) { | ||
EvalFrame frame = getFrame(frameIndex); | ||
if (frame == null) { | ||
frame = new EvalFrame(null, new String[0]); | ||
} | ||
return new EvalRuntime(scope, frame); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.