Skip to content

Commit

Permalink
Allow Spin2 structs to access their parent's symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Dec 8, 2024
1 parent f00fd01 commit 7bc1389
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Test/Expect/stest314.p2asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
con
_clkfreq = 20000000
_clkmode = 16779595
ARR_SIZ = 12
dat
nop
cogid pa
coginit pa,##$404
orgh $10
long 0 'reserved
long 0 ' clock frequency: will default to 20000000
long 0 ' clock mode: will default to $100094b
orgh $400
_ret_ mov result1, #0
org 0
entry

_zb
add arg02, arg01
rdbyte result1, arg02
add result1, #12
_zb_ret
ret
builtin_bytefill_
shr arg03, #1 wc
if_c wrbyte arg02, arg01
if_c add arg01, #1
movbyts arg02, #0
builtin_wordfill_
shr arg03, #1 wc
if_c wrword arg02, arg01
if_c add arg01, #2
setword arg02, arg02, #1
builtin_longfill_
wrfast #0,arg01
cmp arg03, #0 wz
if_nz rep #1, arg03
if_nz wflong arg02
ret

result1
long 0
COG_BSS_START
fit 480
orgh
org COG_BSS_START
arg01
res 1
arg02
res 1
fit 480
8 changes: 8 additions & 0 deletions Test/stest314.spin2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{$Spin2_v46}

CON
ARR_SIZ = 12
STRUCT st( byte a[ARR_SIZ] )

PUB zb(^st b, i) : r
r := b.a[i] + sizeof(b)
5 changes: 4 additions & 1 deletion frontends/spin/spin.y
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ SpinDeclareStruct(AST *ident, AST *defs)
current->subclasses = P;
P->superclass = current;
P->fullname = current->fullname; // for finding "class using"
newobj->d.ptr = (void *)P;
newobj->d.ptr = (void *)P;
P->isPacked = 1;

/* import parent's symbols into P */
P->objsyms.next = &current->objsyms;
}

PushCurrentModule();
Expand Down

0 comments on commit 7bc1389

Please sign in to comment.