use of suite.lp.doer.Generalizer in project suite by stupidsing.
the class Assembler method assemble.
public Bytes assemble(String in0) {
Set<Character> whitespaces = Collections.singleton('\n');
Fun<String, List<Run>> gct = CommentPreprocessor.groupCommentPreprocessor(whitespaces);
Fun<String, List<Run>> lct = CommentPreprocessor.lineCommentPreprocessor(whitespaces);
String in1 = Preprocess.transform(List.of(gct, lct), in0).t0;
Generalizer generalizer = new Generalizer();
List<String> lines = List.of(in1.split("\n"));
Pair<String, String> pe;
int start = 0;
while (!(pe = String_.split2(lines.get(start), "=")).t1.isEmpty()) {
generalizer.getVariable(Atom.of(pe.t0)).bound(Suite.parse(pe.t1));
start++;
}
List<Pair<Reference, Node>> lnis = //
Read.from(//
List_.right(lines, start)).map(line -> {
Pair<String, String> pt = String_.split2(line, "\t");
String label = pt.t0;
String command = pt.t1;
Reference reference = String_.isNotBlank(label) ? generalizer.getVariable(Atom.of(label)) : null;
Node instruction = generalizer.generalize(Suite.parse(command));
return Pair.of(reference, instruction);
}).toList();
return assemble(generalizer, lnis);
}
use of suite.lp.doer.Generalizer in project suite by stupidsing.
the class CompileGeneralizerImpl method generalizer.
@Override
public Generalize_ generalizer(Node node) {
VariableMapper<Reference> mapper = cc.mapper();
Generalizer generalizer = new Generalizer();
Generalize_ generalize = cc.cloner(generalizer.generalize(node))::apply;
Map<Reference, Atom> indices = new IdentityHashMap<>();
for (Atom variableName : generalizer.getVariableNames()) indices.put(generalizer.getVariable(variableName), variableName);
vm = mapper.mapKeys(indices::get);
return generalize;
}
use of suite.lp.doer.Generalizer in project suite by stupidsing.
the class SewingProverImpl method compileCpsRules.
private Cps compileCpsRules(Prototype prototype, List<Rule> rules, TraceLevel traceLevel) {
Streamlet<Cps> cpss = Read.from(rules).map(rule -> {
Generalizer generalizer = new Generalizer();
Node head = generalizer.generalize(rule.head);
Node tail = generalizer.generalize(rule.tail);
return compileCpsRule(head, tail);
});
Cps cps0 = orCps(cpss);
return saveEnvCps(cps0);
}
use of suite.lp.doer.Generalizer in project suite by stupidsing.
the class SewingProverImpl method compileTrRules.
private Trampoline compileTrRules(Prototype prototype, List<Rule> rules, TraceLevel traceLevel) {
Streamlet<Trampoline> trs = Read.from(rules).map(rule -> {
Generalizer generalizer = new Generalizer();
Node head = generalizer.generalize(rule.head);
Node tail = generalizer.generalize(rule.tail);
return compileTrRule(head, tail);
});
Trampoline tr0 = orTr(trs);
Trampoline tr1 = cutBegin(tr0);
Trampoline tr2 = saveEnvTr(tr1);
return log(tr2, traceLevel);
}
use of suite.lp.doer.Generalizer in project suite by stupidsing.
the class Chr method chr.
private Streamlet<State> chr(State state, Rule rule) {
Generalizer generalizer = new Generalizer();
Trail trail = new Trail();
Streamlet<State> states = Read.each(state);
for (Node if_ : rule.ifs) states = chrIf(states, trail, generalizer.generalize(if_));
for (Node given : rule.givens) states = chrGiven(states, trail, generalizer.generalize(given));
states = chrWhen(states, generalizer.generalize(rule.when));
for (Node then : rule.thens) states = chrThen(states, generalizer.generalize(then));
return states;
}
Aggregations