@@ -30,6 +30,7 @@ data BCOp = PUSH SValue
30 -- places constructor args on stack, last to first (first at ref 0)
30 -- places constructor args on stack, last to first (first at ref 0)
31 | SPLIT -- get arguments from constructor form
31 | SPLIT -- get arguments from constructor form
32 | CALL Name Int -- name, number of arguments to take
32 | CALL Name Int -- name, number of arguments to take
33+ | CLOSURE Name Int -- as CALL, but always make the closure
33 | CALLVAR Int Int -- stack ref, number of arguments to take
34 | CALLVAR Int Int -- stack ref, number of arguments to take
34 | FOREIGNCALL String CType [CType] -- TT constants for types
35 | FOREIGNCALL String CType [CType] -- TT constants for types
35 | PRIMOP SPrim [Int] -- apply to list of stack references
36 | PRIMOP SPrim [Int] -- apply to list of stack references
@@ -77,6 +78,14 @@ instance BC SCExp where
77 = [CALLVAR (length args) (length args)]
78 = [CALLVAR (length args) (length args)]
78 bc' locs (x : xs) = bc locs x ++
79 bc' locs (x : xs) = bc locs x ++
79 bc' (offset locs) xs
80 bc' (offset locs) xs
81+ bc locs (SLazyApp f args)
82+ = bc' locs (reverse args) f
84+ = case lookup n locs of
85+ Just i -> error "Internal error: Lazy call"
86+ Nothing -> [CLOSURE n (length args)]
87+ bc' locs (x : xs) f = bc locs x ++
88+ bc' (offset locs) xs f
80 bc locs (SLet n v sc)
89 bc locs (SLet n v sc)
81 = bc locs v ++
90 = bc locs v ++
82 bc ((n, 0) : offset locs) sc ++
91 bc ((n, 0) : offset locs) sc ++
@@ -85,7 +94,7 @@ instance BC SCExp where
85 bc locs (SFCall cname ty args)
94 bc locs (SFCall cname ty args)
86 = bc' locs (reverse (map fst args))
95 = bc' locs (reverse (map fst args))
87 where bc' locs [] = [FOREIGNCALL cname ty (map snd args)]
96 where bc' locs [] = [FOREIGNCALL cname ty (map snd args)]
88− bc' locs (x : xs) = bc locs x ++ bc' (offset locs) xs
97+ bc' locs (x : xs) = bc locs x ++ EVAL True : bc' (offset locs) xs
90 bc locs (SCon t args)
99 bc locs (SCon t args)
91 = bc' locs (reverse args)
100 = bc' locs (reverse args)
@@ -103,7 +112,7 @@ instance BC SCExp where
104 bc locs (SCase n alts)
113 bc locs (SCase n alts)
105 = let (def, cases, ty) = getCases CASE Nothing [] alts in
114 = let (def, cases, ty) = getCases CASE Nothing [] alts in
106− bc locs (SRef n) ++ [ty cases def]
115+ bc locs (SRef n) ++ [EVAL True, ty cases def]
107 where getCases ty def cs [] = (def, reverse cs, ty)
116 where getCases ty def cs [] = (def, reverse cs, ty)
108 getCases ty _ cs (SDefaultCase e : rest)
117 getCases ty _ cs (SDefaultCase e : rest)
109 = getCases ty (Just (bc locs e)) cs rest
118 = getCases ty (Just (bc locs e)) cs rest
@@ -119,4 +128,5 @@ instance BC SCExp where
119 bc locs (SPrimOp p args)
128 bc locs (SPrimOp p args)
120 = bc' locs (reverse args)
129 = bc' locs (reverse args)
121 where bc' locs [] = [PRIMOP p [0..length args-1]]
130 where bc' locs [] = [PRIMOP p [0..length args-1]]
122− bc' locs (x : xs) = bc locs x ++ bc' (offset locs) xs
131+ bc' locs (x : xs) = bc locs x ++ EVAL True : bc' (offset locs) xs