added bool to syntax files

This commit is contained in:
Irmen de Jong 2022-07-07 23:27:18 +02:00
parent 1dfa8ee7d8
commit 9633c0b07a
5 changed files with 6 additions and 29 deletions

View File

@ -80,30 +80,6 @@ Optimizations:
- when a for loop's loopvariable isn't referenced in the body, and the iterations are known, replace the loop by a repeatloop
but we have no efficient way right now to see if the body references a variable.
BOOL data type?
---------------
Logical expressions now need to sprinkle boolean() calls on their operands to yield the correct boolean 0 or 1 result.
This is inefficient because most of the time the operands already are boolean but the compiler doesn't know this
because the type of boolean values is UBYTE (so theoretically the value can be anything from 0 - 255)
So the idea is to add a true 'bool' type
- add BOOL datatype to enumeration
- optional (lot of work):
- add BooleanLiteral ast node to hold true and false, of type BOOL
- make 'true' and 'false' parse into BooleanLiterals
- make sure everything works again (all places using NumericLiteral also have to consider BooleanLiteral...)
- idea: let BooleanLiteral subclass from NumericLiteral ?
- add 'bool' type to grammar and parser
- remove builtin function boolean() replace with typecast to BOOL
- logical expressions don't cast operands of BOOL type to BOOL anymore (is this done???)
- before codegen, BOOL type is simply discarded and replaced by UBYTE
THE ABOVE HAS BEEN DONE
- rewrite: boolvar & 1 -> boolvar, (boolvar & 1 == 0) -> not boolvar
- add ARRAY_OF_BOOL array type
STRUCTS again?
--------------

View File

@ -13,11 +13,11 @@
</options>
<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;iso:;petscii:;sc:" />
<keywords3 keywords="@requirezp;@shared;@zp;byte;const;float;str;ubyte;uword;void;word" />
<keywords3 keywords="@requirezp;@shared;@zp;byte;const;float;str;ubyte;uword;bool;void;word" />
<keywords4 keywords="abs;all;any;avg;callfar;callrom;cmp;len;lsb;memory;mkword;msb;peek;peekw;poke;pokew;pop;popw;push;pushw;reverse;rnd;rndw;rol;rol2;ror;ror2;rrestore;rrestorex;rsave;rsavex;sgn;sizeof;sort;sqrt16;swap;|&gt;" />
</highlighting>
<extensionMap>
<mapping ext="p8" />
<mapping ext="prog8" />
</extensionMap>
</filetype>
</filetype>

View File

@ -24,7 +24,7 @@
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">void const&#x000D;&#x000A;str&#x000D;&#x000A;byte ubyte&#x000D;&#x000A;word uword&#x000D;&#x000A;float&#x000D;&#x000A;zp shared requirezp</Keywords>
<Keywords name="Keywords1">void const&#x000D;&#x000A;str&#x000D;&#x000A;byte ubyte bool&#x000D;&#x000A;word uword&#x000D;&#x000A;float&#x000D;&#x000A;zp shared requirezp</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 all any avg callfar callrom cmp len lsb lsl lsr memory mkword msb peek peekw poke pokew push pushw pop popw rsave rsavex rrestore rrestorex reverse rnd rndw rol rol2 ror ror2 sgn sizeof sort sqrt16 swap</Keywords>

View File

@ -6,6 +6,7 @@
; FIXME #31
main {
str input = "string literal\r\n\"\\"
bool bb = false
ubyte c = 'x' ; character literal in bold
ubyte decimal = 0 + 1 - 2 * 3
float pi = 3.1415

View File

@ -38,9 +38,9 @@ syn match prog8Directive "\(^\|\s\)%\(zpreserved\|address\|import\|option\)\>"
syn match prog8Directive "\(^\|\s\)%\(asmbinary\|asminclude\|breakpoint\)\>"
syn match prog8Directive "\(^\|\s\)%asm\>"
syn match prog8Type "\<\%(u\?byte\|u\?word\|float\|str\)\>"
syn match prog8Type "\<\%(u\?byte\|u\?word\|float\|str\|bool\)\>"
syn region prog8ArrayType matchgroup=prog8Type
\ start="\<\%(u\?byte\|u\?word\|float\|str\)\[" end="\]"
\ start="\<\%(u\?byte\|u\?word\|float\|str\|bool\)\[" end="\]"
\ transparent
syn keyword prog8StorageClass const
syn match prog8StorageClass "\(^\|\s\)\(@zp\|@shared\|@requirezp\)\>"