A2osX/BIN/CC.S.KW.txt

730 lines
11 KiB
Plaintext
Raw Normal View History

NEW
AUTO 3,1
*--------------------------------------
* Built in Keywords
*--------------------------------------
KW.IF jsr KW.BEGIN00
2022-08-20 14:37:37 +00:00
bcs .99
jsr CC.GetCharNB
bcs .9
cmp #'('
bne .9
jsr CORE.GetNCharNB
bcs .9
jsr EXP.Eval00 Any var type
2022-01-30 21:47:08 +00:00
bcs .99
jsr KW.TestZero Y,A=T/Q
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #'E'
jsr SYM.LookupA
bcs .99
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP else
jsr CODE.TOABSYX
bcs .99
jsr CC.GetCharNB
bcs .99
cmp #')'
bne .9
jmp KW.STMT
.9 lda #E.CSYN
sec
2022-08-20 14:37:37 +00:00
.99 rts
*--------------------------------------
KW.IF.END jsr CORE.GetCharNBNL
2022-08-20 14:37:37 +00:00
bcs .1
2022-08-20 14:37:37 +00:00
cmp #';'
beq .1
2022-08-20 14:37:37 +00:00
>LDYA L.CC.KW2.IF Check allowed KW for IF....
jsr CC.LookupID
bcc .2
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
.1 lda #'E' define ELSE Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
2022-08-20 14:37:37 +00:00
clv pop context
rts
*--------------------------------------
.2 lda #'X'
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .99
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP exit
jsr CODE.TOABSYX
bcs .99
2022-08-20 14:37:37 +00:00
lda #'E' define ELSE Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
inc CStackPtr pop ; or }
lda #4 replace IF by ELSE keyword
ldy CStackPtr
sta (ZPCCStack),y
jsr KW.STMT
2022-08-20 14:37:37 +00:00
bcs .99
bit .99 set V : DONT pop context
2022-01-30 21:47:08 +00:00
rts
2022-08-20 14:37:37 +00:00
.9 lda #E.CSYN
sec
.99 rts
*--------------------------------------
KW.ELSE lda #E.CSYN illegal
2022-08-20 14:37:37 +00:00
sec
rts
*--------------------------------------
KW.ELSE.END lda #'X' define EXIT Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
clv pop context
.99 rts
*--------------------------------------
KW.WHILE jsr KW.BEGIN00
2022-08-20 14:37:37 +00:00
bcs .99
lda #'C' define CONT Label
jsr SYM.NewA
2022-08-20 14:37:37 +00:00
bcs .99
jsr CC.GetCharNB
bcs .9
2022-08-20 14:37:37 +00:00
cmp #'('
bne .9
2022-01-30 21:47:08 +00:00
jsr CORE.GetNCharNB
bcs .9
2022-06-22 06:26:44 +00:00
jsr EXP.Eval00 Any var type
2022-08-20 14:37:37 +00:00
bcs .99
jsr KW.TestZero
2022-08-20 14:37:37 +00:00
lda #'B'
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .99
2022-06-22 06:26:44 +00:00
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP break:
2022-01-30 21:47:08 +00:00
jsr CODE.TOABSYX
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
jsr CC.GetCharNB
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
cmp #')'
bne .9
2022-01-30 21:47:08 +00:00
jmp KW.STMT
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
.9 lda #E.CSYN
2022-01-30 21:47:08 +00:00
sec
2022-08-20 14:37:37 +00:00
.99 rts
2022-01-30 21:47:08 +00:00
*--------------------------------------
KW.WHILE.END >LDYA L.PCC.SLEEP
jsr CODE.EmitPCC
bcs .99
lda #'C'
jsr KW.GetLabel
2022-08-20 14:37:37 +00:00
bcs .99
lda #$4C
jsr CODE.TOABSYX emit JMP cont:
bcs .99
lda #'B' define BREAK Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
clv pop context
.99 rts
*--------------------------------------
KW.DO jsr KW.BEGIN00
2022-08-20 14:37:37 +00:00
bcs .99
lda #'C' define CONT Label
jsr SYM.NewA
2022-08-20 14:37:37 +00:00
bcs .99
jmp KW.STMT
2022-08-20 14:37:37 +00:00
.99 rts
*--------------------------------------
KW.DO.END >LDYA L.CC.KW2.DO Check allowed KW for DO....
2022-08-20 14:37:37 +00:00
jsr CC.LookupID
bcs .9
jsr CC.GetCharNB
bcs .9
cmp #'('
bne .9
jsr CORE.GetNCharNB
2022-08-20 14:37:37 +00:00
bcs .9
jsr EXP.Eval00 Any var type
2022-08-20 14:37:37 +00:00
bcs .99
jsr KW.TestnZero
2022-08-20 14:37:37 +00:00
lda #'C'
jsr KW.GetLabel
2022-08-20 14:37:37 +00:00
bcs .99
lda #$4C emit JMP cont
jsr CODE.TOABSYX
bcs .99
lda #'B' define BREAK Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
jsr CC.GetCharNB
bcs .99
cmp #')'
bne .9
jsr CORE.GetNCharNB
2022-08-20 14:37:37 +00:00
bcs .9
clv pop context
2022-01-30 21:47:08 +00:00
clc
rts
2022-08-20 14:37:37 +00:00
.9 lda #E.CSYN
sec
.99 rts
2022-01-30 21:47:08 +00:00
*--------------------------------------
2022-08-20 14:37:37 +00:00
* for (s1;e2;s3) s;
2022-01-30 21:47:08 +00:00
*
2022-06-12 20:42:22 +00:00
* { <- new scope : allows for(int i=1; ....)
2022-08-20 14:37:37 +00:00
* s1;
2022-06-12 20:42:22 +00:00
* loop:
2022-08-20 14:37:37 +00:00
* while (e2) jmp break:
2022-06-12 20:42:22 +00:00
* {
2022-08-20 14:37:37 +00:00
* s; jsr s:
2022-06-12 20:42:22 +00:00
* cont:
2022-08-20 14:37:37 +00:00
* s3; jmp loop:
2022-06-12 20:42:22 +00:00
* }
2022-08-20 14:37:37 +00:00
* s:
* <s>;
* break:
2022-01-30 21:47:08 +00:00
* }
*--------------------------------------
KW.FOR jsr CC.GetCharNB
2022-08-20 14:37:37 +00:00
bcs .29
2022-01-30 21:47:08 +00:00
cmp #'('
2022-08-20 14:37:37 +00:00
bne .29
2022-01-30 21:47:08 +00:00
jsr KW.BEGIN00
2022-08-20 14:37:37 +00:00
bcs .29
jsr CORE.GetNCharNB skip '('
2022-08-20 14:37:37 +00:00
bcs .29
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
>LDYA L.CC.TYPEQUAL
jsr CC.LookupID
bcs .1
2022-06-22 06:26:44 +00:00
jsr DECL.X
2022-08-20 14:37:37 +00:00
bcc .2
.19 rts
.1 jsr STMT.Get get s1
2022-08-20 14:37:37 +00:00
bcs .19
* jsr KW.StackDiscard
2022-08-20 14:37:37 +00:00
.2 jsr CC.GetCharNB
2022-06-12 20:42:22 +00:00
bcs .9
2022-01-30 21:47:08 +00:00
cmp #';'
2022-06-12 20:42:22 +00:00
bne .9
2022-01-30 21:47:08 +00:00
jsr CORE.GetNCharNB skip ';'
2022-06-12 20:42:22 +00:00
bcs .9
2022-01-30 21:47:08 +00:00
*--------------------------------------
2022-08-20 14:37:37 +00:00
lda #'L' LOOP Label
jsr SYM.NewA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
jsr EXP.Eval00 get e2
2022-01-30 21:47:08 +00:00
.29 bcs .99
jsr KW.TestZero
2022-01-30 21:47:08 +00:00
bcs .99
2022-08-20 14:37:37 +00:00
lda #'B'
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP break:
jsr CODE.TOABSYX
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #'S'
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #$20 emit JSR s:
jsr CODE.TOABSYX
2022-01-30 21:47:08 +00:00
jsr CC.GetCharNB
bcs .9
2022-01-30 21:47:08 +00:00
cmp #';'
bne .9
jsr CORE.GetNCharNB skip ';'
2022-01-30 21:47:08 +00:00
bcs .9
*--------------------------------------
2022-08-20 14:37:37 +00:00
lda #'C' CONT Label
jsr SYM.NewA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
jsr STMT.Get get s3
2022-01-30 21:47:08 +00:00
bcs .99
* jsr KW.StackDiscard
2022-01-30 21:47:08 +00:00
jsr CC.GetCharNB
bcs .9
cmp #')'
bne .9
2022-08-20 14:37:37 +00:00
lda #'L'
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #$4C
jsr CODE.TOABSYX emit JMP loop
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #'S' S Label
jsr SYM.NewA
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
jmp KW.STMT
2022-01-30 21:47:08 +00:00
.9 lda #E.CSYN
sec
.99 rts
*--------------------------------------
KW.FOR.END lda #$60
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
jsr CODE.EmitByte set RTS for JSR code;
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda #'B' define BREAK Label
jsr KW.NewLabel
2022-08-20 14:37:37 +00:00
bcs .99
2022-08-20 14:37:37 +00:00
clv pop context
2022-08-20 14:37:37 +00:00
.99 rts
*--------------------------------------
KW.SWITCH jsr CC.GetCharNB
bcs .98
cmp #'('
bne .98
jsr CORE.GetNCharNB
bcs .98
jsr EXP.Eval00 Any var type
bcs .99 Y,A=T/Q
tax
bne .97
cpy #SYM.T.UCHAR
bcc .97
cpy #SYM.T.FLOAT
bcs .97
phy
tya
jsr CC.Push push integral type
ply
bcs .99
lda CC.TYPESIZE-1,y
jsr CC.Push push SizeOf(type)
bcs .99
jsr KW.BEGIN
bcs .99
jsr CC.GetCharNB
bcs .99
cmp #')'
bne .98
jmp KW.STMT
.97 lda #E.TMISMATCH
sec
rts
.98 lda #E.CSYN
sec
.99 rts
*--------------------------------------
KW.SWITCH.END
lda #'B' define BREAK Label
jsr KW.NewLabel
bcs .99
clv pop context
.99 rts
*--------------------------------------
KW.CASE ldy CStackPtr
beq .9
iny skip ; or }
lda (ZPCCStack),y
cmp #10 SWITCH ??
bne .9
lda CStackPtr
clc
adc #7
tay
lda (ZPCCStack),y type
tay
lda #0 for integral type
jsr EXP.Eval
bcs .99
jsr CC.GetCharNB
bcs .9
cmp #':'
bne .9
jsr CORE.GetNCharNB skip ':'
clc
rts
.9 lda #E.CSYN
2022-06-12 20:42:22 +00:00
sec
.99 rts
*--------------------------------------
KW.DEFAULT ldy CStackPtr
beq .9
iny skip ; or }
lda (ZPCCStack),y
cmp #10 SWITCH ??
bne .9
jsr CC.GetCharNB
bcs .9
cmp #':'
bne .9
jsr CORE.GetNCharNB skip ':'
clc
2022-06-12 20:42:22 +00:00
rts
.9 lda #E.CSYN
sec
.99 rts
2022-06-12 20:42:22 +00:00
*--------------------------------------
KW.BREAK lda #'B'
2022-08-20 14:37:37 +00:00
jsr KW.LookupLabel
2022-08-20 14:37:37 +00:00
bcs .9
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP break
jmp CODE.TOABSYX
2022-08-20 14:37:37 +00:00
.9 lda #E.CSYN
2022-06-12 20:42:22 +00:00
sec
rts
*--------------------------------------
KW.CONTINUE lda #'C'
2022-08-20 14:37:37 +00:00
jsr KW.LookupLabel
2022-08-20 14:37:37 +00:00
bcs .9
2022-08-20 14:37:37 +00:00
lda #$4C emit JMP cont
jmp CODE.TOABSYX
2022-08-20 14:37:37 +00:00
.9 lda #E.CSYN
2022-01-30 21:47:08 +00:00
sec
rts
*--------------------------------------
KW.RETURN ldy CStackPtr
2022-01-30 21:47:08 +00:00
beq .9
.1 iny skip ; or }
lda (ZPCCStack),y
bmi .7 f()
tya
clc
2022-08-20 14:37:37 +00:00
adc #5 skip CPStmt (6 bytes)
2022-01-30 21:47:08 +00:00
tay
bcc .1
.9 lda #E.STACKERROR
sec
.99 rts
.7 iny skip bState
iny skip Locals
2022-06-22 06:26:44 +00:00
2022-08-20 14:37:37 +00:00
iny
iny skip CPSID
2022-01-30 21:47:08 +00:00
iny get SYM.T
lda (ZPCCStack),y
2022-06-22 06:26:44 +00:00
2022-01-30 21:47:08 +00:00
pha
iny get SYM.Q
lda (ZPCCStack),y
2022-06-22 06:26:44 +00:00
2022-01-30 21:47:08 +00:00
ply
jsr EXP.Eval
2022-01-30 21:47:08 +00:00
bcs .99
jsr SYM.GetYASizeOfInAXC Y,A=T/Q
2022-01-30 21:47:08 +00:00
tax X = sizeof
jsr CODE.SetRetValue
2022-08-20 14:37:37 +00:00
bcs .99
2022-06-22 06:26:44 +00:00
2022-08-20 14:37:37 +00:00
>LDYA L.PCC.LEAVE
jmp CODE.EmitPCC
2022-01-30 21:47:08 +00:00
*--------------------------------------
KW.SIZEOF
2022-02-04 14:57:17 +00:00
lda #E.CSYN
sec
rts
*--------------------------------------
KW.BEGIN00 lda #0
jsr CC.Push no T/Q
bcs KW.BEGIN.RTS
jsr CC.Push
bcs KW.BEGIN.RTS
KW.BEGIN jsr SYM.NewCPSID
2022-08-20 14:37:37 +00:00
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
>LDA.G CC.CPSPFX+3
jsr CC.Push
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
>LDA.G CC.CPSPFX+2
jsr CC.Push
bcs .99
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
lda LocalPtr Locals
2022-01-30 21:47:08 +00:00
jsr CC.Push
bcs .99
2022-06-22 06:26:44 +00:00
2022-08-20 14:37:37 +00:00
lda #0 bState
jsr CC.Push
bcs .99
>LDA.G CC.CmdSave
jmp CC.Push
.99
KW.BEGIN.RTS rts
2022-08-20 14:37:37 +00:00
*--------------------------------------
KW.STMT jsr CORE.GetNCharNBNL
2022-08-20 14:37:37 +00:00
bcs .9
cmp #'{'
bne .1
jsr CORE.GetNCharNB skip '{'
2022-08-20 14:37:37 +00:00
bcs .99
lda #'}'
jmp CC.Push
.1 lda #';'
2022-01-30 21:47:08 +00:00
jmp CC.Push
2022-06-22 06:26:44 +00:00
2022-01-30 21:47:08 +00:00
.9 lda #E.CSYN
sec
2022-06-22 06:26:44 +00:00
.99 rts
*--------------------------------------
KW.NewLabel pha
2022-08-20 14:37:37 +00:00
lda CStackPtr
clc
adc #4
tay
lda (ZPCCStack),y
pha
iny
lda (ZPCCStack),y
ply
>STYA.G CC.CPSPFX+2
pla
jmp SYM.NewA
2022-08-20 14:37:37 +00:00
*--------------------------------------
KW.GetLabel pha
2022-08-20 14:37:37 +00:00
lda CStackPtr
clc
adc #4
tay
lda (ZPCCStack),y
pha
iny
lda (ZPCCStack),y
ply
>STYA.G CC.CPSPFX+2
pla
jmp SYM.LookupA
2022-08-20 14:37:37 +00:00
*--------------------------------------
KW.LookupLabel pha
2022-08-20 14:37:37 +00:00
ldy CStackPtr
sty ArgIndex
.1 ldy ArgIndex
beq .9
iny skip ; or }
lda (ZPCCStack),y
bmi .9 f()
2022-08-20 14:37:37 +00:00
iny
iny
iny
lda (ZPCCStack),y
pha
iny
lda (ZPCCStack),y
iny
iny
iny
2022-08-20 14:37:37 +00:00
sty ArgIndex
2022-08-20 14:37:37 +00:00
ply
>STYA.G CC.CPSPFX+2
pla
pha
jsr SYM.LookupA
2022-08-20 14:37:37 +00:00
bcs .1
2022-08-20 14:37:37 +00:00
pla
.8 rts
2022-08-20 14:37:37 +00:00
.9 pla
lda #E.CSYN
sec
.99 rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
* Input : Value on Stack, Y,A = Type/Qual
*--------------------------------------
KW.TestZero jsr EXP.GetYASizeOfInAXC
2022-01-30 21:47:08 +00:00
tax
2022-08-20 14:37:37 +00:00
cpx #1
bne .1
2022-08-20 14:37:37 +00:00
>LDYA L.PCC.TestZero1
jmp CODE.EmitPCC
2022-08-20 14:37:37 +00:00
.1 cpx #2
bne .2
2022-01-30 21:47:08 +00:00
2022-08-20 14:37:37 +00:00
>LDYA L.PCC.TestZero2
jmp CODE.EmitPCC
2022-08-20 14:37:37 +00:00
.2 jsr CODE.LDXI
bcs .9
>LDYA L.PCC.TestZeroX
jmp CODE.EmitPCC
.9 rts
*--------------------------------------
2022-08-20 14:37:37 +00:00
* Input : Value on Stack, Y,A = Type/Qual
*--------------------------------------
KW.TestnZero jsr EXP.GetYASizeOfInAXC
2022-08-20 14:37:37 +00:00
tax
cpx #1
bne .1
2022-08-20 14:37:37 +00:00
>LDYA L.PCC.TestnZero1
jmp CODE.EmitPCC
2022-08-20 14:37:37 +00:00
.1 cpx #2
bne .2
>LDYA L.PCC.TestnZero2
jmp CODE.EmitPCC
.2 jsr CODE.LDXI
bcs .9
>LDYA L.PCC.TestnZeroX
jmp CODE.EmitPCC
.9 rts
*--------------------------------------
2022-01-30 21:47:08 +00:00
* Input : Value on Stack, Y,A = Type/Qual
*--------------------------------------
KW.StackDiscard jsr TYPE.SizeOf
2022-01-30 21:47:08 +00:00
txa
beq .8 void
2022-01-30 21:47:08 +00:00
jsr CODE.AddLocal
.8 clc
2022-01-30 21:47:08 +00:00
.9 rts
*--------------------------------------
MAN
SAVE usr/src/bin/cc.s.kw
LOAD usr/src/bin/cc.s
ASM