Search in sources :

Example 1 with Environment

use of catdata.Environment in project fql by CategoricalData.

the class MplDriver method makeEnv.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Environment<MplObject> makeEnv(@SuppressWarnings("unused") String str, Program<MplExp<String, String>> init) {
    Environment<MplObject> ret = new Environment<>();
    for (String k : init.order) {
        MplExp se = init.exps.get(k);
        try {
            MplObject xxx = (MplObject) se.accept(new Unit(), new MplOps(ret));
            ret.put(k, xxx);
        } catch (Throwable t) {
            t.printStackTrace();
            throw new LineException(t.getLocalizedMessage(), k, "");
        }
    }
    return ret;
}
Also used : MplExp(catdata.mpl.Mpl.MplExp) LineException(catdata.LineException) Environment(catdata.Environment) Unit(catdata.Unit)

Example 2 with Environment

use of catdata.Environment in project fql by CategoricalData.

the class OplDriver method makeEnv.

// : let x be the position of the first change between old and new
// program.
// a definition y is 'safe' if definition y+1 begins before x.
// each code editor's driver should copy over the safe definitions and start
// the driver
// at the appropriate spot
public static Environment<OplObject> makeEnv(String str, Program<OplExp> init, String[] toUpdate, String last_str, Program<OplExp> last_prog, Environment<OplObject> last_env) {
    Environment<OplObject> ret = new Environment<>();
    // Map<String, Integer> extra = new HashMap<>();
    boolean usesPragma = false;
    for (String k : init.order) {
        OplExp se = init.exps.get(k);
        if (se instanceof OplPragma) {
            se.accept(init, new OplOps(ret));
            ret.put(k, se);
            usesPragma = true;
        }
    }
    if (DefunctGlobalOptions.debug.opl.opl_lazy_gui && usesPragma) {
        throw new RuntimeException("Pragmas and lazy guis are not compatible");
    }
    if (DefunctGlobalOptions.debug.opl.opl_prover_force_prec) {
        inferPrec(init);
    }
    Set<String> unchanged = new HashSet<>();
    int i = 0;
    if (last_str != null && DefunctGlobalOptions.debug.opl.opl_cache_gui) {
        for (String k : init.order) {
            if (i >= last_prog.order.size()) {
                break;
            }
            String v = last_prog.order.get(i);
            if (!v.equals(k)) {
                break;
            }
            OplExp a = init.exps.get(k);
            OplExp b = last_prog.exps.get(k);
            if (!a.equals(b)) {
                break;
            }
            unchanged.add(k);
            i++;
        }
    }
    // toUpdate[0] = "Processed:";
    for (String k : init.order) {
        OplExp se = init.exps.get(k);
        if (se instanceof OplPragma) {
            continue;
        }
        if (unchanged.contains(k)) {
            ret.put(k, last_env.get(k));
            continue;
        }
        try {
            OplObject xxx = se.accept(init, new OplOps(ret));
            ret.put(k, xxx);
            if (toUpdate != null) {
                toUpdate[0] = "Last Processed: " + k;
            }
        // i++;
        } catch (Throwable t) {
            t.printStackTrace();
            throw new LineException(t.getLocalizedMessage(), k, "");
        }
    }
    return ret;
}
Also used : LineException(catdata.LineException) Environment(catdata.Environment) OplPragma(catdata.opl.OplExp.OplPragma) HashSet(java.util.HashSet)

Aggregations

Environment (catdata.Environment)2 LineException (catdata.LineException)2 Unit (catdata.Unit)1 MplExp (catdata.mpl.Mpl.MplExp)1 OplPragma (catdata.opl.OplExp.OplPragma)1 HashSet (java.util.HashSet)1