예제 #1
0
def s_core_map(env, fn, items):
    l = types.SList()
    for item in items:
        result = types.SCallable.call_procedure(fn, env, [item])
        env = result.env
        l.add(result.ret)
    return types.SResult(env, l)
예제 #2
0
def s_core_call_cc(env, proc):
    cont = env.continuation.clone()
    ret_handler = gen_continuation_func(cont)
    l = types.SList()
    l.add(proc)
    l.add(ret_handler)
    return l.realize(env)
예제 #3
0
def s_core_hashmap_from_list(env, key_list, value_list):
    """
	scheme 的hashmap暂时用list(key_list, value_list)的形式表示。
	将来打算再写一个SHashMap的类做这个功能
	"""
    l = types.SList()
    l.add(key_list)
    l.add(value_list)
    return types.SResult(env, l)
예제 #4
0
def s_cons2(env, *items):
    seq = types.SList()
    import copy
    list = items[-1]
    items = items[:-1]
    seq.items = copy.copy(list.items)
    for i in range(len(items)):
        item = items[i]
        seq.items.insert(i, item)
    return types.SResult(env, seq)
예제 #5
0
def p_statement_form(p):
    """expression : LEFT_PARENTHESES expressionlist RIGHT_PARENTHESES
					| LEFT_PARENTHESES expression RIGHT_PARENTHESES"""
    # """expression : LEFT_PARENTHESES expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression expression expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression expression expression expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression expression expression expression expression RIGHT_PARENTHESES
    #                 | LEFT_PARENTHESES expression expression expression expression expression expression expression RIGHT_PARENTHESES"""
    # p[0] = ['seq-expression']
    # for i in range(2, len(p) - 1):
    #     p[0].append(p[i])
    # p[0] = tuple(p[0])
    if isinstance(p[2], types.SExprList):
        p[0] = types.SList()
        for item in p[2]:
            p[0].add(item)
    else:
        p[0] = types.SList()
        p[0].add(p[2])
예제 #6
0
def s_list(env, *items):
    seq = types.SList()
    for item in items:
        seq.add(item)
    return types.SResult(env, seq)
예제 #7
0
def s_cons(env, head, tail):
    seq = types.SList()
    seq.add(head)
    seq.add(tail)
    return types.SResult(env, seq)
예제 #8
0
def p_statement_quote_expr(p):
    """expression : QUOTE expression"""
    p[0] = types.SList()
    p[0].add(p[1])
    p[0].add(p[2])