mirror of
https://github.com/irmen/prog8.git
synced 2025-02-24 13:29:10 +00:00
added progend() builtin function
This commit is contained in:
parent
bedc3bdb56
commit
8dcd49934a
@ -160,6 +160,7 @@ internal class AsmGen(private val program: Program,
|
|||||||
val floatvalue = flt.key
|
val floatvalue = flt.key
|
||||||
out("${flt.value}\t.byte $floatFill ; float $floatvalue")
|
out("${flt.value}\t.byte $floatFill ; float $floatvalue")
|
||||||
}
|
}
|
||||||
|
out("prog8_program_end\t; end of program label for progend()")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun block2asm(block: Block) {
|
private fun block2asm(block: Block) {
|
||||||
|
@ -5,10 +5,7 @@ import prog8.ast.Node
|
|||||||
import prog8.ast.Program
|
import prog8.ast.Program
|
||||||
import prog8.ast.base.*
|
import prog8.ast.base.*
|
||||||
import prog8.ast.expressions.*
|
import prog8.ast.expressions.*
|
||||||
import prog8.ast.statements.ArrayIndex
|
import prog8.ast.statements.*
|
||||||
import prog8.ast.statements.DirectMemoryWrite
|
|
||||||
import prog8.ast.statements.FunctionCallStatement
|
|
||||||
import prog8.ast.statements.Subroutine
|
|
||||||
import prog8.compiler.AssemblyError
|
import prog8.compiler.AssemblyError
|
||||||
import prog8.compiler.target.CompilationTarget
|
import prog8.compiler.target.CompilationTarget
|
||||||
import prog8.compiler.target.Cx16Target
|
import prog8.compiler.target.Cx16Target
|
||||||
@ -93,6 +90,17 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
translateArguments(fcall.args, func, scope)
|
translateArguments(fcall.args, func, scope)
|
||||||
asmgen.out(" jmp prog8_lib.func_exit")
|
asmgen.out(" jmp prog8_lib.func_exit")
|
||||||
}
|
}
|
||||||
|
"progend" -> {
|
||||||
|
if(resultToStack)
|
||||||
|
asmgen.out("""
|
||||||
|
lda #<prog8_program_end
|
||||||
|
sta P8ESTACK_LO,x
|
||||||
|
lda #>prog8_program_end
|
||||||
|
sta P8ESTACK_HI,x
|
||||||
|
dex""")
|
||||||
|
else
|
||||||
|
asmgen.out(" lda #<prog8_program_end | ldy #>prog8_program_end")
|
||||||
|
}
|
||||||
else -> TODO("missing asmgen for builtin func ${func.name}")
|
else -> TODO("missing asmgen for builtin func ${func.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,7 @@ private val functionSignatures: List<FSignature> = listOf(
|
|||||||
FSignature("set_irqd" , false, emptyList(), null),
|
FSignature("set_irqd" , false, emptyList(), null),
|
||||||
FSignature("clear_irqd" , false, emptyList(), null),
|
FSignature("clear_irqd" , false, emptyList(), null),
|
||||||
FSignature("read_flags" , false, emptyList(), DataType.UBYTE),
|
FSignature("read_flags" , false, emptyList(), DataType.UBYTE),
|
||||||
|
FSignature("progend" , true, emptyList(), DataType.UWORD),
|
||||||
FSignature("swap" , false, listOf(FParam("first", NumericDatatypes), FParam("second", NumericDatatypes)), null),
|
FSignature("swap" , false, listOf(FParam("first", NumericDatatypes), FParam("second", NumericDatatypes)), null),
|
||||||
FSignature("memcopy" , false, listOf(
|
FSignature("memcopy" , false, listOf(
|
||||||
FParam("from", IterableDatatypes + DataType.UWORD),
|
FParam("from", IterableDatatypes + DataType.UWORD),
|
||||||
|
@ -894,6 +894,10 @@ set_irqd() / clear_irqd()
|
|||||||
swap(x, y)
|
swap(x, y)
|
||||||
Swap the values of numerical variables (or memory locations) x and y in a fast way.
|
Swap the values of numerical variables (or memory locations) x and y in a fast way.
|
||||||
|
|
||||||
|
progend()
|
||||||
|
Returns the last address of the program in memory + 1.
|
||||||
|
Can be used to load dynamic data after the program, instead of hardcoding something.
|
||||||
|
|
||||||
|
|
||||||
Library routines
|
Library routines
|
||||||
----------------
|
----------------
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- add minv(a,b) and maxv(a,b) functions to determine the max or min of 2 values
|
|
||||||
- add progend() builtin function that returns the last address of the program in memory + 1 (to be able to stick dynamic data after the program easily)
|
|
||||||
- see if we can group some errors together for instance the (now single) errors about unidentified symbols
|
- see if we can group some errors together for instance the (now single) errors about unidentified symbols
|
||||||
- Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines.
|
- Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines.
|
||||||
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import diskio
|
%import diskio
|
||||||
%import floats
|
%import floats
|
||||||
|
%import graphics
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start () {
|
||||||
|
uword xx = progend()
|
||||||
|
txt.print_uwhex(xx, 1)
|
||||||
|
txt.print_uwhex(progend(), 1)
|
||||||
|
|
||||||
test_stack.test()
|
test_stack.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<keywords keywords="&;->;@;\$;and;as;asmsub;break;clobbers;continue;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;not;or;repeat;return;romsub;step;sub;to;true;until;when;while;xor;~" ignore_case="false" />
|
<keywords keywords="&;->;@;\$;and;as;asmsub;break;clobbers;continue;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;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;%target;%zeropage;%zpreserved" />
|
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%target;%zeropage;%zpreserved" />
|
||||||
<keywords3 keywords="byte;const;float;str;struct;ubyte;uword;void;word;zp" />
|
<keywords3 keywords="byte;const;float;str;struct;ubyte;uword;void;word;zp" />
|
||||||
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;ceil;clear_carry;clear_irqd;cos;cos16;cos16u;cos8;cos8u;deg;exit;floor;leftstr;len;ln;log2;lsb;lsl;lsr;max;memcopy;memset;memsetw;min;mkword;msb;rad;read_flags;reverse;rightstr;rnd;rndf;rndw;rol;rol2;ror;ror2;round;rrestore;rsave;set_carry;set_irqd;sgn;sin;sin16;sin16u;sin8;sin8u;sizeof;sort;sqrt;sqrt16;strcmp;strlen;substr;sum;swap;tan" />
|
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;ceil;clear_carry;clear_irqd;cos;cos16;cos16u;cos8;cos8u;deg;exit;floor;leftstr;len;ln;log2;lsb;lsl;lsr;max;memcopy;memset;memsetw;min;mkword;msb;progend;rad;read_flags;reverse;rightstr;rnd;rndf;rndw;rol;rol2;ror;ror2;round;rrestore;rsave;set_carry;set_irqd;sgn;sin;sin16;sin16u;sin8;sin8u;sizeof;sort;sqrt;sqrt16;strcmp;strlen;substr;sum;swap;tan" />
|
||||||
</highlighting>
|
</highlighting>
|
||||||
<extensionMap>
|
<extensionMap>
|
||||||
<mapping ext="p8" />
|
<mapping ext="p8" />
|
||||||
|
@ -6,3 +6,6 @@ The exact path may vary with the version of the IDE,
|
|||||||
but for me it is currently this on Linux:
|
but for me it is currently this on Linux:
|
||||||
|
|
||||||
$HOME/.config/JetBrains/IntelliJIdea2020.2/filetypes/
|
$HOME/.config/JetBrains/IntelliJIdea2020.2/filetypes/
|
||||||
|
|
||||||
|
|
||||||
|
(note the version number in the path, adjust accordingly)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user