Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; Macroinstructions for defining data structures
  3.  
  4. macro struct@overridedefs [datadef] {
  5.         struc datadef [val:?] \{ \common
  6.                 match any:no,force@alignment:@rstruct \\{ define field@struct -,align,datadef#.align \\}
  7.                 define field@struct .,datadef,<val> \}
  8.         macro datadef [val:?] \{ \common
  9.                 match any:no,force@alignment:@rstruct \\{ define field@struct -,align,datadef#.align \\}
  10.                 define field@struct -,datadef,<val> \} }
  11. ;==============================================================
  12. macro struct@overridersvs [datadef] {
  13.         match ddd,def.#datadef \{
  14.         struc datadef count \\{ \\common
  15.                 match any:no,force@alignment:@rstruct \\\{ define field@struct -,align,ddd\#.align \\\}
  16.                 define field@struct .,ddd,count dup (?) \\}
  17.         macro datadef count \\{ \\common
  18.                 match any:no,force@alignment:@rstruct \\\{ define field@struct -,align,ddd\#.align \\\}
  19.                 define field@struct -,ddd,count dup (?) \\} \} }
  20. ;==============================================================
  21. macro struct@overridealgn [datadef] {
  22.         struc datadef amount:default.#datadef \{ define field@struct -,datadef,amount \}
  23.         macro datadef amount:default.#datadef \{ define field@struct -,datadef,amount \} }
  24. ;==============================================================
  25. macro struct@restoredefs [datadef] {
  26.         restruc datadef
  27.         purge datadef }
  28.  
  29. ;==============================================================
  30. ; GLOBAL ASSUMPTIONS FOR THIS MACRO SET
  31. ; THERE IS NO PRACTICAL SENSE TO ENCLOSE IN UNION OR STRUCT NO ONE FIELD
  32. ; THERE IS NO PRACTICAL SENSE TO ENCLOSE IN SUBUNION OR SUBSTRUCT ONLY 1 FIELD OR EVEN NO ONE
  33. ; THERE IS NO PRACTICAL SENSE TO ENCLOSE IN SUBUNION ONLY UNNAMED FIELDS
  34. ;==============================================================
  35.  
  36. macro struct definition {
  37.         match name tail, definition: \{
  38.                 virtual
  39.                         db \`name
  40.                         load initial@struct byte from $$
  41.                         if initial@struct = '.'
  42.                                 display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
  43.                                 err
  44.                         end if
  45.                 end virtual
  46.  
  47.                 macro ends \\{
  48.                         match , sub@struct \\\{
  49.                                 if $
  50.                                         display 'Error: definition of ',\`name,' contains illegal instructions.',0Dh,0Ah
  51.                                         err
  52.                                 end if
  53.  
  54.                                 match any,datadef@directives \\\\{ struct@restoredefs any \\\\}
  55.                                 match any,datarsv@directives \\\\{ struct@restoredefs any \\\\}
  56.                                 match any,algnmnt@directives \\\\{ struct@restorealgn any \\\\}
  57.  
  58.                                 purge union,struct,rstruct,ends
  59.  
  60.                                 irpv fields,field@struct \\\\{
  61.                                         restore field@struct
  62.                                  \\\\common
  63.                                         restore @struct
  64.                                         make@struct name,fields
  65.                                         define fields@\#name fields \\\\}
  66.                                 end virtual \\\} ;end virtual must be after make@struct
  67.                         match any, sub@struct \\\{
  68.                                 tmp@struct equ field@struct
  69.                                 restore field@struct
  70.                                 field@struct equ tmp@struct> \\\}
  71.                         restore sub@struct \\}
  72.  
  73.                 ;match :,tail \\{ \\}
  74.                 match parent:,tail \\{ field@struct equ fields@\\#parent \\} \}
  75.  
  76.         match any,datadef@directives \{ struct@overridedefs any \}
  77.         match any,datarsv@directives \{ struct@overridersvs any \}
  78.         match any,algnmnt@directives \{ struct@overridealgn any \}
  79.         irp datadef,union,struct,rstruct \{
  80.                 macro datadef \\{
  81.                         field@struct equ ,sub\#datadef,<
  82.                         sub@struct equ sub\#datadef \\} \}
  83.  
  84.         define @struct
  85.         sub@struct equ
  86.         virtual at 0 }
  87. ;==============================================================
  88. macro union definition {
  89.         struct definition
  90.         define @union }
  91. ;==============================================================
  92. macro rstruct definition {
  93.         struct definition
  94.         define @rstruct }
  95. ;==============================================================
  96. macro make@struct name,[field,type,def] {
  97.     common
  98.         local CONVERTED,PREVIOUS,CURRENT
  99.         define CONVERTED name
  100.         define CURRENT 1
  101.     forward
  102.         PREVIOUS equ CURRENT
  103.         define CURRENT 1
  104.         local sub
  105.         match , field \{ define CURRENT 2
  106.                          make@substruct type,name,sub def \}
  107.         match -, field \{ define CURRENT 0 \}
  108.         match =1:=0, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED, < <type def>                                           \}
  109.         match =0:=0, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED              , <type def>                            \}
  110.         match =1:=1, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED,                           , .#field,  type, <def> \}
  111.         match =0:=1, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED                           >, .#field,  type, <def> \}
  112.         match =1:=2, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED,                           , .,        sub,        \}
  113.         match =0:=2, PREVIOUS:CURRENT \{ CONVERTED equ CONVERTED                           >, .,        sub,        \}
  114.         match =2, CURRENT             \{ define CURRENT 1 \}
  115.     common
  116.         local anonymous
  117.         match =0, CURRENT             \{ CONVERTED equ CONVERTED                           >, anonymous,:,          \}
  118.         match converted, CONVERTED \{
  119.                 match no:no, @union:@rstruct \\{ define@struct converted \\}
  120.                 match no:, @union:@rstruct \\{
  121.                         restore @rstruct
  122.                         define@rstruct converted \\}
  123.                 match :no, @union:@rstruct \\{
  124.                         restore @union
  125.                         define@union converted \\} \} }
  126. ;==============================================================
  127. macro define@union name,[anon,field,type,def] {
  128.  forward
  129.         match any, anon \{
  130.                 irp anondef,any \\{
  131.                         \\local anonsize
  132.                         virtual at 0
  133.                                 anondef
  134.                                 anonsize = $
  135.                         end virtual
  136.                         if anonsize > $
  137.                                 rb anonsize - $
  138.                         end if
  139.                         \\}  \}
  140.         if ~ field eq .
  141.                 virtual at 0
  142.                         name#field type def
  143.                         sizeof.#name#field = $ - name#field
  144.                 end virtual
  145.                 if sizeof.#name#field > $
  146.                         rb sizeof.#name#field - $
  147.                 end if
  148.         else
  149.                 virtual at 0
  150.                         label name#.#type
  151.                         rb sizeof.#type
  152.                 end virtual
  153.                 if sizeof.#type > $
  154.                         rb sizeof.#type - $
  155.                 end if
  156.         end if
  157.  common
  158.         sizeof.#name = $
  159.         restruc name
  160.         struc name value \{
  161.                 \local \..base
  162.                 match , @struct \\{ define field@struct .,name,value \\}
  163.                 match no, @struct \\{
  164.                         label \..base
  165.                         last@union equ
  166.  forward
  167.                         match any, last@union \\\{
  168.                         virtual at \..base
  169.                                 field type def
  170.                         end virtual \\\}
  171.                         match , last@union \\\{
  172.                                 match , value \\\\{ field type def \\\\}
  173.                                 match any, value \\\\{ field type value \\\\} \\\}
  174.                         last@union equ field
  175.  common
  176.                         if sizeof.#name > $ - \..base
  177.                                 rb sizeof.#name - ($ - \..base)
  178.                         end if
  179.                         label . at \..base \\}
  180.         \}
  181.         macro name value \{
  182.                 \local \..base
  183.                 match , @struct \\{ define field@struct -,name,value \\}
  184.                 match no, @struct \\{
  185.                         label \..base
  186.                         last@union equ
  187.  forward
  188.                         match , last@union \\\{ match any, value \\\\{ field type value \\\\} \\\}
  189.                         last@union equ field
  190.  common
  191.                         if sizeof.#name > $ - \..base
  192.                                 rb sizeof.#name - ($ - \..base)
  193.                         end if \\} \} }
  194. ;==============================================================
  195. macro define@rstruct name,[anon,field,type,def] {
  196.  common
  197.         local list,..start,..size
  198.         list equ
  199.         virtual at -..size
  200.                 ..start:
  201.  forward
  202.                 local anonsize
  203. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  204.                 anonsize = $
  205.                 match any, anon \{ irp anondef,any \\{ anondef \\} \}
  206.                 anonsize = $-anonsize
  207. ;    END OF ASSUMPTION
  208.                 if ~ field eq .
  209.                         name#field type def
  210.                         sizeof.#name#field = $ - name#field
  211.                 else
  212.                         label name#.#type
  213.                         rb sizeof.#type
  214.                 end if
  215.                 local value
  216.                 match any, list \{ list equ list, \}
  217.                 list equ list <value>
  218.  common
  219.                 ..size = $ - ..start
  220.         end virtual
  221.         sizeof.#name = ..size
  222.         restruc name
  223.         match values, list \{
  224.                 struc name value \\{
  225.                         match , @struct \\\{ define field@struct .,name,<values> \\\}
  226.                         match no, @struct \\\{
  227.  forward
  228. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  229.                                 rb anonsize
  230. ;    END of ASSUMPTION
  231.                                 match , value \\\\{ field type def \\\\}
  232.                                 match any, value \\\\{
  233.                                         field type value
  234.                                         if ~ field eq .                           ; MAIN PURPOSE OF THEESE 3 LINES - REALISATION OF LEGACY ALIGNMENT STYLE IN STRUCTURES
  235.                                                 rb sizeof.#name#field - ($-field) ; BECAUSE ALIGNED FIELD PRECIDED WITH ANOTHER SHORTER SIZE FIELD - WE CAN EMULATE ALIGNMENT BY ADDING SEQUENCE OF ",?" TO END OF THAT SHORTER SIZE FIELD
  236.                                         end if                                    ; 2ND PURPOSE - COMPARISON THAT DATA PASSED TO INITIALIZE STRUCTURE WILL FIT IN ITS MEMBERS; IN COMMON CASE MORE OPTIMAL SUCH COMPARISON FOR WHOLE STRUCTURE NOT PER FIELD
  237.                                         \\\\}
  238.  common
  239.  
  240.                                 ;if $-\\..base-sizeof.#name                       ; IF WE REMOVE 3 LINES ABOVE COMMENTED AS LEGACY
  241.                                 ;        err                                      ; THEN WE MUST UNCOMMENT THESE 3 LINES
  242.                                 ;end if                                           ;
  243.                                 label . \\\}
  244.                 \\}
  245.                 macro name value \\{
  246.                         \\local anonymous
  247.                         match , @struct \\\{ define field@struct -,name,<values> \\\}
  248.                         match no, @struct \\\{ anonymous name value \\\} \\} \} }
  249. ;==============================================================
  250. macro define@struct name,[anon,field,type,def] {
  251.  common
  252.         local list
  253.         list equ
  254.  forward
  255.         local anonsize
  256. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  257.         anonsize = $
  258.         match any, anon \{ irp anondef,any \\{ anondef \\} \}
  259.         anonsize = $-anonsize
  260. ;    END OF ASSUMPTION
  261.         if ~ field eq .
  262.                 name#field type def
  263.                 sizeof.#name#field = $ - name#field
  264.         else
  265.                 label name#.#type
  266.                 rb sizeof.#type
  267.         end if
  268.         local value
  269.         match any, list \{ list equ list, \}
  270.         list equ list <value>
  271.  common
  272.         sizeof.#name = $
  273.         restruc name
  274.         match values, list \{
  275.                 struc name value \\{
  276.                         \\local \\..base
  277.                         match , @struct \\\{ define field@struct .,name,<values> \\\}
  278.                         match no, @struct \\\{
  279.                                 label \\..base
  280.  forward
  281. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  282.                                 rb anonsize
  283. ;    END of ASSUMPTION
  284.                                 match , value \\\\{ field type def \\\\}
  285.                                 match any, value \\\\{
  286.                                         field type value
  287.                                         if ~ field eq .                           ; MAIN PURPOSE OF THEESE 3 LINES - REALISATION OF LEGACY ALIGNMENT STYLE IN STRUCTURES
  288.                                                 rb sizeof.#name#field - ($-field) ; BECAUSE ALIGNED FIELD PRECIDED WITH ANOTHER SHORTER SIZE FIELD - WE CAN EMULATE ALIGNMENT BY ADDING SEQUENCE OF ",?" TO END OF THAT SHORTER SIZE FIELD
  289.                                         end if                                    ; 2ND PURPOSE - COMPARISON THAT DATA PASSED TO INITIALIZE STRUCTURE WILL FIT IN ITS MEMBERS; IN COMMON CASE MORE OPTIMAL SUCH COMPARISON FOR WHOLE STRUCTURE NOT PER FIELD
  290.                                         \\\\}
  291.  common
  292.  
  293.                                 ;if $-\\..base-sizeof.#name                       ; IF WE REMOVE 3 LINES ABOVE COMMENTED AS LEGACY
  294.                                 ;        err                                      ; THEN WE MUST UNCOMMENT THESE 3 LINES
  295.                                 ;end if                                           ;
  296.                                 label . at \\..base \\\}
  297.                 \\}
  298.                 macro name value \\{
  299.                         \\local anonymous
  300.                         match , @struct \\\{ define field@struct -,name,<values> \\\}
  301.                         match no, @struct \\\{ anonymous name value \\\} \\} \} }
  302. ;==============================================================
  303. macro enable@substruct {
  304.         macro make@substruct substruct,parent,name,[field,type,def] \{
  305.          \common
  306.                 \local CONVERTED,PREVIOUS,CURRENT
  307.                 define CONVERTED parent,name
  308.                 define CURRENT 1
  309.          \forward
  310.                 PREVIOUS equ CURRENT
  311.                 define CURRENT 1
  312.                 \local sub
  313.                 match , field \\{
  314.                         match any, type \\\{
  315.                                 define CURRENT 2
  316.                                 enable@substruct
  317.                                 make@substruct type,parent,sub def
  318.                                 purge make@substruct \\\} \\}
  319.                 match -, field \\{ define CURRENT 0 \\}
  320.                 match =1:=0, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED, < <type def>                                      \\}
  321.                 match =0:=0, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED              , <type def>                          \\}
  322.                 match =1:=1, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED,                           , .\#field, type, <def> \\}
  323.                 match =0:=1, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED                           >, .\#field, type, <def> \\}
  324.                 match =1:=2, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED,                           , .,        sub,        \\}
  325.                 match =0:=2, PREVIOUS:CURRENT \\{ CONVERTED equ CONVERTED                           >, .,        sub,        \\}
  326.                 match =2, CURRENT \\{ define CURRENT 1 \\}
  327.          \common
  328.                 \local anonymous
  329.                 match =0, CURRENT \\{ CONVERTED equ CONVERTED                                       >,anonymous, :,          \\}
  330.                 match converted, CONVERTED \\{ define@\#substruct converted \\} \} }
  331. ;==============================================================
  332. enable@substruct
  333. ;==============================================================
  334. macro define@subunion parent,name,[anon,field,type,def] {
  335.  common
  336.         virtual at parent#.#name
  337.  forward
  338.                 match any, anon \{
  339.                         irp anondef,any \\{
  340.                                 \\local anonsize
  341.                                 virtual at 0
  342.                                         anondef
  343.                                         anonsize = $
  344.                                 end virtual
  345.                                 if anonsize > $ - parent#.#name
  346.                                         rb anonsize - ($-$$)
  347.                                 end if
  348.                                 \\}  \}
  349.                 if ~ field eq .
  350.                         virtual at parent#.#name
  351.                                 parent#field type def
  352.                                 sizeof.#parent#field = $ - parent#field
  353.                         end virtual
  354.                         if sizeof.#parent#field > $ - parent#.#name
  355.                                 rb sizeof.#parent#field - ($ - parent#.#name)
  356.                         end if
  357.                 else
  358.                         virtual at parent#.#name
  359.                                 label parent#.#type
  360.                                 type def
  361.                         end virtual
  362.                         label name#.#type at parent#.#name
  363.                         if sizeof.#type > $ - parent#.#name
  364.                                 rb sizeof.#type - ($ - parent#.#name)
  365.                         end if
  366.                 end if
  367.  common
  368.                 sizeof.#name = $ - parent#.#name
  369.         end virtual
  370.         struc name value \{
  371.                 label .\#name
  372.                 last@union equ
  373.  forward
  374.                 match any, last@union \\{
  375.                         virtual at .\#name
  376.                                 field type def
  377.                         end virtual \\}
  378.                 match , last@union \\{
  379.                         match , value \\\{ field type def \\\}
  380.                         match any, value \\\{ field type value \\\} \\}
  381.                 last@union equ field
  382.  common
  383.                 rb sizeof.#name - ($ - .\#name) \}
  384.         macro name value \{
  385.                 label .\#name
  386.                 last@union equ
  387.  forward
  388.                 match , last@union \\{ match any, value \\\{ field type value \\\} \\}
  389.                 last@union equ field
  390.  common
  391.                 rb sizeof.#name - ($ - .\#name) \} }
  392. ;==============================================================
  393. macro define@subrstruct parent,name,[anon,field,type,def] {
  394.  common
  395.         local ..start,..size
  396.         virtual at parent#.#name-..size
  397.                 ..start:
  398.  forward
  399.                 local value,anonsize
  400. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  401.                 anonsize = $
  402.                 match any, anon \{ irp anondef,any \\{ anondef \\} \}
  403.                 anonsize = $-anonsize
  404. ;    END OF ASSUMPTION
  405.                 if ~ field eq .
  406.                         parent#field type def
  407.                         sizeof.#parent#field = $ - parent#field
  408.                 else
  409.                         label parent#.#type
  410.                         rb sizeof.#type
  411.                 end if
  412.  common
  413.                 ..size = $ - ..start
  414.                 sizeof.#name = ..size
  415.         end virtual
  416.         struc name value \{
  417.                 label .\#name
  418.  forward
  419. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  420.                 rb anonsize
  421. ;    END of ASSUMPTION
  422.                 match , value \\{ field type def \\}
  423.                 match any, value \\{
  424.                         field type value
  425.                         if ~ field eq .                             ; MAIN PURPOSE OF THEESE 3 LINES - REALISATION OF LEGACY ALIGNMENT STYLE IN STRUCTURES
  426.                                 rb sizeof.#parent#field - ($-field) ; BECAUSE ALIGNED FIELD PRECIDED WITH ANOTHER SHORTER SIZE FIELD - WE CAN EMULATE ALIGNMENT BY ADDING SEQUENCE OF ",?" TO END OF THAT SHORTER SIZE FIELD
  427.                         end if \\}                                  ; 2ND PURPOSE - COMPARISON THAT DATA PASSED TO INITIALIZE STRUCTURE WILL FIT IN ITS MEMBERS; IN COMMON CASE MORE OPTIMAL SUCH COMPARISON FOR WHOLE STRUCTURE NOT PER FIELD
  428.  common
  429.                                 ;if $-.\#name-sizeof.#name          ; IF WE REMOVE 3 LINES ABOVE COMMENTED AS LEGACY
  430.                                 ;        err                        ; THEN WE MUST UNCOMMENT THESE 3 LINES
  431.                                 ;end if                             ;
  432.         \}
  433.         macro name value \{
  434.                 \local ..anonymous
  435.                 ..anonymous name \} }
  436. ;==============================================================
  437. macro define@substruct parent,name,[anon,field,type,def] {
  438.  common
  439.         virtual at parent#.#name
  440.  forward
  441.                 local value,anonsize
  442. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  443.                 anonsize = $
  444.                 match any, anon \{ irp anondef,any \\{ anondef \\} \}
  445.                 anonsize = $-anonsize
  446. ;    END OF ASSUMPTION
  447.                 if ~ field eq .
  448.                         parent#field type def
  449.                         sizeof.#parent#field = $ - parent#field
  450.                 else
  451.                         label parent#.#type
  452.                         rb sizeof.#type
  453.                 end if
  454.  common
  455.                 sizeof.#name = $ - parent#.#name
  456.         end virtual
  457.         struc name value \{
  458.                 label .\#name
  459.  forward
  460. ;!!! WE MAKING ASSUMPTION THAT UNNAMED FIELDS ARE JUST RESERVE SPACE
  461.                 rb anonsize
  462. ;    END of ASSUMPTION
  463.                 match , value \\{ field type def \\}
  464.                 match any, value \\{
  465.                         field type value
  466.                         if ~ field eq .                             ; MAIN PURPOSE OF THEESE 3 LINES - REALISATION OF LEGACY ALIGNMENT STYLE IN STRUCTURES
  467.                                 rb sizeof.#parent#field - ($-field) ; BECAUSE ALIGNED FIELD PRECIDED WITH ANOTHER SHORTER SIZE FIELD - WE CAN EMULATE ALIGNMENT BY ADDING SEQUENCE OF ",?" TO END OF THAT SHORTER SIZE FIELD
  468.                         end if \\}                                  ; 2ND PURPOSE - COMPARISON THAT DATA PASSED TO INITIALIZE STRUCTURE WILL FIT IN ITS MEMBERS; IN COMMON CASE MORE OPTIMAL SUCH COMPARISON FOR WHOLE STRUCTURE NOT PER FIELD
  469.  common
  470.                                 ;if $-.\#name-sizeof.#name          ; IF WE REMOVE 3 LINES ABOVE COMMENTED AS LEGACY
  471.                                 ;        err                        ; THEN WE MUST UNCOMMENT THESE 3 LINES
  472.                                 ;end if                             ;
  473.         \}
  474.         macro name value \{
  475.                 \local ..anonymous
  476.                 ..anonymous name \} }