A2osX/BIN/CSH.S.EXP.txt

490 lines
7.7 KiB
Plaintext
Raw Normal View History

2020-08-02 12:19:43 +00:00
NEW
AUTO 3,1
.LIST OFF
*--------------------------------------
* Input:
2021-05-30 20:34:03 +00:00
* ZPInputBufPtr, Y,A = Expected type/qual
2020-08-02 12:19:43 +00:00
* Output:
* CS, A = EC
2021-05-30 20:34:03 +00:00
* CC, Y,A = type/qual, Value on Stack
2020-08-02 12:19:43 +00:00
*--------------------------------------
CSH.ExpEval ldx ZPPtr1
phx
ldx ZPPtr1+1 local : used by lookup
phx
2021-05-30 20:34:03 +00:00
2020-08-02 12:19:43 +00:00
ldx ZPPtr2 local : VarType
phx
2021-05-30 20:34:03 +00:00
ldx ZPPtr2+1 local : VarQual
phx
ldx ZPPtr3 local : BOP
2020-08-02 12:19:43 +00:00
phx
2021-05-30 20:34:03 +00:00
>STYA ZPPtr2 local : expected type/qual
2020-08-02 12:19:43 +00:00
2021-05-30 20:34:03 +00:00
lda #$ff no previous OP
2020-08-02 12:19:43 +00:00
pha
*--------------------------------------
.10 jsr CSH.GetCharNB
bcs .19
.11 cmp #'('
bne .20
jsr CSH.GetNextCharNB skip (
bcs .19
2021-05-30 20:34:03 +00:00
>LDYA ZPPtr2
2020-08-02 12:19:43 +00:00
jsr CSH.ExpEval
bcs .19
2021-05-22 21:05:12 +00:00
2021-05-30 20:34:03 +00:00
>STYA ZPPtr2 update type/qual
2020-08-02 12:19:43 +00:00
jsr CSH.GetCharNB
bcs .19
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
cmp #')'
bne .19
jsr CSH.GetNextCharNB skip )
bcc .31
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
.19 jmp .90
*--------------------------------------
.20 jsr CSH.IsLetter define, Fnc or Var ?
bcs .22
jsr CSH.GetDefine
bcc .10
2021-05-30 20:34:03 +00:00
jsr CSH.VarLookup
2020-08-02 12:19:43 +00:00
bcs .21
2021-05-30 20:34:03 +00:00
jsr CSH.GetValue Check type & Get value on stack
2020-08-02 12:19:43 +00:00
bcs .29
bra .30
2021-05-30 20:34:03 +00:00
.21 >LDYA ZPPtr2 var type/qual
2020-08-02 12:19:43 +00:00
jsr CSH.fCall X = function index
bcs .29
2021-05-30 20:34:03 +00:00
>STYA ZPPtr2 store real var type
2020-08-02 12:19:43 +00:00
bra .30
2021-05-30 20:34:03 +00:00
*--------------------------------------
2020-08-02 12:19:43 +00:00
.22 jsr CSH.IsDigit10 number ?
bcs .24
2021-05-30 20:34:03 +00:00
ldy ZPPtr2
2020-08-02 12:19:43 +00:00
bne .23
2021-05-30 20:34:03 +00:00
ldy #CSH.T.SINT
sty ZPPtr2
stz ZPPtr2+1
2020-08-02 12:19:43 +00:00
.23 jsr CSH.GetNumOnStack
bcs .29
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
bra .30
.24 cmp #'"' String literal
bne .90
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
jsr CSH.AddContCharP
.29 bcs .99
*--------------------------------------
.30 jsr CSH.GetCharNB
bcs .90
2021-05-22 21:05:12 +00:00
.31 cmp #';'
2020-08-02 12:19:43 +00:00
beq .80
2020-12-23 14:54:57 +00:00
2021-05-22 21:05:12 +00:00
cmp #','
2020-08-02 12:19:43 +00:00
beq .80
2020-12-23 14:54:57 +00:00
2021-05-22 21:05:12 +00:00
cmp #')'
2020-08-02 12:19:43 +00:00
beq .80
jsr CSH.IsOPChar
bcs .90
>LDYA L.CSH.BOPS we are at V1 op1 V2 op2...
jsr CSH.LookupOP
bcs .90
2021-05-30 20:34:03 +00:00
stx ZPPtr3 save OP(n)
2020-08-02 12:19:43 +00:00
2021-05-30 20:34:03 +00:00
.32 plx get OP(n-1)
2020-08-02 12:19:43 +00:00
bmi .33 $ff....
2021-05-30 20:34:03 +00:00
cpx ZPPtr3
2020-08-02 12:19:43 +00:00
bcc .33 OP(n) has precedence, on stack : V1,V2
2021-05-30 20:34:03 +00:00
>LDYA ZPPtr2 OP(n-1) has precedence...
2020-08-02 12:19:43 +00:00
jsr CSH.BOP.EXEC compute V(n-1) <OP(n-1)> V(n)
bcc .32
bcs .99
2021-05-30 20:34:03 +00:00
.33 phx push back OP(n-1)
lda ZPPtr3 get OP(n)
2020-08-02 12:19:43 +00:00
pha push OP(n) on stack
jmp .10 go check for next token
*--------------------------------------
2021-05-30 20:34:03 +00:00
.80 plx any OP on stack ?
2020-08-02 12:19:43 +00:00
bmi .88
2021-05-30 20:34:03 +00:00
>LDYA ZPPtr2 Var Type
2020-08-02 12:19:43 +00:00
jsr CSH.BOP.EXEC
bcc .80
bcs .99
2021-05-04 17:31:21 +00:00
.90 lda #E.ESYN
2020-08-02 12:19:43 +00:00
.99 plx
bpl .99
sec
2021-05-30 20:34:03 +00:00
bra .89
2020-08-02 12:19:43 +00:00
.88 clc
2021-05-30 20:34:03 +00:00
>LDYA ZPPtr2 Type/Qual
.89 plx
stx ZPPtr3
plx
stx ZPPtr2+1
plx
stx ZPPtr2
plx
stx ZPPtr1+1
plx
stx ZPPtr1
2020-08-02 12:19:43 +00:00
rts
*--------------------------------------
CSH.AddContCharP
ldy #0
.1 jsr CSH.GetNextChar
bcs .9
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
cmp #C.CR
beq .9
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
cmp #'"'
beq .2
2021-05-22 21:05:12 +00:00
2020-08-02 12:19:43 +00:00
sta (ZPCSHConst),y
iny
bra .1
.2 lda #0
sta (ZPCSHConst),y
>PUSHW ZPCSHConst Push PTR on stack
tya
sec
adc ZPCSHConst
sta ZPCSHConst
bcc .3
2021-05-30 20:34:03 +00:00
2020-08-02 12:19:43 +00:00
inc ZPCSHConst+1
.3 jsr CSH.GetNextChar Skip "
clc
rts
2021-05-04 17:31:21 +00:00
.9 lda #E.ESYN
2020-08-02 12:19:43 +00:00
sec
rts
*--------------------------------------
CSH.GetNumOnStack
2021-05-30 20:34:03 +00:00
cpy #CSH.T.FLOAT
2021-05-04 17:31:21 +00:00
bcc .1
2021-05-30 20:34:03 +00:00
2021-05-04 17:31:21 +00:00
bne .99
2020-08-02 12:19:43 +00:00
2020-12-23 14:54:57 +00:00
>PUSHW ZPInputBufPtr
>PUSHWI ZPInputBufPtr
2020-08-02 12:19:43 +00:00
>SYSCALL StrToF
clc
rts
2020-12-23 14:54:57 +00:00
.1 >PUSHW ZPInputBufPtr
>PUSHWI ZPInputBufPtr
2020-08-02 12:19:43 +00:00
>PUSHBI 10
bcc .2
2021-01-12 21:14:13 +00:00
2020-08-02 12:19:43 +00:00
>SYSCALL StrToUL
bra .3
.2 >SYSCALL StrToL
2021-05-30 20:34:03 +00:00
.3 bcs .9
2020-08-02 12:19:43 +00:00
2021-05-30 20:34:03 +00:00
ldy ZPPtr2
lda CSH.TYPESIZE-1,y
2020-08-02 12:19:43 +00:00
cmp #4
beq .8
cmp #2
bne .4
2021-01-12 21:14:13 +00:00
2020-08-02 12:19:43 +00:00
ldy #1
>PULLA
sta (pStack),y
>PULLA
sta (pStack),y
clc
rts
.4 >PULLA
inc pStack
inc pStack
sta (pStack)
2021-01-12 21:14:13 +00:00
2020-08-02 12:19:43 +00:00
.8 clc
.9 rts
2021-05-04 17:31:21 +00:00
.99 lda #E.TMISMATCH
2020-08-02 12:19:43 +00:00
sec
rts
*--------------------------------------
2021-05-30 20:34:03 +00:00
CSH.VarLookup >PUSHB.G CSH.hSymbols
>PUSHW ZPInputBufPtr
>SYSCALL SListLookup
bcs .9
phy
pha
txa
* clc
adc ZPInputBufPtr
sta ZPInputBufPtr
bcc .1
inc ZPInputBufPtr+1
clc
.1 >PUSHB.G CSH.hSymbols
pla
>PUSHA
pla
>PUSHA KeyID
>PUSHEA.G CSH.VarDef
>PUSHWI 8 8 bytes
2021-07-24 20:42:23 +00:00
>PUSHWZ From Start
2021-05-30 20:34:03 +00:00
>SYSCALL SListGetData
.9 rts
*--------------------------------------
CSH.GetValue lda ZPPtr2 target type
beq .1
>LDA.G CSH.VarDef Type
cmp #CSH.T.VOID
beq .11
cmp ZPPtr2
bne .9
.11 lda ZPPtr2+1 qual
>CMP.G CSH.VarDef+1
beq .2
.9 lda #E.TMISMATCH
sec
rts
.1 >LDA.G CSH.VarDef Type
sta ZPPtr2
iny
lda (pData),y
sta ZPPtr2+1
.2 lda ZPPtr3
pha
lda ZPPtr3+1
pha
>LDA.G CSH.VarDef+4
sta ZPPtr3
iny
lda (pData),y
sta ZPPtr3+1
ldx ZPPtr2
ldy CSH.TYPESIZE-1,x
.3 dey
lda (ZPPtr3),y
>PUSHA
tya
bne .3
pla
sta ZPPtr3+1
pla
sta ZPPtr3
clc
rts
*--------------------------------------
* Input:
* ZPInputBufPtr, Y,A = Expected type/qual
* Output:
* CS, A = EC
* CC, Y,A = type/qual, Result on Stack
*--------------------------------------
CSH.fCall ldx ZPPtr1
phx
ldx ZPPtr1+1 local : fdef Ptr
phx
ldx ZPPtr2 local : type
phx
ldx ZPPtr2+1 local : qual
phx
ldx ZPPtr3 local : variadic size
phx
ldx ZPPtr3+1 local : f
phx
>STYA ZPPtr2 save Type/qual
stz ZPPtr3 Reset VARIADIC byte count
>LDYA L.CSH.FN
jsr CSH.LookupFN
bcs .10
stx ZPPtr3+1 X = function index
>STYA ZPPtr1 f() definition, starting at returned type
jsr CSH.GetCharNB
bcs .10
cmp #'('
bne .52
jsr CSH.GetNextCharNB skip '('
bcs .10
jsr CSH.ZPPtr1GetW Y,A = Return value Type/Qual
ldx ZPPtr2
beq .1 no check required
cpy ZPPtr2
bne .91
cmp ZPPtr2+1
bne .91
.1 >STYA ZPPtr2 this will be the returned type/qual
jsr CSH.ZPPtr1GetNextW advance to arg list type
beq .7 end of list, go check ending ')'
*--------------------------------------
.3 cpy #CSH.T.VARIADIC if VARIADIC, don't advance to next arg and assume type = 0
bne .4
ldy #0
lda #0
.4 jsr CSH.ExpEval Y,A = 0 if VARIADIC
bcs .93
jsr CSH.GetVarSize Y,A = Var Type/Qual
tax
lda (ZPPtr1)
eor #CSH.T.VARIADIC
bne .5
txa
clc make sure pointer only 2 bytes
adc ZPPtr3
sta ZPPtr3 Add to byte count
bra .51 stay on VARIADIC tag
.5 jsr CSH.ZPPtr1NextW
.51 jsr CSH.GetCharNB
.10 bcs .90
cmp #','
bne .6
jsr CSH.GetNextCharNB Skip ,
jsr CSH.ZPPtr1GetW
bne .3 Another ARG....
.52 bra .90 extra args....error
.6 cmp #')'
bne .90
jsr CSH.ZPPtr1GetW
beq .8 no more arg after ')', exit
cpy #CSH.T.VARIADIC
bne .90 missing arg
>PUSHB ZPPtr3 push VARIADIC byte count
bra .8
.7 jsr CSH.GetCharNB
bcs .90
cmp #')'
bne .90
.8 jsr CSH.GetNextCharNB Skip )
ldx ZPPtr3+1
jsr CSH.Exec
bcs .93
>LDYA ZPPtr2 type/qual
bra .93
.90 lda #E.CSYN
bra .92
.91 lda #E.TMISMATCH
.92 sec
.93 plx
stx ZPPtr3+1
plx
stx ZPPtr3
plx
stx ZPPtr2+1
plx
stx ZPPtr2
plx
stx ZPPtr1+1
plx
stx ZPPtr1
.99 rts
*--------------------------------------
2020-08-02 12:19:43 +00:00
MAN
SAVE usr/src/bin/csh.s.exp
LOAD usr/src/bin/csh.s
ASM