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
def While(cond, body): global counter counter += 1 return Object().update({ "id": counter, "type": "While", "cond": cond, "body": body })
def UnOp(op, value): global counter counter += 1 return Object().update({ "id": counter, "type": "Unary", "op": op, "right": value })
def Go(ap, then=None): global counter counter += 1 return Object().update({ "id": counter, "type": "Go", "ap": ap, "chain": then })
def DecApply(iden, actual): global counter counter += 1 return Object().update({ "id": counter, "type": "DecApply", "iden": iden, "actual": actual })
def SAccessor(iden, index): global counter counter += 1 return Object().update({ "id": counter, "type": "SAcc", "iden": iden, "index": index })
def Match(obj, cases): global counter counter += 1 return Object().update({ "id": counter, "type": "Match", "obj": obj, "cases": cases })
def For(var, iter, body): global counter counter += 1 return Object().update({ "id": counter, "type": "For", "var": var, "iter": iter, "body": body })
def BinOp(op, left, right): global counter counter += 1 return Object().update({ "id": counter, "type": "Binary", "left": left, "op": op, "right": right })
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 })
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 })
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.
def Spread(iter): global counter counter += 1 return Object().update({"id": counter, "type": "Spread", "iter": iter})
def List(con): global counter counter += 1 return Object().update({"id": counter, "type": "List", "con": con})
def Lazy(exp): global counter counter += 1 return Object().update({"id": counter, "type": "Lazy", "exp": exp})
def ObjectLit(kv): global counter counter += 1 return Object().update({"id": counter, "type": "Obj", "kv": kv})
def Atom(value): global counter counter += 1 return Object().update({"id": counter, "type": "Atom", "value": value})
def Force(exp): global counter counter += 1 return Object().update({"id": counter, "type": "Force", "exp": exp})
def Literal(v): global counter counter += 1 return Object().update({"id": counter, "type": "Lit", "val": v})
def Block(exps): global counter counter += 1 return Object().update({"id": counter, "type": "Block", "exp": exps})
def SExpr(l): global counter counter += 1 return Object().update({"id": counter, "type": "SExpr", "l": l})