@@ -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,25 +1060,26 @@ 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 $
1077
1079
[tfuture,
1078
1080
tchain,
1079
1081
Statement futureChain] ++
1080
- result )
1082
+ closResult )
1081
1083
else do
1082
1084
tmp <- Ctx. genSym
1083
1085
result <- Ctx. genSym
@@ -1146,53 +1148,84 @@ 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
1153
+ fwdInClos = case eCtx of
1154
+ Ctx. ClosureContext _ -> True
1155
+ _ -> False
1156
+ when (A. isVarAccess chain && isAsyncForward) $
1157
+ if (fwdInClos)
1158
+ then error $ " Expr.hs: The closure that contains forward must be defined in chain."
1159
+ else return ()
1150
1160
return $ (Var result,
1151
1161
Seq $ [tfuture,
1152
1162
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)]
1163
+ if (Util. isForwardInExpr chain && isAsyncForward)
1164
+ then Statement $
1165
+ (Call futureChainWithFut
1166
+ [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain,
1167
+ AsExpr ((Deref envName) `Dot ` futNam), AsExpr $ AsLval $ Nam " true" ])
1168
+ else Assign (Decl (C. future, Var result))
1169
+ (Call futureChainActor [AsExpr encoreCtxVar, AsExpr nfuture, ty, AsExpr nchain])
1170
+ ] ++
1171
+ if (Util. isForwardInExpr chain && isAsyncForward)
1172
+ then [assignVar futNam (Decl (C. future, Var result))]
1158
1173
else [] )
1159
1174
where
1160
1175
metaId = Meta. getMetaId . A. getMeta $ chain
1161
1176
envName = closureEnvName metaId
1162
- assignVar lhs rhs = Assign rhs (( Deref envName) `Dot ` lhs )
1177
+ assignVar lhs rhs = Assign ( Decl ( C. future, lhs)) (( Deref envName) `Dot ` rhs )
1163
1178
1164
1179
translate clos@ (A. Closure {A. eparams, A. body}) = do
1165
1180
tmp <- Ctx. genSym
1166
- fut <- Ctx. genNamedSym " fut "
1181
+ futClos <- Ctx. genNamedSym " fut_closure "
1167
1182
globalFunctionNames <- gets Ctx. getGlobalFunctionNames
1168
1183
isAsyncForward <- gets Ctx. isAsyncForward
1169
1184
let bound = map (ID. qLocal . A. pname) eparams
1170
1185
freeVars = filter (ID. isLocalQName . fst ) $
1171
1186
Util. freeVariables bound body
1172
1187
ty = runtimeType . A. getType $ body
1173
- futArg = if isAsyncForward
1174
- then futVar
1175
- else (Var fut)
1176
1188
fillEnv <- insertAllVars freeVars fTypeVars
1177
1189
return
1178
1190
(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])])
1191
+ Seq $
1192
+ mkEnv envName : fillEnv ++
1193
+ if isAsyncForward then
1194
+ if forwardInBody
1195
+ then [Assign (Decl (future, Var futClos))
1196
+ (Call futureMkFn [AsExpr encoreCtxVar, ty])
1197
+ ,assignVar futNam (Var futClos)
1198
+ ,Assign (Decl (closure, Var tmp))
1199
+ (Call closureMkFn [encoreCtxName, funNameAsync, envName, traceNameAsync, nullName])]
1200
+ else [Assign (Decl (closure, Var tmp))
1201
+ (Call closureMkFn [encoreCtxName, funName, envName, traceName, nullName])]
1202
+ else
1203
+ [Assign (Decl (closure, Var tmp))
1204
+ (Call closureMkFn [encoreCtxName, funName, envName, traceName, nullName])])
1190
1205
where
1206
+ forwardInBody = Util. isForwardInExpr body
1207
+ metaIdAsync = metaId ++ " _async"
1208
+ idClos = A. isIdClosure body
1209
+ funNameAsync = if idClos || not forwardInBody then funName
1210
+ else closureFunName metaIdAsync
1211
+ traceNameAsync = if idClos || not forwardInBody then traceName
1212
+ else closureTraceName metaIdAsync
1191
1213
metaId = Meta. getMetaId . A. getMeta $ clos
1192
1214
funName = closureFunName metaId
1193
1215
envName = closureEnvName metaId
1194
1216
traceName = closureTraceName metaId
1217
+ metaIdAsync = metaId ++ " _async"
1218
+ idClos = A. isIdClos body
1219
+ fwdInBody = Util. isForwardInExpr body
1220
+ funNameAsync = if idClos || not fwdInBody
1221
+ then funName
1222
+ else closureFunName metaIdAsync
1223
+ traceNameAsync = if idClos || not fwdInBody
1224
+ then traceName
1225
+ else closureTraceName metaIdAsync
1195
1226
fTypeVars = Util. freeTypeVars body
1227
+ futureMake f ty = Assign (Decl (future, Var f))
1228
+ (Call futureMkFn [AsExpr encoreCtxVar, ty])
1196
1229
mkEnv name =
1197
1230
Assign (Decl (Ptr $ Struct name, AsLval name))
1198
1231
(Call encoreAllocName [AsExpr (Deref encoreCtxVar), Sizeof $ Struct name])
0 commit comments