mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 01:38:06 +11:00
lib/expr: add left/right shifting operators
This commit is contained in:
parent
a03c5ac700
commit
2f71ad6d2f
@ -91,8 +91,12 @@ this way, it's going to mess with the parser.
|
|||||||
|
|
||||||
An expression is a bunch of literals or symbols assembled by operators.
|
An expression is a bunch of literals or symbols assembled by operators.
|
||||||
Supported operators are `+`, `-`, `*`, `/`, `%` (modulo), `&` (bitwise and),
|
Supported operators are `+`, `-`, `*`, `/`, `%` (modulo), `&` (bitwise and),
|
||||||
`|` (bitwise or) and `^` (bitwise xor). Bitwise operator always operate on
|
`|` (bitwise or), `^` (bitwise xor), `{` (shift left), `}` (shift right).
|
||||||
the whole 16-bits.
|
Bitwise operator always operate on the whole 16-bits.
|
||||||
|
|
||||||
|
Shift operators break from the `<<` and `>>` tradition because the complexity
|
||||||
|
if two-sized operator is significant and deemed not worth it. The shift
|
||||||
|
operator shift the left operand X times, X being the right operand.
|
||||||
|
|
||||||
There is no parenthesis support yet.
|
There is no parenthesis support yet.
|
||||||
|
|
||||||
|
@ -123,6 +123,10 @@ exprTbl:
|
|||||||
.dw .or
|
.dw .or
|
||||||
.db '^'
|
.db '^'
|
||||||
.dw .xor
|
.dw .xor
|
||||||
|
.db '}'
|
||||||
|
.dw .rshift
|
||||||
|
.db '{'
|
||||||
|
.dw .lshift
|
||||||
.db 0 ; end of table
|
.db 0 ; end of table
|
||||||
|
|
||||||
.plus:
|
.plus:
|
||||||
@ -198,3 +202,35 @@ exprTbl:
|
|||||||
push hl \ pop ix
|
push hl \ pop ix
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
.rshift:
|
||||||
|
push ix \ pop hl
|
||||||
|
ld a, l
|
||||||
|
and 0xf
|
||||||
|
ret z
|
||||||
|
push bc
|
||||||
|
ld b, a
|
||||||
|
.rshiftLoop:
|
||||||
|
srl d
|
||||||
|
rr e
|
||||||
|
djnz .rshiftLoop
|
||||||
|
push de \ pop ix
|
||||||
|
pop bc
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
|
||||||
|
.lshift:
|
||||||
|
push ix \ pop hl
|
||||||
|
ld a, l
|
||||||
|
and 0xf
|
||||||
|
ret z
|
||||||
|
push bc
|
||||||
|
ld b, a
|
||||||
|
.lshiftLoop:
|
||||||
|
sla e
|
||||||
|
rl d
|
||||||
|
djnz .lshiftLoop
|
||||||
|
push de \ pop ix
|
||||||
|
pop bc
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
@ -145,6 +145,10 @@ testParseExpr:
|
|||||||
call .testEQ
|
call .testEQ
|
||||||
ld iy, .t5
|
ld iy, .t5
|
||||||
call .testEQ
|
call .testEQ
|
||||||
|
ld iy, .t6
|
||||||
|
call .testEQ
|
||||||
|
ld iy, .t7
|
||||||
|
call .testEQ
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.testEQ:
|
.testEQ:
|
||||||
@ -176,6 +180,12 @@ testParseExpr:
|
|||||||
.t5:
|
.t5:
|
||||||
.dw 0x96f8
|
.dw 0x96f8
|
||||||
.db "0x99f7^0x0f0f", 0
|
.db "0x99f7^0x0f0f", 0
|
||||||
|
.t6:
|
||||||
|
.dw 0x133e
|
||||||
|
.db "0x99f7}3", 0
|
||||||
|
.t7:
|
||||||
|
.dw 0xcfb8
|
||||||
|
.db "0x99f7{3", 0
|
||||||
|
|
||||||
nexttest:
|
nexttest:
|
||||||
ld a, (testNum)
|
ld a, (testNum)
|
||||||
|
Loading…
Reference in New Issue
Block a user