diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index dedd82f..c0ba821 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -184,6 +184,7 @@ cgenOps = GenOps { genActual = cgenActual, genActuals = cgenActuals, genAlt = cgenAlt, + genAllocMobile = cgenAllocMobile, genArrayLiteralElems = cgenArrayLiteralElems, genArraySize = cgenArraySize, genArraySizesLiteral = cgenArraySizesLiteral, @@ -1843,3 +1844,11 @@ cgenAssert ops m e --}}} --}}} +--{{{ mobiles +cgenAllocMobile :: GenOps -> Meta -> A.Type -> Maybe A.Expression -> CGen() +cgenAllocMobile ops m (A.Mobile t) Nothing = tell ["malloc("] >> call genBytesIn ops t (Left False) >> tell [")"] +--TODO add a pass, just for C, that pulls out the initialisation expressions for mobiles +-- into a subsequent assignment +cgenAllocMobile ops _ _ _ = call genMissing ops "Mobile allocation with initialising-expression" + +--}}} diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 59a825f..8d1c884 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -98,6 +98,7 @@ cppgenOps = cgenOps { declareInit = cppdeclareInit, genActual = cppgenActual, genActuals = cppgenActuals, + genAllocMobile = cppgenAllocMobile, genAlt = cppgenAlt, genArraySizesLiteral = cppgenArraySizesLiteral, genArrayStoreName = cppgenArrayStoreName, @@ -1106,3 +1107,11 @@ cppgenRetypeSizes ops m destT destN srcT srcV -- Not array; just check the size is 1. _ -> checkSize + +cppgenAllocMobile :: GenOps -> Meta -> A.Type -> Maybe A.Expression -> CGen () +cppgenAllocMobile ops m (A.Mobile t) me + = do tell ["new "] + call genType ops t + case me of + Just e -> tell ["("] >> call genExpression ops e >> tell [")"] + Nothing -> return ()