;$VER:MethodBBLib V1.4 (26.07.97)
;
;(C)opyright 1997 by Erwan Fouret
;
;

;***************************************************
;*  V1.4 : Command VarArgs added by Julian Kinraid *
;*  V1.0 : First release                           *
;***************************************************

#methodbblib=XX ;put here a free lib number

!libheader {#methodbblib,0,0,0,0}

!acommand  {#long}
!args      {#long,#long}
!libs
!subs      {_DoMethodA,0,0}
!name      {"DoMethodA","(Obj,Message)"}

!acommand  {#long}
!repargs   {1,1,#long,#long}
!libs
!subs      {_DoMethod,0,0}
!name      {"DoMethod","(Obj,MethodID,Tag[,Tag..])"}

!acommand  {#long}
!args      {#long,#long,#long}
!libs
!subs      {_DoSuperMethodA,0,0}
!name      {"DoSuperMethodA","(Class,Obj,Message)"}

!acommand  {#long}
!repargs   {2,1,#long,#long,#long}
!libs
!subs      {_DoSuperMethod,0,0}
!name      {"DoSuperMethod","(Class,Obj,MethodID,Tag[,Tag..])"}

!acommand  {#long}
!args      {#long,#long,#long}
!libs
!subs      {_CoerceMethodA,0,0}
!name      {"CoerceMethodA","(Class,Obj,Message)"}

!acommand  {#long}
!repargs   {2,1,#long,#long,#long}
!libs
!subs      {_CoerceMethod,0,0}
!name      {"CoerceMethod","(Class,Obj,MethodID,Tag[,Tag..])"}

!acommand  {#long}
!repargs   {2,1,#long,#long,#long}
!libs
!subs      {_SetSuperAttrs,0,0}
!name      {"SetSuperAttrs","(Class,Obj,Tag[,Tag..])"}

;***** Code added by Julian Kinraid (jkinraid@clear.net.nz) *****
                                                               ;*
!afunction {#long}                                             ;*
!repargs   {0,1,#long}                                         ;*
!libs                                                          ;*
!subs      {_VarArgs,0,0}                                      ;*
!name      {"VarArgs","(Tag[,Tag..])"}                         ;*
                                                               ;*
;****************************************************************

!libfin

._DoMethodA:
        TST.l   d0
        BEQ.b   cmnullreturn
        MOVE.l  d0,a2
        MOVE.l  d1,a1
        MOVE.l  -4(a2),a0
        BRA     cminvoke

._DoMethod:
        TST.l   d0
        BEQ.b   cmnullreturn
        LEA.l   args(pc),a1
        MOVE.l  a1,d1
        SUBQ    #1,d7
Loop:   MOVE.l  -(a2),(a1)+
        DBF     d7,Loop
        MOVE.l  d0,a2
        MOVE.l  d1,a1
        MOVE.l  -4(a2),a0
        BRA     cminvoke

._DoSuperMethodA:
        MOVE.l  d1,a2
        BEQ.b   cmnullreturn
        MOVE.l  d0,a0
        BEQ.b   cmnullreturn
        MOVE.l  d2,a1
        MOVEA.l $18(a0),a0
        BRA     cminvoke

._DoSuperMethod:
        LEA.l   args(pc),a1
        MOVE.l  a1,d2
        SUBQ    #1,d7
Loop1:  MOVE.l  -(a2),(a1)+
        DBF     d7,Loop1
        MOVE.l  d1,a2
        BEQ.b   cmnullreturn
        MOVE.l  d0,a0
        BEQ.b   cmnullreturn
        MOVE.l  d2,a1
        MOVEA.l $18(a0),a0
        BRA     cminvoke

._CoerceMethodA:
        MOVE.l  d1,a2
        BEQ.b   cmnullreturn
        MOVE.l  d0,a0
        BEQ.b   cmnullreturn
        MOVE.l  d2,a1
        BRA     cminvoke

._CoerceMethod:
        LEA.l   args(pc),a1
        MOVE.l  a1,d2
        SUBQ    #1,d7
Loop2:  MOVE.l  -(a2),(a1)+
        DBF     d7,Loop2
        MOVE.l  d1,a2
        BEQ.b   cmnullreturn
        MOVE.l  d0,a0
        BEQ.b   cmnullreturn
        MOVE.l  d2,a1
        BRA     cminvoke

._SetSuperAttrs:
        LEA.l   args(pc),a1
        MOVE.l  a1,d2
        SUBQ    #1,d7
Loop3:  MOVE.l  -(a2),(a1)+
        DBF     d7,Loop3
        MOVE.l  d1,a2
        BEQ.b   cmnullreturn
        MOVE.l  d0,a0
        BEQ.b   cmnullreturn
        MOVEA.l $18(a0),a0
        MOVE.l  #0,-(a7)
        MOVE.l  d2,-(a7)
        MOVE.l  #$103,-(a7)
        LEA.l   (a7),a1
        PEA.l   ssaret(pc)
        MOVE.l  8(a0),-(a7)
        RTS

cminvoke:
        PEA.l   cmreturn(pc)
        MOVE.l  8(a0),-(a7)
        RTS

cmnullreturn:
        MOVEQ   #0,d0

cmreturn:
        RTS

ssaret:
        LEA.l   $c(a7),a7
        MOVEA.l (a7)+,a2
        RTS

;***** Code added by Julian Kinraid (jkinraid@clear.net.nz) *****
                                                               ;*
._VarArgs                                                      ;*
        LEA     args(pc),a1                                    ;*
        MOVE.l  a1,d0                                          ;*
        SUBQ    #1,d7                                          ;*
Loop4:  MOVE.l  -(a2),(a1)+                                    ;*
        DBF     d7,Loop4                                       ;*
        RTS                                                    ;*
                                                               ;*
;****************************************************************

args:           Dcb.l   20,0
