From dcc9dd17186907d105cf01358b39e1551c0fc874 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 24 Jul 2017 18:22:04 +0200 Subject: Use B-stack for basic arguments (not locals): resolve #9 --- Sil/Types.icl | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'Sil/Types.icl') 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 -- cgit v1.2.3