Implemented (most of the needed) support for AllocMobile in the C and C++ backends

This commit is contained in:
Neil Brown 2007-10-24 19:32:58 +00:00
parent 31642036b7
commit dd86b240b5
2 changed files with 18 additions and 0 deletions

View File

@ -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"
--}}}

View File

@ -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 ()