Search in sources :

Example 11 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class HB method visit.

@Override
public ExpCore visit(Block s) {
    ExpCore result = null;
    for (Block.Dec di : s.getDecs()) {
        result = acc(result, di.getInner().accept(this));
    }
    result = acc(result, s.getInner().accept(this));
    if (result == null && onlyAroundHole) {
        return null;
    }
    assert !onlyAroundHole || result instanceof WalkBy : onlyAroundHole + " " + result;
    for (Block.Dec dec : s.getDecs()) {
        if (xs.contains(dec.getX())) {
            throw new ErrorMessage.VariableDeclaredMultipleTimes(dec.getX(), s.getP());
        }
        this.xs.add(dec.getX());
        this.xsRes.add(dec.getX());
    }
    try {
        if (!onlyAroundHole && !s.getOns().isEmpty()) {
            for (On on : s.getOns()) {
                if (xs.contains(on.getX())) {
                    throw new ErrorMessage.VariableDeclaredMultipleTimes(on.getX(), s.getP());
                }
                xs.add(on.getX());
                xsRes.add(on.getX());
                on.getInner().accept(this);
                xs.remove(on.getX());
            }
        }
        return result;
    } finally {
        for (Block.Dec dec : s.getDecs()) {
            this.xs.remove(dec.getX());
        }
    }
}
Also used : ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) WalkBy(ast.ExpCore.WalkBy) On(ast.ExpCore.Block.On)

Example 12 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class TsBlock method kTypeCatchAny.

default default TOutK kTypeCatchAny(TIn in, Tr tr, On k) {
    Block e = (Block) k.getE();
    ExpCore e0 = e.getDecs().get(0).getInner();
    TIn in1 = in.removeG(k.getX());
    TOut _out = type(in1.withE(e0, Path.Void().toImmNT()));
    if (!_out.isOk()) {
        return _out.toError();
    }
    TOk ok = _out.toOk();
    if (!ok.exceptions.isEmpty() || !ok.returns.isEmpty()) {
        return new TErr(in, "", null, ErrorKind.UnsafeCatchAny);
    }
    ExpCore newE = e.withDeci(0, e.getDecs().get(0).withInner(ok.annotated));
    return new TOkK(tr, k.withE(newE), in.expected);
/*
   (catch and rethrow any)// could be sugared as "on throw doAndPropagate e"  
   Phase |p |G |Tr|-catch throw Any x (e0 throw x) ~> catch throw Any x (e0' throw x): T<=T | Tr
     where //Note: e0, e, e0',e' are using the sugar imm Void x=e == e
     e0=(e catch error Any z void void)
     e0'=(e' catch error Any z void void)
     Phase |p |G\x |- e ~> e':_ <=imm Void | empty
     catchRethrow(catch throw Any x(e0 throw x)) 
*/
}
Also used : ExpCore(ast.ExpCore) Block(ast.ExpCore.Block)

Example 13 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class Executor method subst.

public static ExpCore subst(ExpCore ctxVal, Redex.Subst r) {
    Block e1 = r.getThat();
    int i = r.getSubstIndex();
    ExpCore val = e1.getDecs().get(i).getInner();
    String x = e1.getDecs().get(i).getX();
    ArrayList<Block.Dec> decs = new ArrayList<Block.Dec>(e1.getDecs());
    decs.remove(i);
    Block e2 = new Block(e1.getDoc(), decs, e1.getInner(), e1.getOns(), e1.getP());
    ExpCore result = ReplaceX.of(e2, val, x);
    return ReplaceCtx.of(ctxVal, result);
}
Also used : ExpCore(ast.ExpCore) Dec(ast.ExpCore.Block.Dec) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block)

Example 14 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class Executor method meta1Prop.

protected ClassB meta1Prop(Program p, ClassB cb, NestedClass m) {
    log("---meta1Prop--");
    //get cb-->ct
    //get p'
    Program p1 = p.evilPush(cb);
    //extract e
    ExpCore e = m.getInner();
    //extract cb
    Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
    //run cb1-->cb2
    ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
    ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
    //compose cb with new member
    return cb.withMember(m.withInner(e2));
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 15 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class TestHelper method getExpCore.

public static ExpCore getExpCore(String source, String _e1) {
    Expression code1 = Parser.parse("GeneratedByTestHelper_", _e1);
    Expression code2 = Desugar.of(code1);
    ExpCore e1 = code2.accept(new InjectionOnCore());
    return e1;
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) InjectionOnCore(sugarVisitors.InjectionOnCore)

Aggregations

ExpCore (ast.ExpCore)62 ArrayList (java.util.ArrayList)25 ClassB (ast.ExpCore.ClassB)18 Member (ast.ExpCore.ClassB.Member)11 MethodWithType (ast.ExpCore.ClassB.MethodWithType)10 Expression (ast.Expression)10 Block (ast.ExpCore.Block)9 MethodType (ast.Ast.MethodType)8 Doc (ast.Ast.Doc)7 Path (ast.Ast.Path)7 Assertions (tools.Assertions)7 MethodSelector (ast.Ast.MethodSelector)6 Position (ast.Ast.Position)6 Program (programReduction.Program)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Type (ast.Ast.Type)5 ErrorMessage (ast.ErrorMessage)5 CloneVisitor (coreVisitors.CloneVisitor)5 List (java.util.List)5