Skip to content
Snippets Groups Projects
Commit fd2bfc16 authored by Mick Jordan's avatar Mick Jordan
Browse files

Implement .Options baseenv variable

parent 3e8fc621
Branches
No related tags found
No related merge requests found
...@@ -28,7 +28,9 @@ import com.oracle.truffle.r.runtime.data.RIntVector; ...@@ -28,7 +28,9 @@ import com.oracle.truffle.r.runtime.data.RIntVector;
import com.oracle.truffle.r.runtime.data.RLanguage; import com.oracle.truffle.r.runtime.data.RLanguage;
import com.oracle.truffle.r.runtime.data.RLogicalVector; import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RPairList;
import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment;
/** /**
* Central location for all R options, that is for the {@code options(...)} and {@code getOption} * Central location for all R options, that is for the {@code options(...)} and {@code getOption}
...@@ -51,6 +53,7 @@ public class ROptions { ...@@ -51,6 +53,7 @@ public class ROptions {
private ContextStateImpl(HashMap<String, Object> map) { private ContextStateImpl(HashMap<String, Object> map) {
this.map = map; this.map = map;
// cannot call updateDotOptions here
} }
public Set<Entry<String, Object>> getValues() { public Set<Entry<String, Object>> getValues() {
...@@ -83,6 +86,7 @@ public class ROptions { ...@@ -83,6 +86,7 @@ public class ROptions {
} else { } else {
map.put(name, coercedValue); map.put(name, coercedValue);
} }
updateDotOptions();
return previous; return previous;
} }
...@@ -95,6 +99,25 @@ public class ROptions { ...@@ -95,6 +99,25 @@ public class ROptions {
} }
return new ContextStateImpl(map); return new ContextStateImpl(map);
} }
/**
* Creates/updates the {@code .Options} variable in {@code baseenv}.
*/
public void updateDotOptions() {
// TODO make incremental?
RPairList ppl = null;
RPairList head = null;
for (Map.Entry<String, Object> entry : getValues()) {
RPairList pl = RDataFactory.createPairList(entry.getValue(), RNull.instance, RDataFactory.createSymbol(entry.getKey()));
if (ppl != null) {
ppl.setCdr(pl);
} else {
head = pl;
}
ppl = pl;
}
REnvironment.baseEnv().safePut(DOT_OPTIONS, head);
}
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
...@@ -108,6 +131,11 @@ public class ROptions { ...@@ -108,6 +131,11 @@ public class ROptions {
} }
} }
/**
* S compatibility - pair list of the options
*/
private static final String DOT_OPTIONS = ".Options";
private static final Set<String> CHECKED_OPTIONS_SET = new HashSet<>(Arrays.asList("width", "deparse.cutoff", "digits", "expressions", "keep.source", "editor", "continue", "prompt", "contrasts", private static final Set<String> CHECKED_OPTIONS_SET = new HashSet<>(Arrays.asList("width", "deparse.cutoff", "digits", "expressions", "keep.source", "editor", "continue", "prompt", "contrasts",
"check.bounds", "warn", "warning.length", "warning.expression", "max.print", "nwarnings", "error", "show.error.messages", "echo", "OutDec", "max.contour.segments", "check.bounds", "warn", "warning.length", "warning.expression", "max.print", "nwarnings", "error", "show.error.messages", "echo", "OutDec", "max.contour.segments",
"rl_word_breaks", "warnPartialMatchDollar", "warnPartialMatchArgs", "warnPartialMatchAttr", "showWarnCalls", "showErrorCalls", "showNCalls", "par.ask.default", "rl_word_breaks", "warnPartialMatchDollar", "warnPartialMatchArgs", "warnPartialMatchAttr", "showWarnCalls", "showErrorCalls", "showNCalls", "par.ask.default",
......
...@@ -478,6 +478,7 @@ public final class RContext extends ExecutionContext implements TruffleObject { ...@@ -478,6 +478,7 @@ public final class RContext extends ExecutionContext implements TruffleObject {
doEnvOptionsProfileInitialization(); doEnvOptionsProfileInitialization();
validateContextStates(); validateContextStates();
engine.activate(stateREnvironment); engine.activate(stateREnvironment);
stateROptions.updateDotOptions();
initialContextInitialized = true; initialContextInitialized = true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment