Skip to content

Commit

Permalink
Do not keep negative numbers as literals
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Dec 9, 2024
1 parent 0bcfd66 commit 20feae5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,18 @@ wrapTermination = [fmt|Φ.org.eolang.error(α0 ↦ Φ.org.eolang.string(as-bytes
Bytes bytes = stringToBytes "unknown error"

wrapBytesInConstInt :: Bytes -> Object
wrapBytesInConstInt bytes = [fmt|Φ.org.eolang.int(as-bytes ↦ {bytesToInt bytes})|]
wrapBytesInConstInt bytes@(Bytes bs)
| n < 0 = [fmt|Φ.org.eolang.int(as-bytes ↦ Φ.org.eolang.bytes(Δ ⤍ {bs}))|]
| otherwise = [fmt|Φ.org.eolang.int(as-bytes ↦ {n})|]
where
n = bytesToInt bytes

wrapBytesInConstFloat :: Bytes -> Object
wrapBytesInConstFloat bytes = [fmt|Φ.org.eolang.float(as-bytes ↦ {bytesToFloat bytes})|]
wrapBytesInConstFloat bytes@(Bytes bs)
| x < 0 = [fmt|Φ.org.eolang.float(as-bytes ↦ Φ.org.eolang.bytes(Δ ⤍ {bs}))|]
| otherwise = [fmt|Φ.org.eolang.float(as-bytes ↦ {x})|]
where
x = bytesToFloat bytes

wrapBytesInConstString :: Bytes -> Object
wrapBytesInConstString bytes = [fmt|Φ.org.eolang.string(as-bytes ↦ {show (bytesToString bytes)})|]
Expand Down

0 comments on commit 20feae5

Please sign in to comment.