Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; Macroinstructions for defining data structures
  3.  
  4. macro struct name
  5.  { fields@struct equ name
  6.    match child parent, name \{ fields@struct equ child,fields@\#parent \}
  7.    sub@struct equ
  8.    struc db [val] \{ \common fields@struct equ fields@struct,.,db,<val> \}
  9.    struc dw [val] \{ \common fields@struct equ fields@struct,.,dw,<val> \}
  10.    struc du [val] \{ \common fields@struct equ fields@struct,.,du,<val> \}
  11.    struc dd [val] \{ \common fields@struct equ fields@struct,.,dd,<val> \}
  12.    struc dp [val] \{ \common fields@struct equ fields@struct,.,dp,<val> \}
  13.    struc dq [val] \{ \common fields@struct equ fields@struct,.,dq,<val> \}
  14.    struc dt [val] \{ \common fields@struct equ fields@struct,.,dt,<val> \}
  15.    struc rb count \{ fields@struct equ fields@struct,.,db,count dup (?) \}
  16.    struc rw count \{ fields@struct equ fields@struct,.,dw,count dup (?) \}
  17.    struc rd count \{ fields@struct equ fields@struct,.,dd,count dup (?) \}
  18.    struc rp count \{ fields@struct equ fields@struct,.,dp,count dup (?) \}
  19.    struc rq count \{ fields@struct equ fields@struct,.,dq,count dup (?) \}
  20.    struc rt count \{ fields@struct equ fields@struct,.,dt,count dup (?) \}
  21.    macro db [val] \{ \common \local anonymous
  22.                      fields@struct equ fields@struct,anonymous,db,<val> \}
  23.    macro dw [val] \{ \common \local anonymous
  24.                      fields@struct equ fields@struct,anonymous,dw,<val> \}
  25.    macro du [val] \{ \common \local anonymous
  26.                      fields@struct equ fields@struct,anonymous,du,<val> \}
  27.    macro dd [val] \{ \common \local anonymous
  28.                      fields@struct equ fields@struct,anonymous,dd,<val> \}
  29.    macro dp [val] \{ \common \local anonymous
  30.                      fields@struct equ fields@struct,anonymous,dp,<val> \}
  31.    macro dq [val] \{ \common \local anonymous
  32.                      fields@struct equ fields@struct,anonymous,dq,<val> \}
  33.    macro dt [val] \{ \common \local anonymous
  34.                      fields@struct equ fields@struct,anonymous,dt,<val> \}
  35.    macro rb count \{ \local anonymous
  36.                      fields@struct equ fields@struct,anonymous,db,count dup (?) \}
  37.    macro rw count \{ \local anonymous
  38.                      fields@struct equ fields@struct,anonymous,dw,count dup (?) \}
  39.    macro rd count \{ \local anonymous
  40.                      fields@struct equ fields@struct,anonymous,dd,count dup (?) \}
  41.    macro rp count \{ \local anonymous
  42.                      fields@struct equ fields@struct,anonymous,dp,count dup (?) \}
  43.    macro rq count \{ \local anonymous
  44.                      fields@struct equ fields@struct,anonymous,dq,count dup (?) \}
  45.    macro rt count \{ \local anonymous
  46.                      fields@struct equ fields@struct,anonymous,dt,count dup (?) \}
  47.    macro union \{ fields@struct equ fields@struct,,union,<
  48.                   sub@struct equ union \}
  49.    macro struct \{ fields@struct equ fields@struct,,substruct,<
  50.                   sub@struct equ substruct \}
  51.    virtual at 0 }
  52.  
  53. macro ends
  54.  { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt
  55.                          restruc rb,rw,rd,rp,rq,rt
  56.                          purge db,dw,du,dd,dp,dq,dt
  57.                          purge rb,rw,rd,rp,rq,rt
  58.                          purge union,struct
  59.                          match name=,fields,fields@struct \\{ fields@struct equ
  60.                                                               make@struct name,fields
  61.                                                               fields@\\#name equ fields \\}
  62.                          end virtual \}
  63.    match any, sub@struct \{ fields@struct equ fields@struct> \}
  64.    restore sub@struct }
  65.  
  66. macro make@struct name,[field,type,def]
  67.  { common
  68.     if $
  69.      display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah
  70.      err
  71.     end if
  72.     local define
  73.     define equ name
  74.    forward
  75.     local sub
  76.     match , field \{ make@substruct type,name,sub def
  77.                      define equ define,.,sub, \}
  78.     match any, field \{ define equ define,.#field,type,<def> \}
  79.    common
  80.     match fields, define \{ define@struct fields \} }
  81.  
  82. macro define@struct name,[field,type,def]
  83.  { common
  84.     local list
  85.     list equ
  86.    forward
  87.     if ~ field eq .
  88.      name#field type def
  89.      sizeof.#name#field = $ - name#field
  90.     else
  91.      rb sizeof.#type
  92.     end if
  93.     local value
  94.     match any, list \{ list equ list, \}
  95.     list equ list <value>
  96.    common
  97.     sizeof.#name = $
  98.     restruc name
  99.     match values, list \{
  100.     struc name value \\{
  101.     match any, fields@struct \\\{ fields@struct equ fields@struct,.,name,<values> \\\}
  102.     match , fields@struct \\\{ label .
  103.    forward
  104.      match , value \\\\{ field type def \\\\}
  105.      match any, value \\\\{ field type value
  106.                            if ~ field eq .
  107.                             rb sizeof.#name#field - ($-field)
  108.                            end if \\\\}
  109.    common \\\} \\} \} }
  110.  
  111. macro enable@substruct
  112.  { macro make@substruct substruct,parent,name,[field,type,def]
  113.     \{ \common
  114.         \local define
  115.         define equ parent,name
  116.        \forward
  117.         \local sub
  118.         match , field \\{ match any, type \\\{ enable@substruct
  119.                                                make@substruct type,name,sub def
  120.                                                purge make@substruct
  121.                                                define equ define,.,sub, \\\} \\}
  122.         match any, field \\{ define equ define,.\#field,type,<def> \\}
  123.        \common
  124.         match fields, define \\{ define@\#substruct fields \\} \} }
  125.  
  126. enable@substruct
  127.  
  128. macro define@union parent,name,[field,type,def]
  129.  { common
  130.     virtual at 0
  131.    forward
  132.     if ~ field eq .
  133.      virtual at 0
  134.       parent#field type def
  135.       sizeof.#parent#field = $ - parent#field
  136.      end virtual
  137.      if sizeof.#parent#field > $
  138.       rb sizeof.#parent#field - $
  139.      end if
  140.     else if sizeof.#type > $
  141.      rb sizeof.#type - $
  142.     end if
  143.    common
  144.     sizeof.#name = $
  145.     end virtual
  146.     struc name [value] \{ \common
  147.     label .\#name
  148.     last@union equ
  149.    forward
  150.     match any, last@union \\{ virtual at .\#name
  151.                                field type def
  152.                               end virtual \\}
  153.     match , last@union \\{ match , value \\\{ field type def \\\}
  154.                            match any, value \\\{ field type value \\\} \\}
  155.     last@union equ field
  156.    common rb sizeof.#name - ($ - .\#name) \} }
  157.  
  158. macro define@substruct parent,name,[field,type,def]
  159.  { common
  160.     virtual at 0
  161.    forward
  162.     if ~ field eq .
  163.      parent#field type def
  164.      sizeof.#parent#field = $ - parent#field
  165.     else
  166.      rb sizeof.#type
  167.     end if
  168.     local value
  169.    common
  170.     sizeof.#name = $
  171.     end virtual
  172.     struc name value \{
  173.     label .\#name
  174.    forward
  175.      match , value \\{ field type def \\}
  176.      match any, value \\{ field type value
  177.                           if ~ field eq .
  178.                            rb sizeof.#parent#field - ($-field)
  179.                           end if \\}
  180.    common \} }
  181.