use of primal.fp.Funs.Fun in project suite by stupidsing.
the class AsmSl method assemble.
public Bytes assemble(String in0) {
var whitespaces = Collections.singleton('\n');
Fun<String, List<Run>> gct = CommentPreprocessor.ofGroupComment(whitespaces)::preprocess;
Fun<String, List<Run>> lct = CommentPreprocessor.ofLineComment(whitespaces)::preprocess;
var in1 = Preprocess.transform(List.of(gct, lct), in0).k;
var generalizer = new Generalizer();
var lines = List.of(in1.split("\n"));
Pair<String, String> pe;
var start = 0;
while ((pe = Split.string(lines.get(start), "=")) != null) {
generalizer.getVariable(Atom.of(pe.k)).bound(Suite.parse(pe.v));
start++;
}
var lnis = //
Read.from(//
Right.of(lines, start)).map(line -> Split.strl(line, "\t").map((label, command) -> {
var reference = //
Is.notBlank(label) ? //
generalizer.getVariable(Atom.of(label)) : new Reference();
var instruction = generalizer.generalize(Suite.parse(command));
return Pair.of(reference, instruction);
})).toList();
return assemble(generalizer, lnis);
}
use of primal.fp.Funs.Fun in project suite by stupidsing.
the class FunCreatorTest method testObject.
@Test
public void testObject() {
Int_Int inc = i -> i + 1;
Iterate<FunExpr> fun = i -> f.object(inc).invoke("apply", i);
assertEquals(3, LambdaInstance.of(Int_Int.class, fun).newFun().apply(2));
}
use of primal.fp.Funs.Fun in project suite by stupidsing.
the class Chr method chrThen.
private Streamlet<State> chrThen(Streamlet<State> states, Node then) {
var generalizer = new Generalizer();
Atom a = atom(".a"), b = atom(".b");
if (Binder.bind(then, generalizer.generalize(Suite.substitute(".0 = .1", a, b)))) {
// built-in syntactic equality
var from = generalizer.getVariable(a);
var to = generalizer.getVariable(b);
states = states.map(new Fun<>() {
public State apply(State state) {
var factsByPrototype1 = PerMap.<Prototype, PerSet<Node>>empty();
for (var e : state.factsByPrototype) factsByPrototype1 = factsByPrototype1.put(e.k, replace(e.v));
return new State(factsByPrototype1);
}
private PerSet<Node> replace(PerSet<Node> facts) {
var facts1 = PerSet.<Node>empty();
for (var node : facts) facts1 = facts1.replace(rw.replace(from, to, node));
return facts1;
}
});
}
return states.map(state -> {
var prototype = Prototype.of(then);
var facts = getFacts(state, prototype);
return setFacts(state, prototype, facts.replace(then));
});
}
use of primal.fp.Funs.Fun in project suite by stupidsing.
the class InterpretedProverBuilder method build.
@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
return goal -> {
var goal1 = SewingGeneralizerImpl.generalize(goal);
return (source, sink) -> {
var proverCfg1 = new ProverCfg(ruleSet, proverCfg);
proverCfg1.setSource(source);
proverCfg1.setSink(sink);
new Prover(proverCfg1).elaborate(goal1);
};
};
}
Aggregations