mirror of
https://github.com/irmen/prog8.git
synced 2024-11-28 10:51:14 +00:00
ast printing fixes, added alias to syntax files
This commit is contained in:
parent
18e37accf9
commit
90f1e7fd6a
@ -218,17 +218,15 @@ class AstPreprocessor(val program: Program,
|
|||||||
val namesInSub = symbolsInSub.map{ it.first }.toSet()
|
val namesInSub = symbolsInSub.map{ it.first }.toSet()
|
||||||
if(subroutine.asmAddress==null) {
|
if(subroutine.asmAddress==null) {
|
||||||
if(!subroutine.isAsmSubroutine && subroutine.parameters.isNotEmpty()) {
|
if(!subroutine.isAsmSubroutine && subroutine.parameters.isNotEmpty()) {
|
||||||
val vars = subroutine.statements.asSequence().filterIsInstance<VarDecl>().map { it.name }.toSet()
|
val existingVars = subroutine.statements.asSequence().filterIsInstance<VarDecl>().map { it.name }.toSet()
|
||||||
if(!vars.containsAll(subroutine.parameters.map{it.name})) {
|
|
||||||
return subroutine.parameters
|
return subroutine.parameters
|
||||||
.filter { it.name !in namesInSub }
|
.filter { it.name !in namesInSub && it.name !in existingVars }
|
||||||
.map {
|
.map {
|
||||||
val vardecl = VarDecl.fromParameter(it)
|
val vardecl = VarDecl.fromParameter(it)
|
||||||
IAstModification.InsertFirst(vardecl, subroutine)
|
IAstModification.InsertFirst(vardecl, subroutine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,10 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(block: Block) {
|
override fun visit(block: Block) {
|
||||||
|
if(block.isInLibrary && skipLibraries) {
|
||||||
|
outputln("; library block skipped: ${block.name}")
|
||||||
|
return
|
||||||
|
}
|
||||||
val addr = if(block.address!=null) block.address.toHex() else ""
|
val addr = if(block.address!=null) block.address.toHex() else ""
|
||||||
outputln("${block.name} $addr {")
|
outputln("${block.name} $addr {")
|
||||||
scopelevel++
|
scopelevel++
|
||||||
@ -527,4 +531,8 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
|
|||||||
whenChoice.statements.accept(this)
|
whenChoice.statements.accept(this)
|
||||||
outputln("")
|
outputln("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visit(alias: Alias) {
|
||||||
|
output("alias ${alias.alias} = ${alias.target.nameInSource.joinToString(".")}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,35 +2,9 @@
|
|||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
alias print = txt.print_ub
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
foo(42)
|
print(42)
|
||||||
bar(9999,55)
|
|
||||||
txt.nl()
|
|
||||||
test(1,2,3)
|
|
||||||
test2(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
sub foo(ubyte arg) {
|
|
||||||
txt.print_ub(arg)
|
|
||||||
txt.nl()
|
|
||||||
}
|
|
||||||
|
|
||||||
sub bar(uword arg, ubyte arg2) {
|
|
||||||
txt.print_uw(arg)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_ub(arg2)
|
|
||||||
txt.nl()
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub test(ubyte a1 @R1, ubyte a2 @R1, ubyte a3 @R2) { ; TODO should give register reuse error
|
|
||||||
%asm {{
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub test2(uword a1 @AY) clobbers(A, X) -> ubyte @X {
|
|
||||||
%asm {{
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<option name="HAS_PARENS" value="true" />
|
<option name="HAS_PARENS" value="true" />
|
||||||
<option name="HAS_STRING_ESCAPES" value="true" />
|
<option name="HAS_STRING_ESCAPES" value="true" />
|
||||||
</options>
|
</options>
|
||||||
<keywords keywords="&;->;@;and;as;asmsub;break;clobbers;continue;do;downto;else;extsub;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;step;sub;to;true;unroll;until;when;while;xor;~" ignore_case="false" />
|
<keywords keywords="&;->;@;alias;and;as;asmsub;break;clobbers;continue;do;downto;else;extsub;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;step;sub;to;true;unroll;until;when;while;xor;~" ignore_case="false" />
|
||||||
<keywords2 keywords="%address;%align;%asm;%asmbinary;%asminclude;%breakpoint;%encoding;%import;%ir;%launcher;%memtop;%option;%output;%zeropage;%zpallowed;%zpreserved;@align64;@alignpage;@alignword;@bank;@dirty;@nozp;@requirezp;@shared;@split;@zp;atascii:;cp437:;default:;iso16:;iso5:;iso:;kata:;petscii:;sc:" />
|
<keywords2 keywords="%address;%align;%asm;%asmbinary;%asminclude;%breakpoint;%encoding;%import;%ir;%launcher;%memtop;%option;%output;%zeropage;%zpallowed;%zpreserved;@align64;@alignpage;@alignword;@bank;@dirty;@nozp;@requirezp;@shared;@split;@zp;atascii:;cp437:;default:;iso16:;iso5:;iso:;kata:;petscii:;sc:" />
|
||||||
<keywords3 keywords="bool;byte;const;float;long;str;ubyte;uword;void;word" />
|
<keywords3 keywords="bool;byte;const;float;long;str;ubyte;uword;void;word" />
|
||||||
<keywords4 keywords="abs;bankof;call;callfar;callfar2;clamp;cmp;defer;divmod;len;lsb;max;memory;min;mkword;msb;peek;peekf;peekw;poke;pokef;pokew;rol;rol2;ror;ror2;rrestore;rrestorex;rsave;rsavex;setlsb;setmsb;sgn;sizeof;sqrt" />
|
<keywords4 keywords="abs;bankof;call;callfar;callfar2;clamp;cmp;defer;divmod;len;lsb;max;memory;min;mkword;msb;peek;peekf;peekw;poke;pokef;pokew;rol;rol2;ror;ror2;rrestore;rrestorex;rsave;rsavex;setlsb;setmsb;sgn;sizeof;sqrt" />
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<Keywords name="Keywords1">void const
str
byte ubyte bool
long word uword
float
zp shared split requirezp nozp</Keywords>
|
<Keywords name="Keywords1">void const
str
byte ubyte bool
long word uword
float
zp shared split requirezp nozp</Keywords>
|
||||||
<Keywords name="Keywords2">%address
%asm
%ir
%asmbinary
%asminclude
%align
%breakpoint
%encoding
%import
%memtop
%launcher
%option
%output
%zeropage
%zpreserved
%zpallowed</Keywords>
|
<Keywords name="Keywords2">%address
%asm
%ir
%asmbinary
%asminclude
%align
%breakpoint
%encoding
%import
%memtop
%launcher
%option
%output
%zeropage
%zpreserved
%zpallowed</Keywords>
|
||||||
<Keywords name="Keywords3">inline sub asmsub extsub
clobbers
asm
if
when else
if_cc if_cs if_eq if_mi if_neg if_nz if_pl if_pos if_vc if_vs if_z
for in step do while repeat unroll
break continue return goto</Keywords>
|
<Keywords name="Keywords3">inline sub asmsub extsub
clobbers
asm
if
when else
if_cc if_cs if_eq if_mi if_neg if_nz if_pl if_pos if_vc if_vs if_z
for in step do while repeat unroll
break continue return goto</Keywords>
|
||||||
<Keywords name="Keywords4">abs call callfar callfar2 clamp cmp defer divmod len lsb lsl lsr memory mkword min max msb bankof peek peekw peekf poke pokew pokef rsave rsavex rrestore rrestorex rnd rndw rol rol2 ror ror2 setlsb setmsb sgn sizeof sqrtw</Keywords>
|
<Keywords name="Keywords4">alias abs call callfar callfar2 clamp cmp defer divmod len lsb lsl lsr memory mkword min max msb bankof peek peekw peekf poke pokew pokef rsave rsavex rrestore rrestorex rnd rndw rol rol2 ror ror2 setlsb setmsb sgn sizeof sqrtw</Keywords>
|
||||||
<Keywords name="Keywords5">true false
not and or xor
as to downto |></Keywords>
|
<Keywords name="Keywords5">true false
not and or xor
as to downto |></Keywords>
|
||||||
<Keywords name="Keywords6"></Keywords>
|
<Keywords name="Keywords6"></Keywords>
|
||||||
<Keywords name="Keywords7"></Keywords>
|
<Keywords name="Keywords7"></Keywords>
|
||||||
|
@ -117,7 +117,7 @@ contexts:
|
|||||||
general__5:
|
general__5:
|
||||||
- include: general
|
- include: general
|
||||||
keywords:
|
keywords:
|
||||||
- match: (\b(sub|if|if_cs|if_cc|if_eq|if_ne|if_pl|if_mi|if_vs|if_vc|if_z|if_nz|if_pos|if_neg|for|in|to|step|do|while|until|repeat|else|when|return|break|as|goto|asmsub|clobbers)\b)
|
- match: (\b(sub|if|if_cs|if_cc|if_eq|if_ne|if_pl|if_mi|if_vs|if_vc|if_z|if_nz|if_pos|if_neg|for|in|to|step|do|while|until|repeat|else|when|return|break|as|goto|asmsub|clobbers|alias)\b)
|
||||||
scope: keyword.control.prog8
|
scope: keyword.control.prog8
|
||||||
- match: (\b(and|or)\b)
|
- match: (\b(and|or)\b)
|
||||||
scope: keyword.operator.prog8
|
scope: keyword.operator.prog8
|
||||||
|
@ -15,7 +15,7 @@ syn keyword prog8BuiltInFunc len
|
|||||||
" Miscellaneous functions
|
" Miscellaneous functions
|
||||||
syn keyword prog8BuiltInFunc cmp divmod lsb msb bankof mkword min max peek peekw peekf poke pokew pokef rsave rsavex rrestore rrestorex
|
syn keyword prog8BuiltInFunc cmp divmod lsb msb bankof mkword min max peek peekw peekf poke pokew pokef rsave rsavex rrestore rrestorex
|
||||||
syn keyword prog8BuiltInFunc rol rol2 ror ror2 sizeof setlsb setmsb
|
syn keyword prog8BuiltInFunc rol rol2 ror ror2 sizeof setlsb setmsb
|
||||||
syn keyword prog8BuiltInFunc memory call callfar callfar2 clamp defer
|
syn keyword prog8BuiltInFunc memory call callfar callfar2 clamp defer alias
|
||||||
|
|
||||||
|
|
||||||
" c64/floats.p8
|
" c64/floats.p8
|
||||||
|
Loading…
Reference in New Issue
Block a user