Skip to content

Commit

Permalink
Fix example patch tests and stop tracking prev and next tokens (#15)
Browse files Browse the repository at this point in the history
The example patch tests were broken because the parser was
initialized but never run. Additionally, none of the example patches
were complex enough to hit the recursion depth limit. I added a few
longer patches and run the parser, which reproduced the recursion
depth limit within tests.

To fix the recursion limit, which was caused by deep copying tokens,
and by extension all other tokens given that they are doubly linked,
I removed tracking of previous and next tokens. This was initially
implemented to handle multi-word instructions by traversing to
neighboring tokens, but that is now handled by TokenRegistry, and
there are no other apparent use cases. If I find that I need that
functionality in the future, it can be re-implemented and the _clone
method can be rewritten to avoid deeply copying neighboring tokens.
  • Loading branch information
aazuspan authored Aug 13, 2024
1 parent 2be226d commit 16921f1
Show file tree
Hide file tree
Showing 8 changed files with 836 additions and 13 deletions.
11 changes: 0 additions & 11 deletions src/spinasm_lsp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class Token:
The symbol parsed by asfv1 representing the token.
range : lsp.Range
The location range of the token in the source file.
next_token : Token | None
The token that follows this token in the source file.
prev_token : Token | None
The token that precedes this token in the source file.
"""

def __init__(
Expand All @@ -67,8 +63,6 @@ def __init__(

self.symbol: Symbol = symbol
self.range: lsp.Range = lsp.Range(start=start, end=end)
self.next_token: Token | None = None
self.prev_token: Token | None = None

def __repr__(self) -> str:
return self.symbol["stxt"]
Expand Down Expand Up @@ -135,11 +129,6 @@ def register_token(self, token: Token) -> None:
if token.range.start.line not in self._tokens_by_line:
self._tokens_by_line[token.range.start.line] = []

# Record the previous and next token for each token to allow traversing
if self._prev_token:
token.prev_token = self._prev_token
self._prev_token.next_token = token

# Store the token on its line
self._tokens_by_line[token.range.start.line].append(token)
self._prev_token = token
Expand Down
1 change: 0 additions & 1 deletion tests/patches/LICENSE

This file was deleted.

5 changes: 5 additions & 0 deletions tests/patches/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The `Basic` and `GA_DEMO` patches are reproduced from the Spin Semiconductor [Guitar Amp Applications](https://www.spinsemi.com/guitar_amp_application.html) written by Keith Barr, Copyright (C) 2018 Spin Semiconductor, Inc.

The `rev_pl` patches are reproduced from the [Free DSP Programs](https://www.spinsemi.com/programs.php) licensed under the Spin Semiconductor Open Reverb License, and were submitted by Harmon Grold.

The `freeverb` patch is reproduced from an [FV-1 port by basilrush](http://www.spinsemi.com/forum/viewtopic.php?t=309) of the public domain [Freeverb algorithm by Jezar](https://github.com/sinshu/freeverb).
240 changes: 240 additions & 0 deletions tests/patches/freeverb.spn
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
; freeverb from
; http://www.spinsemi.com/forum/viewtopic.php?t=309

; pot0: combfeedback
; pot1:
; pot2:

equ comb1filt 32
equ comb2filt 33
equ comb3filt 34
equ comb4filt 35
equ comb5filt 36
equ comb6filt 37
equ comb7filt 38
equ comb8filt 39

equ combR1filt 32+12
equ combR2filt 33+12
equ combR3filt 34+12
equ combR4filt 35+12
equ combR5filt 36+12
equ combR6filt 37+12
equ combR7filt 38+12
equ combR8filt 39+12

equ combfeedback pot0
equ stereospread 23
equ filtco 0.5
equ allpassamt 0.5
mem comb1 1116
mem comb2 1188
mem comb3 1277
mem comb4 1356
mem comb5 1422
mem comb6 1491
mem comb7 1557
mem comb8 1617

mem combR1 1116+stereospread
mem combR2 1188+stereospread
mem combR3 1277+stereospread
mem combR4 1356+stereospread
mem combR5 1422+stereospread
mem combR6 1491+stereospread
mem combR7 1557+stereospread
mem combR8 1617+stereospread

mem allpass1 556
mem allpass2 441
mem allpass3 341
mem allpass4 225

mem allpassR1 556+stereospread
mem allpassR2 441+stereospread
mem allpassR3 341+stereospread
mem allpassR4 225+stereospread

; LEFT CHANNEL

;* NOW do freeverb style comb with lowpass filters, sum outputs
; output = delay output
; delay-input = [filteredoutput * feedback + input]

; get delay and one pole low pass
rda comb1#, 1-filtco ; read delay output
rdax comb1filt, filtco ; filter using one sample delay
wrax comb1filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb1, 0 ; write to the buffer

rda comb2#, 1-filtco ; read delay output
rdax comb2filt, filtco ; filter using one sample delay
wrax comb2filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb2, 0 ; write to the buffer

rda comb3#, 1-filtco ; read delay output
rdax comb3filt, filtco ; filter using one sample delay
wrax comb3filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb3, 0 ; write to the buffer

rda comb4#, 1-filtco ; read delay output
rdax comb4filt, filtco ; filter using one sample delay
wrax comb4filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb4, 0 ; write to the buffer

rda comb5#, 1-filtco ; read delay output
rdax comb5filt, filtco ; filter using one sample delay
wrax comb5filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb5, 0 ; write to the buffer

rda comb6#, 1-filtco ; read delay output
rdax comb6filt, filtco ; filter using one sample delay
wrax comb6filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb6, 0 ; write to the buffer

rda comb7#, 1-filtco ; read delay output
rdax comb7filt, filtco ; filter using one sample delay
wrax comb7filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb7, 0 ; write to the buffer

rda comb8#, 1-filtco ; read delay output
rdax comb8filt, filtco ; filter using one sample delay
wrax comb8filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra comb8, 0 ; write to the buffer

; RIGHT CHANNEL

;* NOW do freeverb style combR with lowpass filters, sum outputs
; output = delay output
; delay-input = [filteredoutput * feedback + input]

; get delay and one pole low pass
rda combR1#, 1-filtco ; read delay output
rdax combR1filt, filtco ; filter using one sample delay
wrax combR1filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR1, 0 ; write to the buffer

rda combR2#, 1-filtco ; read delay output
rdax combR2filt, filtco ; filter using one sample delay
wrax combR2filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR2, 0 ; write to the buffer

rda combR3#, 1-filtco ; read delay output
rdax combR3filt, filtco ; filter using one sample delay
wrax combR3filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR3, 0 ; write to the buffer

rda combR4#, 1-filtco ; read delay output
rdax combR4filt, filtco ; filter using one sample delay
wrax combR4filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR4, 0 ; write to the buffer

rda combR5#, 1-filtco ; read delay output
rdax combR5filt, filtco ; filter using one sample delay
wrax combR5filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR5, 0 ; write to the buffer

rda combR6#, 1-filtco ; read delay output
rdax combR6filt, filtco ; filter using one sample delay
wrax combR6filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR6, 0 ; write to the buffer

rda combR7#, 1-filtco ; read delay output
rdax combR7filt, filtco ; filter using one sample delay
wrax combR7filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR7, 0 ; write to the buffer

rda combR8#, 1-filtco ; read delay output
rdax combR8filt, filtco ; filter using one sample delay
wrax combR8filt, 1 ; store one sample delay, scale by feedback amount
mulx combfeedback
rdax adcl, 0.5 ; add the input
wra combR8, 0 ; write to the buffer


;LEFT CHANNEL

;* NOW sum outputs
rda comb1#, 1
rda comb2#, 1
rda comb3#, 1
rda comb4#, 1
rda comb5#, 1
rda comb6#, 1
rda comb7#, 1
rda comb8#, 1

; feed through allpass filters in series

; get delay -> add to -1*acc ->

rda allpass1#, -allpassamt
wrap allpass1, allpassamt
rda allpass2#, -allpassamt
wrap allpass2, allpassamt
rda allpass3#, -allpassamt
wrap allpass3, allpassamt
rda allpass4#, -allpassamt
wrap allpass4, allpassamt


;** OUTPUT
wrax dacl, 0

; RIGHT CHANNEL

;* NOW sum outputs
rda combR1#, 1
rda combR2#, 1
rda combR3#, 1
rda combR4#, 1
rda combR5#, 1
rda combR6#, 1
rda combR7#, 1
rda combR8#, 1

; feed through allpass filters in series

; get delay -> add to -1*acc ->

rda allpassR1#, -allpassamt
wrap allpassR1, allpassamt
rda allpassR2#, -allpassamt
wrap allpassR2, allpassamt
rda allpassR3#, -allpassamt
wrap allpassR3, allpassamt
;rda allpassR4#, -allpassamt
;wrap allpassR4, allpassamt

;** OUTPUT
wrax dacr, 0
Loading

0 comments on commit 16921f1

Please sign in to comment.