aboutsummaryrefslogtreecommitdiff
path: root/Sil/Types.icl
diff options
context:
space:
mode:
Diffstat (limited to 'Sil/Types.icl')
-rw-r--r--Sil/Types.icl29
1 files changed, 24 insertions, 5 deletions
diff --git a/Sil/Types.icl b/Sil/Types.icl
index 40fc0cb..cd9b9a4 100644
--- a/Sil/Types.icl
+++ b/Sil/Types.icl
@@ -2,9 +2,12 @@ implementation module Sil.Types
from StdFunc import const
import StdList
+import StdMisc
import StdOverloaded
import StdString
+import GenEq
+
import Control.Applicative
import Control.Monad
import Data.Error
@@ -12,7 +15,7 @@ from Data.Func import $
import Data.Maybe
from Text import <+
-import GenEq
+from ABC.Assembler import :: BasicType(..)
import Sil.Syntax
@@ -30,10 +33,26 @@ instance toString TypeError
where
toString (IllegalApplication ft et) = "Cannot apply a " <+ et <+ " to a " <+ ft <+ "."
-typeSize :: Type -> Int
-typeSize TVoid = 0
-typeSize TBool = 1
-typeSize TInt = 1
+instance zero TypeSize where zero = {asize=0, bsize=0, btypes=[]}
+
+typeSize :: Type -> TypeSize
+typeSize TVoid = zero
+typeSize TBool = {zero & bsize=1, btypes=[BT_Bool]}
+typeSize TInt = {zero & bsize=1, btypes=[BT_Int]}
+
+(+~) infixl 6 :: TypeSize TypeSize -> TypeSize
+(+~) a b =
+ { asize = a.asize + b.asize
+ , bsize = a.bsize + b.bsize
+ , btypes = a.btypes ++ b.btypes
+ }
+
+(-~) infixl 6 :: TypeSize TypeSize -> TypeSize
+(-~) a b =
+ { asize = a.asize - b.asize
+ , bsize = a.bsize - b.bsize
+ , btypes = abort "btypes after -~\r\n"
+ }
instance zero TypeResolver where zero = const Nothing