Subversion Repositories Kolibri OS

Rev

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

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