Skip to content
Snippets Groups Projects
Commit 1983c5a2 authored by Simon Marlow's avatar Simon Marlow
Browse files

[project @ 1998-05-11 16:19:46 by simonm]

Convert floating point literals from interfaces directly to Rationals,
rather than go via Doubles.
parent 27ecd468
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,8 @@ import FastString ...@@ -53,6 +53,8 @@ import FastString
import StringBuffer import StringBuffer
import GlaExts import GlaExts
import ST ( runST ) import ST ( runST )
import PrelRead ( readRational__ ) -- Glasgow non-std
\end{code} \end{code}
%************************************************************************ %************************************************************************
...@@ -219,7 +221,7 @@ data IfaceToken ...@@ -219,7 +221,7 @@ data IfaceToken
| ITccall (Bool,Bool) -- (is_casm, may_gc) | ITccall (Bool,Bool) -- (is_casm, may_gc)
| ITscc CostCentre | ITscc CostCentre
| ITchar Char | ITstring FAST_STRING | ITchar Char | ITstring FAST_STRING
| ITinteger Integer | ITdouble Double | ITinteger Integer | ITrational Rational
| ITinteger_lit | ITfloat_lit | ITrational_lit | ITaddr_lit | ITlit_lit | ITstring_lit | ITinteger_lit | ITfloat_lit | ITrational_lit | ITaddr_lit | ITlit_lit | ITstring_lit
| ITunknown String -- Used when the lexer can't make sense of it | ITunknown String -- Used when the lexer can't make sense of it
| ITeof -- end of file token | ITeof -- end of file token
...@@ -443,13 +445,19 @@ lex_num cont minus acc# buf = ...@@ -443,13 +445,19 @@ lex_num cont minus acc# buf =
-- presence of floating point numbers in interface -- presence of floating point numbers in interface
-- files is not that common. (ToDo) -- files is not that common. (ToDo)
case expandWhile (isDigit) (incLexeme buf') of case expandWhile (isDigit) (incLexeme buf') of
buf'' -> -- points to first non digit char buf2 -> -- points to first non digit char
case reads (lexemeToString buf'') of let l = case currentChar# buf2 of
[(v,_)] -> cont (ITdouble v) (stepOverLexeme buf'') 'e'# -> let buf3 = incLexeme buf2 in
case currentChar# buf3 of
'-'# -> expandWhile (isDigit) (incLexeme buf3)
_ -> expandWhile (isDigit) buf3
_ -> buf2
in let v = readRational__ (lexemeToString l) in
cont (ITrational v) (stepOverLexeme l)
_ -> cont (ITinteger (fromInt (minus acc'))) (stepOverLexeme buf') _ -> cont (ITinteger (fromInt (minus acc'))) (stepOverLexeme buf')
-- case reads (lexemeToString buf') of
-- [(i,_)] -> cont (ITinteger i) (stepOverLexeme buf')
------------ ------------
lex_keyword cont buf = lex_keyword cont buf =
......
...@@ -102,7 +102,7 @@ import Outputable ...@@ -102,7 +102,7 @@ import Outputable
CHAR { ITchar $$ } CHAR { ITchar $$ }
STRING { ITstring $$ } STRING { ITstring $$ }
INTEGER { ITinteger $$ } INTEGER { ITinteger $$ }
DOUBLE { ITdouble $$ } RATIONAL { ITrational $$ }
INTEGER_LIT { ITinteger_lit } INTEGER_LIT { ITinteger_lit }
FLOAT_LIT { ITfloat_lit } FLOAT_LIT { ITfloat_lit }
...@@ -572,8 +572,8 @@ core_lit : INTEGER { MachInt $1 True } ...@@ -572,8 +572,8 @@ core_lit : INTEGER { MachInt $1 True }
| CHAR { MachChar $1 } | CHAR { MachChar $1 }
| STRING { MachStr $1 } | STRING { MachStr $1 }
| STRING_LIT STRING { NoRepStr $2 } | STRING_LIT STRING { NoRepStr $2 }
| DOUBLE { MachDouble (toRational $1) } | RATIONAL { MachDouble $1 }
| FLOAT_LIT DOUBLE { MachFloat (toRational $2) } | FLOAT_LIT RATIONAL { MachFloat $2 }
| INTEGER_LIT INTEGER { NoRepInteger $2 (panic "NoRepInteger type") | INTEGER_LIT INTEGER { NoRepInteger $2 (panic "NoRepInteger type")
-- The type checker will add the types -- The type checker will add the types
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment