Skip to content
Snippets Groups Projects
Commit be441ef4 authored by Florian Angerer's avatar Florian Angerer
Browse files

Hiding active binding for '.Random.seed'.

parent df3f069f
No related branches found
No related tags found
No related merge requests found
...@@ -211,7 +211,7 @@ final class REngine implements Engine, Engine.Timings { ...@@ -211,7 +211,7 @@ final class REngine implements Engine, Engine.Timings {
private void initializeRNG() { private void initializeRNG() {
assert REnvironment.globalEnv() != null; assert REnvironment.globalEnv() != null;
RFunction fun = context.lookupBuiltin(".fastr.set.seed"); RFunction fun = context.lookupBuiltin(".fastr.set.seed");
ActiveBinding dotRandomSeed = new ActiveBinding(RType.Any, fun); ActiveBinding dotRandomSeed = new ActiveBinding(RType.Any, fun, true);
Frame frame = REnvironment.globalEnv().getFrame(); Frame frame = REnvironment.globalEnv().getFrame();
FrameSlot slot = FrameSlotChangeMonitor.findOrAddFrameSlot(frame.getFrameDescriptor(), RRNG.RANDOM_SEED, FrameSlotKind.Object); FrameSlot slot = FrameSlotChangeMonitor.findOrAddFrameSlot(frame.getFrameDescriptor(), RRNG.RANDOM_SEED, FrameSlotKind.Object);
FrameSlotChangeMonitor.setActiveBinding(frame, slot, dotRandomSeed, false, null); FrameSlotChangeMonitor.setActiveBinding(frame, slot, dotRandomSeed, false, null);
......
...@@ -69,14 +69,14 @@ public abstract class Exists extends RBuiltinNode.Arg4 { ...@@ -69,14 +69,14 @@ public abstract class Exists extends RBuiltinNode.Arg4 {
if (modeType != RType.Any && obj instanceof RPromise) { if (modeType != RType.Any && obj instanceof RPromise) {
obj = PromiseHelperNode.evaluateSlowPath((RPromise) obj); obj = PromiseHelperNode.evaluateSlowPath((RPromise) obj);
} }
return RRuntime.asLogical(obj != null && obj != RMissing.instance && RRuntime.checkType(obj, modeType)); return RRuntime.asLogical(obj != null && RRuntime.checkType(obj, modeType));
} }
for (REnvironment e = env; e != REnvironment.emptyEnv(); e = e.getParent()) { for (REnvironment e = env; e != REnvironment.emptyEnv(); e = e.getParent()) {
Object obj = e.get(name); Object obj = e.get(name);
if (modeType != RType.Any && obj instanceof RPromise) { if (modeType != RType.Any && obj instanceof RPromise) {
obj = PromiseHelperNode.evaluateSlowPath((RPromise) obj); obj = PromiseHelperNode.evaluateSlowPath((RPromise) obj);
} }
if (obj != null && obj != RMissing.instance && RRuntime.checkType(obj, modeType)) { if (obj != null && RRuntime.checkType(obj, modeType)) {
return RRuntime.LOGICAL_TRUE; return RRuntime.LOGICAL_TRUE;
} }
} }
......
...@@ -151,7 +151,9 @@ public class RNGFunctions { ...@@ -151,7 +151,9 @@ public class RNGFunctions {
int[] seedsArr = (int[]) seeds; int[] seedsArr = (int[]) seeds;
return RDataFactory.createIntVector(seedsArr, RDataFactory.INCOMPLETE_VECTOR); return RDataFactory.createIntVector(seedsArr, RDataFactory.INCOMPLETE_VECTOR);
} }
assert seeds != null; if (seeds == null) {
return RNull.instance;
}
return seeds; return seeds;
} }
} }
......
...@@ -39,10 +39,17 @@ public class ActiveBinding implements RTruffleObject { ...@@ -39,10 +39,17 @@ public class ActiveBinding implements RTruffleObject {
private final RType expectedType; private final RType expectedType;
private final RFunction function; private final RFunction function;
private boolean initialized = false;
private boolean hidden = false;
public ActiveBinding(RType expectedType, RFunction fun) { public ActiveBinding(RType expectedType, RFunction fun, boolean hidden) {
this.expectedType = Objects.requireNonNull(expectedType); this.expectedType = Objects.requireNonNull(expectedType);
this.function = Objects.requireNonNull(fun); this.function = Objects.requireNonNull(fun);
this.hidden = hidden;
}
public ActiveBinding(RType expectedType, RFunction fun) {
this(expectedType, fun, false);
} }
public RFunction getFunction() { public RFunction getFunction() {
...@@ -62,11 +69,29 @@ public class ActiveBinding implements RTruffleObject { ...@@ -62,11 +69,29 @@ public class ActiveBinding implements RTruffleObject {
return "active binding"; return "active binding";
} }
public boolean isHidden() {
return hidden;
}
public boolean isInitialized() {
return initialized;
}
public Object writeValue(Object value) { public Object writeValue(Object value) {
return RContext.getEngine().evalFunction(function, REnvironment.baseEnv().getFrame(), RCaller.createInvalid(null), true, null, value); Object result = RContext.getEngine().evalFunction(function, REnvironment.baseEnv().getFrame(), RCaller.createInvalid(null), true, null, value);
initialized = true;
return result;
} }
public Object readValue() { public Object readValue() {
return RContext.getEngine().evalFunction(function, REnvironment.baseEnv().getFrame(), RCaller.createInvalid(null), true, null); return RContext.getEngine().evalFunction(function, REnvironment.baseEnv().getFrame(), RCaller.createInvalid(null), true, null);
} }
public static boolean isListed(Object value) {
if (isActiveBinding(value)) {
ActiveBinding binding = (ActiveBinding) value;
return !binding.hidden || binding.initialized;
}
return true;
}
} }
...@@ -39,6 +39,7 @@ import com.oracle.truffle.r.runtime.RError; ...@@ -39,6 +39,7 @@ import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RError.Message;
import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.env.REnvironment.PutException; import com.oracle.truffle.r.runtime.env.REnvironment.PutException;
...@@ -75,7 +76,10 @@ public final class REnvTruffleFrameAccess extends REnvFrameAccess { ...@@ -75,7 +76,10 @@ public final class REnvTruffleFrameAccess extends REnvFrameAccess {
Object value = FrameSlotChangeMonitor.getValue(slot, frame); Object value = FrameSlotChangeMonitor.getValue(slot, frame);
// special treatment for active binding: call bound function // special treatment for active binding: call bound function
if (ActiveBinding.isActiveBinding(value)) { if (ActiveBinding.isActiveBinding(value)) {
return ((ActiveBinding) value).readValue(); Object readValue = ((ActiveBinding) value).readValue();
// special case: if the active binding returns RMissing, then this should behave
// like the variable does not exist.
return readValue != RMissing.instance ? readValue : null;
} }
return value; return value;
} }
...@@ -161,7 +165,8 @@ public final class REnvTruffleFrameAccess extends REnvFrameAccess { ...@@ -161,7 +165,8 @@ public final class REnvTruffleFrameAccess extends REnvFrameAccess {
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
String name = names[i]; String name = names[i];
FrameSlot frameSlot = fd.findFrameSlot(name); FrameSlot frameSlot = fd.findFrameSlot(name);
if (FrameSlotChangeMonitor.getValue(frameSlot, frame) == null) { Object value = FrameSlotChangeMonitor.getValue(frameSlot, frame);
if (value == null || !ActiveBinding.isListed(value)) {
continue; continue;
} }
if (REnvironment.includeName(name, allNames, pattern)) { if (REnvironment.includeName(name, allNames, pattern)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment