--- gforth/prims2x.fs 2002/12/08 09:57:53 1.122 +++ gforth/prims2x.fs 2002/12/31 14:50:53 1.126 @@ -162,6 +162,7 @@ struct% cell% 2* field stack-pointer \ stackpointer name cell% field stack-type \ name for default type of stack items cell% field stack-in-index-xt \ ( in-size item -- in-index ) + cell% field stack-access-transform \ ( nitem -- index ) end-struct stack% struct% @@ -197,7 +198,9 @@ create stacks max-stacks cells allot \ a 1 next-stack-number +! r@ stack-type ! save-mem r@ stack-pointer 2! - ['] stack-in-index r> stack-in-index-xt ! ; + ['] stack-in-index r@ stack-in-index-xt ! + ['] noop r@ stack-access-transform ! + rdrop ; : map-stacks { xt -- } \ perform xt for all stacks @@ -333,13 +336,15 @@ defer inst-stream-f ( -- stack ) \ stack access stuff -: normal-stack-access1 ( n stack -- ) - stack-pointer 2@ type - dup - if - ." [" 0 .r ." ]" +: normal-stack-access0 { n stack -- } + n stack stack-access-transform @ execute ." [" 0 .r ." ]" ; + +: normal-stack-access1 { n stack -- } + stack stack-pointer 2@ type + n if + n stack normal-stack-access0 else - drop ." TOS" + ." TOS" endif ; : normal-stack-access ( n stack -- ) @@ -645,7 +650,7 @@ stack inst-stream IP Cell stack stack-out @ 0<> stack stack-in @ 0= and if ." IF_" stack stack-pointer 2@ 2dup type ." TOS(" - 2dup type ." [0] = " type ." TOS);" cr + 2dup type 0 stack normal-stack-access0 ." = " type ." TOS);" cr endif ; : flush-tos ( -- ) @@ -655,7 +660,7 @@ stack inst-stream IP Cell stack stack-out @ 0= stack stack-in @ 0<> and if ." IF_" stack stack-pointer 2@ 2dup type ." TOS(" - 2dup type ." TOS = " type ." [0]);" cr + 2dup type ." TOS = " type 0 stack normal-stack-access0 ." );" cr endif ; : fill-tos ( -- ) @@ -668,14 +673,21 @@ stack inst-stream IP Cell : fetches ( -- ) prim prim-effect-in prim prim-effect-in-end @ ['] fetch map-items ; +: stack-update-transform ( n1 stack -- n2 ) + \ n2 is the number by which the stack pointer should be + \ incremented to pop n1 items + stack-access-transform @ dup >r execute + 0 r> execute - ; + : stack-pointer-update { stack -- } - \ stack grow downwards + \ stacks grow downwards stack stack-diff ?dup-if \ this check is not necessary, gcc would do this for us stack inst-stream = if ." INC_IP(" 0 .r ." );" cr else - stack stack-pointer 2@ type ." += " 0 .r ." ;" cr + stack stack-pointer 2@ type ." += " + stack stack-update-transform 0 .r ." ;" cr endif endif ; @@ -724,6 +736,12 @@ stack inst-stream IP Cell endif 2drop ; +: output-nextp2 ( -- ) + ." NEXT_P2;" cr ; + +variable tail-nextp2 \ xt to execute for printing NEXT_P2 in INST_TAIL +' output-nextp2 tail-nextp2 ! + : output-label2 ( -- ) ." LABEL2(" prim prim-c-name 2@ type ." )" cr ." NEXT_P2;" cr ; @@ -745,13 +763,13 @@ stack inst-stream IP Cell xt execute ; : output-c-tail ( -- ) - ['] noop output-c-tail1 ; + tail-nextp2 @ output-c-tail1 ; : output-c-tail2 ( -- ) ['] output-label2 output-c-tail1 ; : output-c-tail-no-stores ( -- ) - ['] noop output-c-tail1-no-stores ; + tail-nextp2 @ output-c-tail1-no-stores ; : output-c-tail2-no-stores ( -- ) ['] output-label2 output-c-tail1-no-stores ; @@ -917,7 +935,7 @@ stack inst-stream IP Cell \ cr ; : output-label ( -- ) - ." INST_ADDR(" prim prim-c-name 2@ type ." )," cr ; + ." INST_ADDR(" prim prim-c-name 2@ type ." )" cr ; : output-alias ( -- ) ( primitive-number @ . ." alias " ) ." Primitive " prim prim-name 2@ type cr ; @@ -1166,7 +1184,7 @@ stack inst-stream IP Cell r> in-part ! ; : part-stack-pointer-updates ( -- ) - max-stacks 0 +do + next-stack-number @ 0 +do i part-num @ 1+ s-c-max-depth @ dup i num-combined @ s-c-max-depth @ = \ final depth swap i part-num @ s-c-max-depth @ <> \ just reached now @@ -1418,7 +1436,7 @@ Variable c-flag (( (( ` g || ` G )) {{ start }} nonl ** {{ end forth-flag @ IF ." group " type cr THEN - c-flag @ IF ." GROUP(" type ." )" cr THEN }} + c-flag @ IF ." GROUP(" type ." , " function-number @ 0 .r ." )" cr THEN }} )) <- group-comment (( (( eval-comment || forth-comment || c-comment || else-comment || if-comment || group-comment )) ?? nonl ** )) <- comment-body