Search in sources :

Example 6 with Fun

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);
}
Also used : Asm(suite.asm.Assembler.Asm) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2) Fail.fail(primal.statics.Fail.fail) Fun(primal.fp.Funs.Fun) Amd64Assemble(suite.assembler.Amd64Assemble) Right(primal.Verbs.Right) Is(primal.Verbs.Is) ArrayList(java.util.ArrayList) Node(suite.node.Node) CommentPreprocessor(suite.parser.CommentPreprocessor) Preprocess(suite.text.Preprocess) Utf8(primal.Nouns.Utf8) Split(primal.MoreVerbs.Split) Run(suite.text.Preprocess.Run) Take(primal.Verbs.Take) Binder(suite.lp.doer.Binder) RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) Amd64Mode(suite.assembler.Amd64Mode) Pair(primal.adt.Pair) Reference(suite.node.Reference) Suite(suite.Suite) Amd64Parse(suite.assembler.Amd64Parse) Finder(suite.lp.search.ProverBuilder.Finder) TermOp(suite.node.io.TermOp) Read(primal.MoreVerbs.Read) Bytes(primal.primitive.adt.Bytes) Tree(suite.node.Tree) List(java.util.List) Atom(suite.node.Atom) Fail.failBool(primal.statics.Fail.failBool) BytesBuilder(primal.primitive.adt.Bytes.BytesBuilder) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) Collections(java.util.Collections) Str(suite.node.Str) Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Fun

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));
}
Also used : Reference(suite.node.Reference) Suite(suite.Suite) BaseOp(suite.node.io.BaseOp) Dump(suite.inspect.Dump) PrintlnFunExpr(suite.jdk.gen.FunExprM.PrintlnFunExpr) Fun(primal.fp.Funs.Fun) Source(primal.fp.Funs.Source) IntSource(primal.primitive.IntPrim.IntSource) Iterate(primal.fp.Funs.Iterate) ProfileFunExpr(suite.jdk.gen.FunExprM.ProfileFunExpr) Tree(suite.node.Tree) Node(suite.node.Node) Test(org.junit.jupiter.api.Test) BiPredicate(java.util.function.BiPredicate) LambdaInstance(suite.jdk.lambda.LambdaInstance) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) Type(org.apache.bcel.generic.Type) Int_Int(primal.primitive.Int_Int) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FunExpr(suite.jdk.gen.FunExpression.FunExpr) Int(suite.node.Int) Flt_Flt(primal.primitive.Flt_Flt) LambdaInterface(suite.jdk.lambda.LambdaInterface) Int_Int(primal.primitive.Int_Int) PrintlnFunExpr(suite.jdk.gen.FunExprM.PrintlnFunExpr) ProfileFunExpr(suite.jdk.gen.FunExprM.ProfileFunExpr) FunExpr(suite.jdk.gen.FunExpression.FunExpr) Test(org.junit.jupiter.api.Test)

Example 8 with Fun

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));
    });
}
Also used : Generalizer(suite.lp.doer.Generalizer) Prototype(suite.lp.kb.Prototype) Node(suite.node.Node) PerSet(primal.persistent.PerSet) Atom(suite.node.Atom) Fun(primal.fp.Funs.Fun)

Example 9 with Fun

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);
        };
    };
}
Also used : Prover(suite.lp.doer.Prover) SewingGeneralizerImpl(suite.lp.sewing.impl.SewingGeneralizerImpl) Fun(primal.fp.Funs.Fun) Finder(suite.lp.search.ProverBuilder.Finder) ProverCfg(suite.lp.Configuration.ProverCfg) Builder(suite.lp.search.ProverBuilder.Builder) RuleSet(suite.lp.kb.RuleSet) Node(suite.node.Node) ProverCfg(suite.lp.Configuration.ProverCfg) Prover(suite.lp.doer.Prover)

Aggregations

Fun (primal.fp.Funs.Fun)9 Node (suite.node.Node)6 Read (primal.MoreVerbs.Read)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Map (java.util.Map)3 Pair (primal.adt.Pair)3 Source (primal.fp.Funs.Source)3 Fail.fail (primal.statics.Fail.fail)3 Streamlet (primal.streamlet.Streamlet)3 Set (java.util.Set)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Test (org.junit.jupiter.api.Test)2 Split (primal.MoreVerbs.Split)2 Equals (primal.Verbs.Equals)2 Is (primal.Verbs.Is)2 PerMap (primal.persistent.PerMap)2 IntIntSink (primal.primitive.IntIntSink)2 Suite (suite.Suite)2 Generalizer (suite.lp.doer.Generalizer)2