@@ -221,7 +221,7 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
221
221
let string = head args
222
222
rest = tail args
223
223
unless (Ty. isStringType $ A. getType string) $
224
- error " Expr.hs: Print expects first argument to be a string literal"
224
+ error $ " Expr.hs: Print expects first argument to be a string literal"
225
225
targs <- mapM translate rest
226
226
let argNames = map (AsExpr . fst ) targs
227
227
argDecls = map snd targs
@@ -1032,7 +1032,8 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
1032
1032
If futVar
1033
1033
(Seq [Statement forwardingCall])
1034
1034
(Seq [Statement oneWayMsg])] ++
1035
- result)
1035
+ result
1036
+ )
1036
1037
else do
1037
1038
(sendn, sendt) <- translate A. MessageSend {A. emeta
1038
1039
,A. target
@@ -1059,18 +1060,19 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
1059
1060
isAsyncForward <- gets Ctx. isAsyncForward
1060
1061
let ty = getRuntimeType chain
1061
1062
dtraceExit = getDtraceExit eCtx
1062
- result =
1063
- case eCtx of
1064
- Ctx. ClosureContext clos -> []
1065
- _ -> [dtraceExit, Return Skip ]
1063
+ result = case eCtx of
1064
+ Ctx. ClosureContext clos -> []
1065
+ _ -> [dtraceExit, Return Skip ]
1066
1066
futureChain =
1067
1067
if Util. isForwardInExpr chain
1068
- then
1069
- Call futureChainActor
1070
- [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain]
1071
- else
1072
- Call futureChainWithFut
1073
- [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain, AsExpr futVar]
1068
+ then Call futureChainActor
1069
+ [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain]
1070
+ else Call futureChainWithFut
1071
+ [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain
1072
+ ,AsExpr futVar, AsExpr $ AsLval $ Nam " false" ]
1073
+ when (A. isVarAccess chain) $
1074
+ unless (A. isIdClosure chain) $
1075
+ error $ " Expr.hs: The closure that contains forward must be defined in chain."
1074
1076
if isAsyncForward
1075
1077
then do
1076
1078
return (unit, Seq $
@@ -1146,15 +1148,21 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
1146
1148
(nfuture,tfuture) <- translate future
1147
1149
(nchain, tchain) <- translate chain
1148
1150
result <- Ctx. genSym
1151
+ isAsyncForward <- gets Ctx. isAsyncForward
1149
1152
let ty = getRuntimeType chain
1150
1153
return $ (Var result,
1151
1154
Seq $ [tfuture,
1152
1155
tchain,
1153
- (Assign (Decl (C. future, Var result))
1154
- (Call futureChainActor
1155
- [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain]
1156
- ))] ++
1157
- if (Util. isForwardInExpr chain) then [assignVar futNam (Nam result)]
1156
+ if (Util. isForwardInExpr chain && isAsyncForward)
1157
+ then Statement $
1158
+ (Call futureChainWithFut
1159
+ [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain,
1160
+ AsExpr ((Deref envName) `Dot ` futNam), AsExpr $ AsLval $ Nam " true" ])
1161
+ else Assign (Decl (C. future, Var result))
1162
+ (Call futureChainActor [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain])
1163
+ ] ++
1164
+ if (Util. isForwardInExpr chain && isAsyncForward)
1165
+ then [assignVar futNam (Decl (C. future, Var result))]
1158
1166
else [] )
1159
1167
where
1160
1168
metaId = Meta. getMetaId . A. getMeta $ chain
@@ -1163,31 +1171,38 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
1163
1171
1164
1172
translate clos@ (A. Closure {A. eparams, A. body}) = do
1165
1173
tmp <- Ctx. genSym
1166
- fut <- Ctx. genNamedSym " fut "
1174
+ futClos <- Ctx. genNamedSym " fut_closure "
1167
1175
globalFunctionNames <- gets Ctx. getGlobalFunctionNames
1168
1176
isAsyncForward <- gets Ctx. isAsyncForward
1169
1177
let bound = map (ID. qLocal . A. pname) eparams
1170
1178
freeVars = filter (ID. isLocalQName . fst ) $
1171
1179
Util. freeVariables bound body
1172
1180
ty = runtimeType . A. getType $ body
1173
- futArg = if isAsyncForward
1174
- then futVar
1175
- else (Var fut)
1176
1181
fillEnv <- insertAllVars freeVars fTypeVars
1177
1182
return
1178
1183
(Var tmp,
1179
- Seq $
1180
- mkEnv envName : fillEnv ++
1181
- (if isAsyncForward || (not $ Util. isForwardInExpr body)
1182
- then []
1183
- else [Assign (Decl (future, Var fut))
1184
- (Call futureMkFn [AsExpr encoreCtxVar, ty])]) ++
1185
- (if Util. isForwardInExpr body
1186
- then [assignVar futNam futArg]
1187
- else [] ) ++
1188
- [Assign (Decl (closure, Var tmp))
1189
- (Call closureMkFn [encoreCtxName, funName, envName, traceName, nullName])])
1184
+ Seq $
1185
+ mkEnv envName : fillEnv ++
1186
+ if isAsyncForward then
1187
+ if forwardInBody
1188
+ then [Assign (Decl (future, Var futClos))
1189
+ (Call futureMkFn [AsExpr encoreCtxVar, ty])
1190
+ ,assignVar futNam (Var futClos)
1191
+ ,Assign (Decl (closure, Var tmp))
1192
+ (Call closureMkFn [encoreCtxName, funNameAsync, envName, traceNameAsync, nullName])]
1193
+ else [Assign (Decl (closure, Var tmp))
1194
+ (Call closureMkFn [encoreCtxName, funName, envName, traceName, nullName])]
1195
+ else
1196
+ [Assign (Decl (closure, Var tmp))
1197
+ (Call closureMkFn [encoreCtxName, funName, envName, traceName, nullName])])
1190
1198
where
1199
+ forwardInBody = Util. isForwardInExpr body
1200
+ metaIdAsync = metaId ++ " _async"
1201
+ idClos = A. isIdClosure body
1202
+ funNameAsync = if idClos || not forwardInBody then funName
1203
+ else closureFunName metaIdAsync
1204
+ traceNameAsync = if idClos || not forwardInBody then traceName
1205
+ else closureTraceName metaIdAsync
1191
1206
metaId = Meta. getMetaId . A. getMeta $ clos
1192
1207
funName = closureFunName metaId
1193
1208
envName = closureEnvName metaId
0 commit comments