Repository navigation
Fix INPUT into DATA arrays, -ls listings, native long lines, block order and INC optimization - #123
Open
kimslawson wants to merge 8 commits into
Open
kimslawson wants to merge 8 commits into
kimslawson wants to merge 8 commits into
Conversation
On platforms where char is signed (x86, x86-64, Windows), the test for $9B never matched, so '-ls' wrote a raw ATASCII EOL inside the string. The cross compiler reads it back, but the native compiler and the IDE split the line there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
The documentation says each line is of N characters or less, but lines were only joined up to N-1 characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
INPUT_VAR tried VAR_WORD_LVALUE_SADDR first, which creates a variable with the name of the DATA array and then accepts it as a word variable, so "INPUT D(1)" gave a parse error at the parenthesis. Try the byte array first, like GET does, and add the floating point DATA alternative at the start of the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
The loop that copies the line to the buffer indexes with Y until it finds the EOL, so with 256 or more characters it wrapped around and never ended. Costs 4 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
Blocks were collected from a map ordered by label name, so "jump_lbl_10" came before "jump_lbl_9", and sorted with std::sort, which is not stable. Several DATA arrays in one line could be placed in any order, unlike in the native compiler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
The rule "TOK_VAR / x / TOK_PUSH / TOK_NUM / y / TOK_ADD" matched first,
so the existing INC rule never did and "X=X+1" used 5 bytes instead of
2 ("X=X-1" already gave DEC). Saves 3 bytes in fedora.bas and 18 in
testloop.bas.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
The Windows fallback was a static "strndup", which conflicts with the declaration in newer MinGW <string.h>, failing the Windows CI. Use another name for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM
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.
Daniel,
While building fbp, a minimizer/pretty-printer that reuses FastBasic's
.syngrammar and checks every rewrite by comparing bytecode, I ran into a few bugs in FastBasic. (I did this work with Claude Code, an AI assistant.) Each fix is a separate commit, so you can take any of them on their own.Everything was tested against
master(212de72). "Native" meansfbc.xex/fbci.xexrun in the testsuite's mini65, not the IDE or real hardware.The fixes
-lswrote a raw $9B inside strings (986ba16).? "A"$9B"B"became?"A<$9B>B". The cross compiler reads that back, but the native compiler fails withparse error at line 1 column 3.add_s_str()already escapes it, but tests(unsigned) c == 155, which never matches wherecharis signed (x86, x86-64, Windows, Apple arm64). Fixed with(unsigned char). On the samples, the-ls:120output still compiles to identical code, andmastodon.basnow has 8 real lines instead of 12 $9B bytes.-ls:Nonly made lines of N−1 characters (4584961).USAGE.mdsays "N characters or less". Eleven 10-character statements now fit one 120-character line.carrera3d.basgoes from 15 lines to 14.INPUTinto byte or floating point DATA arrays was a parse error (91da76c).DATA D() BYTE = 1,2,3 : INPUT D(1)gave "expected: ','", both native and cross, int and fp. Word DATA andDIMarrays work.INPUT_VARtriedVAR_WORD_LVALUE_SADDRfirst. ItsE_VAR_CREATEcreates a variableD, the next alternative accepts it as a word variable, and(1)then fails outsideINPUT_VAR.basic.syn,ARRAY_BYTE_ADDRnow comes first, as inGETK_EXPR/GET_EXPR. It only searches, so other cases compile as before.float.syn, the FP DATA alternative is added withINPUT_VAR:<. Putting all ofVAR_FP_LVALUE_SADDRfirst would breakINPUT A%for a newA%.input-data,fp-input-data.ucase_lineindexes withYuntil it finds $9B, so it wrapped around forever. It now reportstoo long. Costs 4 bytes. New test:err-line-long.FORloops,DATA FIRST() BYTE=1 : DATA SECOND() BYTE=2putSECONDbeforeFIRST. With 17 DATA arrays in one line, the order wasQ I H G F E D C B A P O N M L K J. Native keeps source order.full_code()takes the blocks from a map ordered by label string (jump_lbl_10<jump_lbl_9), then usesstd::sort, which isn't stable.std::stable_sort.data-order.X=X+1wasn't optimized toINC X(c8ded2b). TheTOK_VAR / x / TOK_PUSH / TOK_NUM / y / TOK_ADDrule matched first, so theINCrule never did, andX=X+1used 5 bytes instead of 2.X=X-1already becameDEC. A new rule matches the rewritten form, coveringX+1and1+X. Saves 3 bytes each infedora.basandstmt-data.bas, and 18 intestloop.bas. The oldTOK_VAR_LOADINC rule is now unreachable and could be removed.parse::peek()(fa23ab9):p >= 'z'should bep <= 'z'. Harmless, as it's only called with':'.Testing
make test: 87/87, which is the 83 existing tests plus the 4 new ones. Each new test fails without its fix.atari-fpandatari-int, except theINCsavings above.-lshas no testsuite coverage, so I checked fixes 1 and 2 by hand on all the samples.fb.xex/fbc.xexgrow by 20 bytes (16 from the FPINPUT_VARtable, 4 from the line check).fbi.xex/fbci.xexgrow by 4.Not in this PR
dmsc/mini65-sim):dosfopen()declareschar fullname[strlen(root) + strlen(name) + 1]but writes"%s/%s", one byte past the end. With Ubuntu 24.04's default_FORTIFY_SOURCE=3, everyfbtestrun aborts with "buffer overflow detected".+ 2fixes it. I ran the tests above with that change applied locally.CHR$/STR$share one buffer:CHR$(65)=CHR$(66)is true.func-chr.chkexpects that, but the manual only mentions the shared buffer for[]slicing.Thanks for FastBasic!
🤖 Generated with Claude Code
https://claude.ai/code/session_01NASRhH2Xg6HmeBUZTSPhwM