star refactor

This commit is contained in:
~d6 2022-01-30 14:59:30 -05:00
parent 656acfaa0d
commit 127379830e
1 changed files with 18 additions and 6 deletions

View File

@ -155,6 +155,13 @@
@peek ( -> c^ )
;pos LDA2 LDA JMP2r
@peek-to-star ( -> is-star^ )
;pos LDA2 LDA LIT '* EQU JMP2r
( pos += 1 )
@skip
;pos LDA2 INC2 ;pos STA2 JMP2r
( TODO: [] + ? )
( compile an expression string into a regex graph )
@compile ( expr* -> regex* )
@ -180,14 +187,20 @@
@compile-region-loop
;read JSR2
DUP #00 EQU ;c-done JCN2
DUP LIT '* EQU ;c-star JCN2
DUP LIT '| EQU ;c-or JCN2
DUP LIT '. EQU ;c-dot JCN2
DUP LIT '( EQU ;c-lpar JCN2
DUP LIT ') EQU ;c-rpar JCN2
DUP LIT '\ EQU ;c-esc JCN2
DUP LIT '* EQU ;c-star JCN2
;c-char JMP2
@c-peek-and-finalize ( r* -> r2* )
;peek-to-star JSR2 ( r next-is-star? )
,&next-is-star JCN ,&finally JMP ( r )
&next-is-star ;skip JSR2 ;alloc-star JSR2 ( star )
&finally DUP2 ;push-next JSR2 ;compile-region-loop JMP2
@c-done ( c^ -> r2* )
POP
;parens LDA2 #0000 GTH2 ,&mismatched-parens JCN
@ -215,13 +228,12 @@
@c-dot ( c^ -> r2* )
POP
;alloc-dot JSR2 DUP2 ;push-next JSR2
;compile-region-loop JMP2
;alloc-dot JSR2 ( dot )
;c-peek-and-finalize JMP2
@c-char ( c^ -> r2* )
;alloc-lit JSR2
DUP2 ;push-next JSR2
;compile-region-loop JMP2
;alloc-lit JSR2 ( lit )
;c-peek-and-finalize JMP2
( TODO: escaping rules not quite right )
@c-esc ( c^ -> r2* )