Search in sources :

Example 6 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class AqlMultiDriver method call.

@Override
public Unit call() {
    String k2 = "";
    String n = "";
    try {
        while (true) {
            n = null;
            synchronized (this) {
                if (/*stop == true ||*/
                todo.isEmpty() || Thread.currentThread().isInterrupted()) {
                    break;
                }
                n = nextAvailable();
                if (n == null) {
                    update();
                    // just in case
                    wait(5000);
                    continue;
                }
                processing.add(n);
                todo.remove(n);
                update();
            }
            Exp<?> exp = env.prog.exps.get(n);
            Kind k = exp.kind();
            k2 = k.toString();
            long time1 = System.currentTimeMillis();
            Object val = Util.timeout(() -> exp.eval(env), (Long) exp.getOrDefault(env, AqlOption.timeout) * 1000);
            if (val == null) {
                throw new RuntimeException("anomaly, please report: null result on " + exp);
            } else if (k.equals(Kind.PRAGMA)) {
                ((Pragma) val).execute();
            }
            long time2 = System.currentTimeMillis();
            synchronized (this) {
                env.defs.put(n, k, val);
                env.performance.put(n, (time2 - time1) / (1000f));
                processing.remove(n);
                completed.add(n);
                update();
                notifyAll();
            }
        }
    } catch (InterruptedException exp) {
        exn.add(new RuntimeInterruptedException(exp));
    } catch (RuntimeInterruptedException exp) {
        exn.add(exp);
    } catch (Exception e) {
        e.printStackTrace();
        synchronized (this) {
            if (e instanceof LocException) {
                exn.add((LocException) e);
            } else {
                exn.add(new LineException(e.getMessage(), n, k2));
            }
            notifyAll();
            interruptAll();
        }
    }
    update();
    return notifyOfDeath();
}
Also used : Kind(catdata.aql.Kind) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LineException(catdata.LineException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LineException(catdata.LineException)

Example 7 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class CodeEditor method run.

@Override
public // TODO aql put this on another thread besides the event dispatch thread
void run() {
    String program = topArea.getText();
    Progg init;
    Env env;
    init = tryParse(program);
    if (init == null) {
        return;
    }
    long start;
    long middle;
    try {
        start = System.currentTimeMillis();
        env = makeEnv(program, init);
        middle = System.currentTimeMillis();
        toDisplay = "Computation finished, creating viewer... (max " + init.timeout() + " seconds)";
        DateFormat format = DateFormat.getTimeInstance();
        String foo2 = title;
        foo2 += " - " + format.format(new Date(start));
        foo2 += " - " + format.format(new Date(start));
        String foo = foo2;
        long t = (Long) init.timeout() * 1000;
        display = Util.timeout(() -> makeDisplay(foo, init, env, start, middle), t);
        // display = makeDisplay(foo, init, env, start, middle);
        if (display.exn() == null) {
            // "Done";
            toDisplay = textFor(env);
            // "Done");
            respArea.setText(textFor(env));
        } else {
            throw display.exn();
        }
    } catch (LineException e) {
        toDisplay = "Error in " + e.kind + " " + e.decl + ": " + e.getLocalizedMessage();
        respArea.setText(toDisplay);
        e.printStackTrace();
        Integer theLine = init.getLine(e.decl);
        setCaretPos(theLine);
    } catch (LocException e) {
        toDisplay = "Error: " + e.getLocalizedMessage();
        respArea.setText(toDisplay);
        e.printStackTrace();
        setCaretPos(e.loc);
    } catch (Throwable re) {
        toDisplay = "Error: " + re.getLocalizedMessage();
        respArea.setText(toDisplay);
        re.printStackTrace();
    }
    interruptAndNullify();
}
Also used : LocException(catdata.aql.exp.LocException) DateFormat(java.text.DateFormat) LineException(catdata.LineException) Date(java.util.Date)

Example 8 with LineException

use of catdata.LineException 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)

Example 9 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class EnrichViewer method translate.

private String translate(String program) {
    XProgram init;
    try {
        init = XParser.program(program);
    } catch (ParserException e) {
        int col = e.getLocation().column;
        int line = e.getLocation().line;
        topArea.requestFocusInWindow();
        topArea.area.setCaretPosition(topArea.area.getDocument().getDefaultRootElement().getElement(line - 1).getStartOffset() + (col - 1));
        // String s = e.getMessage();
        // String t = s.substring(s.indexOf(" "));
        // t.split("\\s+");
        e.printStackTrace();
        return "Syntax error: " + e.getLocalizedMessage();
    } catch (Throwable e) {
        e.printStackTrace();
        return "Error: " + e.getLocalizedMessage();
    }
    if (init == null) {
        return "";
    }
    String isaX = null, matX = null;
    XSchema isa = null, mat = null;
    for (String line : init.order) {
        XExp exp = init.exps.get(line);
        if (exp instanceof XSchema) {
            if (isaX == null) {
                isaX = line;
                isa = (XSchema) exp;
                continue;
            }
            if (matX == null) {
                matX = line;
                mat = (XSchema) exp;
                continue;
            }
            throw new RuntimeException("More than two schemas");
        }
    }
    if (isaX == null || matX == null) {
        throw new RuntimeException("Fewer than two schemas");
    }
    /*		if (isa.arrows.size() != 2) {
			String temp = isaX;
			XExp.XSchema temp2 = isa;
			isaX = matX;
			isa = mat;
			matX = temp;
			mat = temp2;
		} */
    XEnvironment env;
    try {
        env = XDriver.makeEnv(program, init);
    } catch (LineException e) {
        String toDisplay = "Error in " + e.kind + " " + e.decl + ": " + e.getLocalizedMessage();
        e.printStackTrace();
        topArea.requestFocusInWindow();
        Integer theLine = init.getLine(e.decl);
        topArea.area.setCaretPosition(theLine);
        return toDisplay;
    } catch (Throwable re) {
        return "Error: " + re.getLocalizedMessage();
    }
    @SuppressWarnings("unchecked") XCtx<String> isa0 = (XCtx<String>) env.objs.get(isaX);
    @SuppressWarnings("unchecked") XCtx<String> mat0 = (XCtx<String>) env.objs.get(matX);
    return go(isa, mat, isaX, matX, isa0, mat0, name.getText(), kid.getText(), instField.getText(), isaField.getText());
}
Also used : ParserException(org.jparsec.error.ParserException) XSchema(catdata.fpql.XExp.XSchema) LineException(catdata.LineException)

Aggregations

LineException (catdata.LineException)9 HashMap (java.util.HashMap)4 Environment (catdata.Environment)2 Triple (catdata.Triple)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Pair (catdata.Pair)1 RuntimeInterruptedException (catdata.RuntimeInterruptedException)1 Unit (catdata.Unit)1 Kind (catdata.aql.Kind)1 LocException (catdata.aql.exp.LocException)1 Flower (catdata.fpql.XExp.Flower)1 XSchema (catdata.fpql.XExp.XSchema)1 FQLException (catdata.fql.FQLException)1 InstExp (catdata.fql.decl.InstExp)1 InstOps (catdata.fql.decl.InstOps)1 TransExp (catdata.fql.decl.TransExp)1 ExpPSM (catdata.fql.sql.ExpPSM)1