From : Peter Liebetrau (zippo@edina.xnc.com)
Subject : Prototyping

the  problem  was,  that  there  is  no  forward referencing in BB2
Statements and Functions.

I wrote a prototyping-system wich makes forwardjumps to statements
and functions possible.

All in all it is just a simple mixture of BB2-InlineAssembler, and
BB2-Labelhandling.

It is not a library, just an includefile.
There are 6 macros to realize prototyping in BB2.

Here they are ...

1. Macro proto
~~~~~~~~~~~~~~
   Creates a Statement-Prototype
   Parameters
   1 = Name of Statement
   2-x = Parameters of Statement

   Example:
                              !proto{write,a$}
   creates this source
                              Statement write{a$}
                                JMP write
                              End Statement

2. Macro fproto
~~~~~~~~~~~~~~~
   Creates a Function-Prototype
   Parameters
   1 = Type of Function
   2 = Name of Function
   3 - x = Parameters of Function
   y = The last parameter is the the variable for Function Return

   Example:
                              !fproto{.l,inc,a.l,b.l}
   creates this source
                              Function.l inc{a.l}
                                JSR inc
                                Function Return b.l
                              End Function
3. Macro stat
~~~~~~~~~~~~~
   Replacement for "Statement"

   Example:
                              !stat{write,a$}
   creates this source
                              Statement write_{a$}
                              write:

4. Macro endstat
~~~~~~~~~~~~~~~~
   Replacement for "End Statement"

5. Macro func
~~~~~~~~~~~~~
   Replacement for "Function"

   Example:
                              !func{.l,inc,a.l}
   creates this source
                              Function.l inc_{a.l}
                              inc:
6. Macro endfunc
~~~~~~~~~~~~~~~~
   Replacement for "End Function"

   Example:
                              !endfunc
   creates this source
                                RTS
                              End Function
; -----------------------------------------------------------------


                              Da rulez

1. For each statement and function, create a prototype
2. Use the macros stat and func *allways*. Don`t use  Statement  or
   Function !
3. Please, let me know, if it works, if u like it, if u use it
4. Please, send me money, HD`s, A4000`s, Ferraries, WARP-Drives
5. Don`t stay with your mama
6. Never smoke in pyjamas
7. Use condoms


; [begin of the includefile]
; -----------------------------------------------------------------
;
; BB2 - Prototyping
; V1.0 (c) 1996 by Peter Liebetrau
; email: zippo@edina.xnc.com
;
; -----------------------------------------------------------------

Macro proto
; Creates a Statement-Prototype
; Parameters
; 1 = Name of Statement
; 2-x = Parameters of Statement

  CNIF `0=0
    CERR "Not enough parameters !"
  CEND
  CNIF `0>7
    CERR "Wrong number of parameters !"
  CEND
  CNIF `0=7 : Statement `1{`2,`3,`4,`5,`6,`7} : CEND
  CNIF `0=6 : Statement `1{`2,`3,`4,`5,`6}    : CEND
  CNIF `0=5 : Statement `1{`2,`3,`4,`5}       : CEND
  CNIF `0=4 : Statement `1{`2,`3,`4}          : CEND
  CNIF `0=3 : Statement `1{`2,`3}             : CEND
  CNIF `0=2 : Statement `1{`2}                : CEND
  CNIF `0=1 : Statement `1{}                  : CEND
                JMP `1
              End Statement
End Macro

Macro fproto
; Creates a Function-Prototype
; Parameters
; 1 = Type of Function
; 2 = Name of Function
; 3 - x = Parameters of Function
; y = The last parameter is the the variable for Function Return

  CNIF `0<3
    CERR "Not enough parameters !"   ; Type, Name, Return
  CEND
  CNIF `0>9
    CERR "Wrong number of parameters !"
  CEND
  CNIF `0=9 : Function`1 `2{`3,`4,`5,`6,`7,`8}
                JSR  `2
                Function Return `9
              End Function                     : CEND
  CNIF `0=8 : Function`1 `2{`3,`4,`5,`6,`7}
                JSR  `2
                Function Return `8
              End Function                     : CEND
  CNIF `0=7 : Function`1 `2{`3,`4,`5,`6}
                JSR  `2
                Function Return `7
              End Function                     : CEND
  CNIF `0=6 : Function`1 `2{`3,`4,`5}
                JSR  `2
                Function Return `6
              End Function                     : CEND
  CNIF `0=5 : Function`1 `2{`3,`4}
                JSR  `2
                Function Return `5
              End Function                     : CEND
  CNIF `0=4 : Function`1 `2{`3}
                JSR  `2
                Function Return `4
              End Function                     : CEND
  CNIF `0=3 : Function`1 `2{}
                JSR  `2
                Function Return `3
              End Function                     : CEND
End Macro ; fproto

Macro stat
  CNIF `0=0
    CERR "Not enough parameters !"
  CEND
  CNIF `0>7
    CERR "Wrong number of parameters !"
  CEND
  CNIF `0=7 : Statement `1_{`2,`3,`4,`5,`6,`7} : CEND
  CNIF `0=6 : Statement `1_{`2,`3,`4,`5,`6}    : CEND
  CNIF `0=5 : Statement `1_{`2,`3,`4,`5}       : CEND
  CNIF `0=4 : Statement `1_{`2,`3,`4}          : CEND
  CNIF `0=3 : Statement `1_{`2,`3}             : CEND
  CNIF `0=2 : Statement `1_{`2}                : CEND
  CNIF `0=1 : Statement `1_{}                  : CEND
              `1:
End Macro
Macro endstat
  End Statement
End Macro

Macro func
  CNIF `0<2          ; Type, Name
    CERR "Not enough parameters !"
  CEND
  CNIF `0>8
    CERR "Wrong number of parameters !"
  CEND
  CNIF `0=8 : Function`1 `2_{`3,`4,`5,`6,`7}    : CEND
  CNIF `0=7 : Function`1 `2_{`3,`4,`5,`6,`7}    : CEND
  CNIF `0=6 : Function`1 `2_{`3,`4,`5,`6}       : CEND
  CNIF `0=5 : Function`1 `2_{`3,`4,`5}          : CEND
  CNIF `0=4 : Function`1 `2_{`3,`4}             : CEND
  CNIF `0=3 : Function`1 `2_{`3}                : CEND
  CNIF `0=2 : Function`1 `2_{}                  : CEND
              `2:
End Macro
Macro endfunc
    RTS
  End Function
End Macro

; -----------------------------------------------------------------
; [end of the includefile]



; -----------------------------------------------------
;                The final example
; -----------------------------------------------------

; - Prototypes of statements and functions ------------

!proto {stdout,a$}
!fproto {$,stdin,a$,b$}

; - The main program ----------------------------------


stdout{"Hello World"+Chr$(10)}
c$=stdin{"Prompt > "}
stdout{"Your command was <"+c$+">"+Chr$(10)}
MouseWait
End


; - The Statements and functions ----------------------

!func {$,stdin,a$}
  stdout{a$}         ; oops, a forward jump ?!
  b$=Edit$(256)      ; Read_ with lengthcheck didn`t work ?!
!endfunc

!stat {stdout,a$}
  Write_ Output_, &a$, Len(a$)
!endstat

; -----------------------------------------------------