Skip to content

Commit 0811ae8

Browse files
authored
Merge pull request #68 from TerrorJack/wasm32-wasi
Fix pointer type detection in cross mode
2 parents 59c5e82 + ed747c7 commit 0811ae8

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

Diff for: src/CrossCodegen.hs

+36-13
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ computeType z@(ZCursor (Special pos _ value) _ _) = do
483483
testLogAtPos pos ("computing type of " ++ value) $ do
484484
integral <- testLog ("checking if type " ++ value ++ " is an integer") $ do
485485
success <- runCompileBooleanTest z $ "(" ++ value ++ ")(int)(" ++ value ++ ")1.4 == (" ++ value ++ ")1.4"
486-
testLog' $ "result: " ++ (if success then "integer" else "floating")
486+
testLog' $ "result: " ++ (if success then "integer" else "pointer or floating")
487487
return success
488488
typeRet <- if integral
489489
then do
@@ -494,18 +494,25 @@ computeType z@(ZCursor (Special pos _ value) _ _) = do
494494
size <- computeConst z ("sizeof(" ++ value ++ ")")
495495
return $ (if signed then "Int" else "Word") ++ (show (size * 8))
496496
else do
497-
let checkSize test = testLog ("checking if " ++ test) $ do
498-
success <- runCompileBooleanTest z test
499-
testLog' $ "result: " ++ show success
500-
return success
501-
ldouble <- checkSize ("sizeof(" ++ value ++ ") > sizeof(double)")
502-
if ldouble
503-
then return "LDouble"
504-
else do
505-
double <- checkSize ("sizeof(" ++ value ++ ") == sizeof(double)")
506-
if double
507-
then return "Double"
508-
else return "Float"
497+
pointer <- testLog ("checking if type " ++ value ++ " is a pointer") $ do
498+
success <- runCompileIsPointerTest z value
499+
testLog' $ "result: " ++ (if success then "pointer" else "floating")
500+
return success
501+
if pointer
502+
then return "CUIntPtr"
503+
else do
504+
let checkSize test = testLog ("checking if " ++ test) $ do
505+
success <- runCompileBooleanTest z test
506+
testLog' $ "result: " ++ show success
507+
return success
508+
ldouble <- checkSize ("sizeof(" ++ value ++ ") > sizeof(double)")
509+
if ldouble
510+
then return "LDouble"
511+
else do
512+
double <- checkSize ("sizeof(" ++ value ++ ") == sizeof(double)")
513+
if double
514+
then return "Double"
515+
else return "Float"
509516
testLog' $ "result: " ++ typeRet
510517
return typeRet
511518
computeType _ = error "computeType argument isn't a Special"
@@ -572,6 +579,22 @@ runCompileBooleanTest (ZCursor s above below) booleanTest = do
572579
(concatMap outHeaderCProg' below)
573580
runCompileTest test
574581

582+
runCompileIsPointerTest :: ZCursor Token -> String -> TestMonad Bool
583+
runCompileIsPointerTest (ZCursor s above below) ty = do
584+
config <- testGetConfig
585+
flags <- testGetFlags
586+
let test = -- all the surrounding code
587+
outTemplateHeaderCProg (cTemplate config) ++
588+
(concatMap outFlagHeaderCProg flags) ++
589+
(concatMap outHeaderCProg' above) ++
590+
outHeaderCProg' s ++
591+
-- the test
592+
"void _hsc2hs_test(" ++ ty ++ " val) {\n" ++
593+
" memset(val, 0, 0);\n" ++
594+
"}\n" ++
595+
(concatMap outHeaderCProg' below)
596+
runCompileTest test
597+
575598
runCompileAsmIntegerTest :: ZCursor Token -> TestMonad Integer
576599
runCompileAsmIntegerTest (ZCursor s@(Special _ _ value) above below) = do
577600
config <- testGetConfig

0 commit comments

Comments
 (0)