shithub: MicroHs

Download patch

ref: dfa5b622f261ca873793928f9dd5a5d162bce3ae
parent: ea363bdc806556780a708f630990c18ad5414c8e
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Wed Sep 20 05:54:11 EDT 2023

Improve location info a little.

--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -305,11 +305,12 @@
 
 -- XXX Should use locations in ELit
 getSLocExpr :: Expr -> SLoc
-getSLocExpr e = head $ map getSLocIdent (allVarsExpr e) ++ [noSLoc]
+getSLocExpr e = head $ filter (not . isNoSLoc) (map getSLocIdent (allVarsExpr e)) ++ [noSLoc]
 
 setSLocExpr :: SLoc -> Expr -> Expr
 setSLocExpr l (EVar i) = EVar (setSLocIdent l i)
 setSLocExpr l (ECon c) = ECon (setSLocCon l c)
+setSLocExpr l (ELit _ k) = ELit l k
 setSLocExpr _ _ = undefined  -- what other cases do we need?
 
 setSLocCon :: SLoc -> Con -> Con
--- a/src/MicroHs/Ident.hs
+++ b/src/MicroHs/Ident.hs
@@ -8,7 +8,8 @@
   forceIdent,
   isLower_, isIdentChar, isOperChar, isConIdent,
   unQualString,
-  SLoc(..), noSLoc, showSLoc
+  SLoc(..), noSLoc, isNoSLoc,
+  showSLoc
   ) where
 import Prelude --Xhiding(showString)
 import Data.Char
@@ -21,11 +22,15 @@
 data SLoc = SLoc FilePath Line Col
   --Xderiving (Show, Eq)
 
+data Ident = Ident SLoc String
+  --Xderiving (Show, Eq)
+
 noSLoc :: SLoc
 noSLoc = SLoc "" 0 0
 
-data Ident = Ident SLoc String
-  --Xderiving (Show, Eq)
+isNoSLoc :: SLoc -> Bool
+isNoSLoc (SLoc "" 0 0) = True
+isNoSLoc _ = False
 
 mkIdent :: String -> Ident
 mkIdent = Ident noSLoc
--