sys.push(), sys.pop() etc etc are now builtin functions again push() pop() to avoid storing value in temporary variables

this means that all of the syslib.p8 library files no longer contain all those stack related asmsubs
This commit is contained in:
Irmen de Jong
2026-02-21 00:59:42 +01:00
parent 9aff85f08a
commit 093be9f2dd
55 changed files with 502 additions and 1256 deletions
@@ -1,5 +1,6 @@
Prog8 compiler v12.1.1 by Irmen de Jong (irmen@razorvine.net)
Prog8 compiler v12.2-SNAPSHOT by Irmen de Jong (irmen@razorvine.net)
Prerelease version from git commit 9aff85f0 in branch master
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiling program import-all-c128.p8
@@ -52,10 +53,10 @@ smallstack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> ubyte
}
@@ -66,10 +67,10 @@ stack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> uword
}
@@ -645,15 +646,9 @@ sys {
memcopy (uword source @R0, uword target @R1, uword count @AY) clobbers (A,X,Y)
memset (uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers (A,X,Y)
memsetw (uword mem @R0, uword numwords @R1, uword value @AY) clobbers (A,X,Y)
pop () -> ubyte @A
popl () -> long @R0R1
popw () -> uword @AY
progend () -> uword @AY
progstart () -> uword @AY
push (ubyte value @A)
push_returnaddress (uword address @XY)
pushl (long value @R0R1)
pushw (uword value @AY)
read_flags () -> ubyte @A
reset_system ()
restore_irq () clobbers (A)
@@ -1,5 +1,6 @@
Prog8 compiler v12.1.1 by Irmen de Jong (irmen@razorvine.net)
Prog8 compiler v12.2-SNAPSHOT by Irmen de Jong (irmen@razorvine.net)
Prerelease version from git commit 9aff85f0 in branch master
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiling program import-all-c64.p8
@@ -52,10 +53,10 @@ smallstack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> ubyte
}
@@ -66,10 +67,10 @@ stack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> uword
}
@@ -307,10 +308,8 @@ floats {
minf (float f1, float f2) -> float
normalize (float value @FAC1) -> float @FAC1
parse (str value @AY) -> float @FAC1
pop () -> float @FAC1
pow (float value, float power) -> float
print (float value @FAC1) clobbers (A,X,Y)
push (float value @FAC1)
rad (float angle) -> float
rnd () -> float
rndseed (float seed)
@@ -758,15 +757,9 @@ sys {
memcopy (uword source @R0, uword target @R1, uword count @AY) clobbers (A,X,Y)
memset (uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers (A,X,Y)
memsetw (uword mem @R0, uword numwords @R1, uword value @AY) clobbers (A,X,Y)
pop () -> ubyte @A
popl () -> long @R0R1
popw () -> uword @AY
progend () -> uword @AY
progstart () -> uword @AY
push (ubyte value @A)
push_returnaddress (uword address @XY)
pushl (long value @R0R1)
pushw (uword value @AY)
read_flags () -> ubyte @A
reset_system ()
restore_irq () clobbers (A)
@@ -1,5 +1,6 @@
Prog8 compiler v12.1.1 by Irmen de Jong (irmen@razorvine.net)
Prog8 compiler v12.2-SNAPSHOT by Irmen de Jong (irmen@razorvine.net)
Prerelease version from git commit 9aff85f0 in branch master
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiling program import-all-cx16.p8
@@ -91,10 +92,10 @@ smallstack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> ubyte
}
@@ -105,10 +106,10 @@ stack {
init (ubyte rambank)
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> uword
}
@@ -403,10 +404,8 @@ floats {
minf (float f1, float f2) -> float
normalize (float value @FAC1) -> float @FAC1
parse (str value @AY) -> float @FAC1
pop () -> float @FAC1
pow (float value, float power) -> float
print (float value @FAC1) clobbers (A,X,Y)
push (float value @FAC1)
rad (float angle) -> float
rnd () -> float
rndseed (float seed)
@@ -1421,16 +1420,10 @@ sys {
memcopy (uword source @R0, uword target @R1, uword count @AY) clobbers (A,X,Y)
memset (uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers (A,X,Y)
memsetw (uword mem @R0, uword numwords @R1, uword value @AY) clobbers (A,X,Y)
pop () -> ubyte @A
popl () -> long @R0R1
popw () -> uword @AY
poweroff_system ()
progend () -> uword @AY
progstart () -> uword @AY
push (ubyte value @A)
push_returnaddress (uword address @XY)
pushl (long value @R0R1)
pushw (uword value @AY)
read_flags () -> ubyte @A
reset_system ()
restore_irq () clobbers (A)
@@ -1,5 +1,6 @@
Prog8 compiler v12.1.1 by Irmen de Jong (irmen@razorvine.net)
Prog8 compiler v12.2-SNAPSHOT by Irmen de Jong (irmen@razorvine.net)
Prerelease version from git commit 9aff85f0 in branch master
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiling program import-all-pet32.p8
@@ -52,10 +53,10 @@ smallstack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> ubyte
}
@@ -66,10 +67,10 @@ stack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> uword
}
@@ -271,10 +272,8 @@ floats {
log2 (float value) -> float
maxf (float f1, float f2) -> float
minf (float f1, float f2) -> float
pop () -> float @FAC1
pow (float value, float power) -> float
print (float value @FAC1) clobbers (A,X,Y)
push (float value @FAC1)
rad (float angle) -> float
rndseed (float seed)
round (float value) -> float
@@ -582,15 +581,9 @@ sys {
memcopy (uword source @R0, uword target @R1, uword count @AY) clobbers (A,X,Y)
memset (uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers (A,X,Y)
memsetw (uword mem @R0, uword numwords @R1, uword value @AY) clobbers (A,X,Y)
pop () -> ubyte @A
popl () -> long @R0R1
popw () -> uword @AY
progend () -> uword @AY
progstart () -> uword @AY
push (ubyte value @A)
push_returnaddress (uword address @XY)
pushl (long value @R0R1)
pushw (uword value @AY)
read_flags () -> ubyte @A
reset_system ()
restore_prog8_internals ()
@@ -1,5 +1,6 @@
Prog8 compiler v12.1.1 by Irmen de Jong (irmen@razorvine.net)
Prog8 compiler v12.2-SNAPSHOT by Irmen de Jong (irmen@razorvine.net)
Prerelease version from git commit 9aff85f0 in branch master
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiling program import-all-virtual.p8
@@ -32,10 +33,10 @@ smallstack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> ubyte
}
@@ -46,10 +47,10 @@ stack {
init ()
isempty () -> bool
isfull () -> bool
pop () -> ubyte
popw () -> uword
push (ubyte value)
pushw (uword value)
pop_b () -> ubyte
pop_w () -> uword
push_b (ubyte value)
push_w (uword value)
size () -> uword
}
@@ -192,10 +193,8 @@ floats {
minf (float f1, float f2) -> float
normalize (float value) -> float
parse (str value) -> float
pop () -> float
pow (float value, float power) -> float
print (float value)
push (float value)
rad (float angle) -> float
rnd () -> float
rndseed (float seed)
@@ -391,15 +390,9 @@ sys {
memcopy (uword source, uword tgt, uword count)
memset (uword mem, uword numbytes, ubyte value)
memsetw (uword mem, uword numwords, uword value)
pop () -> ubyte
popl () -> long
popw () -> uword
progend () -> uword
progstart () -> uword
push (ubyte b)
push_returnaddress (uword w)
pushl (long l)
pushw (uword w)
read_flags () -> ubyte
reset_system ()
restore_prog8_internals ()
+39 -24
View File
@@ -88,6 +88,43 @@ Math
Accepts unsigned integer (result is ubyte), long (result is uword), and floating point numbers.
To do the reverse - squaring a number - just write ``x*x``.
CPU Stack
^^^^^^^^^
:index:`push` (value)
pushes a byte value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
:index:`pushw` (value)
pushes a 16-bit word value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
Don't assume anything about the order in which the bytes are pushed - popw will make sense of them again.
:index:`pushl` (value)
pushes a 32-bit value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
Don't assume anything about the order in which the bytes are pushed - popl will make sense of them again.
:index:`pushf` (value)
pushes a floating point value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
Don't assume anything about the order in which the bytes are pushed - popf will make sense of them again.
:index:`pop` ()
pops a byte value off the CPU hardware stack and returns it.
Low-level function that is seldomly used in user code.
:index:`popw` ()
pops a 16-bit word value off the CPU hardware stack that was pushed before by pushw, and returns it.
Low-level function that is seldomly used in user code.
:index:`popl` ()
pops a 32-bit value off the CPU hardware stack that was pushed before by pushl, and returns it.
Low-level function that is seldomly used in user code.
:index:`popf` ()
pops a floating point value off the CPU hardware stack that was pushed before by pushl, and returns it.
Low-level function that is seldomly used in user code.
Miscellaneous
^^^^^^^^^^^^^
@@ -1433,36 +1470,14 @@ processor stack
'''''''''''''''
.. index:: pair: Libraries; processor stack
``push (value)``
pushes a byte value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
``pushw (value)``
pushes a 16-bit word value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
Don't assume anything about the order in which the bytes are pushed - popw will make sense of them again.
``pushl (value)``
pushes a 32-bit value on the CPU hardware stack.
Low-level function that is seldomly used in user code.
Don't assume anything about the order in which the bytes are pushed - popl will make sense of them again.
Pushing and popping values on the CPU hardware stack can be done via the stack related :ref:`builtinfunctions` (pop, push etc).
There is a very specialized function in the sys module here as well:
``push_returnaddress (address)``
pushes a 16 bit memory address on the CPU hardware stack in the same byte order as a JSR instruction would,
which means the next RTS instruction will jump to that address instead.you
You cannot use pushw() for this because the bytes pushed by JSR are different
``pop ()``
pops a byte value off the CPU hardware stack and returns it.
Low-level function that is seldomly used in user code.
``popw ()``
pops a 16-bit word value off the CPU hardware stack that was pushed before by pushw, and returns it.
Low-level function that is seldomly used in user code.
``popl ()``
pops a 32-bit value off the CPU hardware stack that was pushed before by pushl, and returns it.
Low-level function that is seldomly used in user code.
textio (txt.*)
+1 -6
View File
@@ -1193,17 +1193,12 @@ flag such as Carry (Pc).
It is not possible to use floating point arguments or return values in an asmsub.
**inline:** Trivial ``asmsub`` routines can be tagged as ``inline`` to tell the compiler to copy their code
in-place to the locations where the subroutine is called, rather than inserting an actual call and return to the
subroutine. This may increase code size significantly and can only be used in limited scenarios, so YMMV.
Note that the routine's code is copied verbatim into the place of the subroutine call in this case,
so pay attention to any jumps and rts instructions in the inlined code!
.. note::
Asmsubs can also be tagged as ``inline asmsub`` to make trivial pieces of assembly inserted
directly instead of a call to them. Note that it is literal copy-paste of code that is done,
so make sure the assembly is actually written to behave like such - which probably means you
don't want a ``rts`` or ``jmp`` or ``bra`` in it!
Inlining may increase code size significantly and can only be used in limited scenarios
.. note::
The **sixteen 'virtual' 16-bit registers** from the Commander X16 can also be specified as ``R0`` .. ``R15`` .
-4
View File
@@ -1,10 +1,6 @@
TODO
====
push() and pop() (and pushw, pushl etc) should be builtin functions again instead of subs in sys, because you really want to avoid filling an intermediate parameter variable first before it actually does the pha/pla's
add a nice conversion error message for that.
Known bugs:
- fix chained aliasing errors see test "chained aliasing"
- fix crash in ir loader/vm for deeply nested symbol reference, see test "deeply scoped variable references"