added sys.push() and sys.pop() to put values on cpu stack. Added missing builtin functions to syntax-files.

This commit is contained in:
Irmen de Jong 2021-11-27 18:09:15 +01:00
parent 62485b6851
commit e8e25c6fd6
8 changed files with 117 additions and 20 deletions

View File

@ -67,6 +67,8 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
"peek" -> throw AssemblyError("peek() should have been replaced by @()")
"pokew" -> funcPokeW(fcall)
"poke" -> throw AssemblyError("poke() should have been replaced by @()")
// "push", "pushw" -> funcPush(fcall, func)
// "pop", "popw" -> funcPop(func)
"cmp" -> funcCmp(fcall)
"callfar" -> funcCallFar(fcall)
"callrom" -> funcCallRom(fcall)
@ -74,6 +76,30 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
}
}
// private fun funcPop(func: FSignature) {
// if(func.name=="pop") {
// asmgen.out(" pla")
// } else {
// if (asmgen.isTargetCpu(CpuType.CPU65c02))
// asmgen.out(" ply | pla")
// else
// asmgen.out(" pla | tay | pla")
// }
// }
//
// private fun funcPush(fcall: IFunctionCall, func: FSignature) {
// if(func.name=="push") {
// asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.A)
// asmgen.out(" pha")
// } else {
// asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
// if (asmgen.isTargetCpu(CpuType.CPU65c02))
// asmgen.out(" pha | phy")
// else
// asmgen.out(" pha | tya | pha")
// }
// }
private fun funcCallFar(fcall: IFunctionCall) {
if(asmgen.options.compTarget !is Cx16Target)
throw AssemblyError("callfar only works on cx16 target at this time")

View File

@ -627,32 +627,60 @@ _longcopy
inline asmsub read_flags() -> ubyte @A {
%asm {{
php
pla
php
pla
}}
}
inline asmsub push(ubyte @A) {
%asm {{
pha
}}
}
inline asmsub pop() -> ubyte @A {
%asm {{
pla
}}
}
inline asmsub pushw(uword @AY) {
%asm {{
pha
tya
pha
}}
}
inline asmsub popw() -> uword @AY {
%asm {{
pla
tay
pla
}}
}
inline asmsub clear_carry() {
%asm {{
clc
clc
}}
}
inline asmsub set_carry() {
%asm {{
sec
sec
}}
}
inline asmsub clear_irqd() {
%asm {{
cli
cli
}}
}
inline asmsub set_irqd() {
%asm {{
sei
sei
}}
}

View File

@ -887,27 +887,53 @@ sys {
}}
}
inline asmsub push(ubyte value @A) {
%asm {{
pha
}}
}
inline asmsub pop() -> ubyte @A {
%asm {{
pla
}}
}
inline asmsub pushw(uword value @AY) {
%asm {{
pha
phy
}}
}
inline asmsub popw() -> uword @AY {
%asm {{
ply
pla
}}
}
inline asmsub clear_carry() {
%asm {{
clc
clc
}}
}
inline asmsub set_carry() {
%asm {{
sec
sec
}}
}
inline asmsub clear_irqd() {
%asm {{
cli
cli
}}
}
inline asmsub set_irqd() {
%asm {{
sei
sei
}}
}

View File

@ -142,6 +142,10 @@ private val functionSignatures: List<FSignature> = listOf(
FSignature("peekw" , true, listOf(FParam("address", arrayOf(DataType.UWORD))), DataType.UWORD),
FSignature("poke" , false, listOf(FParam("address", arrayOf(DataType.UWORD)), FParam("value", arrayOf(DataType.UBYTE))), null),
FSignature("pokew" , false, listOf(FParam("address", arrayOf(DataType.UWORD)), FParam("value", arrayOf(DataType.UWORD))), null),
// FSignature("pop" , false, emptyList(), DataType.UBYTE),
// FSignature("popw" , false, emptyList(), DataType.UWORD),
// FSignature("push" , false, listOf(FParam("value", ByteDatatypes)), null),
// FSignature("pushw" , false, listOf(FParam("value", WordDatatypes)), null),
FSignature("rnd" , false, emptyList(), DataType.UBYTE),
FSignature("rndw" , false, emptyList(), DataType.UWORD),
FSignature("rndf" , false, emptyList(), DataType.FLOAT),

View File

@ -1,13 +1,26 @@
%import test_stack
main {
sub start() {
uword ww
test_stack.test()
main.routine2.num = ww+1
main.routine2.switch=true
sys.push(-22 as ubyte)
sys.push(44)
sys.pushw(-11234 as uword)
sys.pushw(12345)
sys.push(1)
sys.push(2)
ubyte @shared ub = sys.pop()
byte @shared bb = sys.pop() as byte
uword @shared uw = sys.popw()
word @shared ww = sys.popw() as word
void sys.pop()
void sys.pop()
routine2(ww+1, true)
; routine2(uw+1, true)
test_stack.test()
repeat {
}

View File

@ -14,7 +14,7 @@
<keywords keywords="&amp;;-&gt;;@;\$;and;as;asmsub;break;clobbers;do;downto;else;false;for;goto;if;if_cc;if_cs;if_eq;if_mi;if_ne;if_neg;if_nz;if_pl;if_pos;if_vc;if_vs;if_z;in;inline;not;or;repeat;return;romsub;step;sub;to;true;until;when;while;xor;~" ignore_case="false" />
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%zeropage;%zpreserved" />
<keywords3 keywords="byte;const;float;shared;str;ubyte;uword;void;word;zp" />
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;callfar;callrom;ceil;cmp;cos;cos16;cos16u;cos8;cos8u;deg;floor;len;ln;log2;lsb;lsl;lsr;max;memory;min;mkword;msb;peek;peekw;poke;pokew;rad;reverse;rnd;rndf;rndw;rol;rol2;ror;ror2;round;sgn;sin;sin16;sin16u;sin8;sin8u;sizeof;sort;sqrt;sqrt16;sum;swap;tan" />
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;callfar;callrom;ceil;cmp;cos;cos16;cos16u;cos8;cos8u;cosr16;cosr16u;cosr8;cosr8u;deg;floor;len;ln;log2;lsb;lsl;lsr;max;memory;min;mkword;msb;peek;peekw;poke;pokew;rad;reverse;rnd;rndf;rndw;rol;rol2;ror;ror2;round;sgn;sin;sin16;sin16u;sin8;sin8u;sinr16;sinr16u;sinr8;sinr8u;sizeof;sort;sqrt;sqrt16;sum;swap;tan" />
</highlighting>
<extensionMap>
<mapping ext="p8" />

View File

@ -27,7 +27,7 @@
<Keywords name="Keywords1">void const&#x000D;&#x000A;str&#x000D;&#x000A;byte ubyte&#x000D;&#x000A;word uword&#x000D;&#x000A;float&#x000D;&#x000A;zp shared</Keywords>
<Keywords name="Keywords2">%address&#x000D;&#x000A;%asm&#x000D;&#x000A;%asmbinary&#x000D;&#x000A;%asminclude&#x000D;&#x000A;%breakpoint&#x000D;&#x000A;%import&#x000D;&#x000A;%launcher&#x000D;&#x000A;%option&#x000D;&#x000A;%output&#x000D;&#x000A;%zeropage&#x000D;&#x000A;%zpreserved</Keywords>
<Keywords name="Keywords3">inline sub asmsub romsub&#x000D;&#x000A;clobbers&#x000D;&#x000A;asm&#x000D;&#x000A;if&#x000D;&#x000A;when else&#x000D;&#x000A;if_cc if_cs if_eq if_mi if_neg if_nz if_pl if_pos if_vc if_vs if_z&#x000D;&#x000A;for in step do while repeat&#x000D;&#x000A;break return goto</Keywords>
<Keywords name="Keywords4">abs acos all any asin atan avg callfar callrom ceil cmp cos cos16 cos16u cos8 cos8u deg floor len ln log2 lsb lsl lsr max memory min mkword msb peek peekw poke pokew rad reverse rnd rndf rndw rol rol2 ror ror2 round sgn sin sin16 sin16u sin8 sin8u sizeof sort sqrt sqrt16 sum swap tan&#x000D;&#x000A;</Keywords>
<Keywords name="Keywords4">abs acos all any asin atan avg callfar callrom ceil cmp cos cos16 cos16u cos8 cos8u cosr8 cosr8u cosr16 cosr16u deg floor len ln log2 lsb lsl lsr max memory min mkword msb peek peekw poke pokew rad reverse rnd rndf rndw rol rol2 ror ror2 round sgn sin sin16 sin16u sin8 sin8u sinr8 sinr8u sinr16 sinr16u sizeof sort sqrt sqrt16 sum swap tan&#x000D;&#x000A;</Keywords>
<Keywords name="Keywords5">true false&#x000D;&#x000A;not and or xor&#x000D;&#x000A;as to downto</Keywords>
<Keywords name="Keywords6"></Keywords>
<Keywords name="Keywords7"></Keywords>

View File

@ -7,8 +7,8 @@
" Built-in functions
" Math functions
syn keyword prog8BuiltInFunc abs atan ceil cos cos8u cos8 cos16u cos16 deg floor
syn keyword prog8BuiltInFunc ln log2 rad round sin sgn sin8u sin8 sin16u sin16
syn keyword prog8BuiltInFunc abs atan ceil cos cos8u cos8 cos16u cos16 cosr8 cosr8u cosr16 cosr16u deg floor
syn keyword prog8BuiltInFunc ln log2 rad round sin sgn sin8u sin8 sin16u sin16 sinr8 sinr8u sinr16 sinr16u
syn keyword prog8BuiltInFunc sqrt16 sqrt tan
" Array functions