Spin2 method multiple return values issue
ozpropdev
Posts: 2,793
in Propeller 2
Hi Chip
The code below has 3 method variants, 2 work Ok and the 3rd (oz3) fails.
The oz3 method returns a zero value for the second value instead of 56.
The code below has 3 method variants, 2 work Ok and the 3rd (oz3) fails.
The oz3 method returns a zero value for the second value instead of 56.
'return multiple results test
pub main()|x,y
x,y := oz3(12) 'oz1,oz2 = Ok : oz3 error
if x == 34
pinl(56) '1st result Ok
if y == 56
pinl(57) '2nd result Ok
if y == 0
pinl(59) '2nd result == 0m wrong!
repeat
pub oz1(z) :fred,barney 'works Ok
fred := 34
barney := 56
pub oz2(z) :fred,barney 'works Ok
fred := 34
barney := 56
return
pub oz3(z) :fred,barney '2nd result == 0 wrong!
return 34,56

Comments
' ' ' RETURN Z=0 - return results in stack ' RETURN x,y,z Z=1 - return args on top of stack ' ' ptra = dbase (point to current stack) ' ptra[-6] --> v (top of caller stack) ' ptra[-5] --> pbase | flags (trap_flag in bit 1, push_flag in bit 0) ' ptra[-4] --> vbase ' ptra[-3] --> dbase (lower stack pointer) ' ptra[-2] --> msend ' ptra[-1] --> w (bytecode return pointer) ' ptra -= 6 (point to top of caller stack) ' ' case {trap_flag, push_flag} ' %00: restore caller stack ' %01: return (Z ? stack_args : results) ' %10: restore caller stack ' %11: return 0 ' returnh if_z mov y,ptra 'if returning arg(s), save ptra (x holds last arg) if_nz mov y,dbase 'if returning result(s), save dbase mov ptra,dbase 'ptra points to dbase setq #6-1 'pop v/pbase/vbase/dbase/msend/w rdlong v,--ptra 'ptra points to caller's stack top after pop rczr pbase wcz 'save Z, get trap_flag into C and push_flag into Z if_c_and_z add ptra,#1*4 'if trap_flag and push_flag, return #0 if_c_and_z mov v,#0 if_c_or_nz jmp #.top 'if !push_flag, restore caller's stack top getnib z,w,#5 'get return-value count and decrement djf z,#.top 'if 0 return values, restore caller's stack top add ptra,#1*4 '1..15 return values, inc past caller's stack top testb pbase,#30 wz 'restore Z if_z tjz z,#.xok 'if returning 1 arg, ptra and x are already current if_z neg v,z 'if returning 2..15 args, get offset (-$01..-$0E) if_nz getbyte v,w,#3 'if returning 1..15 results, get offset ($00..$7F) shl v,#2 'scale offset add y,v 'add offset setq z 'read args/results into buff rdlong buff,y setq z 'write args/results into stack wrlong buff,ptra++ sub ptra,#1*4 'set ptra to caller's new stack top if_z skip #%11 'if returning 2..15 args, x is already current alts z,#buff 'set stack top to last result .top mov x,v 'restore/update caller's stack top .xok shl pbase,#2 'restore pbase, clearing two lsb's _ret_ rdfast #0,w 'start new bytecode readIn a little bit, I'll get the latest PNut.exe out, along with the background-PASM ADC program.
just saying...
Mike
That would require the streamer, unless the sample rate was very low, like maybe 1 megahertz. Dairy Queen in Polish
Wow, my phone just put that last sentence in. No idea what it heard.
That would be kostiumami
also costume shop or swimsuit?
Mike