@@ -111,6 +111,28 @@ normaliseItem (FuncDecl vis mods (ProcProto name params resources)
111
111
[result, varSet outputVariableName `maybePlace` pos])
112
112
pos]
113
113
pos)
114
+ normaliseItem (ForeignProcDecl vis lang mods proto@ (ProcProto name params resources) pos) = do
115
+ when (mods{modifierImpurity= Pure , modifierDetism= Det , modifierInline= MayInline } /= defaultProcModifiers)
116
+ $ errmsg pos
117
+ $ " Foreign procedure declaration of " ++ name
118
+ ++ " has illegal procedure modifiers. Only purity, determinism, and inlining can be specified."
119
+ mapM_ ((\ (Param {paramType= ty, paramName= name}, pos) -> do
120
+ when (ty == AnyType )
121
+ $ errmsg pos
122
+ $ " Foreign procedure declaration parameters must be typed, but " ++ name ++ " is untyped."
123
+ ) . unPlace) params
124
+
125
+ normaliseItem
126
+ (ProcDecl vis mods proto
127
+ [maybePlace (ForeignCall lang name mods' exps) pos] pos)
128
+ where
129
+ mods' = List. filter (not . List. null )
130
+ [ impurityName (modifierImpurity mods)
131
+ , determinismName (modifierDetism mods) ]
132
+ exps = List. map (uncurry (flip rePlace . paramToVar) . unPlace) params
133
+ ++ List. map (\ (ResourceFlowSpec rs@ (ResourceSpec _ r) dir) ->
134
+ Var r dir (Resource rs) `maybePlace` pos)
135
+ resources
114
136
normaliseItem item@ ProcDecl {} = do
115
137
logNormalise $ " Recording proc without flattening:" ++ show item
116
138
addProc 0 item
@@ -288,7 +310,7 @@ validateModuleName what pos name =
288
310
289
311
-- | Check that the specified module name is valid, reporting and error if not.
290
312
validateModSpec :: OptPos -> ModSpec -> Compiler ()
291
- validateModSpec pos = mapM_ (validateModuleName " module" pos)
313
+ validateModSpec pos = mapM_ (validateModuleName " module" pos)
292
314
293
315
294
316
-- | Information about a non-constant constructor
@@ -400,7 +422,7 @@ nonConstCtorInfo (vis, placedProto) tag = do
400
422
logNormalise $ " Analysing non-constant ctor "
401
423
++ show tag ++ " : " ++ show placedProto
402
424
let (proto,pos) = unPlace placedProto
403
- unless (Set .null $ procProtoResources proto)
425
+ unless (List .null $ procProtoResources proto)
404
426
$ shouldnt $ " Constructor with resources: " ++ show placedProto
405
427
let name = procProtoName proto
406
428
let params = procProtoParams proto
@@ -470,7 +492,7 @@ normaliseModMain modSCC = do
470
492
-- assumes that all resource initialisations have already been completed, and
471
493
-- all are permitted to be modified by the initialisation code, so all
472
494
-- visible initialised resources flow both in and out.
473
- initResources :: [ModSpec ] -> Compiler ( Set ResourceFlowSpec )
495
+ initResources :: [ModSpec ] -> Compiler [ ResourceFlowSpec ]
474
496
initResources modSCC = do
475
497
thisMod <- getModule modSpec
476
498
mods <- getModuleImplementationField (Map. keys . modImports)
@@ -489,7 +511,7 @@ initResources modSCC = do
489
511
-- because that would overwrite them.
490
512
let cmdlineResources =
491
513
if cmdLineModSpec == thisMod
492
- then let cmdline = ResourceSpec cmdLineModSpec
514
+ then let cmdline = ResourceSpec cmdLineModSpec
493
515
in [ResourceFlowSpec (cmdline " argc" ) ParamInOut
494
516
,ResourceFlowSpec (cmdline " argv" ) ParamInOut ]
495
517
else []
@@ -498,7 +520,7 @@ initResources modSCC = do
498
520
<$> Set. toList visibleInitSet)
499
521
logNormalise $ " In initResources for module " ++ showModSpec thisMod
500
522
++ " , resources = " ++ show resources
501
- return ( Set. fromList resources)
523
+ return resources
502
524
503
525
504
526
@@ -538,7 +560,7 @@ constCtorItems typeSpec ((vis, placedProto), num) =
538
560
constName = procProtoName proto
539
561
in [ProcDecl vis (inlineModifiers (ConstructorProc constName) Det )
540
562
(ProcProto constName
541
- [Param outputVariableName typeSpec ParamOut Ordinary `maybePlace` pos] Set. empty )
563
+ [Param outputVariableName typeSpec ParamOut Ordinary `maybePlace` pos] [] )
542
564
[lpvmCastToVar (castTo (iVal num) typeSpec) outputVariableName] pos
543
565
]
544
566
@@ -652,7 +674,7 @@ constructorItems vis ctorName typeSpec params fields size tag tagLimit pos =
652
674
(ProcProto ctorName
653
675
((placedApply (\ p -> maybePlace p {paramFlow= ParamIn , paramFlowType= Ordinary }) <$> params)
654
676
++ [Param outputVariableName typeSpec ParamOut Ordinary `maybePlace` pos])
655
- Set. empty )
677
+ [] )
656
678
-- Code to allocate memory for the value
657
679
([maybePlace (ForeignCall " lpvm" " alloc" []
658
680
[Unplaced $ iVal size,
@@ -702,7 +724,7 @@ deconstructorItems uniq vis ctorName typeSpec params numConsts numNonConsts tag
702
724
(ProcProto ctorName
703
725
((contentApply (\ p -> p {paramFlow= ParamOut , paramFlowType= Ordinary }) <$> params)
704
726
++ [Param outputVariableName typeSpec ParamIn Ordinary `maybePlace` pos])
705
- Set. empty )
727
+ [] )
706
728
-- Code to check we have the right constructor
707
729
(tagCheck pos numConsts numNonConsts tag tagBits tagLimit
708
730
(Just size) outputVariableName
@@ -810,7 +832,7 @@ unboxedConstructorItems vis ctorName typeSpec tag nonConstBit fields pos =
810
832
([Param name paramType ParamIn Ordinary `maybePlace` pPos
811
833
| FieldInfo name pPos _ paramType _ _ _ <- fields]
812
834
++ [Param outputVariableName typeSpec ParamOut Ordinary `maybePlace` pos])
813
- Set. empty
835
+ []
814
836
in [ProcDecl vis (inlineModifiers (ConstructorProc ctorName) Det ) proto
815
837
-- Initialise result to 0
816
838
([ForeignCall " llvm" " move" []
@@ -863,7 +885,7 @@ unboxedDeconstructorItems vis uniq ctorName recType numConsts numNonConsts tag
863
885
(List. map (\ (FieldInfo n pPos _ fieldType _ _ _) -> Param n fieldType ParamOut Ordinary `maybePlace` pPos)
864
886
fields
865
887
++ [Param outputVariableName recType ParamIn Ordinary `maybePlace` pos])
866
- Set. empty )
888
+ [] )
867
889
-- Code to check we have the right constructor
868
890
(tagCheck pos numConsts numNonConsts tag tagBits (wordSizeBytes- 1 ) Nothing
869
891
outputVariableName
@@ -965,13 +987,13 @@ getterSetterItems numConsts numNonConsts recType field infos = do
965
987
[-- The getter:
966
988
ProcDecl fieldVis (setInline inline $ inlineModifiers (GetterProc field fieldType) detism)
967
989
(ProcProto field [Param recName recType ParamIn Ordinary `maybePlace` pos,
968
- Param outputVariableName fieldType ParamOut Ordinary `maybePlace` pos] Set. empty )
990
+ Param outputVariableName fieldType ParamOut Ordinary `maybePlace` pos] [] )
969
991
getBody
970
992
pos,
971
993
-- The setter:
972
994
ProcDecl fieldVis (setInline inline $ inlineModifiers (SetterProc field fieldType) detism)
973
995
(ProcProto field [Param recName recType ParamInOut Ordinary `maybePlace` pos,
974
- Param fieldName fieldType ParamIn Ordinary `maybePlace` pos] Set. empty )
996
+ Param fieldName fieldType ParamIn Ordinary `maybePlace` pos] [] )
975
997
setBody
976
998
pos]
977
999
@@ -1008,7 +1030,7 @@ implicitEquality pos typespec consts nonconsts rep = do
1008
1030
else do
1009
1031
let eqProto = ProcProto " =" [Param leftName typespec ParamIn Ordinary `maybePlace` pos,
1010
1032
Param rightName typespec ParamIn Ordinary `maybePlace` pos]
1011
- Set. empty
1033
+ []
1012
1034
let (body,inline) = equalityBody pos consts nonconsts rep
1013
1035
return [ProcDecl Public (setInline inline
1014
1036
$ setDetism SemiDet defaultProcModifiers)
@@ -1024,7 +1046,7 @@ implicitDisequality pos typespec consts nonconsts _ = do
1024
1046
else do
1025
1047
let neProto = ProcProto " ~=" [Param leftName typespec ParamIn Ordinary `maybePlace` pos,
1026
1048
Param rightName typespec ParamIn Ordinary `maybePlace` pos]
1027
- Set. empty
1049
+ []
1028
1050
let neBody = [maybePlace (Not $
1029
1051
ProcCall (First [] " =" Nothing ) SemiDet False
1030
1052
[varGetTyped leftName typespec `maybePlace` pos,
0 commit comments