Example #1
0
def defObject(ast, env, abort, next):
    obj = Object()
    for e in ast["kv"]:
        if isinstance(e[0], str) or e[0]["type"] == "Atom":
            key = None
            if (not isinstance(e[0], str)) and e[0]["type"] == "Atom":
                key = e[0]["value"]
            else:
                key = e[0]
                obj.update({
                    key: eval(e[1], env)
                })
        else:
            abort("Expected identifier or string")
    return obj
Example #2
0
def While(cond, body):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "While",
        "cond": cond,
        "body": body
    })
Example #3
0
def UnOp(op, value):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Unary",
        "op": op,
        "right": value
    })
Example #4
0
def Go(ap, then=None):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Go",
        "ap": ap,
        "chain": then
    })
Example #5
0
def DecApply(iden, actual):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "DecApply",
        "iden": iden,
        "actual": actual
    })
Example #6
0
def SAccessor(iden, index):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "SAcc",
        "iden": iden,
        "index": index
    })
Example #7
0
def Match(obj, cases):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Match",
        "obj": obj,
        "cases": cases
    })
Example #8
0
def For(var, iter, body):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "For",
        "var": var,
        "iter": iter,
        "body": body
    })
Example #9
0
def BinOp(op, left, right):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Binary",
        "left": left,
        "op": op,
        "right": right
    })
Example #10
0
def CondOp(cond, b1, b2, other=None):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Cond",
        "cond": cond,
        "b1": b1,
        "other": other,
        "b2": b2
    })
Example #11
0
def Func(name, params, body, scope):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "Func",
        "name": name,
        "params": params,
        "body": body,
        scope: scope
    })
Example #12
0
def ListComp(exp, lists, conds):
    global counter
    counter += 1
    return Object().update({
        "id": counter,
        "type": "ListComp",
        "exp": exp,
        "lists": lists,
        "conds": conds
    })


# Add Sum types etc.
Example #13
0
def Spread(iter):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Spread", "iter": iter})
Example #14
0
def List(con):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "List", "con": con})
Example #15
0
def Lazy(exp):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Lazy", "exp": exp})
Example #16
0
def ObjectLit(kv):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Obj", "kv": kv})
Example #17
0
def Atom(value):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Atom", "value": value})
Example #18
0
def Force(exp):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Force", "exp": exp})
Example #19
0
def Literal(v):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Lit", "val": v})
Example #20
0
def Block(exps):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "Block", "exp": exps})
Example #21
0
def SExpr(l):
    global counter
    counter += 1
    return Object().update({"id": counter, "type": "SExpr", "l": l})