diff --git a/.Floppies/A2OSX.BUILD.po b/.Floppies/A2OSX.BUILD.po index cbc43182..19980193 100644 Binary files a/.Floppies/A2OSX.BUILD.po and b/.Floppies/A2OSX.BUILD.po differ diff --git a/BIN/CSH.S.CORE.txt b/BIN/CSH.S.CORE.txt index ad8c1022..78cb3792 100644 --- a/BIN/CSH.S.CORE.txt +++ b/BIN/CSH.S.CORE.txt @@ -140,59 +140,64 @@ CSH.Run.1 cmp #C.CR empty line.... .10 jsr CSH.IsLetter bcc .20 +* TODO: PREOPS ++ --..... - - bcs .29 error, todo : PREOPS ++ --..... + bcs .29 *-------------------------------------- .20 >LDYA L.CSH.TMODS jsr CSH.LookupID bcs .50 - jsr CSH.tDecl.JMP + jsr CSH.tDecl bcs .59 - jsr CSH.AddSymbol add with undef value... - bcs .99 OOM or DUP + >STYA ZPVarType Type/Qual + jsr CSH.AddSymbol add with undef value... + bcs .29 OOM or DUP + + lda ZPVarQual + bit #CSH.Q.FUNC + bne .21 + jsr CSH.GetCharNB bcs .99 cmp #';' - beq .8 + beq .69 cmp #'=' - bne .21 + bne .99 jsr CSH.GetNextCharNB skip '=' bcs .99 - lda ZPVarType + >LDYA ZPVarType T/Q jsr CSH.ExpEval bcs .9 - jsr CSH.SetVarValueFromStack X= Type, Set value to this var -.29 bcs .99 + jsr CSH.SetVarValue Y,A Type/qual, Set value to this var +.29 bcs .9 bra .68 -.21 cmp #'(' - bne .99 - - jsr CSH.fDecl - bcs .99 +.21 jsr CSH.fDecl + bcs .9 bra .68 *-------------------------------------- .50 jsr CSH.SavePtr Save Ptr, in case of while,for.... + >LDYA L.CSH.KW jsr CSH.LookupID bcs .6 not an internal CSH keyword.... jsr CSH.KW.JMP .59 bcs .9 - bra .8 -.6 jsr CSH.GetVar + bra .8 +*-------------------------------------- +.6 jsr CSH.GetVar I = ? bcs .7 >STYA ZPVarID @@ -202,8 +207,13 @@ CSH.Run.1 cmp #C.CR empty line.... lda ZPVarQual bit #CSH.Q.FUNC beq .60 - + ldy #0 func( ? + lda #0 + jsr CSH.fExec + bcs .9 + + bra .8 *-------------------------------------- .60 jsr CSH.GetCharNB bcs .9 @@ -214,27 +224,29 @@ CSH.Run.1 cmp #C.CR empty line.... jsr CSH.GetNextChar Skip = bcs .99 - lda ZPVarType + >LDYA ZPVarType T/Q jsr CSH.ExpEval bcs .9 - jsr CSH.SetVarValueFromStack X = Exp Type + jsr CSH.SetVarValue bcs .9 .68 jsr CSH.GetCharNB cmp #';' - beq .8 +.69 beq .8 .99 lda #E.CSYN sec .9 rts - -.7 lda #0 no return value type check required - jsr CSH.fCall +*-------------------------------------- +.7 ldy #0 no return value type check required + lda #0 + + jsr CSH.fCall Y,A = Type/Qual bcs .9 - jsr CSH.GetVarSize X = returned value type - clc A = Sizeof CC to ignore Pointer hMem + jsr CSH.GetVarSize Y,A = returned value type + clc A = Sizeof, CC to ignore Pointer hMem adc pStack sta pStack Discard value on stack @@ -260,10 +272,12 @@ CSH.COMMENTS jsr CSH.GetNextChar *-------------------------------------- CSH.SkipLine jsr CSH.GetNextChar bcs .9 + cmp #C.CR bne CSH.SkipLine - clc + jmp CSH.GetNextChar Skip CR + .9 rts *-------------------------------------- CSH.SavePtr >LDYA ZPInputBufPtr @@ -328,9 +342,10 @@ CSH.Lookup phy Y = len >LDA.G CSH.LookupOpt bpl .1 - ldy #$0 Start at Y=1 for VOID func() + ldy #$0 Start at Y=2 for VOID func() .6 iny + iny lda (ZPPtr1),y bne .6 @@ -342,9 +357,27 @@ CSH.Lookup phy Y = len sec rts *-------------------------------------- -CSH.ZPPtr1Next inc ZPPtr1 +CSH.ZPPtr1GetNextW + jsr CSH.ZPPtr1NextW +*-------------------------------------- +CSH.ZPPtr1GetW lda (ZPPtr1) + beq .8 + + pha + + ldy #1 + lda (ZPPtr1),y + ply + +.8 rts +*-------------------------------------- +CSH.ZPPtr1NextW jsr .1 + +.1 inc ZPPtr1 bne .8 + inc ZPPtr1+1 + .8 rts *-------------------------------------- CSH.ZPPtr1AddAp1 @@ -363,7 +396,8 @@ CSH.AddSymbol >LDA.G CSH.hSymbols bcs .9 >STYA ZPVarID - ldx ZPVarType + + >LDYA ZPVarType jsr CSH.GetVarSize CS if pointer sta ZPVarSizeOf @@ -386,10 +420,33 @@ CSH.AddSymbol >LDA.G CSH.hSymbols bcs .99 - >PUSHB.G CSH.hSymbols + jsr CSH.GetCharNB + bcs .8 + + cmp #'(' + beq .7 + + lda ZPVarQual + and #CSH.Q.FUNC + beq .8 + + lda #E.CSYN + sec + rts + +.7 lda #CSH.Q.FUNC + tsb ZPVarQual + + lda ZPCSHfDecl + sta ZPVarDefPtr + + lda ZPCSHfDecl+1 + sta ZPVarDefPtr+1 + +.8 >PUSHB.G CSH.hSymbols >PUSHW ZPVarID >PUSHWI ZPVarDef - >PUSHWI 6 + >PUSHWI 8 >SYSCALL SListAddData .9 rts @@ -397,91 +454,288 @@ CSH.AddSymbol >LDA.G CSH.hSymbols * sec rts *-------------------------------------- -CSH.fDecl lda ZPCSHfDecl - sta ZPVarDataPtr - - lda ZPCSHfDecl+1 - sta ZPVarDataPtr+1 +* ZPVarDataPtr = fDef +*-------------------------------------- +CSH.fExec 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 - lda ZPVarID + >STYA ZPPtr2 save Type/qual + + >LDYA ZPVarDefPtr + >STYA ZPPtr1 + + stz ZPPtr3 Reset VARIADIC byte count + + 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 eor #CSH.Q.FUNC + >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 + +.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 +*-------------------------------------- +CSH.fDecl >ENTER 2 + + lda #0 + sta (pStack) hLocal + + lda ZPVarType jsr CSH.fDeclAddA - lda ZPVarID+1 + lda ZPVarQual jsr CSH.fDeclAddA - >DEBUG + jsr CSH.GetNextCharNB Skip ( bcs .9 .1 cmp #')' - beq .5 + beq .6 .2 jsr CSH.fDeclGetArg bcs .99 + pha + + tya + jsr CSH.fDeclAddA + + pla + jsr CSH.fDeclAddA + jsr CSH.GetCharNB bcs .9 + + jsr CSH.IsLetter + bcs .5 - cmp #')' - beq .5 +* TODO: AddLocal - cmp #',' - bne .9 - - jsr CSH.GetNextCharNB Skip , +.3 jsr CSH.GetNextCharNB bcs .9 + jsr CSH.IsLetterOrDigit + bcc .3 + + + +.5 cmp #')' + beq .6 + + cmp #',' + bne .9 + + jsr CSH.GetNextCharNB Skip , + bcs .9 + bra .2 -.5 jsr CSH.GetNextCharNB Skip ) +.6 jsr CSH.GetNextCharNB Skip ) bcs .9 cmp #';' - bne .9 - - jsr CSH.GetNextCharNB Skip ; + beq .7 + + +* TODO: f() body + + bra .9 +*-------------------------------------- +.7 lda #0 +* sta ZPVarDataPtr +* sta ZPVarDataPtr+1 .8 lda #0 - sta (ZPCSHfDecl) - - jmp CSH.SetVarValueFromStack + jsr CSH.fDeclAddA + + clc + bra .99 .9 lda #E.CSYN sec -.99 rts + +.99 >LEAVE + rts *-------------------------------------- -CSH.fDeclGetArg >ENTER 4 - - >LDYA L.CSH.TMODS +CSH.fDeclGetArg lda (ZPInputBufPtr) + cmp #'.' + bne .5 + + ldx #2 + +.1 jsr CSH.GetNextChar + bcs .9 + + cmp #'.' + bne .9 + + dex + bne .1 + + jsr CSH.GetNextCharNB + bcs .9 + + eor #')' + bne .9 + + ldy #CSH.T.VARIADIC Type +* lda #0 Qual +* clc + rts + +.5 >LDYA L.CSH.TMODS jsr CSH.LookupID bcs .9 - + jsr CSH.tDecl bcs .9 - - + +* Y,A = Type/Qual + bra .8 - + .9 lda #E.CSYN sec -.8 >LEAVE - rts +.8 rts *-------------------------------------- CSH.fDeclAddA sta (ZPCSHfDecl) inc ZPCSHfDecl bne .8 - - inc ZPCSHfDecl+1 - -.8 rts -*-------------------------------------- -CSH.tDecl jsr CSH.tDecl.JMP - bcs .9 - - - -.9 rts -CSH.tDecl.JMP jmp (J.CSH.TMODS,x) + inc ZPCSHfDecl+1 + +.8 rts +*-------------------------------------- +CSH.tDecl >ENTER 2 + lda #0 + sta (pStack) Type + ldy #1 + sta (pStack),y Qual + + jsr .7 + bcs .99 + + ldy #1 + lda (pStack),y + pha + lda (pStack) + tay Y = Type + pla A = Qual + + clc + +.99 >LEAVE + rts + +.7 jmp (J.CSH.TMODS,x) *-------------------------------------- CSH.NewKey >PUSHA >PUSHW ZPInputBufPtr @@ -489,6 +743,8 @@ CSH.NewKey >PUSHA bcs .9 pha + phy + txa * clc adc ZPInputBufPtr @@ -498,15 +754,18 @@ CSH.NewKey >PUSHA inc ZPInputBufPtr+1 .1 clc + ply pla .9 rts *-------------------------------------- -* X=Type +* Y,A = Type/Qual *-------------------------------------- -CSH.SetVarValueFromStack - cpx ZPVarType X = type +CSH.SetVarValue cpy ZPVarType bne .99 + cmp ZPVarQual + bne .99 + ldy #0 .1 lda (pStack) @@ -565,9 +824,12 @@ CSH.Get >PUSHW ZPInputBufPtr adc ZPInputBufPtr sta ZPInputBufPtr bcc .1 + inc ZPInputBufPtr+1 clc + .1 pla Y,A = VarID + .9 rts *-------------------------------------- CSH.GetVarDef phy @@ -580,85 +842,18 @@ CSH.GetVarDef phy >PUSHA KeyID >PUSHWI ZPVarDef - >PUSHWI 6 6 bytes + >PUSHWI 8 8 bytes >PUSHWI 0 From Start >SYSCALL SListGetData rts *-------------------------------------- -* Input : -* X=Var Type (or 0) -* YA=VarID -* Output : Stack, X = Var Type -*-------------------------------------- -CSH.GetVarValueOnStack - phx - phy - pha - >PUSHB.G CSH.hSymbols - - pla - >PUSHA - pla - >PUSHA KeyID - - >PUSHEA.G CSH.VarDef - >PUSHWI 6 6 bytes - >PUSHWI 0 From Start - >SYSCALL SListGetData - plx - - bcs .9 - - txa - beq .1 any type - - >CMP.G CSH.VarDef Type - beq .2 - - and #CSH.Q.PPPOINTER - beq .99 not pointer....mismatch - - >EOR.G CSH.VarDef - and #CSH.Q.PPPOINTER - bne .99 compare only pointer depth - -.1 >LDA.G CSH.VarDef - beq * - -.2 tax - jsr CSH.GetVarSize - pha - - >LDA.G CSH.VarDef+4 - sta ZPPtr3 - iny - lda (pData),y - sta ZPPtr3+1 - - ply - -.3 dey - lda (ZPPtr3),y - >PUSHA - tya - bne .3 - - >LDA.G CSH.VarDef - tax - clc X = Var Type -.9 rts - -.99 lda #E.TMISMATCH - sec - rts -*-------------------------------------- -* Input : Value on Stack, X = Var Type +* Input : Value on Stack, Y,A = Type/Qual * Output : CC = true, CS = false *-------------------------------------- -CSH.IsValue0 cpx #CSH.T.FLOAT +CSH.IsValue0 cpy #CSH.T.FLOAT bcc .1 char,int,long - ldy CSH.TYPESIZE,x + lda CSH.TYPESIZE-1,y lda (ZPVarDataPtr),y bne .9 @@ -763,10 +958,13 @@ CSH.SkipBlock ldy #0 not in "", TOTO:skip comments .1 jsr CSH.GetNextCharNB bcs .9 + cmp #'{' bne .2 + tya bmi .1 + inx bra .1 @@ -775,55 +973,66 @@ CSH.SkipBlock ldy #0 not in "", TOTO:skip comments tya bmi .1 + dex bne .1 + clc rts .3 cmp #'"' bne .1 + tya eor #$ff tay bra .1 - jmp CSH.GetNextCharNB skip '}' + .9 rts *-------------------------------------- CSH.GetCharNB jsr CSH.GetChar bcs CSH.GetNextCharNB.RTS + jsr CSH.CheckCharNB bcc CSH.GetNextCharNB.RTS *-------------------------------------- CSH.GetNextCharNB jsr CSH.GetNextChar bcs CSH.GetNextCharNB.RTS + jsr CSH.CheckCharNB bcs CSH.GetNextCharNB + CSH.GetNextCharNB.RTS rts *-------------------------------------- CSH.CheckSpace jsr CSH.GetChar bcs .90 + cmp #C.SPACE bne .90 jsr CSH.GetNextCharNB - bcc CSH.GetNextCharNB.RTS + bcc .99 .90 lda #E.CSYN sec - rts +.99 rts *-------------------------------------- CSH.CheckCharNB cmp #C.SPACE beq .9 + cmp #C.LF beq .9 + cmp #C.TAB beq .9 + clc .9 rts *-------------------------------------- CSH.GetNextChar inc ZPInputBufPtr bne CSH.GetChar + inc ZPInputBufPtr+1 *-------------------------------------- CSH.GetChar lda (ZPInputBufPtr) @@ -911,29 +1120,26 @@ CSH.IsLetterRTS rts *--------------------------------------- CSH.IsDigit10 cmp #'0' bcc .9 + cmp #'9'+1 rts cc if ok, cs if not + .9 sec rts *-------------------------------------- -* in : X = type, out : X = type, A = size +* in : Y,A = type/qual +* out : A = size *-------------------------------------- -CSH.GetVarSize txa - and #CSH.Q.PPPOINTER +CSH.GetVarSize and #CSH.Q.PPPOINTER bne .2 - txa - and #$f - phx - tax - lda CSH.TYPESIZE,x - plx + lda CSH.TYPESIZE-1,y clc rts -.2 sec +1 for hMem Storage - lda #2 +.2 lda #2 pointer + sec +1 for hMem Storage rts *-------------------------------------- MAN diff --git a/BIN/CSH.S.EXEC.txt b/BIN/CSH.S.EXEC.txt index ed743890..97915a11 100644 --- a/BIN/CSH.S.EXEC.txt +++ b/BIN/CSH.S.EXEC.txt @@ -2,7 +2,7 @@ NEW AUTO 3,1 .LIST OFF *-------------------------------------- -* Y = Type, A = OP +* Y,A = Type/Qual, X = OP *-------------------------------------- CSH.BOP.EXEC cpy #CSH.T.UINT bcs .3 @@ -17,13 +17,12 @@ CSH.BOP.EXEC cpy #CSH.T.UINT sec rts -.1 tax - jmp (J.CSH.bBOPS,x) +.1 jmp (J.CSH.bBOPS,x) -.2 tax - jmp (J.CSH.cBOPS,x) +.2 jmp (J.CSH.cBOPS,x) -.3 clc +.3 txa + clc adc CSH.Type2FPU-CSH.T.UINT,y tax jsr A2osX.FPUCALL @@ -114,6 +113,8 @@ CSH.BOPS.LOR clc rts *-------------------------------------- +CSH.Exec jmp (J.CSH.EXEC,x) +**-------------------------------------- EXEC.pwr >FPU PWR clc rts @@ -190,7 +191,8 @@ EXEC.malloc >PULLYA EXEC.fopen >SYSCALL FOpen >PUSHYA *-------------------------------------- -EXEC.fclose >SYSCALL FClose +EXEC.fclose >PULLA + >SYSCALL FClose >PUSHYA *-------------------------------------- EXEC.fread >SYSCALL FRead diff --git a/BIN/CSH.S.EXP.txt b/BIN/CSH.S.EXP.txt index f9b4a2d6..a8fe6460 100644 --- a/BIN/CSH.S.EXP.txt +++ b/BIN/CSH.S.EXP.txt @@ -3,23 +3,27 @@ NEW .LIST OFF *-------------------------------------- * Input: -* ZPInputBufPtr, A = Expected type +* ZPInputBufPtr, Y,A = Expected type/qual * Output: * CS, A = EC -* CC, X = Var Type, Value on Stack +* CC, Y,A = type/qual, Value on Stack *-------------------------------------- CSH.ExpEval ldx ZPPtr1 phx ldx ZPPtr1+1 local : used by lookup phx + ldx ZPPtr2 local : VarType phx - ldx ZPPtr2+1 local : BOP + ldx ZPPtr2+1 local : VarQual phx - sta ZPPtr2 local : expected type + ldx ZPPtr3 local : BOP + phx - lda #$ff + >STYA ZPPtr2 local : expected type/qual + + lda #$ff no previous OP pha *-------------------------------------- .10 jsr CSH.GetCharNB @@ -31,12 +35,11 @@ CSH.ExpEval ldx ZPPtr1 jsr CSH.GetNextCharNB skip ( bcs .19 - lda ZPPtr2 - + >LDYA ZPPtr2 jsr CSH.ExpEval bcs .19 - stx ZPPtr2 + >STYA ZPPtr2 update type/qual jsr CSH.GetCharNB bcs .19 @@ -55,32 +58,30 @@ CSH.ExpEval ldx ZPPtr1 jsr CSH.GetDefine bcc .10 - jsr CSH.GetVar + jsr CSH.VarLookup bcs .21 - ldx ZPPtr2 YA=VarID, X=expected var type (or 0=any) - - jsr CSH.GetVarValueOnStack Y,A = VarID, Get value on stack + jsr CSH.GetValue Check type & Get value on stack bcs .29 - stx ZPPtr2 store real var type bra .30 -.21 lda ZPPtr2 var type +.21 >LDYA ZPPtr2 var type/qual jsr CSH.fCall X = function index bcs .29 - stx ZPPtr2 store real var type + >STYA ZPPtr2 store real var type bra .30 - +*-------------------------------------- .22 jsr CSH.IsDigit10 number ? bcs .24 - ldx ZPPtr2 + ldy ZPPtr2 bne .23 - ldx #CSH.T.SINT - stx ZPPtr2 + ldy #CSH.T.SINT + sty ZPPtr2 + stz ZPPtr2+1 .23 jsr CSH.GetNumOnStack bcs .29 @@ -112,31 +113,31 @@ CSH.ExpEval ldx ZPPtr1 jsr CSH.LookupOP bcs .90 - stx ZPPtr2+1 save OP(n) + stx ZPPtr3 save OP(n) -.32 pla get OP(n-1) +.32 plx get OP(n-1) bmi .33 $ff.... - cmp ZPPtr2+1 + cpx ZPPtr3 bcc .33 OP(n) has precedence, on stack : V1,V2 - ldy ZPPtr2 OP(n-1) has precedence... - + >LDYA ZPPtr2 OP(n-1) has precedence... jsr CSH.BOP.EXEC compute V(n-1) V(n) bcc .32 bcs .99 -.33 pha push back OP(n-1) - lda ZPPtr2+1 get OP(n) +.33 phx push back OP(n-1) + + lda ZPPtr3 get OP(n) pha push OP(n) on stack jmp .10 go check for next token *-------------------------------------- -.80 pla any OP on stack ? +.80 plx any OP on stack ? bmi .88 - ldy ZPPtr2 Var Type + >LDYA ZPPtr2 Var Type jsr CSH.BOP.EXEC bcc .80 @@ -148,19 +149,23 @@ CSH.ExpEval ldx ZPPtr1 bpl .99 sec - .HS 90 BCC + bra .89 + .88 clc - ldx ZPPtr2 X = Var Type + >LDYA ZPPtr2 Type/Qual + +.89 plx + stx ZPPtr3 + plx + stx ZPPtr2+1 + plx + stx ZPPtr2 + plx + stx ZPPtr1+1 + plx + stx ZPPtr1 - ply - sty ZPPtr2+1 - ply - sty ZPPtr2 - ply - sty ZPPtr1+1 - ply - sty ZPPtr1 rts *-------------------------------------- CSH.AddContCharP @@ -188,6 +193,7 @@ CSH.AddContCharP adc ZPCSHConst sta ZPCSHConst bcc .3 + inc ZPCSHConst+1 .3 jsr CSH.GetNextChar Skip " @@ -199,11 +205,9 @@ CSH.AddContCharP rts *-------------------------------------- CSH.GetNumOnStack - txa - beq .99 - - cpx #CSH.T.FLOAT + cpy #CSH.T.FLOAT bcc .1 + bne .99 >PUSHW ZPInputBufPtr @@ -215,8 +219,6 @@ CSH.GetNumOnStack .1 >PUSHW ZPInputBufPtr >PUSHWI ZPInputBufPtr >PUSHBI 10 - phx - bcc .2 >SYSCALL StrToUL @@ -224,10 +226,10 @@ CSH.GetNumOnStack .2 >SYSCALL StrToL -.3 plx - bcs .9 +.3 bcs .9 - lda CSH.TYPESIZE,x + ldy ZPPtr2 + lda CSH.TYPESIZE-1,y cmp #4 beq .8 @@ -254,6 +256,233 @@ CSH.GetNumOnStack sec rts *-------------------------------------- +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 + >PUSHWI 0 From Start + >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 +*-------------------------------------- MAN SAVE usr/src/bin/csh.s.exp LOAD usr/src/bin/csh.s diff --git a/BIN/CSH.S.KW.txt b/BIN/CSH.S.KW.txt index e4a8f839..a7b83459 100644 --- a/BIN/CSH.S.KW.txt +++ b/BIN/CSH.S.KW.txt @@ -18,10 +18,13 @@ CSH.IF jsr CSH.GetCharNB jsr CSH.GetNextCharNB bcs .9 - lda #0 Any var type + ldy #0 Any var type + lda #0 jsr CSH.ExpEval bcs .99 + jsr CSH.IsValue0 result in X + jsr CSH.GetCharNB bcs .99 @@ -29,16 +32,16 @@ CSH.IF jsr CSH.GetCharNB bne .9 jsr CSH.GetNextCharNB skip ')' - bcs .99 + bcs .9 cmp #'{' bne .9 jsr CSH.GetNextCharNB Skip '{' - bcs .99 + bcs .9 - jsr CSH.IsValue0 X = var type from ExpEval - bcc .6 Value=0, skip {{....}} + txa + beq .6 Value=0, skip {{....}} >LDA.G CSH.CmdSave beq .1 IF @@ -54,15 +57,16 @@ CSH.IF jsr CSH.GetCharNB lda #'}' Tell '}' is expected at the end of block jsr CSH.Push - bcs .99 - rts +.99 rts + .6 jsr CSH.SkipBlock bcc .99 + .9 lda #E.CSYN sec -.99 rts + rts *-------------------------------------- CSH.IF.END clc rts @@ -97,16 +101,20 @@ CSH.STRUCT >ENTER 4 jsr CSH.NewKey bcs .99 - sta (pStack) - + sta (pStack) Y,A = KeyID + tya + ldy #1 + sta (pStack),y jsr CSH.GetNextCharNB bcs .99 + cmp #'{' bne .99 .1 jsr CSH.GetNextCharNB bcs .99 + cmp #'}' bne .1 @@ -116,14 +124,22 @@ CSH.STRUCT >ENTER 4 .99 >LEAVE rts *-------------------------------------- -CSH.CONST lda #CSH.Q.CONST +* Type Declaration keywords +*-------------------------------------- +CSH.CONST ldy #1 - tsb ZPVarQual + lda (pStack),y + ora #CSH.Q.CONST + sta (pStack),y + + jsr CSH.CheckSpace + bcs .9 + >LDYA L.CSH.TMODS2 jsr CSH.LookupID bcs .9 - jmp (J.CSH.TMODS2-2,x) + jmp (J.CSH.TMODS2,x) .9 lda #E.CSYN sec @@ -143,10 +159,10 @@ CSH.UNSIGNED clc bcs .9 - cpx #2 - bcc .9 + cpx #CSH.T.UCHAR + bcc .9 void - cpx #8 only char int long allowed + cpx #CSH.T.SLONG+1 only char int long allowed bcs .9 plp @@ -177,44 +193,55 @@ CSH.SHORT jsr CSH.CheckSpace sec rts *-------------------------------------- -CSH.VOID ldx #CSH.T.VOID +CSH.VOID lda #CSH.T.VOID bra CSH.TYPE -CSH.SCHAR ldx #CSH.T.SCHAR - bra CSH.TYPE CSH.CHAR -CSH.UCHAR ldx #CSH.T.UCHAR +CSH.UCHAR lda #CSH.T.UCHAR bra CSH.TYPE + +CSH.SCHAR lda #CSH.T.SCHAR + bra CSH.TYPE + +CSH.UINT lda #CSH.T.UINT + bra CSH.TYPE + CSH.INT -CSH.SINT ldx #CSH.T.SINT +CSH.SINT lda #CSH.T.SINT bra CSH.TYPE -CSH.UINT ldx #CSH.T.UINT +CSH.ULONG lda #CSH.T.ULONG bra CSH.TYPE + CSH.LONG -CSH.SLONG ldx #CSH.T.SLONG +CSH.SLONG lda #CSH.T.SLONG bra CSH.TYPE -CSH.ULONG ldx #CSH.T.ULONG - bra CSH.TYPE +CSH.FLOAT lda #CSH.T.FLOAT -CSH.FLOAT ldx #CSH.T.FLOAT +CSH.TYPE sta (pStack) -CSH.TYPE stx ZPVarType - -.11 jsr CSH.GetNextCharNB + jsr CSH.GetCharNB bcs .9 - cmp #'*' + ldy #1 + +.1 cmp #'*' bne .10 - lda ZPVarType + lda (pStack),y clc adc #CSH.Q.POINTER - sta ZPVarType - bcc .11 + bcs .9 more than *** + + sta (pStack),y - bra .9 more than *** + jsr CSH.GetNextCharNB + bcc .1 + +.9 lda #E.CSYN + sec +.99 rts .10 jsr CSH.IsLetter bcs .8 @@ -226,151 +253,16 @@ CSH.TYPE stx ZPVarType sec ror bFastCall - lda #CSH.Q.FUNC - tsb ZPVarQual + ldy #1 + lda (pStack),y + ora #CSH.Q.FUNC + sta (pStack),y jsr CSH.GetNextCharNB bcs .9 next char is an identifier, ",", "(",")" .8 clc rts - -.9 lda #E.CSYN - sec -.99 rts -*-------------------------------------- -* Input: -* ZPInputBufPtr, A = Expected type -* Output: -* CS, A = EC -* CC, Result on Stack, X = Type -*-------------------------------------- -CSH.fCall ldx ZPPtr1 - phx - ldx ZPPtr1+1 local : fdef - phx - ldx ZPPtr2 local : type - phx - ldx ZPPtr2+1 local : variadic size - phx - - sta ZPPtr2 save Type - stz ZPPtr2+1 Reset VARIADIC byte count - >LDYA L.CSH.FN - jsr CSH.LookupFN - phx X = function index - bcs .10 - - >STYA ZPPtr1 f() definition, starting at returned type - - jsr CSH.GetCharNB - bcs .10 - - cmp #'(' - bne .52 - - jsr CSH.GetNextCharNB skip '(' -.10 bcs .90 - - lda ZPPtr2 - bne .11 - - lda (ZPPtr1) - sta ZPPtr2 - bra .1 expected type is 0, no check - -.11 cmp (ZPPtr1) Get Return value Type - bne .91 - -.1 jsr CSH.ZPPtr1Next advance to arg list type - - lda (ZPPtr1) get type of first arg - beq .7 end of list, go check ending ')' -*-------------------------------------- -.3 eor #CSH.T.VARIADIC if VARIADIC, don't advance to next arg and assume type = 0 - beq .4 - - eor #CSH.T.VARIADIC restore type... - -.4 jsr CSH.ExpEval A=0 if VARIADIC - bcs .9 X = Var Type - - lda (ZPPtr1) get current arg type - eor #CSH.T.VARIADIC - bne .5 - - jsr CSH.GetVarSize X = Var Type - - clc make sure pointer only 2 bytes - adc ZPPtr2+1 - sta ZPPtr2+1 Add to byte count - bra .51 - -.5 jsr CSH.ZPPtr1Next - -.51 jsr CSH.GetCharNB - bcs .90 - - cmp #',' - bne .6 - - jsr CSH.GetNextCharNB Skip , - lda (ZPPtr1) - bne .3 Another ARG.... - -.52 bra .90 extra args....error - -.6 cmp #')' - bne .90 - lda (ZPPtr1) - beq .8 no more arg after ')', exit - - eor #CSH.T.VARIADIC - bne .90 missing arg - - >PUSHB ZPPtr2+1 push VARIADIC byte count - bra .8 -.7 jsr CSH.GetCharNB - bcs .90 - cmp #')' - bne .90 - -.8 jsr CSH.GetNextCharNB Skip ) - - plx restore X = function index - ldy ZPPtr2 get type in Y - pla - sta ZPPtr2+1 - pla - sta ZPPtr2 - pla - sta ZPPtr1+1 - pla - sta ZPPtr1 - phy - jsr CSH.fCall.Exec - plx restore returned type - rts - -.90 lda #E.CSYN - .HS 2C BIT ABS -.91 lda #E.TMISMATCH - sec - -.9 plx Discard function index - - plx - stx ZPPtr2+1 - plx - stx ZPPtr2 - plx - stx ZPPtr1+1 - plx - stx ZPPtr1 - -.99 rts -*-------------------------------------- -CSH.fCall.Exec jmp (J.CSH.EXEC,x) *-------------------------------------- MAN SAVE usr/src/bin/csh.s.kw diff --git a/BIN/CSH.S.txt b/BIN/CSH.S.txt index c39b142c..be7391f1 100644 --- a/BIN/CSH.S.txt +++ b/BIN/CSH.S.txt @@ -10,20 +10,19 @@ NEW .INB inc/mli.i .INB inc/mli.e.i *-------------------------------------- -CSH.T.VOID .EQ 0 -CSH.T.UCHAR .EQ 1 -CSH.T.SCHAR .EQ 2 -CSH.T.UINT .EQ 3 -CSH.T.SINT .EQ 4 -CSH.T.ULONG .EQ 5 -CSH.T.SLONG .EQ 6 -CSH.T.FLOAT .EQ 7 +CSH.T.VOID .EQ 1 +CSH.T.UCHAR .EQ 2 +CSH.T.SCHAR .EQ 3 +CSH.T.UINT .EQ 4 +CSH.T.SINT .EQ 5 +CSH.T.ULONG .EQ 6 +CSH.T.SLONG .EQ 7 +CSH.T.FLOAT .EQ 8 CSH.T.VARIADIC .EQ $FF *-------------------------------------- CSH.Q.POINTER .EQ %01000000 CSH.Q.PPOINTER .EQ %10000000 CSH.Q.PPPOINTER .EQ %11000000 -CSH.Q.PCONST .EQ %00100000 CSH.Q.CONST .EQ %00010000 CSH.Q.FUNC .EQ %00001000 *-------------------------------------- @@ -36,30 +35,26 @@ ZPCSHCode .BS 2 ZPCSHConst .BS 2 ZPCSHData .BS 2 ZPCSHStack .BS 2 -ZPCSHfDecl .BS 2 +ZPCSHfDecl .BS 2 +ZPInputBufPtr .BS 2 +hDefine .BS 1 +hInclude .BS 1 ZPVarID .BS 2 -ZPVarDef .EQ * + +ZPVarDef .EQ * ZPVarType .BS 1 ZPVarQual .BS 1 ZPVarSizeOf .BS 2 ZPVarDataPtr .BS 2 +ZPVarDefPtr .BS 2 -ZPInputBufPtr .BS 2 - - +ArgIndex .BS 1 bFastCall .BS 1 -bCompil .BS 1 - -hDefine .BS 1 -hInclude .BS 1 - ZPPtr1 .BS 2 ZPPtr2 .BS 2 ZPPtr3 .BS 2 -ArgIndex .BS 1 - ZS.END .ED *-------------------------------------- * File Header (16 Bytes) @@ -163,9 +158,12 @@ J.CSH.UTYPES .DA CSH.UCHAR J.CSH.STYPES .DA CSH.SCHAR .DA CSH.SINT .DA CSH.SLONG +*-------------------------------------- J.CSH.KW.END .DA CSH.IF.END .DA CSH.WHILE.END *-------------------------------------- +L.CSH.LIBC .DA CSH.LIBC +*-------------------------------------- J.CSH.EXEC .DA EXEC.pwr .DA EXEC.log .DA EXEC.sqr @@ -239,12 +237,12 @@ CS.RUN >PUSHW L.MSG.GREETINGS sec rts *-------------------------------------- -CS.RUN.ARGS inc ArgIndex +CS.RUN.ARGS inc ArgIndex lda ArgIndex >SYSCALL ArgV bcs .7 - + >STYA ZPPtr1 lda (ZPPtr1) cmp #'-' @@ -276,7 +274,7 @@ CS.RUN.ARGS inc ArgIndex bcs .9 >STYA ZPInputBufPtr - + txa >STA.G hFileBuf bra CS.RUN.ARGS @@ -317,23 +315,24 @@ PrintErrMsg lda hDefine >LDYA.G CSH.SaveDefine >STYA ZPInputBufPtr - + .10 lda hInclude beq .11 - - + + bra .12 .11 >LDA.G hFileBuf .12 >SYSCALL GetMemPtr >STYA ZPPtr1 - + stz ZPPtr2 stz ZPPtr2+1 Line counter .1 inc ZPPtr2 bne .2 + inc ZPPtr2+1 .2 >LDYA ZPPtr1 @@ -343,9 +342,11 @@ PrintErrMsg lda hDefine inc ZPPtr1 bne .3 + inc ZPPtr1+1 .3 cmp #C.CR bne .20 Scan until EoL + ldx ZPPtr1 cpx ZPInputBufPtr lda ZPPtr1+1 @@ -354,7 +355,7 @@ PrintErrMsg lda hDefine .4 >LDA.G bTrace bmi .5 - + jsr PrintTraceMsg.3 .5 lda ZPPtr3 @@ -362,7 +363,7 @@ PrintErrMsg lda hDefine bne .6 lda ZPPtr3+1 - cmp ZPInputBufPtr+1 + cmp ZPInputBufPtr+1 beq .8 .6 ldy #S.PS.hStdErr @@ -375,7 +376,7 @@ PrintErrMsg lda hDefine inc ZPPtr3+1 bra .5 - + .8 ldy #S.PS.hStdErr lda (pPS),y >PUSHA @@ -389,9 +390,9 @@ PrintErrMsg lda hDefine PrintDebugMsg >LDYA pStack >STYA ZPPtr2 >PUSHW L.MSG.DEBUG - + >PUSHW ZPPtr2 - + >PUSHBI 2 >SYSCALL PrintF rts @@ -403,16 +404,16 @@ PrintTraceMsg.3 ldy #S.PS.hStdErr >PUSHA >PUSHBI '>' >SYSCALL FPutC - + ldy #$ff .1 iny lda (ZPPtr3),y beq .8 - + cmp #C.CR beq .8 - + phy pha ldy #S.PS.hStdErr @@ -423,11 +424,11 @@ PrintTraceMsg.3 ldy #S.PS.hStdErr >SYSCALL FPutC ply bra .1 - + .8 ldy #S.PS.hStdErr lda (pPS),y >PUSHA - + >PUSHW L.MSG.ECHOCRLF >PUSHBI 0 >SYSCALL FPrintF @@ -449,8 +450,8 @@ MSG.USAGE .AS "Usage : CSH