def compile_lambda(self, exp, env, cont, istail=False): def got_body(body_code): body_code += [ (inst_ret,), ] code = [ (inst_closure, (len(params), len(params)), body_code, isvararg), ] return bounce(cont, code) params, body = cadr(exp), cddr(exp) isvararg = False if lib_issymbol(params): # variable arguments, (lambda x ...) params = [params] isvararg = True elif lib_islist(params): # normal argument, (lambda (x y) ...) params = to_python_list(params) else: # dotted tail arguments, (lambda (x . y) ...) tmplist = [] while isinstance(cdr(params), Pair): tmplist.append(car(params)) params = cdr(params) tmplist.append(car(params)) tmplist.append(cdr(params)) params = tmplist isvararg = True # list() is needed, or `params' will be modified # if the lambda body creates new bindings newenv = Frame(list(params), env) defs = define_dumb(body, newenv) return bounce(self.compile_sequence, body, defs, newenv, got_body, istail=True)
def testToPythonList(self): self.assertEqual(to_python_list(lib_list(1, 2, 3)), [1, 2, 3])