Subversion Repositories Kolibri OS

Rev

Rev 2381 | Rev 2460 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. ; Macroinstructions for defining data structures
  9.  
  10. macro struct name
  11.  { virtual at 0
  12.    fields@struct equ name
  13.    match child parent, name \{ fields@struct equ child,fields@\#parent \}
  14.    sub@struct equ
  15.    struc db [val] \{ \common define field@struct .,db,<val>
  16.                              fields@struct equ fields@struct,field@struct \}
  17.    struc dw [val] \{ \common define field@struct .,dw,<val>
  18.                              fields@struct equ fields@struct,field@struct \}
  19.    struc du [val] \{ \common define field@struct .,du,<val>
  20.                              fields@struct equ fields@struct,field@struct \}
  21.    struc dd [val] \{ \common define field@struct .,dd,<val>
  22.                              fields@struct equ fields@struct,field@struct \}
  23.    struc dp [val] \{ \common define field@struct .,dp,<val>
  24.                              fields@struct equ fields@struct,field@struct \}
  25.    struc dq [val] \{ \common define field@struct .,dq,<val>
  26.                              fields@struct equ fields@struct,field@struct \}
  27.    struc dt [val] \{ \common define field@struct .,dt,<val>
  28.                              fields@struct equ fields@struct,field@struct \}
  29.    struc rb count \{ define field@struct .,db,count dup (?)
  30.                      fields@struct equ fields@struct,field@struct \}
  31.    struc rw count \{ define field@struct .,dw,count dup (?)
  32.                      fields@struct equ fields@struct,field@struct \}
  33.    struc rd count \{ define field@struct .,dd,count dup (?)
  34.                      fields@struct equ fields@struct,field@struct \}
  35.    struc rp count \{ define field@struct .,dp,count dup (?)
  36.                      fields@struct equ fields@struct,field@struct \}
  37.    struc rq count \{ define field@struct .,dq,count dup (?)
  38.                      fields@struct equ fields@struct,field@struct \}
  39.    struc rt count \{ define field@struct .,dt,count dup (?)
  40.                      fields@struct equ fields@struct,field@struct \}
  41.    macro db [val] \{ \common \local anonymous
  42.                      define field@struct anonymous,db,<val>
  43.                      fields@struct equ fields@struct,field@struct \}
  44.    macro dw [val] \{ \common \local anonymous
  45.                      define field@struct anonymous,dw,<val>
  46.                      fields@struct equ fields@struct,field@struct \}
  47.    macro du [val] \{ \common \local anonymous
  48.                      define field@struct anonymous,du,<val>
  49.                      fields@struct equ fields@struct,field@struct \}
  50.    macro dd [val] \{ \common \local anonymous
  51.                      define field@struct anonymous,dd,<val>
  52.                      fields@struct equ fields@struct,field@struct \}
  53.    macro dp [val] \{ \common \local anonymous
  54.                      define field@struct anonymous,dp,<val>
  55.                      fields@struct equ fields@struct,field@struct \}
  56.    macro dq [val] \{ \common \local anonymous
  57.                      define field@struct anonymous,dq,<val>
  58.                      fields@struct equ fields@struct,field@struct \}
  59.    macro dt [val] \{ \common \local anonymous
  60.                      define field@struct anonymous,dt,<val>
  61.                      fields@struct equ fields@struct,field@struct \}
  62.    macro rb count \{ \local anonymous
  63.                      define field@struct anonymous,db,count dup (?)
  64.                      fields@struct equ fields@struct,field@struct \}
  65.    macro rw count \{ \local anonymous
  66.                      define field@struct anonymous,dw,count dup (?)
  67.                      fields@struct equ fields@struct,field@struct \}
  68.    macro rd count \{ \local anonymous
  69.                      define field@struct anonymous,dd,count dup (?)
  70.                      fields@struct equ fields@struct,field@struct \}
  71.    macro rp count \{ \local anonymous
  72.                      define field@struct anonymous,dp,count dup (?)
  73.                      fields@struct equ fields@struct,field@struct \}
  74.    macro rq count \{ \local anonymous
  75.                      define field@struct anonymous,dq,count dup (?)
  76.                      fields@struct equ fields@struct,field@struct \}
  77.    macro rt count \{ \local anonymous
  78.                      define field@struct anonymous,dt,count dup (?)
  79.                      fields@struct equ fields@struct,field@struct \}
  80.    macro union \{ fields@struct equ fields@struct,,union,<
  81.                   sub@struct equ union \}
  82.    macro struct \{ fields@struct equ fields@struct,,substruct,<
  83.                   sub@struct equ substruct \} }
  84.  
  85. macro ends
  86.  { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt
  87.                          restruc rb,rw,rd,rp,rq,rt
  88.                          purge db,dw,du,dd,dp,dq,dt
  89.                          purge rb,rw,rd,rp,rq,rt
  90.                          purge union,struct
  91.                          match name tail,fields@struct, \\{ if $
  92.                                                             display 'Error: definition of ',\\`name,' contains illegal instructions.',0Dh,0Ah
  93.                                                             err
  94.                                                             end if \\}
  95.                          match name=,fields,fields@struct \\{ fields@struct equ
  96.                                                               make@struct name,fields
  97.                                                               define fields@\\#name fields \\}
  98.                          end virtual \}
  99.    match any, sub@struct \{ fields@struct equ fields@struct> \}
  100.    restore sub@struct }
  101.  
  102. macro make@struct name,[field,type,def]
  103.  { common
  104.     local define
  105.     define equ name
  106.    forward
  107.     local sub
  108.     match , field \{ make@substruct type,name,sub def
  109.                      define equ define,.,sub, \}
  110.     match any, field \{ define equ define,.#field,type,<def> \}
  111.    common
  112.     match fields, define \{ define@struct fields \} }
  113.  
  114. macro define@struct name,[field,type,def]
  115.  { common
  116.     virtual
  117.     db `name
  118.     load initial@struct byte from 0
  119.     if initial@struct = '.'
  120.     display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
  121.     err
  122.     end if
  123.     end virtual
  124.     local list
  125.     list equ
  126.    forward
  127.     if ~ field eq .
  128.      name#field type def
  129.      sizeof.#name#field = $ - name#field
  130.     else
  131.      label name#.#type
  132.      rb sizeof.#type
  133.     end if
  134.     local value
  135.     match any, list \{ list equ list, \}
  136.     list equ list <value>
  137.    common
  138.     sizeof.#name = $
  139.     restruc name
  140.     match values, list \{
  141.     struc name value \\{ \\local \\..base
  142.     match any, fields@struct \\\{ fields@struct equ fields@struct,.,name,<values> \\\}
  143.     match , fields@struct \\\{ label \\..base
  144.    forward
  145.      match , value \\\\{ field type def \\\\}
  146.      match any, value \\\\{ field type value
  147.                             if ~ field eq .
  148.                              rb sizeof.#name#field - ($-field)
  149.                             end if \\\\}
  150.    common label . at \\..base \\\}
  151.    \\}
  152.     macro name value \\{
  153.     match any, fields@struct \\\{ \\\local anonymous
  154.                                   fields@struct equ fields@struct,anonymous,name,<values> \\\}
  155.     match , fields@struct \\\{
  156.    forward
  157.      match , value \\\\{ type def \\\\}
  158.      match any, value \\\\{ \\\\local ..field
  159.                            ..field = $
  160.                            type value
  161.                            if ~ field eq .
  162.                             rb sizeof.#name#field - ($-..field)
  163.                            end if \\\\}
  164.    common \\\} \\} \} }
  165.  
  166. macro enable@substruct
  167.  { macro make@substruct substruct,parent,name,[field,type,def]
  168.     \{ \common
  169.         \local define
  170.         define equ parent,name
  171.        \forward
  172.         \local sub
  173.         match , field \\{ match any, type \\\{ enable@substruct
  174.                                                make@substruct type,parent,sub def
  175.                                                purge make@substruct
  176.                                                define equ define,.,sub, \\\} \\}
  177.         match any, field \\{ define equ define,.\#field,type,<def> \\}
  178.        \common
  179.         match fields, define \\{ define@\#substruct fields \\} \} }
  180.  
  181. enable@substruct
  182.  
  183. macro define@union parent,name,[field,type,def]
  184.  { common
  185.     virtual at parent#.#name
  186.    forward
  187.     if ~ field eq .
  188.      virtual at parent#.#name
  189.       parent#field type def
  190.       sizeof.#parent#field = $ - parent#field
  191.      end virtual
  192.      if sizeof.#parent#field > $ - parent#.#name
  193.       rb sizeof.#parent#field - ($ - parent#.#name)
  194.      end if
  195.     else
  196.      virtual at parent#.#name
  197.       label parent#.#type
  198.       type def
  199.      end virtual
  200.      label name#.#type at parent#.#name
  201.      if sizeof.#type > $ - parent#.#name
  202.       rb sizeof.#type - ($ - parent#.#name)
  203.      end if
  204.     end if
  205.    common
  206.     sizeof.#name = $ - parent#.#name
  207.     end virtual
  208.     struc name [value] \{ \common
  209.     label .\#name
  210.     last@union equ
  211.    forward
  212.     match any, last@union \\{ virtual at .\#name
  213.                                field type def
  214.                               end virtual \\}
  215.     match , last@union \\{ match , value \\\{ field type def \\\}
  216.                            match any, value \\\{ field type value \\\} \\}
  217.     last@union equ field
  218.    common rb sizeof.#name - ($ - .\#name) \}
  219.     macro name [value] \{ \common \local ..anonymous
  220.                           ..anonymous name value \} }
  221.  
  222. macro define@substruct parent,name,[field,type,def]
  223.  { common
  224.     virtual at parent#.#name
  225.    forward
  226.     if ~ field eq .
  227.      parent#field type def
  228.      sizeof.#parent#field = $ - parent#field
  229.     else
  230.      label parent#.#type
  231.      rb sizeof.#type
  232.     end if
  233.    common
  234.     sizeof.#name = $ - parent#.#name
  235.     end virtual
  236.     struc name value \{
  237.     label .\#name
  238.    forward
  239.      match , value \\{ field type def \\}
  240.      match any, value \\{ field type value
  241.                           if ~ field eq .
  242.                            rb sizeof.#parent#field - ($-field)
  243.                           end if \\}
  244.    common \}
  245.     macro name value \{ \local ..anonymous
  246.                         ..anonymous name \} }
  247.