never executed always true always false
    1 -- Copyright (C) 2018 Jun Zhang <zhangjunphy[at]gmail[dot]com>
    2 --
    3 -- This file is a part of decafc.
    4 --
    5 -- decafc is free software: you can redistribute it and/or modify it under the
    6 -- terms of the MIT (X11) License as described in the LICENSE file.
    7 --
    8 -- decafc is distributed in the hope that it will be useful, but WITHOUT ANY
    9 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   10 -- FOR A PARTICULAR PURPOSE.  See the X11 license for more details.
   11 
   12 -- Types -- Common types
   13 module Types (VID, Name, ScopeID, BBID, CompileError(..)) where
   14 
   15 import Data.Text (Text)
   16 import Util.SourceLoc qualified as SL
   17 import Formatting (sformat, int, stext, (%), formatToString)
   18 
   19 -- Variable ID
   20 type VID = Int
   21 
   22 -- Var/Function name
   23 type Name = Text
   24 
   25 -- Scope of function, basic block, etc.
   26 type ScopeID = Int
   27 
   28 -- Basic block ID
   29 type BBID = Int
   30 
   31 data CompileError = CompileError
   32   { sl :: !(Maybe SL.Range)
   33   , msg :: !Text
   34   }
   35 
   36 instance Show CompileError where
   37   show (CompileError (Just sl) msg) = formatToString (int % ":" % int % ": error: " % stext) (SL.row (SL.start sl) + 1) (SL.col (SL.start sl) + 1) msg
   38   show (CompileError Nothing msg) = formatToString ("error: " % stext) msg