Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

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