def make_let(args, body, function): bindings = [] for b in args: if not isinstance(b, dexpr._lshift): raise DinpySyntaxError() vars, value = b.x, preparse(b.y) if isinstance(vars, _VarSymbol): bindings.append((preparse(vars), value)) else: if isinstance(vars, dexpr._lshift): vars = get_let_vars(vars, dexpr._lshift) i = len(vars) - 1 v2 = varcache(vars[i].name) bindings.append((v2, value)) while i > 0: v1 = varcache(vars[i - 1].name) bindings.append((v1, v2)) v2 = v1 i -= 1 elif isinstance(vars, dexpr._div): bindings += [ (varcache(v.name), value) for v, value in zip(get_let_vars(vars, dexpr._div), value) ] else: raise DinpySyntaxError() body = preparse(body) if isinstance(body, tuple): return function(bindings, *body) else: return function(bindings, body)
def make_fun3(name, args, body, klass): fun = varcache(name) head = args body = preparse(body) if isinstance(body, AtForm): body = body.clauses if len(body)>1: raise DinpySyntaxError() if body[0][0] is not None: raise DinpySyntaxError() return insert_def(fun, head, body[0][1], klass) else: return insert_def(fun, head, [body], klass)
def make_fun3(name, args, body, klass): fun = varcache(name) head = args body = preparse(body) if isinstance(body, AtForm): body = body.clauses if len(body) > 1: raise DinpySyntaxError() if body[0][0] is not None: raise DinpySyntaxError() return insert_def(fun, head, body[0][1], klass) else: return insert_def(fun, head, [body], klass)
def make_fun6(name, rules, klass): fun = varcache(name) rules = preparse(rules) if isinstance(rules, AtForm): clauses = [(head if head is not None else (), bodies) for head, bodies in rules.clauses] return special.begin(*[insert_def(fun, head, bodies, klass) for head, bodies in clauses]) elif isinstance(rules, list): return insert_def(fun, head, [rules], klass) else: raise DinpySyntaxError()
def make_fun1(name, rules, klass): fun = varcache(name) if len(rules)==0: return replace_def(fun, (), [[]], klass) if len(rules)==1: return replace_def(fun, preparse(rules[0][0]), preparse(rules[0][1]), klass) replaces = [] for head, bodies in rules: head = preparse(head) bodies = preparse(bodies) replaces .append(replace_def(fun, head, bodies, klass)) return special.begin(*replaces)
def make_fun6(name, rules, klass): fun = varcache(name) rules = preparse(rules) if isinstance(rules, AtForm): clauses = [(head if head is not None else (), bodies) for head, bodies in rules.clauses] return special.begin( * [insert_def(fun, head, bodies, klass) for head, bodies in clauses]) elif isinstance(rules, list): return insert_def(fun, head, [rules], klass) else: raise DinpySyntaxError()
def make_fun1(name, rules, klass): fun = varcache(name) if len(rules) == 0: return replace_def(fun, (), [[]], klass) if len(rules) == 1: return replace_def(fun, preparse(rules[0][0]), preparse(rules[0][1]), klass) replaces = [] for head, bodies in rules: head = preparse(head) bodies = preparse(bodies) replaces.append(replace_def(fun, head, bodies, klass)) return special.begin(*replaces)
def make_fun4(name, rules, klass): fun = varcache(name) rules = preparse(rules) if isinstance(rules, AtForm): rules1 = [] for head, bodies in rules.clauses: if head is None: head = () for body in bodies: rules1.append((head,)+tuple(body)) return assign(fun, klass(*rules1)) elif isinstance(rules, list): return assign(fun, klass(((), rules))) else: raise DinpySyntaxError()
def make_fun4(name, rules, klass): fun = varcache(name) rules = preparse(rules) if isinstance(rules, AtForm): rules1 = [] for head, bodies in rules.clauses: if head is None: head = () for body in bodies: rules1.append((head, ) + tuple(body)) return assign(fun, klass(*rules1)) elif isinstance(rules, list): return assign(fun, klass(((), rules))) else: raise DinpySyntaxError()
def make_let(args, body, function): bindings = [] for b in args: if not isinstance(b, dexpr._lshift): raise DinpySyntaxError() vars, value = b.x, preparse(b.y) if isinstance(vars, _VarSymbol): bindings.append((preparse(vars), value)) else: if isinstance(vars, dexpr._lshift): vars = get_let_vars(vars, dexpr._lshift) i = len(vars)-1 v2 = varcache(vars[i].name) bindings.append((v2, value)) while i>0: v1 = varcache(vars[i-1].name) bindings.append((v1, v2)) v2 = v1 i -= 1 elif isinstance(vars, dexpr._div): bindings += [(varcache(v.name), value) for v, value in zip(get_let_vars(vars, dexpr._div), value)] else: raise DinpySyntaxError() body = preparse(body) if isinstance(body, tuple): return function(bindings, *body) else: return function(bindings, body)
def make_fun8(name, args, klass): # remove fun = varcache(name) args = preparse(args) return remove(fun, args, klass)
def getvar(name, klass=Var): return varcache(name, klass)