Skip to content

Commit

Permalink
Linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Jul 1, 2018
1 parent 8e19a41 commit 67e1169
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
11 changes: 11 additions & 0 deletions SYNTAX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,17 @@ These are defined in df-code.lisp:

but allows the GUI to display it as a list.

``<df-linked-list-type type-name='foo_link' item-type='foo'/>``

Defines a DF-style linked list node. This translates to::

<struct-type type-name='foo_link'>
<pointer name='item' type-name='foo'/>
<pointer name='prev' type-name='foo_link'/>
<pointer name='next' type-name='foo_link'/>
</struct-type>

with some extra code to make it easier to interact with.

Class type definition
=====================
Expand Down
3 changes: 3 additions & 0 deletions StructType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ sub render_struct_type {

my $tag_name = $tag->getAttribute('ld:meta');
my $is_class = ($tag_name eq 'class-type');
my $is_linked_list = (($tag->getAttribute('ld:subtype') or '') eq 'df-linked-list-type');
my $custom_methods = is_attr_true($tag, 'custom-methods') || $tag->findnodes('custom-methods/cmethod');
my $has_methods = $is_class || is_attr_true($tag, 'has-methods');
my $inherits = $tag->getAttribute('inherits-from');
Expand All @@ -206,6 +207,8 @@ sub render_struct_type {
$ispec = ' : '.$inherits;
} elsif ($is_class) {
$ispec = ' : virtual_class';
} elsif ($is_linked_list) {
$ispec = ' : DfLinkedList<'.$typename.', '.$tag->getAttribute('item-type').'>';
}

with_struct_block {
Expand Down
7 changes: 1 addition & 6 deletions df.jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@
<flag-bit name='milk'/>
</bitfield-type>

<struct-type type-name='job_list_link'>
<code-helper name='describe'>(describe-obj $.item)</code-helper>
<pointer name='item' type-name='job'/>
<pointer name='prev' type-name='job_list_link'/>
<pointer name='next' type-name='job_list_link'/>
</struct-type>
<df-linked-list-type type-name='job_list_link' item-type='job'/>

<bitfield-type type-name='job_flags' base-type='uint32_t'>
<flag-bit name='repeat'/>
Expand Down
12 changes: 2 additions & 10 deletions df.map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@
</custom-methods>
</struct-type>

<struct-type type-name='block_burrow_link'>
<pointer name='item' type-name='block_burrow'/>
<pointer name='prev' type-name='block_burrow_link'/>
<pointer name='next' type-name='block_burrow_link'/>
</struct-type>
<df-linked-list-type type-name='block_burrow_link' item-type='block_burrow'/>

<struct-type type-name='map_block'>
<bitfield name='flags' type-name='block_flags'/>
Expand Down Expand Up @@ -328,11 +324,7 @@
</static-array>
</struct-type>

<struct-type type-name='cave_column_link'>
<pointer name='item' type-name='cave_column'/>
<pointer name='prev' type-name='cave_column_link'/>
<pointer name='next' type-name='cave_column_link'/>
</struct-type>
<df-linked-list-type type-name='cave_column_link' item-type='cave_column'/>

<class-type type-name='cave_column' original-name='cave_columnst'>
<int16_t/>
Expand Down
6 changes: 1 addition & 5 deletions df.projectile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
<enum-item name='Magic'/>
</enum-type>

<struct-type type-name='proj_list_link'>
<pointer name='item' type-name='projectile'/>
<pointer name='prev' type-name='proj_list_link'/>
<pointer name='next' type-name='proj_list_link'/>
</struct-type>
<df-linked-list-type type-name='proj_list_link' item-type='projectile'/>

<bitfield-type type-name='projectile_flags'>
<flag-bit name='no_impact_destroy'/>
Expand Down
15 changes: 15 additions & 0 deletions lower-1.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@
</ld:global-type>
</xsl:template>

<xsl:template match='df-linked-list-type'>
<ld:global-type ld:meta='struct-type' ld:subtype='df-linked-list-type' ld:level='0' type-name='{@type-name}' item-type='{@item-type}'>
<code-helper name="describe"><xsl:text>(describe-obj $.item)</xsl:text></code-helper>
<ld:field name='item' type-name='{@item-type}' ld:level='1' ld:meta='pointer' ld:is-container='true'>
<ld:item ld:level='2' ld:meta='global' type-name='{@item-type}'/>
</ld:field>
<ld:field name='prev' type-name='{@type-name}' ld:level='1' ld:meta='pointer' ld:is-container='true'>
<ld:item ld:level='2' ld:meta='global' type-name='{@type-name}'/>
</ld:field>
<ld:field name='next' type-name='{@type-name}' ld:level='1' ld:meta='pointer' ld:is-container='true'>
<ld:item ld:level='2' ld:meta='global' type-name='{@type-name}'/>
</ld:field>
</ld:global-type>
</xsl:template>

<!-- Code to properly annotate references to types by name -->

<xsl:key name="primitive-type-lookup" match="prim-type" use="@ld:subtype"/>
Expand Down

0 comments on commit 67e1169

Please sign in to comment.