@@ -52,6 +52,8 @@ data SAlt = SConCase Tag [Name] SCExp
5252 | SDefaultCase SCExp
5353 deriving Show
5454
55+type Prims = [(Name, ([CType], CType, SPrim))]
56+
5557sInt, sFloat, sChar, sString, sPtr, sBigInt :: CType
5658sInt = Just IType
5759sFloat = Just FlType
@@ -62,6 +64,15 @@ sBigInt = Just BIType
6264
6365type SCState = ([(Name, SCDef)], Name)
6466
67+toSC :: Prims -> (Name, Def) -> [(Name, SCDef)]
68+toSC prims (n, d)
69+ = case lookup n prims of
70+ Nothing -> sclift (n, d)
71+ Just (args, rt, op) ->
72+ let anames = zipWith mkA args [0..] in
73+ [(n, SCDef anames (SPrimOp op (map (SRef . fst) anames)))]
74+ where mkA t i = (MN i "primArg", t)
75+
6576sclift :: (Name, Def) -> [(Name, SCDef)]
6677sclift (n, d) = fst (execState (sc [] d) ([], n))
6778