13日目
やるきがでない
59ページ目
ただコピペして2.3.5を終わらせた.文章を理解していないので明日以降読む.
instantiateConstrとかLetとかの型宣言がないのはいいのだろうか
ねむい
scStep :: TiState -> Name -> [Name] -> CoreExpr -> TiState
scStep (stack, dump, heap, globals, stats) sc_name arg_names body = (new_stack, dump, new_heap, globals, stats)
where
new_stack = result_addr : (drop (length arg_names+1) stack)
(new_heap, result_addr) = instantiate body heap env
env = arg_bindings ++ globals
arg_bindings = zip2 arg_names (getargs heap stack)
-- now getargs since getArgs conflicts with Gofer standard.prelude
getargs :: TiHeap -> TiStack -> [Addr]
getargs heap (sc:stack) = map get_arg stack
where get_arg addr = arg where (NAp fun arg) = hLookup heap addr
instantiate :: CoreExpr -- Body of supercombinator
-> TiHeap -- Heap before instantiation
-> ASSOC Name Addr -- Association of names to addresses
-> (TiHeap, Addr) -- Heap after instantiation, and
-- address of root of instance
instantiate (ENum n) heap env = hAlloc heap (NNum n)
instantiate (EAp e1 e2) heap env = hAlloc heap2 (NAp a1 a2)
where
(heap1, a1) = instantiate e1 heap env
(heap2, a2) = instantiate e2 heap1 env
instantiate (EVar v) heap env = (heap, aLookup env v (error ("Undefined name " ++ show v)))
instantiate (EConstr tag arity) heap env = instantiateConstr tag arity heap env
instantiate (ELet isrec defs body) heap env = instantiateLet isrec defs body heap env
instantiate (ECase e alts) heap env = error "Can’t instantiate case exprs"
instantiateConstr tag arity heap env = error "Can’t instantiate constructors yet"
instantiateLet isrec defs body heap env = error "Can’t instantiate let(rec)s yet"
2.3.5のコードをコピペした