A2osX/BIN/CC.S.CORE.txt

640 lines
9.8 KiB
Plaintext
Raw Normal View History

NEW
AUTO 3,1
*--------------------------------------
CORE.Init >SYSCALL SListNew
2022-06-12 20:42:22 +00:00
bcs .9
>STA.G CC.hDefines
>SYSCALL SListNew
2022-06-12 20:42:22 +00:00
bcs .9
>STA.G CC.hTags
>SYSCALL SListNew
bcs .9
2022-06-22 06:26:44 +00:00
>STA.G CC.hScopes
sty ScopeIdx
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA ZPSymBufPtr
txa
>STA.G CC.hSymBuf
2022-01-30 21:47:08 +00:00
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA ZPCCStack
txa
>STA.G CC.hStack
2022-06-22 06:26:44 +00:00
lda #CC.LookupIdx
tay
sta (pData),y
* clc
.9 rts
*--------------------------------------
CORE.Quit jsr CC.FIO.FClose
bne CORE.Quit
2022-06-22 06:26:44 +00:00
ldy ScopeIdx
beq .1
2022-01-30 21:47:08 +00:00
.10 lda (pData),y
>SYSCALL SListFree
2022-06-22 06:26:44 +00:00
ldy ScopeIdx
cpy #CC.hScopes
2022-01-30 21:47:08 +00:00
beq .1
2022-06-22 06:26:44 +00:00
dec ScopeIdx
2022-01-30 21:47:08 +00:00
dey
bra .10
.1 >LDA.G CC.hTags
beq .2
>SYSCALL SListFree
.2 >LDA.G CC.hDefines
beq .4
>SYSCALL SListFree
2022-06-12 20:42:22 +00:00
.4 >LDA.G CC.hDefineBuf
jsr .7
2022-06-12 20:42:22 +00:00
>LDA.G CC.hSymBuf
jsr .7
.5 jsr CC.SYM.LookupFree
bcc .5
2022-06-22 06:26:44 +00:00
>LDA.G CC.hStack
2022-08-20 14:37:37 +00:00
.7 beq .8
>SYSCALL FreeMem
2022-08-20 14:37:37 +00:00
.8 rts
2022-01-30 21:47:08 +00:00
*--------------------------------------
CC.CompileFile >SLEEP
ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FEOF
bcs .9
tay
bne .1
>SYSCALL GetChar
bcs .9 I/O err
cmp #3 Ctrl-C
beq .9
2022-08-20 14:37:37 +00:00
.1 jsr CC.FIO.FGetS
2022-01-30 21:47:08 +00:00
bcs .9
jsr CC.CompileLine
bcs .9
>LDA.G bDebug
bpl CC.CompileFile
jsr PrintDebugMsg
bra CC.CompileFile
.9 rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
CC.CompileLine jsr CC.GetCharNB
2022-08-20 14:37:37 +00:00
bcs .9
2022-08-20 14:37:37 +00:00
cmp #C.CR EOL....
beq .8
2022-08-20 14:37:37 +00:00
cmp #'#' directive ?
bne .1
jmp CC.DIR
2022-08-20 14:37:37 +00:00
.1 cmp #'/'
bne .2 comments ...
2022-08-20 14:37:37 +00:00
jmp CC.Comments
2022-08-20 14:37:37 +00:00
.2 cmp #'}' End of CPStmt ?
bne .3
2022-08-20 14:37:37 +00:00
jsr CC.GetNextCharNB Skip '}'
2022-08-20 14:37:37 +00:00
jsr CC.STMT.CPStmt.END
bcs .9
2022-08-20 14:37:37 +00:00
bra CC.CompileLine
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
.3 cmp #';' End of Stmt ?
bne .4
2022-08-20 14:37:37 +00:00
jsr CC.GetNextCharNB Skip ';'
2022-08-20 14:37:37 +00:00
jsr CC.STMT.Stmt.END
bcs .9
2022-08-20 14:37:37 +00:00
bra CC.CompileLine
2022-08-20 14:37:37 +00:00
.4 jsr CC.CompileStmt
bcs .9
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
bra CC.CompileLine
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
.8 clc
.9 rts
*--------------------------------------
* keyword : for, while ....
2022-01-30 21:47:08 +00:00
*--------------------------------------
2022-08-20 14:37:37 +00:00
CC.CompileStmt >LDYA L.CC.KW
jsr CC.LookupID
bcs .10 not an internal CC keyword....
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
txa
>STA.G CC.CmdSave
jmp (J.CC.KW,x)
*--------------------------------------
* Declaration : int var or int func()
*--------------------------------------
.10 >LDYA L.CC.TYPEQUAL
jsr CC.LookupID
bcs .6
2022-08-20 14:37:37 +00:00
jmp CC.DECL
*--------------------------------------
* Statement : ++var, var=, func();
*--------------------------------------
.6 jmp CC.STMT
2022-01-30 21:47:08 +00:00
*--------------------------------------
2022-08-20 14:37:37 +00:00
.99 lda #E.CSYN
2022-01-30 21:47:08 +00:00
sec
2022-08-20 14:37:37 +00:00
.9 rts
2022-01-30 21:47:08 +00:00
*--------------------------------------
2022-08-20 14:37:37 +00:00
CC.Comments jsr CC.GetNextChar TODO : /* ... */
cmp #'/'
bne .90
jmp CC.SkipLine skip line.....
.90 lda #E.CSYN
sec
rts
*--------------------------------------
CC.SkipLine jsr CC.GetNextChar
bcs .9
cmp #C.CR
bne CC.SkipLine
clc
.9 rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
CC.LookupID >STYA ZPLookupPtr
jsr CC.GetIDLen
bra CC.Lookup
2022-08-20 14:37:37 +00:00
CC.LookupAOP >LDYA L.CC.AOPS
>STYA ZPLookupPtr
ldy #$ff
.1 iny
lda (ZPLineBufPtr),y
sec
beq .9
jsr CC.IsOPChar
bcs .9
cmp #'='
bne .1
iny
.8 tya
bra CC.Lookup
.9 rts
2022-01-30 21:47:08 +00:00
CC.LookupOP >STYA ZPLookupPtr
jsr CC.GetOPLen
CC.Lookup phy Y = len
ldx #0
2022-01-30 21:47:08 +00:00
.1 lda (ZPLookupPtr)
beq .9 Ending 0, not found....
pla
pha Get Back Len
2022-01-30 21:47:08 +00:00
cmp (ZPLookupPtr) Same Len ?
bne .4
tay
2022-01-30 21:47:08 +00:00
.2 lda (ZPLookupPtr),y
.3 dey
cmp (ZPLineBufPtr),y
bne .4
tya
bne .2
pla Found keyword...
2022-01-30 21:47:08 +00:00
jsr CC.SkipA ..advance Ptr to char after it..
2022-01-30 21:47:08 +00:00
lda ZPLookupPtr
sec
2022-01-30 21:47:08 +00:00
adc (ZPLookupPtr)
tay
2022-01-30 21:47:08 +00:00
lda ZPLookupPtr+1
adc #0
clc Y,A = F() def, X = F() index
2022-08-20 14:37:37 +00:00
rts
.4 inx
inx
2022-01-30 21:47:08 +00:00
lda (ZPLookupPtr)
jsr CC.ZPLookupPtrAddAp1
bra .1
2022-08-20 14:37:37 +00:00
.9 ldx #$FF
pla
sec
rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
CC.ZPLookupPtrAddAp1
sec
2022-01-30 21:47:08 +00:00
adc ZPLookupPtr
sta ZPLookupPtr
bcc .1
2022-01-30 21:47:08 +00:00
inc ZPLookupPtr+1
.1 rts
*--------------------------------------
2022-06-22 06:26:44 +00:00
CC.GetDefine >LDA.G CC.hDefines
2022-01-30 21:47:08 +00:00
jsr CC.SListLookup
bcs .9
2022-06-22 06:26:44 +00:00
>LDYA ZPLineBufPtr
>STYA.G CC.SaveDefine
2022-06-12 20:42:22 +00:00
txa
>STA.G CC.hDefineBuf
2022-06-22 06:26:44 +00:00
>SYSCALL GetMemPtr
>STYA ZPLineBufPtr
.9 rts
*--------------------------------------
2022-08-20 14:37:37 +00:00
CC.SListLookup >PUSHA hSList
>PUSHA ...for SListGetData
>PUSHW ZPLineBufPtr
>SYSCALL SListLookup
bcs .99
>PUSHA KeyID.HI
tya
>PUSHA KeyID.LO
jsr CC.SkipX
>PUSHWZ allocate
>PUSHWI 65535 all
>PUSHWZ From Start
>SYSCALL SListGetData
.9 rts Y,A = SymSize, X = hSymBuf
.99 inc pStack discard extra hSList
rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
* CT Stack
*--------------------------------------
CC.PushTQ ldy #SYM.Q
lda (ZPSymBufPtr),y
2022-06-22 06:26:44 +00:00
and #$FC ignore SYM.Q.FUNC+SYM.Q.FASTCALL
2022-01-30 21:47:08 +00:00
jsr CC.Push
bcs CC.Push.RTS
2022-01-30 21:47:08 +00:00
lda (ZPSymBufPtr) SYM.T
bra CC.Push
*--------------------------------------
CC.PushCS lda ZPCCCode+1
jsr CC.Push
bcs CC.Push.RTS
2022-01-30 21:47:08 +00:00
lda ZPCCCode
*--------------------------------------
CC.Push ldy CStackPtr
dey
beq .9
2022-01-30 21:47:08 +00:00
sty CStackPtr
2022-01-30 21:47:08 +00:00
sta (ZPCCStack),y
clc
rts
2022-01-30 21:47:08 +00:00
.9 lda #E.STKOVERFLOW
sec
2022-01-30 21:47:08 +00:00
CC.Push.RTS rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
CC.PopYA ldy CStackPtr
beq .9
2022-01-30 21:47:08 +00:00
lda (ZPCCStack),y
pha
2022-01-30 21:47:08 +00:00
iny
beq .90
2022-01-30 21:47:08 +00:00
lda (ZPCCStack),y
2022-01-30 21:47:08 +00:00
iny
sty CStackPtr
2022-06-22 06:26:44 +00:00
2022-01-30 21:47:08 +00:00
ply
2022-06-22 06:26:44 +00:00
2022-01-30 21:47:08 +00:00
clc
rts
2022-01-30 21:47:08 +00:00
.90 pla
.9 lda #E.STACKERROR
sec
2022-06-22 06:26:44 +00:00
rts
*--------------------------------------
2022-08-20 14:37:37 +00:00
CC.Pop jsr CC.Get
inc CStackPtr
* clc
.9 rts
*--------------------------------------
CC.Get ldy CStackPtr
2022-01-30 21:47:08 +00:00
beq .9
2022-01-30 21:47:08 +00:00
lda (ZPCCStack),y
2022-01-30 21:47:08 +00:00
clc
rts
2022-01-30 21:47:08 +00:00
.9 lda #E.STACKERROR
sec
rts
*--------------------------------------
* ZPLineBufPtr related Subs.....
*--------------------------------------
CC.SkipX txa
CC.SkipA clc
adc ZPLineBufPtr
sta ZPLineBufPtr
bcc .8
2022-01-30 21:47:08 +00:00
inc ZPLineBufPtr+1
2022-01-30 21:47:08 +00:00
.8 rts
*--------------------------------------
CC.GetOPLen ldy #0
2022-01-30 21:47:08 +00:00
.1 iny
lda (ZPLineBufPtr),y
beq .8
2022-01-30 21:47:08 +00:00
jsr CC.IsOPChar
bcc .1
2022-01-30 21:47:08 +00:00
.8 tya
rts
*--------------------------------------
CC.GetIDLen ldy #0
2022-01-30 21:47:08 +00:00
.1 iny
lda (ZPLineBufPtr),y
beq .8
2022-01-30 21:47:08 +00:00
jsr CC.IsLetterOrDigit
bcc .1
2022-01-30 21:47:08 +00:00
.8 tya
rts
*--------------------------------------
CC.GetCharNB jsr CC.GetChar
bcs CC.GetNextCharNB.RTS
2022-01-30 21:47:08 +00:00
jsr CC.CheckCharNB
bcc CC.GetNextCharNB.RTS
*--------------------------------------
CC.GetNextCharNB
jsr CC.GetNextChar
bcs CC.GetNextCharNB.RTS
2022-01-30 21:47:08 +00:00
jsr CC.CheckCharNB
bcs CC.GetNextCharNB
2022-01-30 21:47:08 +00:00
CC.GetNextCharNB.RTS
rts
*--------------------------------------
2022-08-20 14:37:37 +00:00
CC.GetCharNBNL jsr CC.GetChar
bcs CC.GetNextCharNB.RTS
jsr CC.CheckCharNB
bcs CC.GetNextCharNBNL
cmp #C.CR
clc
bne CC.GetNextCharNB.RTS
jsr CC.FIO.FGetS
bcs CC.GetNextCharNB.RTS
*--------------------------------------
CC.GetNextCharNBNL
jsr CC.GetNextCharNB
bcs CC.GetNextCharNB.RTS
cmp #C.CR
clc
bne .9
jsr CC.FIO.FGetS
bcc CC.GetNextCharNBNL
.9 rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
CC.CheckSpace jsr CC.GetChar
bcs .90
2022-01-30 21:47:08 +00:00
cmp #C.SPACE
bne .90
jsr CC.GetNextCharNB
bcc .99
.90 lda #E.CSYN
sec
.99 rts
*--------------------------------------
CC.CheckCharNB cmp #C.SPACE
beq .9
cmp #C.TAB
beq .9
clc
.9 rts
*--------------------------------------
CC.GetNextCharEsc
jsr CC.GetNextChar
bcs .9
cmp #'\'
bne .8
jsr CC.GetNextChar
bcs .8
ldx #CC.EscChars.Cnt-1
.1 cmp CC.EscChars,x
beq .6
dex
bpl .1
sec
rts
.6 lda CC.EscCodes,x
bit .9
clc
rts
.8 clc
clv
.9 rts
*--------------------------------------
CC.GetNextChar inc ZPLineBufPtr
bne CC.GetChar
inc ZPLineBufPtr+1
*--------------------------------------
CC.GetChar lda (ZPLineBufPtr)
bne .8
2022-06-12 20:42:22 +00:00
phy
2022-06-12 20:42:22 +00:00
>LDA.G CC.hDefineBuf
beq .1
phx
2022-06-12 20:42:22 +00:00
>SYSCALL FreeMem
2022-06-12 20:42:22 +00:00
>STZ.G CC.hDefineBuf
>LDYA.G CC.SaveDefine
>STYA ZPLineBufPtr
plx
2022-06-12 20:42:22 +00:00
ply
bra CC.GetChar
2022-01-30 21:47:08 +00:00
2022-06-12 20:42:22 +00:00
.1 ply
lda #C.CR
.8 clc
rts
*---------------------------------------
2022-01-30 21:47:08 +00:00
CC.IsEndArg cmp #']'
beq .8
2022-08-20 14:37:37 +00:00
cmp #','
2022-01-30 21:47:08 +00:00
beq .8
2022-08-20 14:37:37 +00:00
cmp #';'
2022-01-30 21:47:08 +00:00
beq .8
cmp #':'
beq .8
2022-01-30 21:47:08 +00:00
cmp #')'
beq .8
sec
rts
.8 clc
rts
*---------------------------------------
CC.IsOPChar ldx #CC.OPChars.Cnt-1
.1 cmp CC.OPChars,x
beq .8
dex
bpl .1
sec
rts
.8 clc
rts
*---------------------------------------
CC.IsLetterOrDigit
jsr CC.IsDigit10
bcc CC.IsLetterRTS
*---------------------------------------
CC.IsLetter cmp #'_'
bne .1
clc
rts
.1 cmp #'A'
bcc .9
cmp #'Z'+1
bcc CC.IsLetterRTS
cmp #'a'
bcc .9
cmp #'z'+1
rts CC if lowercase
.9 sec
CC.IsLetterRTS rts
*---------------------------------------
CC.IsDigit10 cmp #'0'
bcc .9
cmp #'9'+1
rts cc if ok, cs if not
.9 sec
rts
*--------------------------------------
MAN
SAVE usr/src/bin/cc.s.core
LOAD usr/src/bin/cc.s
ASM