@Database "LITTEL.guide"

@Node Main "LITTEL r4"
 

                  LITTEL Language Compiler v0.16

                  Public Release 4

                  @{" Introduction              " link intro}
                  @{" Requirements              " link requ}
                  @{" Installation              " link install}
                  @{" Feautures                 " link feautures}
                  @{" The Instructions/Keywords " link keywords}
                  @{" What the startupcode does " link startcode}
                  @{" Some Rules                " link syntaxrules}
                  @{" Calling Subroutines       " link callsub}
                  @{" Using Data                " link usingdata}
                  @{" Currrent Bugs/Limitations " link buglim}
                  @{" Copying/Using/Disclaimer  " link disc}
                  @{" About the implementation  " link implement}
                  @{" Examples                  " link examples}
                  @{" In the feauture           " link feauture}
                  @{" History                   " link history}
                  @{" The Author                " link author}

                    Copyright © Leif Salomonsson '99

@EndNode

@Node intro "Introduction"

   Its a small and simple language, similar to assembler,
   but with some higher-level 'instructions' or keywords
   that make things like loops and conditional things much
   easyer. The simple integer-instructions also, compared
   to 68k-assembler, is easier to use, have common
   'adressing-modes' and so on. The main idea from the
   beginning was to make a kind of cpu independant, but
   still lowlevel and fast language as a 'base-language'
   for building higher level languages on top of.
   For now it uses PhxAss/Lnk by Frank Wille to
   assemble executables for Amiga 68k.

@EndNode

@Node requ "Requirements"

   Amiga OS 2 +
   68000 + (68010+ for PROCs with params)
   PhxAss 4
   PhxLnk 4

   Some knowledge about Asm/C Amiga Programming.
   Knowing what Objects and Includes are and so on..
  
@EndNode

@Node install "Installation"

   Copy Litteldrawer whwrever you want.
   Assign Littel: to the drawer.

@EndNode

@Node feautures "Feautures"

   * The LITTEL Compiler currently supports 68000 and higher CPUs.

   * Stackbased and registerbased params.

   * PROCs in littel witch recieves params on the stack uses RTD (68010+)

   * Easy creation and use of standard objectfiles .o .lib

   * Easy creation and use of standard Shared Libraries.

   * Local and Global variables.

   * E-like typelessness. ..an E-frontend _could_ be made!

   * All kinds of variables and registers can be used
     directly as PTRs with optional offset.
     (ex D4[B].offset = the byte D4 points at + offset)

   * All instructions are INLINE.

   * Its small and simple.

   * Read on and try it.

@EndNode

@Node keywords "The Keywords (or instructions)"


 LITTEL is still in beta and anything may change!

 dvc = direct value, like : $FFFE/123/-2048/5/etc
 any = STACK+/-STACK/localVar/_globaVar/%parameter/Dx/Ax/localVar[]/_globalvar[]/%paramater[]/Dx[]/Ax[]

      ****************************
      *DATA TRANSFER INSTRUCTIONS*
      ****************************

 COPY source:any/dvc       dest:any
 SWAP target1:any          target2:any
 REGS2STACK                [reglist]    default is D1-D5/A0-A3
 STACK2REGS                [reglist]
 
      *************************
      *ARITMETHIC INSTRUCTIONS*
      *************************

 MUL  with:any/dvc         target/dest:any     altdest:any
 DIV  with:any/dvc         target/dest:any     altdest:any
 SHL  steps:any/dvc        target/dest:any     altdest:any
 SHR  steps:any/dvc        target/dest:any     altdest:any
 ADD  source:any/dvc       target/dest:any     altdest:any
 SUB  source:any/dvc       target/dest:any     altdest:any
 INC  amount:dvc           target:any
 DEC  amount:dvc           target:any
 ABS  target/dest:any      altdest:any
 NEG  target/dest:any      altdest:any
 MAX  source1:any/dvc      source2:any/dvc     dest:any
 MIN  source1:any/dvc      source2:any/dvc     dest:any
 LIMIT min:any/dvc         max:any/dvc         target:any

      ********************
      *LOGIC INSTRUCTIONS*
      ********************

 BGET bitnum:any/dvc       source:any/dvc      dest:any (0 or <>0)
 BCLR bitnum:any/dvc       target/dest:any     altdest:any
 BSET bitnum:any/dvc       target/dest:any     altdest:any
 BCHG bitnum:any/dvc       target/dest:any     altdest:any
 OR   source:any/dvc       target/dest:any     altdest:any
 XOR  source:any/dvc       target/dest:any     altdest:any
 AND  source:any/dvc       target/dest:any     altdest:any
 NOT  target/dest:any      altdest:any

      *******************
      *MISC INSTRUCTIONS*
      *******************

 DOPROC name                 <%param %param pa...>
 CALL   address:any/dvc      offset:dvc
 
 PADR   procname             dest:any
 RETURN list of any/dvc
 PUTPRMS                   p1:any/dvc p2 p3....p19
 REMPRMS                   nrof:any/dvc


      *******************
      *LABELING KEYWORDS*
      *******************

 PROC name:name  [%param1 %param2 ....]

 GVAR _name:first letter '_'   // global var

 STRING _name "this is a string!"  // null-terminated string

 LBLK/WBLK/BBLK _name nrofelements:dvc
                                        // long/word/byte - block
                                        // uninitialised

                                        // l/w/b - block
                                        // initialised
 LONGS/WORDS/BYTES _name listofelements: ex. 10,-16,54,32,100

 Inside PROC :
   VAR var [var2 var3...var19]

      ******************************
      *CONDITIONAL/LOOPING KEYWORDS*
      ******************************

      ?? = EQ/NE/GT/LT/GE/LE

 IF any/dvc ?? any/dvc
 ELSE  // no letting this one out !
 ENDIF

 SELECT Dx     // only Dx can be used here! may change
 CASE any/dvc
 CASE any/dvc
 C...
 DEFAULT      // no letting this one out!
 ENDSELECT

 WHILE any/dvc ?? any/dvc
 ENDWHILE

 REPEAT
 ENDREPEAT any/dvc ?? any/dvc

      ******************
      *SUPPORT KEYWORDS*
      ******************

 OPENLIBRARY anylibrary.library ver:dvc globaltoputbasein

 CLOSELIBRARY libbase:any

      ****************************************
      *MISC COMPILER CONTROL/SUPPORT KEYWORDS*
      ****************************************

 #equ Constantname value:dvc

                              
 #xref name [name name name name..]

 #xdef name [name name name..]

 #incdir "path"

 #include "file" ["file" "file" "file"...] // include asm .i type files with constants

 #mode EXE       (default)
 #mode OBJECT
 #mode LIBRARY ver rev name idstr

 #linkdir "path"  // not ready, LITTEL searches LITTEL:lib/ for now

 #link file.o/file.lib [file2 file3...] link with theese files..

 #insert "src.l" // not ready yet! inserts littel src at spot.

 #nostartup  // 15b : dont link in startupcode, know what youre doin :)

@EndNode

@Node startcode "The startup code of LITTEL v0.14b does :"

   Startup Code Opens Theese Global Vars :
         _ExecBase
         _DOSBase
         _GraphicsBase
         _IntuitionBase
         _UtilityBase
         _stdin
         _stdout
         _arg

@EndNode

@Node syntaxrules "Some Rules"

   LITTEL v0.14

   The only allowed commenting is
   commenting preceeded by '//'
   // this is a comment

   EVERY single line of code starts with an instruction or keyword!

   Only ONE keyword/instruction is allowed per line !

   Local Vars must begin with a-z

   Global Vars must begin with _

   Stackparameters (received) begins with %

   Dataregs begins with D followed by 0-7

   AdrRegs begins with A followed by 0-7

   Constants must begin with A-Z

   Direct Values : %01010, 2000, -3000, $FFFe, -$19, etc..

   PROC name. name can be anyname anycase.

   The first PROC in source is the 'main' procedure

   VAR declarations in PROC must end with ENDVAR
   PARAM declarations in PROC must end with ENDPARAM

   Dont forget the last END in the source !

   PTRs [] :
      With no character between the brackets
      its treated as a PTR TO LONG.
      Valid PTR sizes : L or W or B (LONG, WORD, BYTE)
      ex. myptr[B]
      Illegal : mywindow[w].height
      Legal : mywindow[W].height

      Ptrs can have offsets added to them :
      myptr[].offset
      offset must be direct value or constant.

   NO SPACEes in any names!
   NO SPACEes in following : mywindow[W].height
     this is illegal : mywindow[ W ].height
                       mywindow[] .height
                       etc..

   Between keywords and arguments there can be as much spaces you want.

   Calling a PROC with parameters :

      DOPROC procname any/dvc any/dvc any/dvc ...... etc. Max 7 params (for now)!
      ex. DOPROC myproc 1 2 A0 D4 _myGlobal

      Add FLUSH after the last parameter if the routine you are calling
      doesnt cleanup the parameters on stack.

   The register A4 and A5 is used internally by LITTEL. NO TOUCHING!
   Also registers D6, D7 and A6 is used for scratch by various
   instructions. So dont put anything in them an expect it to be there :)

   See examples for more information.

@EndNode

@Node callsub "Calling Subroutines"

   A subroutine in LITTEL looks like :

   PROC name
      [VAR bla]
      [CODESTART]
      <code>
   ENDPROC   

   If using callbackhooks from other code then Littel
   u must get the A4 register if you want to use any globals
   or librarybases. Do it with GETA4 first thing in PROC
   after (any) variables or params declarations.


   There are two ways of calling in LITTEL.

   Using DOPROC or CALL

   1. DOPROC procname
    like BSR in assembler, it branches to a labeled subroutine.
    You can put params after the procname. All PROCs created
    in LITTEL automatically flushes the params on stack, (if any)
    by using RTD. So there is a special DOPROC-keyword, 'FLUSH'
    that you must put after the params when calling external #imported
    functions if they do not flush the params by them selfes.
    Parameters are put on the stack in _reverse_ order. (C-style ?)
    No registers are saved by default. If external functions could
    trash A4 or A5 then you must save them first!

    By using the instruction 'PADR procname dest' you can get the adr of
    a labeled subroutine. Example of use : callbackhooks.

   2. CALL address offset
    This one you will likely use for calling libraries.
    address can be anything, register or ptr or variablel etc.
    offset can be a direct value or constant.
    If not calling libraries but just an address you can put just
    0 as offset.

    ;The internal registers A4/A5 will get saved before CALLing.
     NOT ANYMORE! (v0.16)

   Registers D0-D5/A0-A3 can ofcource also be used for parameterpassing
   at any time!

@EndNode

@Node usingdata "Using Data"

   Variables

     All variables in LITTEL are of the 32bit LONG Type (signed).

       Definition

         Local to PROC

           VAR name [name name...]
           VAR name
           V....

         Global outside of PROC

           GVAR _name [_name _name...]

         Registers

           D0 D1 D2 D3 D4 D5
           A0 A1 A2 A3
           (you shouldnt touch D6/D7/A4-A7)

         Variables as PTRs

           PTR TO LONG

             myvar[] D0[] _global[] A0[] %param1[]
             myvar[] D0[L] _global[L] A0[] %param1[L] ..etc

           PTR TO WORD, BYTE

             anyvariable[W]
             anyvar[B]
             D3[W] ..etc..

           PTRs with Offset

             myptr[L/W/B].Offset
             mywindow[W].w_Heigth
             myptr[B].1200
             myptr[L].-32000
             etc..

   Stack

      STACK+
      -STACK

      Example

        COPY STACK+ D0
        COPY D0 -STACK

      Should be of rare use.



   Blocks

     Currently in LITTEL all blocks of data are Global.
     Therefore all block names must start with '_'.

   BlockTypes

     Initialized

       STRING _name 'string!'
       LONGS _name val,val,val,val,val....
       WORDS
       BYTES

     UnInitialized

       LBLK _name nrofelements
       WBLK
       BBLK

     Example

       STRING _my "mooo"

       COPY ptr[B] D0 // get first char ('m') from my to D0

@EndNode


@Node buglim "Current Bugs / Limitations"

 Very little errorchecking!
 Probably will not fix this..
 (Should be the task of Language-Frontends to produce ok code)

 SELECT crashes compiler sometimes

 ABS producing bad code

 If u dont give lc any arguments it crashes
 Also be sure to type lc15 namewithout.l or it crashes!

 something else ?

@EndNode

@Node examples "Examples"

   // Hello World in LITTEL :)

   #include "dosfuncoffsets"  // change to your config..

   STRING _hello "hello world!\n"

   PROC main
      COPY _hello D1       // address of our hellostring in D1
      COPY 13 D2                // len of string to D2
      CALL _DOSBase WriteChars  // print it
   ENDPROC

   END  // dont forget this one

   ****** OR *************************

   //
   #link amiga.lib      // for example...
   #xref _puts

   STRING _hello "hello world!"

   PROC main
      DOPROC _puts _hello FLUSH // print it
   ENDPROC

   END

   ***** lotsa ways of doin things :) *****

   Please look into the Examples drawer.

@EndNode

@Node history "History"
                                       

v0.11b ***********************

 introduced  Global vars

 added FUNC, DOFUNC

 added some security checks..

 1:st release to Aminet  ***********************

v0.12b ***********************
       991119

 new naming stuff :
 local vars : first two letters lowercase, a-z
 constants  : first letter uppercase A-Z
 global vars : first letter '_'
 FUNC/PROC/STRING, BLK, DC names : anycase, anything

 new ADR syntax : ADR STRING/BLK/DC/FUNC/PROC name xx

 string_name:
 proc_name:
 func_name
 blk_name:
 dc_name:

  done! :) -> even better :
 STRING, PROC, FUNC, LBLK, WBLK, BBLK, LONGS, WORDS, BYTES

 globals working

 added SWAP instruction

 now u can have the same name of local vars in diffrent PROCs.

 found bug that didnt allow '=' anywhere in src.

 extremely experimental ELSE ! hell.. not working..discarding it.

 Added OPT LARGE in sources

 nnow ELSE is working! New format for IF..:
 IF
 ELSE  -> must be there!
 ENDIF

 added DEFAULT in SELECT block.. DEFAULT MUST be there!

 changing CALL name offset -> CALL adr offset

v0.13b ********************************

           date ??

 getting rid of FUNC
 just PROC
 if a VAR is declared i a PROC then
 we add the link/unlk instructions.. that simple!
 but.. we need ENDVAR
 PROC nisse
 VAR ulla
 VAR albert
 ENDVAR
 <code>

 done!
 optimised PROC/ENDVAR/ENDPROC litle...

 made copy2.e
 simpler but not as optimised.. but that can be done later..
 for now it works fine atleast..

 bugfixed some in copy 2..

 thinking of adding support for parameters to PROCs
 using rtd #paramsize isteda of rts, IF params are used.

 HOPEFULLY.. @param support is now added! :)

 2:nd release to aminet  *********************************

v0.14b *********************************''

           date ??

 lc14 : removing parser, using my own class instead.
 extractwords.e

 adding new 'parametermodes'

 added ABS, NEG, MAX, MIN, LIMIT

 added support for external PROCs/subroutines
 with no own stackcleanup! like powerD.lib for example..
 use FLUSH as last param.

 changed names of STORE_REGS, RESTORE_REGS to
 REGS2STK, STK2REGS
 well its still beta! :)

 things to do : possibly implement "ABCD" -> value

 just remebered.. think the ABS wasnt working right..

 extractwords.e now handles '//' by it self :)

 commented out #export and #mode. no use for them yet anyway.

 added returnvalues after ENDPROC. values in D0/D1/D2....etc

 added RETURN instruction.. put optional values after it.

 created dynamic stringstack, lc14 now only writes to _one_ file. (speedup)
 this will probably later meen that SELECT can handle _any_ type instead of Dx.

 SELECT now handles any type

 Complete rewrite of the COPY instruction (witch other instructions uses)
 much smarter and efficient.

v0.15b *************************************

       Dec 8 99

 DEFAULT in SELECT block no longer must be there.

 Added CONT, an alternativ to CASE. CONTinue with this...

 Added #nostartup keyword. guess what it does...
  pretty dangerous to use this switch right now!
  (the smalldata isnt initialized)

 doesnt use the stringstack for tempdata anymore
 but its now alot faster then before, on the bad side :
 more memory is required and memory could get overwritten
 if my very nasty memory-use-prediction should fail :(

 Strange bug in something.. :) the compiler hangs just before exiting.
 code generation is ok...

 Added GETA4. Handy when getting called from other code (callbackhooks).

 Fixed the strange bug. Bug in EC it seems.. Now im not ENDing
 some objects at programend.. One dont have to anyway.. but it
 shouldnt crash.

 Changed 'ADR' into ADR and PADR, for global datablocks and PROCedures
 respectively.

 Fixed the #mode keyword. Now you can create objects .o ! :)
 Use '#mode OBJECT'. This automatically sets #nostartup also.

 #export is back! guess why..

 Changed #export, #import -> #xdef, #xref    :)

 Optimised COPY instruction to the maximum!

 Optimised Stackrestoration when calling external procedures
 using FLUSH.
   MOVE.L (A7)+, D7 times nrofparams  -> LEA nrofparams*4(A7), A7   :)

 SELECT still buggy, compiler crashes... :(

 3:d release to Aminet  *********************************

 Ohyeah, just found out that FLUSH doesnt work,
 forgot to write the code to tempstrings.. :)
 it didnt hang in the test.l example so who could know ?:)
 *Fixed*

 Also forgot to mention in the .readme that
 LITTEL now requires PhxLnk.. :(

 Added New Targets : -STACK and STACK+

 Added 'FLSHSTK nrofparams' instrcution. flush out nroflongs from stack.

 Changed em back again :) SAVEREGS, LOADREGS -> REGS2STACK, STACK2REGS

 #mode LIBRARY doesnt seem that far away now.. :)
 Just did my first library by hand, with 99% help from aminet/dev/src?/LibrariesGuide.lha

v0.16a *********************************************

       Dec 15 99

 Removing ADR

 Changing internal structures

 (global initialized blocks in code-section instead of data-section
 adding vars for the blocks, vars in data-section..)

 Changing CALL, OPENLIBRARY, CLOSELIBRARY

 on to more changes.. :
 Scrapping PARAM..ENDPARAM and ENDVAR!
 instead params go like this :
   PROC myproc %param1 &param2 %param3.. etc

   if this is gonna work we'll have to welcome
   the old PROCCODE back! :) maybe change its name.. CODESTART..
   must be in _every_ PROC..! (that uses either locals or params!)

   see examples/parvar.l

   PROC blabla [%params...]
      [declarations]
      CODESTART
      <code>


 Changed Names of the startup-globals : see 'What the startupcode does'.

 Removed automatic includes for dos and exec!

 #incdir working!!

 Changed internal outputbuffers..
 MUCH lesser memory used
 4k is allocated regardless of src-size, compared to the old
 style that allocated ~ src-size * 4 bytes.
 no risk of overwriting memory.

 Removed some not-dangerous enforcerhits.
 (Gotta look good)

 Created librarymodule.e

 LITTEL now compiles Shared Libraries!
   not tested the functionality yet and
   there is no support for any global stuff, yet.

 Libraries tested and working! (still no globals)
  I fiddled with it so long and then it was an
  error in the docs I used.. :/
  The doc txt said 'return libbase in D0 in the initfunction..'
  Then in the doc example, wich I followed, NIL was returned..

  Now I am trying to pass stackparams to the functions.
  Why doesnt that work ? It should!

 I almost forgot.. one have to do a '#link library.lib'
 in the library src now. The library.lib contains
 internal functions of the library. that way the
 compiler get smaller and faster + easy changing
 of the libraries behaviour by just using another
 'libraries.lib'.

 rajrajraj.. *singing*

 new keywords for libraries:
 #mode LIBRARY ver rev name idstr
 #fdef FunctionName [additional info] **
 #endfdef basename

 Added functionality to
 #xdef, #xref, #include, VAR, GVAR
 they now accepts multiple arguments..

 Changed name and functionality of #const to #equ
 ex. #equ MyConstant 10

 Increased the maximum nr of stackparams to send
 with DOPROC to function : 15!

@EndNode

@Node feauture "What the feauture might bring"

   * Higher Level Language Preprocessors as plugins.
     This could be your job! :) contact me if youre interested.

   * LITTEL as a shared library. Different language frontends
     calls the librarys functions to create code..

   * Probably caseinsensitive keywords.

   * Maybe PPC support, its just about money.
     As PPC would fits this language perfecly it would rock! :)

   * Exception handling...not sure how to implement it right now.

   * Local blocks of data (not just LONG-vars)

   * #mode LIBRARY *DONE* :)

   * Real Optimising for 020+

   * xxx[index:Size].<offset>

   * suggestions ?

   * Betatesters I hope..

@EndNode

@Node author "The Author"

  suggestions, bugreports or whatever

  leif_salomonsson@swipnet.se

@EndNode

@Node implement "The implementation"

   LITTEL from v0 to this release, v0.15b,
   is/was written completely in E.
   It uses a very simple one-pass technique.
   Just wandering from the top line to the last line,
   parsing the instructions and their arguments
   using my own parser routine. some versions ago,
   I used afc/parser for that.
   The asm-strings from conversionroutines is put into 4 precalcedsized stringbuffers.
   At the end, the buffers are written to the asmfile in a special order.
   The file gets assemled by PhxAss and Linked by PhxLnk.
   All code uses small-data.
   The executable is split into 2 hunks : code and data-bss.

@EndNode

@Node disc "blablabla"

             its freeware anyway
  but i dont want people hacking it and releasing
  their own Littels....  talk to me instead.

  AND.. I will not take ANY responsibility
  for ANYTHING that migth go wrong when/after
  using this compiler. its all AT YOUR OWN RISK!

  The archive may be distributed (untouched) in any way
  as long as no money is earned doing it.

@EndNode

