private K addFreshCell(K body) { if (freshVars.size() == 0) { return body; } KApply cellTerm = IncompleteCellUtils.make(KLabels.GENERATED_COUNTER_CELL, false, KRewrite(FRESH, KApply(KLabel("_+Int_"), FRESH, KToken(Integer.toString(freshVars.size()), Sorts.Int()))), false); return KApply(KLabels.CELLS, body, cellTerm); }
private Rule getExitCodeRule(Definition parsedDefinition) { Module mainMod = parsedDefinition.mainModule(); Set<Production> exitProds = stream(mainMod.productions()).filter(p -> p.att().contains("exit")).collect(Collectors.toSet()); if (exitProds.size() == 0) { return null; } else if (exitProds.size() > 1) { throw KEMException.compilerError("Found more than one or zero productions with 'exit' attribute. Exactly one production, a cell, must have this attribute, designating the exit code of krun. Found:\n" + exitProds); } Production exitProd = exitProds.iterator().next(); return Rule(IncompleteCellUtils.make(exitProd.klabel().get(), false, KApply(KLabel("#SemanticCastToInt"), KVariable("_")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); }
KApply cell(String name, boolean openLeft, boolean openRight, K... ks) { return IncompleteCellUtils.make(KLabel(name), openLeft, Arrays.asList(ks), openRight); }
KApply cell(String name, boolean openLeft, boolean openRight, K... ks) { return IncompleteCellUtils.make(KLabel(name), openLeft, Arrays.asList(ks), openRight); }
return IncompleteCellUtils.make(target, ellipses, otherChildren, ellipses);
private K apply(K term) { if (labelInfo.isFunction(term)) return term; List<K> items = IncompleteCellUtils.flattenCells(term); if (items.size() != 1) { return term; } K item = items.get(0); if (isCell(item)) { return term; } else if (item instanceof KRewrite) { final KRewrite rew = (KRewrite) item; if (Stream.concat( IncompleteCellUtils.flattenCells(rew.left()).stream(), IncompleteCellUtils.flattenCells(rew.right()).stream()) .anyMatch(this::isCell)) { return term; } } KLabel computation = cfg.getCellLabel(cfg.getComputationCell()); return IncompleteCellUtils.make(computation, false, item, true); }
protected K addRootCell(K term) { KLabel root = cfg.getCellLabel(cfg.getRootCell()); if (term instanceof KApply && ((KApply) term).klabel().equals(root)) { return term; } else if (term instanceof KRewrite) { KRewrite rew = (KRewrite) term; K left = addRootCell(rew.left()); if (left == rew.left()) { return KRewrite(rew.left(), rew.right()); } else { return IncompleteCellUtils.make(root, true, term, true); } } else { return IncompleteCellUtils.make(root, true, term, true); } }
if (hasConfigurationOrRegularVariable || isStream) { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel), Terminal("("), NonTerminal(Sorts.Map()), Terminal(")")), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel), INIT), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); } else { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel)), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel)), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); sentences.add(getExitCode); KVariable var = KVariable("Exit", Att.empty().add(Sort.class, Sorts.Int())); Rule getExitCodeRule = Rule(KRewrite(KApply(getExitCodeLabel, IncompleteCellUtils.make(KLabels.GENERATED_TOP_CELL, true, IncompleteCellUtils.make(KLabel(klabel), false, var, false), true)), var), BooleanUtils.TRUE, BooleanUtils.TRUE); sentences.add(getExitCodeRule);
throw KEMException.criticalError("Must have only one klabel with the \"thread\" attribute. Found: " + threadKLabels); Rule matchThreadSet = Rule(IncompleteCellUtils.make(threadKLabels.iterator().next(), false, KVariable("Threads"), false), BooleanUtils.TRUE, BooleanUtils.TRUE); this.matchThreadSet = convert(new Kompile(kompileOptions, files, kem).compileRule(def.kompiledDefinition, matchThreadSet)); Rule rewriteThreadSet = Rule(IncompleteCellUtils.make(threadKLabels.iterator().next(), false, KRewrite(KVariable("Threads"), KVariable("NewThreads")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); this.rewriteThreadSet = convert(new Kompile(kompileOptions, files, kem).compileRule(def.kompiledDefinition, rewriteThreadSet)); this.rewriteThreadSet = Rule(new TransformK() { public K apply(KVariable var) { return KVariable(var.name(), var.att().remove(Sort.class)); } }.apply(this.rewriteThreadSet.body()), Rule makeStuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KSequence(), KApply(KLabel("#STUCK"))), true), BooleanUtils.TRUE, BooleanUtils.TRUE); Rule makeUnstuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KApply(KLabel("#STUCK")), KSequence()), true), BooleanUtils.TRUE, BooleanUtils.TRUE); this.makeStuck = convert(new Kompile(kompileOptions, files, kem).compileRule(def.kompiledDefinition, makeStuck)); this.makeUnstuck = convert(new Kompile(kompileOptions, files, kem).compileRule(def.kompiledDefinition, makeUnstuck));
productionAtts), Rule(KRewrite(KApply(KLabel("initThreadsCell"), KVariable("Init")), IncompleteCellUtils.make(KLabel("<threads>"), false, KApply(KLabel("initThreadCell"), KVariable("Init")), false)), BooleanUtils.TRUE, BooleanUtils.FALSE, initializerAtts), Rule(KRewrite(KApply(KLabel("initThreadCell"), KVariable("Init")), IncompleteCellUtils.make(KLabel("<thread>"), false, Arrays.asList(KApply(KLabel("initKCell"), KVariable("Init")), KApply(KLabels.CELLS)), false)), BooleanUtils.TRUE, BooleanUtils.TRUE, initializerAtts), Rule(KRewrite(KApply(KLabel("initKCell"), KVariable("Init")), IncompleteCellUtils.make(KLabel("<k>"), false, KApply(KLabel("#SemanticCastToKItem"), KApply(KLabel("project:KItem"), KApply(KLabel("Map:lookup"), KVariable("Init"), KToken("$PGM", Sorts.KConfigVar())))), false)), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("projection")), Rule(KRewrite(KApply(KLabel("initOptCell")), IncompleteCellUtils.make(KLabel("<opt>"), false, KApply(KLabel(".Opt")), false)), BooleanUtils.TRUE, BooleanUtils.TRUE, initializerAtts), Production(KLabel("project:KItem"), Sort("KItem"),