diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java index a2a7f8b73f94f5d27ff9000e7dbcd12dea93177b..21336121a86ba029a21b23b5d3b3a9f98ed839f0 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java @@ -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.RLogicalVector; 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.env.REnvironment; /** * Central location for all R options, that is for the {@code options(...)} and {@code getOption} @@ -51,6 +53,7 @@ public class ROptions { private ContextStateImpl(HashMap<String, Object> map) { this.map = map; + // cannot call updateDotOptions here } public Set<Entry<String, Object>> getValues() { @@ -83,6 +86,7 @@ public class ROptions { } else { map.put(name, coercedValue); } + updateDotOptions(); return previous; } @@ -95,6 +99,25 @@ public class ROptions { } 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") @@ -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", "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", diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java index 1e1cf27e2e705f1ee358077f2bb670ec6e9e441e..e3cd344f2d9f499ffd46fed9370fa559da769ab7 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java @@ -478,6 +478,7 @@ public final class RContext extends ExecutionContext implements TruffleObject { doEnvOptionsProfileInitialization(); validateContextStates(); engine.activate(stateREnvironment); + stateROptions.updateDotOptions(); initialContextInitialized = true; }