Skip to content

Commit

Permalink
Misc Update
Browse files Browse the repository at this point in the history
- Fix highlighting of multiple same-name constants in con declaration
- Fix highlighting of variable and method names in debug() statements
- Fix highlighting of constant names in case statements with constant range as match case
- Fix highlighting of org constant name as offset
- Fix highlighting of constant names in complex constant assignment
  • Loading branch information
ironsheep committed May 5, 2022
1 parent 6047055 commit 058d4ad
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 11 deletions.
19 changes: 18 additions & 1 deletion spin2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ Possible next additions:
- Add new-file templates as Snippets
- Add additional Snippets as the community identifies them

## [1.3.7] 2022-05-05

### Miscellaneous semantic highlight fixes

- Fix highlighting of multiple same-name constants in con declaration
- Fix highlighting of variable and method names in debug() statements
- Fix highlighting of constant names in case statements with constant range as match case
- Fix highlighting of org constant name as offset
- Fix highlighting of constant names in complex constant assignment

### - Known Issues w/v1.3.7

- Sadly, The single-quote comment now being handled as semantic (vs. syntactic) is causing external VSCode extensions to do brace, parenthesis, and bracket paring to be marked within our trailing line comments. *We have don't have a fix for this yet.*
- Syntax highlight of DAT section sometimes fails... (although it is less often now...)
- Semantic highlight: the 'modification' attribute is being over-applied, should use more than := as test!!!!
- *I'm sure there are more issues...*

## [1.3.6] 2022-04-22

### Improve debug() highlight methods and named operators correctly - misc fixes
Expand All @@ -31,7 +48,7 @@ Possible next additions:

### - Known Issues w/v1.3.6

- Sadly, The single-quote comment now being handled as semantic (vs. syntactic) is causing external VSCode extensions to do brace, parenthesis, and bracket paring to be marked within our trailing line comments. *We have don't have a fix for this yet.*
- The single-quote comment now being handled as semantic (vs. syntactic) is causing external VSCode extensions to do brace, parenthesis, and bracket paring to be marked within our trailing line comments. *We have don't have a fix for this yet.*
- Syntax highlight of DAT section sometimes fails... (although it is less often now...)
- Semantic highlight: the 'modification' attribute is being over-applied, should use more than := as test!!!!
- *I'm sure there are more issues...*
Expand Down
173 changes: 173 additions & 0 deletions spin2/TEST/220505-fixes.spin2
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
' --------------------------------------------------------------------------------------------------
OBJ

serialIF : "isp_serial_singleton" ' serial I/O
serialQueue : "isp_queue_serial" ' Queued Receive on top of serial I/O

CON

MAX_LEN_USERMSG = 128
WAIT_FOR_STRING = TRUE

DAT
userMsgBuffer BYTE 0[MAX_LEN_USERMSG+1]

PRI handleResponseFor(pStr)
serialQueue.getLine(@userMsgBuffer, MAX_LEN_USERMSG, WAIT_FOR_STRING)
if not strHasPrefix(@userMsgBuffer, pStr)
debug("hrf: unexpected response!")
debug("hrf: ERROR: [", zstr_(pStr), "] NOT found in [", zstr_(@userMsgBuffer), "]")
else
debug("hrf: RX str(", udec_(strsize(pStr)), ")=[", zstr_(pStr), "]") ' <-- missing this strsize should NOT be RED!

PRI strHasPrefix(pTargetStr, pPrefix) : bHasStatus | nIdx
bHasStatus := TRUE
repeat nIdx from 0 to strsize(pPrefix) - 1
if BYTE[pTargetStr][nIdx] <> BYTE[pPrefix][nIdx]
bHasStatus := False
quit ' outta here, we have our answer!

' --------------------------------------------------------------------------------------------------

DAT
bDbgShoMem long FALSE
PRI copyWrappedStr(pUserDest, pSrcStr, lenDest) | nIdx, pSrc, pDest
pDest := pUserDest
pSrc:= pSrcStr
repeat nIdx from 0 to lenDest - 1
' if pointing beyond end, wrap to front!
if BYTE[pSrc] == 0
quit ' at string end, quit loop
BYTE[pDest++] := BYTE[pSrc++]
BYTE[pDest] := 0 ' place final terminator
if bDbgShoMem
debug("-- cws: str(", udec_(strsize(pSrcStr)), ")=[", zstr_(pUserDest), "]") ' <-- missing this strsize should NOT be RED!

' --------------------------------------------------------------------------------------------------

PUB demo() | x, y, fgcol, bgcol, ch, grey, col1, col2, idx

DEBUG("VGA text demo", 13, 10)

' start up the VGA driver
DEBUG("screen started", 13, 10)
DEBUG("clock frequency: ", udec(CLKFREQ), 13, 10) ' <-- missing this CLKFREQ should NOT be RED!

' --------------------------------------------------------------------------------------------------

CON
intensity = 80 '0..128

FIELD_HANDLER = $300 ' location of pixel subroutine in LUT memory
FIELD_HANDLER_END = $3a0
LINE_HANDLER = $3a0
LINE_HANDLER_END = $3ff

DAT

'' 8 bytes/character
'' 24 instructions: so sysclock >= 3 * pixel clock

org LINE_HANDLER ' <-- this should be colored as constant
char8_loop

' --------------------------------------------------------------------------------------------------

CON

PSG_FREQ = 2_000_000.0 ' Clock frequency input on the emulated AY chip
SAMPLE_RATE = round(PSG_FREQ/ 16.0) ' Sample rate of AYcog (PSG_FREQ/ 16.0 is the HW-accurate value)

OSC_CORR = trunc(1.05 * PSG_FREQ * ((PSG_FREQ/ 16.0)/float(SAMPLE_RATE))) ' ' <=== whaaaa ?PSG_FREQ?

' --------------------------------------------------------------------------------------------------

CON
BASE = 2
SIGN_SHIFT = 31
EXP_OFFSET = 127 ' offset for exponent field
EXP_SHIFT = 23 ' shift for reading the exponent field
MAX_EXP = 255
EXP_MASK = MAX_EXP
MIN_SIG = $800_000 ' smallest significand
MIN_SIG_BITS = 23
MAX_SIG = BASE*MIN_SIG ' one more than the largest significand
MAX_SIG_DIGITS = 24 ' number of BASE digits in MIN_SIG

' some special values
NEG_ZERO = $8000_0000
F_INF = MAX_EXP << EXP_SHIFT
F_NEG_INF = NEG_ZERO | F_INF
ONE = (BASE==10) ? ((EXP_OFFSET << EXP_SHIFT) | MIN_SIG) : (EXP_OFFSET<<EXP_SHIFT) ' <=== whaaa???

' --------------------------------------------------------------------------------------------------

CON

'Command Buffer
CMD_BUF_SIZE = 256

'Response/Message Buffer
RESP_BUF_SIZE = 1024
RESP_STR_NUM = 64
NO_MORE_DATA_TIMEOUT = 10

'Response Types
RESP_OK = 0
RESP_ERROR = 1
RESP_OVER = 2
RESP_SEND_FAIL = 3
RESP_TIMEOUT = 4
RESP_NOT_FOUND = 5
RESP_SEND_OK = 6
RESP_FOUND_MESSAGE = 7
RESP_SIZE_MATCH = 8

DAT
'Error
last_error long 0

pub error(mod,fc,err) : error_code | s
error_code := err
case err
RESP_OK :
RESP_ERROR : ' get esp32 error code if any
s := find_string_in_rxbuf(string("ERR CODE:"))
if s
s += 13
byte[s][2] := 0
s := convert_str_to_hex_value(s)
error_code.byte[3] := mod
error_code.byte[2] := fc
error_code.byte[1] := s
RESP_OVER..RESP_NOT_FOUND : error_code.byte[3] := mod ' <=== whaaa???
error_code.byte[2] := fc
RESP_SEND_OK..RESP_SIZE_MATCH : error_code := 0 ' <=== whaaa???
last_error := error_code

pub find_string_in_rxbuf(mptr) : result
'return find_string(mptr,@rxbuf,rxbytes)

'range 0 - 100000000
pub convert_str_to_hex_value(s) : h | i, sz, x, y
sz := strsize(s)
x := 1
repeat i from 1 to sz
y := byte[s][sz - i] - $30
y := y > 9 ? (y - 7) & $DF : y
h := h + (y * x)
x := x * 16

' --------------------------------------------------------------------------------------------------

PUB setup( )
{{ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function to initialize driver and display. So, it should reset
the display and do whatever is needed to initialize it for
operation.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }}

' and initialize the display
debug(`bitmap D title 'DisplayEmulation' SIZE 240 240 RGB16 TRACE 0 RATE 57600 SCROLL 0 0) ' <=== SCROLL is on FEED, not declare! So fix this? or not?

' --------------------------------------------------------------------------------------------------
11 changes: 11 additions & 0 deletions spin2/TEST/github_issue_05.spin2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

DAT
srmfile long FALSE

' autosave
pub main()
if srmfile and long[$e4] and (getct() - long[$e4]) >= clkfreq*3
long[$e4] := 0 'clear first, so if we gat another write while we're busy, it will stiiil be autosaved later
flush_sram()

PRI flush_sram()
2 changes: 1 addition & 1 deletion spin2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Spin2",
"description": "Spin2/Pasm2 Syntax/Semantic Highlighting w/Code Outline support",
"icon": "images/Propeller.ico",
"version": "1.3.6",
"version": "1.3.7",
"publisher": "IronSheepProductionsLLC",
"repository": {
"type": "git",
Expand Down
35 changes: 26 additions & 9 deletions spin2/src/spin2.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,9 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
tokenModifiers: ['readonly', 'missingDeclaration']
});
}

const assignmentRHSStr = assignmentParts[1].trim();
// remove pront LHS of assignment and process remainder
const fistEqualOffset: number = conDeclarationLine.indexOf('=');
const assignmentRHSStr = conDeclarationLine.substring(fistEqualOffset + 1).trim();
currentOffset = line.indexOf(assignmentRHSStr) // skip to RHS of assignment
this._logCON(' -- CON assignmentRHSStr=[' + assignmentRHSStr + ']');
const possNames: string[] = this._getNonWhiteCONLineParts(assignmentRHSStr);
Expand All @@ -1158,6 +1159,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
}
this._logCON(' -- possibleNameSet=[' + possibleNameSet + ']');
const namePart = possibleNameSet[0];
let matchLen: number = namePart.length;
const searchString: string = (possibleNameSet.length == 1) ? possibleNameSet[0] : possibleNameSet[0] + '.' + possibleNameSet[1]
let referenceDetails: IRememberedToken | undefined = undefined;
const nameOffset = line.indexOf(searchString, currentOffset);
Expand All @@ -1170,7 +1172,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
tokenSet.push({
line: lineNumber,
startCharacter: nameOffset,
length: namePart.length,
length: matchLen,
tokenType: referenceDetails.tokenType,
tokenModifiers: referenceDetails.tokenModifiers
});
Expand All @@ -1181,7 +1183,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
tokenSet.push({
line: lineNumber,
startCharacter: nameOffset,
length: namePart.length,
length: matchLen,
tokenType: 'variable',
tokenModifiers: ['readonly', 'missingDeclaration']
});
Expand All @@ -1192,6 +1194,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
// this can NOT be a method name it can only be a constant name
const referenceOffset = line.indexOf(searchString, currentOffset);
const constantPart: string = possibleNameSet[1];
matchLen = constantPart.length;
const nameOffset = line.indexOf(constantPart, referenceOffset)
this._logCON(' -- constantPart=[' + namePart + '](' + nameOffset + ')');
tokenSet.push({
Expand All @@ -1202,6 +1205,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
tokenModifiers: ['readonly']
});
}
currentOffset += matchLen; // skip past this name
}
}
}
Expand Down Expand Up @@ -1251,8 +1255,8 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
this._logVAR('- rptDataDeclLn lineParts=[' + lineParts + ']');
// remember this object name so we can annotate a call to it
if (lineParts.length > 1) {
if (this._isStorageType(lineParts[0]) || lineParts[0].toUpperCase() == "FILE") {
// if we start with storage type (or FILE), not name, process rest of line for symbols
if (this._isStorageType(lineParts[0]) || lineParts[0].toUpperCase() == "FILE" || lineParts[0].toUpperCase() == "ORG") {
// if we start with storage type (or FILE, or ORG), not name, process rest of line for symbols
currentOffset = line.indexOf(lineParts[0], currentOffset);
const allowLocalVarStatus: boolean = false;
const NOT_DAT_PASM: boolean = false;
Expand Down Expand Up @@ -1874,7 +1878,11 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
varNameList = possibleVariableName.split(',');
}
if (possibleVariableName.includes(" ")) {
const lineInfo: IFilteredStrings = this._getNonWhiteSpinLineParts(possibleVariableName);
// force special case range chars to be removed
// Ex: RESP_OVER..RESP_NOT_FOUND : error_code.byte[3] := mod
// change .. to : so it is removed by getNonWhite...
const filteredLine: string = possibleVariableName.replace('..', ':');
const lineInfo: IFilteredStrings = this._getNonWhiteSpinLineParts(filteredLine);
varNameList = lineInfo.lineParts;
}
this._logSPIN(' -- LHS: varNameList=[' + varNameList + ']');
Expand Down Expand Up @@ -2926,7 +2934,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
else {
// handle unknown-name case
const paramIsSymbolName: boolean = newParameter.substring(0, 1).match(/[a-zA-Z_]/) ? true : false; // 3 xyzzy
if (paramIsSymbolName && !this._isDebugMethod(newParameter) && !this._isBinaryOperator(newParameter) && !this._isUnaryOperator(newParameter) && !this._isFloatConversion(newParameter)) {
if (paramIsSymbolName && !this._isDebugMethod(newParameter) && !this._isBinaryOperator(newParameter) && !this._isUnaryOperator(newParameter) && !this._isFloatConversion(newParameter) && !this._isSpinBuiltinMethod(newParameter) && !this._isSpinBuiltInVariable(newParameter)) {
this._logDEBUG(' -- debug() 3 unkParam=[' + newParameter + ']');
tokenSet.push({
line: lineNumber,
Expand Down Expand Up @@ -3577,7 +3585,7 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke

private _getNonWhiteCONLineParts(line: string): string[] {
const nonEqualsLine: string = this._removeDoubleQuotedStrings(line);
let lineParts: string[] | null = nonEqualsLine.match(/[^ \t\(\)\*\+\-\/\>\<]+/g);
let lineParts: string[] | null = nonEqualsLine.match(/[^ \t\(\)\*\+\-\/\>\<\=]+/g);
if (lineParts === null) {
lineParts = [];
}
Expand Down Expand Up @@ -3969,6 +3977,15 @@ class Spin2DocumentSemanticTokensProvider implements vscode.DocumentSemanticToke
return reservedStatus;
}

private _isSpinBuiltInVariable(name: string): boolean {
const spinVariablesOfNote: string[] = [
'clkmode', 'clkfreq', 'varbase',
'pr0', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'pr6', 'pr7', 'ijmp1', 'ijmp2', 'ijmp3', 'iret1',
'iret2', 'iret3', 'pa', 'pb', 'ptra', 'ptrb', 'dira', 'dirb', 'outa', 'outb', 'ina', 'inb',
];
let reservedStatus: boolean = (spinVariablesOfNote.indexOf(name.toLowerCase()) != -1);
return reservedStatus;
}

private _isSpinReservedWord(name: string): boolean {
const spinInstructionsOfNote: string[] = [
Expand Down

0 comments on commit 058d4ad

Please sign in to comment.