Repository navigation
fix(translate): restrict float literal syntax - #129
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ForthLexer::isFloatcalledllvm::to_float, which wrapsstrtod.strtodalso accepts hex (0x10,0x1p3),nan,infandinfinity. Those tokens became f64 literals. So0x10silently stored the bit pattern of 16.0, and: nan 7 ;could not define a word.Change
isFloatnow checks an explicit grammar:[+-]? (D+ '.' D* | '.' D+ | D+) ([eE] [+-]? D+)?. A token must have a.or an exponent to count as a float. EverythingAGENTS.mddocuments still lexes as a float (3.14,-2.0,1.0e-5,1e3)..5,5.and+1.5also still lex as floats, becausestrtodaccepted them before. Anything else is an ordinary word. The diff stays inside the lexer.This PR does not add hex integer literals.
0x10is now an unknown word unless the program defines it.Repro
Before (
warpforthc):After:
\! kernel k : nan 7 ; nanBefore:
After, the kernel compiles and the PTX has
.visible .func ... NAN(.Tests
float-literal-strtod-spellings.forthdefines and callsnan,inf,infinityand0x1p3as words. It fails before the fix.hex-literal-error.forthchecks that0x10reportsunknown word: 0X10. It fails before the fix.float-literals.forthnow also covers1E3,.5,-.5,5.,+1.5and2.5e+2.The tests are committed before the fix.
check-warpforthpasses all 119 tests locally.Fixes #112