home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Mops 2.5 / Mops source.sit / Mops source / Nuc source / Defn.asm / Defn.asm
Encoding:
Assembly Source File  |  1994-11-02  |  10.2 KB  |  689 lines  |  [TEXT/NISI]

  1. ; This file contains the definition of the macros and other items which
  2. ; generally define the structure of the implementation.
  3.  
  4.     mexp    0    ; Set non-zero for expansions
  5.  
  6. ;    =======================
  7.  
  8. ; Flag codes for various word types.  The actual values are quite
  9. ; arbitrary, but let us do conditional comparison on numeric values
  10. ; rather than strings, which is faster and uses less memory during
  11. ; assembly.
  12.  
  13. inline    equ    0
  14. docode    equ    1
  15. docol    equ    3
  16. docon    equ    5
  17. doval    equ    6
  18. doObj    equ    7
  19. dovbl    equ    8
  20. dovect    equ    9
  21. doDynVect    equ    4
  22. spec    equ    10
  23. xinfo    equ    11
  24. nocode    equ    12
  25. doObjPtr    equ    13
  26. xinfoN    equ    14
  27.  
  28. xinfoMk    equ    $4E58    ; This is  UNLK A0  which never appears in
  29.             ;  Mops code.  (Pretty unlikely anywhere!!)
  30.  
  31. ;    ========================
  32.  
  33. FCBlen    equ    204
  34. HOLDlen    equ    30
  35. PADlen    equ    200
  36. TIBlen    equ    400
  37. ErrDumpLen    equ    200
  38. MaxDump    equ    (ErrDumpLen / 8) - 5
  39.  
  40. FBlkLen    equ    FCBlen + HOLDlen + PADlen + TIBlen + ErrDumpLen + 8
  41.                 ; The extra 8 is for the object header
  42.  
  43. ;    ========================
  44.  
  45. hbase    equ    0
  46.  
  47. ; Codes for handler routines.  These must all be negative.
  48.  
  49. inl_h    equ    -1
  50.  
  51. ; The following codes are used to table jump to the right routine within
  52. ; Handlers, and so must be negative and even.
  53.  
  54. col_h    equ    -2
  55. call_h    equ    col_h
  56. const_h    equ    -4
  57. val_h    equ    -6
  58. create_h    equ    -8
  59. vect_h    equ    -10
  60. pm_h    equ    -12
  61. at_h    equ    -14
  62. store_h    equ    -16
  63. callstr_h    equ    -18
  64. reg_h    equ    -20
  65. obj_h    equ    -22
  66. does_h    equ    -24
  67. loc_h    equ    -26
  68. LitAddr    equ    -28
  69. PushDesc_h    equ    -30
  70. cmp_h    equ    -32
  71. hLiteral    equ    -34
  72. CompExit    equ    -36
  73. CompJSRLong    equ    -38
  74. pif    equ    -40
  75. compPlLoop    equ    -42
  76. hmentry    equ    -44
  77. hplentry    equ    -46
  78. heb    equ    -48
  79. hStkObj    equ    -50
  80. hDoEx    equ    -52
  81. hgenaddr    equ    -54
  82. hgenxaddr    equ    -56
  83. class_h    equ    -58
  84. hcompimp    equ    -60
  85. objPtr_h    equ    -62
  86. bit_h    equ    -64
  87. swap_h    equ    -66
  88. hLoadBA    equ    -68
  89. FixDoes    equ    -70
  90. hPatch    equ    -72
  91. Floc_h    equ    -74
  92. Fcon_h    equ    -76
  93. Fval_h    equ    -78
  94. FP1_h    equ    -80
  95. FP2_h    equ    -82
  96. FPcmp_h    equ    -84
  97. hcompFPUL    equ    -86
  98. FCRcon_h    equ    -88
  99. class_in_mod_h    equ    -90
  100. imported_h    equ    -92
  101. hColA    equ    -94
  102. shift_h    equ    -96
  103. hDefnEnd    equ    -98
  104. Fat_h    equ    -100
  105. Fst_h    equ    -102
  106. builds_h    equ    -104
  107. MultDiv_h    equ    -106
  108. Move_h    equ    -108
  109. AlignedMove_h    equ    -110
  110. hNoOpt    equ    -112
  111. colNoOpt_h    equ    -114
  112. hComputedJMP    equ    -116
  113. dynVect_h    equ    -118
  114.  
  115.  
  116. ;        =======================
  117.  
  118. ;                MACROS
  119.  
  120. ;        =======================
  121.  
  122. ; Push and pop macros - modified to use A6 instead of A7.
  123.  
  124. push.b    macrox    &1
  125.     move.b    &1,-(a6)
  126.     endm
  127.  
  128. push.w    macrox    &1
  129.     move.w    &1,-(a6)
  130.     endm
  131.  
  132. push    macrox    &1
  133.     move.w    &1,-(a6)
  134.     endm
  135.  
  136. push.l    macrox    &1
  137.     move.l    &1,-(a6)
  138.     endm
  139.  
  140. pop.b    macrox    &1
  141.     move.b    (a6)+,&1
  142.     endm
  143.  
  144. pop.w    macrox    &1
  145.     move.w    (a6)+,&1
  146.     endm
  147.  
  148. pop    macrox    &1
  149.     move.w    (a6)+,&1
  150.     endm
  151.  
  152. pop.l    macrox    &1
  153.     move.l    (a6)+,&1
  154.     endm
  155.  
  156.  
  157. ; Since we are using A5 as the module base reg, we need to reset it to CurrentA5
  158. ; over many system calls.  We also need to save RP (A7) in case the system calls
  159. ; us back (i.e. to a :PROC).  So here we define macros to set up for a system call
  160. ; then restore things after the system returns.
  161.  
  162. SavA5    macrox
  163.     jsr    DoSavA5-base(a3)
  164.     endm
  165.  
  166. RstA5    macrox
  167.     exg    a6,a7
  168.     move.l    (a7)+,a5
  169.     endm
  170.  
  171.  
  172. ; N assembles a push of the parameter as a literal number, with optimization.
  173.  
  174. N    macrox    &1
  175.     if    &1 = 0
  176.     CLR.L    -(A6)
  177.     else
  178.     if    (&1 < 128) or (-(&1) <= 128)
  179.     MOVEQ    #&1,D0
  180.     PUSH.L    D0
  181.     else
  182.     PUSH.L    #&1
  183.     endi
  184.     endi
  185.     endm
  186.  
  187.  
  188. ADD_M    macrox    &1
  189.     if    (&1 <= 8)
  190.     ADDQ.L    #&1,(A6)
  191.     else
  192.     ADDI.L    #&1,(A6)
  193.     endi
  194.     endm
  195.  
  196. SUB_M    macrox    &1
  197.     if    (&1 <= 8)
  198.     SUBQ.L    #&1,(A6)
  199.     else
  200.     SUBI.L    #&1,(A6)
  201.     endi
  202.     endm
  203.  
  204.  
  205. ; CONSTANTs - fetches of these are optimized, since we have the value
  206. ; available.
  207.  
  208. CONST    macrox    &1,&2,&3,&4    ; len, name, label, value
  209.     head    &1,&2,&3,docon
  210.     h    const_h
  211. &3    dc.l    &4
  212. &3_con    equ    &4
  213.     endm
  214.  
  215. NCONST    macrox    &1,&2    ; Constant with no head
  216.     nohead    &1,docon
  217.     h    const_h
  218. &1    dc.l    &2
  219. &1_con    equ    &2
  220.     endm
  221.  
  222.  
  223. FCon    macrox    &1
  224.     if    &1_con = 0
  225.     CLR.L    -(A6)
  226.     else
  227.     if    (&1_con < 128) or (-(&1_con) <= 128)
  228.     MOVEQ    #&1_con,D0
  229.     PUSH.L    D0
  230.     else
  231.     PUSH.L    &1-base(A3)
  232.     endi
  233.     endi
  234.     endm
  235.  
  236.  
  237. ; VALUEs - these have 3 "methods", fetch, increment, store.
  238.  
  239. VALU    macrox    &1,&2,&3,&4    ; len, name, label, value
  240.     head    &1,&2,&3,doval
  241.     h    val_h
  242.     if    "&4" <> ""
  243. &3    dc.l    &4
  244.     else
  245. &3    dc.l    0
  246.     endi
  247.     endm
  248.  
  249. NVALU    macrox    &1,&2    ; Value with no header
  250.     nohead    &1,doval
  251.     h    val_h
  252.     if    "&2" <> ""
  253. &1    dc.l    &2
  254.     else
  255. &1    dc.l    0
  256.     endi
  257.     endm
  258.  
  259. FVal    macrox    &1
  260.     PUSH.L    &1-base(A3)
  261.     endm
  262.  
  263. IncVal    macrox    &1
  264.     POP.L    D0
  265.     ADD.L    D0,&1-base(A3)
  266.     endm
  267.  
  268. ToVal    macrox    &1
  269.     POP.L    &1-base(A3)
  270.     endm
  271.  
  272. ZVal    macrox    &1
  273.     CLR.L    &1-base(A3)
  274.     endm
  275.  
  276.  
  277. ; Variables.  Note in this assembly we don't automatically allocate
  278. ; storage for a variable.  An explicit  byte n  or whatever must be
  279. ; done.
  280.  
  281. VARBL    macrox    &1,&2,&3,&4
  282.     head    &1,&2,&3,dovbl
  283.     h    create_h
  284. &3
  285.     endm
  286.  
  287. rVbl    macrox    &1
  288.     LEA    &1,A0
  289.     PUSH.L    A0
  290.     endm
  291.  
  292.  
  293. ; Vectors.  These have 3 "methods" - execute, fetch, store.
  294. ; System vectors have a default value, 4 bytes after the normal value.
  295. ; The normal value is a relocatable address, but we assume the default
  296. ; is within the normal dic range, so we use a straight JMP.
  297. ; Dynamic vectors (new with Mops 2.5) are useful for calling words in a (locked)
  298. ; module.  They have to be set at run time since they use an absolute address.
  299.  
  300. SVECT    macrox    &1,&2,&3,&4    ; len, name, label, default value
  301.     head    &1,&2,&3,dovect
  302.     h    vect_h
  303. &3    jsr    DoExVect-base(a3)
  304.     dc.l    0
  305.     if    "&4" <> ""
  306.     bra    &4
  307.     else
  308.     bra    null
  309.     endi
  310.     endm
  311.  
  312. DynVECT    macrox    &1,&2,&3        ; len, name, label
  313.     head    &1,&2,&3,doDynVect
  314.     h    dynVect_h
  315. &3    jsr    DoExDynVect-base(a3)
  316.     dc.l    0
  317.     endm
  318.  
  319. NVECT    macrox    &1    ; Vector with no header and no default
  320.     nohead    &1,dovect
  321. &1    jsr    DoExVect-base(a3)
  322.     dc.l    0
  323.     endm
  324.  
  325.  
  326. ExVect    macrox    &1
  327.     jsr    &1-base(a3)
  328.     endm
  329.  
  330. SetVect    macrox    &1,&2
  331.     lea    &1,a0
  332.     push.l    a0
  333.     lea    &2+4-base(a3),a0
  334.     jsr    DoToVect-base(A3)
  335.     endm
  336.  
  337. ClrVect    macrox    &1
  338.     clr.l    &1+4-base(a3)
  339.     endm
  340.  
  341. ExDynVect    macrox    &1
  342.     jsr    &1-base(a3)
  343.     endm
  344.  
  345. ;        ================
  346.  
  347. pushop    macrox    &1
  348.     PUSH.W    &1-base(A3)
  349.     CLR.W    -(A6)
  350.     endm
  351.  
  352. compop    macrox    &1
  353.     pushop    &1
  354.     parms    wcomma
  355.     endm
  356.  
  357.  
  358. ; Compyl is the macro equivalent of COMPILE (now replaced by POSTPONE).
  359. ; It assembles a call to (COMP) which either moves in inline code or calls
  360. ; the compilation handler for the given word.
  361.  
  362. compyl    macrox    &1
  363.     rVbl    &1
  364.     bsr    doPcomp
  365.     endm
  366.  
  367.  
  368. NEXT    macrox
  369.     rts
  370.     endm
  371.  
  372. H    macrox    &1
  373.     dc.w    &1
  374.     endm
  375.  
  376. INL    macro    &1
  377.     dc.w    .xx-*-2
  378. &1    &1_m
  379. .xx    rts
  380.     endm
  381.  
  382. USE    macrox    &1
  383. &1    &1_m
  384.     rts
  385.     endm
  386.  
  387.  
  388. TOKEN    macrox    &1
  389.     if    &1_t = inline
  390.     &1_m
  391.     else
  392.     if    (&1_t = doval) or (&1_t = doObjPtr)
  393.     FVal    &1
  394.     else
  395.     if    &1_t = docon
  396.     FCon    &1
  397.     else
  398.     if    (&1_t = dovbl) or (&1_t = doObj)
  399.     rVbl    &1
  400.     else
  401.     if    &1_t = dovect
  402.     exVect    &1
  403.     else
  404.     BSR    &1
  405.     endi
  406.     endi
  407.     endi
  408.     endi
  409.     endi
  410.     endm
  411.  
  412.  
  413. HCODE    macrox    &1,&2
  414.     if    "&2" <> ""
  415.     dc.w    &2
  416.     else
  417.     dc.w    &1
  418.     endi
  419.     endm
  420.  
  421.  
  422. ; CODE is called by HEAD and NOHEAD.
  423. ; It's easily the most complex macro here, so I'd better give some commentary:
  424. ; The first if..endi section handles the case where we need a descriptor pushed
  425. ; at compile-time.  This is indicated by the "pushDesc_h" handler code.  Then
  426. ; comes the xinfoMk which tells EXECUTE that this isn't code, then the byte count
  427. ; of the extra info, which in this case is 2 bytes for the descriptor type & subtype,
  428. ; and 2 bytes for the "real" handler code.
  429. ;
  430. ; Next we get rid of the case where there are no parameters after &1.
  431. ; Then after that we deal with all the mutually exclusive special cases with
  432. ; nested if..endi sections.
  433.  
  434. CODE    macrox    &1,&2,&3,&4    ; label,flag,opt,alt-hndlr-code
  435.     if    "&3" <> ""
  436.     dc.w    pushDesc_h
  437.     dc.w    xinfoMk
  438.     dc.w    4
  439.     dc.w    &3
  440.     endi
  441.  
  442.     if    "&2" = ""
  443. &1_t    set    docode
  444.     Hcode    call_h,&4
  445. &1
  446.     else
  447.  
  448. &1_t    set    &2
  449.  
  450.     if    &2 = inline
  451.     inl    &1
  452.  
  453.     else
  454.  
  455.     if    &2 = doObj
  456.     Hcode    obj_h,&4
  457.     dc.w    6
  458.     dc.l    nilP_con
  459.     dc.w    -6
  460. &1
  461.     else
  462.  
  463.     if    &2 = doObjPtr
  464.     Hcode    objPtr_h,&4
  465. &1    dc.l    nilP_con
  466.     dc.l    0
  467.  
  468.     else
  469.  
  470.     if    &2 = xinfo
  471.     Hcode    call_h,&4
  472.     dc.w    xinfoMk
  473.     dc.w    &1-*-2
  474.  
  475.     else
  476.  
  477.     if    &2 = xinfoN
  478.     Hcode    call_h,&4
  479.     dc.w    xinfoMk
  480.     dc.w    0
  481.  
  482.     else
  483.  
  484.     if    ( &2 = docode ) or ( &2 = spec ) or ( &2 = docol ) or ( &2 = nocode )
  485.     Hcode    call_h,&4
  486. &1
  487.     endi
  488.     endi
  489.     endi
  490.     endi
  491.     endi
  492.     endi
  493.     endi
  494.     endm
  495.  
  496.  
  497. linkit    macrox    &1
  498.     if    q%1 = 0
  499.     dc.l    0
  500.     else
  501.     dc.l    q%1+d-*
  502.     endi
  503. q%1    set    *-d-4
  504.     endm
  505.  
  506. ; The HEAD macro defines a dictionary header.
  507. ; The flag field identifies what kind of word this is.  If the flag is
  508. ; "docol", "inline", "spec" or null, it is a word that is called
  509. ; by a JSR, and we assemble the handler field and linking code here.
  510. ; If the flag is anything else, we assume that HEAD has been called from
  511. ; another macro that is looking after everything, so we just assemble the 
  512. ; header.
  513. ; The opt field is non-zero if this word can begin a sequence where
  514. ; optimization of the compiled code is zero.  The opt field is left in 
  515. ; 2 bytes at the start of the definition; at compile time this field is
  516. ; left in CompFlg.
  517.  
  518. HEAD    macrox    &1,&2,&3,&4,&5,&6 ; len-byte,name,label,flag,opt,alt-hdlr
  519.     align
  520.     loc
  521.     linkit    &1 and 7
  522.     dc.b    &1 or $80
  523.     text    &&2
  524.     align
  525.     code    &3,&4,&5,&6
  526.     endm
  527.  
  528.  
  529. NOHEAD    macrox    &1,&2,&3,&4    ; label, flag, opt, alt-hdlr
  530.     code    &1,&2,&3,&4
  531.     endm
  532.  
  533.  
  534. COMH    macrox    &1
  535.     MOVEQ    #&1,D0
  536.     PUSH.L    D0
  537.     parms    wcomma
  538.     endm
  539.  
  540. CALLH    macrox    &1
  541.     if    "&1" <> ""
  542.     MOVEQ    #&1,D0
  543.     endi
  544.     BSR    CallHandlers
  545.     endm
  546.  
  547. JUMPH    macrox    &1
  548.     if    "&1" <> ""
  549.     MOVEQ    #&1,D0
  550.     endi
  551.     BRA    CallHandlers
  552.     endm
  553.  
  554.  
  555. NOOPT    macrox
  556.     bsr    doNoOpt
  557.     endm
  558.  
  559.  
  560. PARMS    macrox    &1,&2,&3,&4,&5,&6
  561.     token    &1
  562.     IF    "&2" <> ""
  563.     token    &2
  564.     ENDI
  565.     IF    "&3" <> ""
  566.     token    &3
  567.     ENDI
  568.     IF    "&4" <> ""
  569.     token    &4
  570.     ENDI
  571.     IF    "&5" <> ""
  572.     token    &5
  573.     ENDI
  574.     IF    "&6" <> ""
  575.     token    &6
  576.     ENDI
  577.     endm
  578.  
  579.  
  580. BRANCH    macrox    &1
  581.     BRA.S    &1
  582.     endm
  583.  
  584. QBRANCH    macrox    &1
  585.     TST.L    (A6)+
  586.     BNE.S    &1
  587.     endm
  588.  
  589. ZBRANCH    macrox    &1
  590.     TST.L    (A6)+
  591.     BEQ.S    &1
  592.     endm
  593.  
  594. EQBRANCH    macrox    &1,&2
  595.     CMPI.L    #&1,(A6)+
  596.     BEQ.S    &2
  597.     endm
  598.  
  599. NEBRANCH    macrox    &1,&2
  600.     CMPI.L    #&1,(A6)+
  601.     BNE.S    &2
  602.     endm
  603.  
  604. msg    macrox    &1
  605.     JSR    pdotq-base(a3)
  606.     text    #&&1
  607.     align
  608.     endm
  609.  
  610. abq    macrox    &1
  611.     JSR    pabq
  612.     text    #&&1
  613.     align
  614.     endm
  615.  
  616.  
  617. ; testing *************
  618. ;
  619. ;d
  620. ;
  621. ;q0    set    0
  622. ;q1    set    0
  623. ;q2    set    0
  624. ;q3    set    0
  625. ;q4    set    0
  626. ;q5    set    0
  627. ;q6    set    0
  628. ;q7    set    0
  629. ;
  630. ;    dc.w    123
  631. ;
  632. ;    head    5,BLOGGS,bloggs
  633. ;    dc.l    9876
  634. ;
  635. ;    valu    4,HAHA,haha,25
  636. ;
  637. ; "Push a descriptor" test
  638. ;otCMP    equ    $26
  639. ;tsGE    equ    otCMP*256 + $C
  640. ;setTrue
  641. ;setFalse
  642. ;
  643. ;    head    2,>=,ge,docode,tsGE
  644. ;    CMPM.L    (A6)+,(A6)+
  645. ;    BGE.S    setTrue
  646. ;    BRA.S    setFalse
  647. ;
  648. ; Push a descriptor with inline
  649. ;nip_m    macrox
  650. ;    POP.L    (A6)
  651. ;    endm
  652. ;    head    3,NIP,nip,inline,tsCCOK
  653. ;
  654. ; "xinfo" test
  655. ;    head    3,YYY,yyy,xinfo
  656. ;    dc.w    123
  657. ;    dc.w    456
  658. ;yyy    moveq    #1,d0
  659. ;    rts
  660. ;
  661. ; xinfo with inline
  662. ;
  663. ;otADD    equ    $21
  664. ;
  665. ;plus_m    macrox
  666. ;    POP.L    D0
  667. ;    ADD.L    D0,(A6)
  668. ;    endm
  669. ;
  670. ;    head    1,+,plus,xinfo,,pm_h
  671. ;    dc.w    otADD
  672. ;    use    plus
  673. ;
  674. ;
  675. ;    head    7,LOCPARM,locparm,nocode,,loc_h
  676. ;
  677. ;
  678. ;    varbl    7,CONTEXT,context
  679. ;
  680. ;    dc.l    q0+d-*
  681. ;    dc.l    q1+d-*
  682. ;    dc.l    q2+d-*
  683. ;    dc.l    q3+d-*
  684. ;    dc.l    q4+d-*
  685. ;    dc.l    q5+d-*
  686. ;    dc.l    q6+d-*
  687. ;    dc.l    q7+d-*
  688. ;
  689. ;