Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2016-11-17 08:56:40 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2016-11-17 23:55:23 -0500
commit1d3aaf3339f30e43ee764e8dd898b382dc9e3e76 (patch)
treea9e878d95820fbbf1999dcf5d1c8a7eb73bbb7e4
parentf396858fb18b915a0f03e6d02c4aebb55b0000bc (diff)
downloadtame-1d3aaf3339f30e43ee764e8dd898b382dc9e3e76.tar.gz
tame-1d3aaf3339f30e43ee764e8dd898b382dc9e3e76.tar.bz2
tame-1d3aaf3339f30e43ee764e8dd898b382dc9e3e76.zip
Extracted param symbol generation
The `preproc:param-dim' template must remain for now, as it is used by others. * src/current/include/preproc/symtable.xsl (preproc:symtable)[lv:param]: Extracted template. * src/symtable/symbols.xsl (preproc:symtable)[lv:param]: Added template. * test/symtable/symbols.xsl (lv:param): Scenario added.
-rw-r--r--src/current/include/preproc/symtable.xsl18
-rw-r--r--src/symtable/symbols.xsl93
-rw-r--r--test/symtable/symbols.xspec71
3 files changed, 162 insertions, 20 deletions
diff --git a/src/current/include/preproc/symtable.xsl b/src/current/include/preproc/symtable.xsl
index e12e5a4..069c22b 100644
--- a/src/current/include/preproc/symtable.xsl
+++ b/src/current/include/preproc/symtable.xsl
@@ -71,6 +71,7 @@
<xsl:include href="path.xsl" />
<xsl:include href="../../tame/src/symtable.xsl" />
+<xsl:include href="../../tame/src/symtable/symbols.xsl" />
<!-- we will recurse through the entire tree rather than performing a series of
@@ -757,23 +758,6 @@
</xsl:template>
-<!-- Will be completed during post-processing so that typedefs can be
- properly resolved -->
-<xsl:template match="lv:param" mode="preproc:symtable" priority="5">
- <xsl:variable name="dim">
- <xsl:call-template name="preproc:param-dim" />
- </xsl:variable>
-
- <!-- we use the primitive data type derived from the typedef to ensure that
- the system can still make use of the type even when the typedef is not
- exported; indeed, typedefs are simply restrictions that need only be
- known for compiling (at least at present). Also note the keep="true" to
- ensure that all param symbols are retained after linking -->
- <preproc:sym name="{@name}" keep="true"
- type="param" dtype="{@type}" dim="{$dim}" desc="{@desc}" tex="{@sym}" />
-</xsl:template>
-
-
<xsl:template match="lv:typedef" mode="preproc:symtable" priority="5">
<!-- FIXME: this is a kluge -->
<xsl:variable name="dtype" as="xs:string?"
diff --git a/src/symtable/symbols.xsl b/src/symtable/symbols.xsl
index 14949c7..3738cea 100644
--- a/src/symtable/symbols.xsl
+++ b/src/symtable/symbols.xsl
@@ -32,6 +32,7 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lv="http://www.lovullo.com/rater"
xmlns:symtable="http://www.lovullo.com/tame/symtable"
+ xmlns:_symtable="http://www.lovullo.com/tame/symtable/_priv"
xmlns:preproc="http://www.lovullo.com/rater/preproc">
<import href="symbols.xsl.apply" />
@@ -72,9 +73,7 @@
@item dim
Dimensions of@tie{}@obj{} as an integer.
- Standard dimensions are scalar@tie{}(0),
- vector@tie{}(1),
- and matrix@tie{}(2).
+ See @ref{_symtable:str-to-dim#1} for supported strings.
@emph{Required}
@item dtype
@@ -129,6 +128,42 @@
<!--
+ Convert a string dimension representation into an integer.
+
+ Standard dimensions are @samp{scalar}@tie{}(0),
+ @samp{vector}@tie{}(1),
+ and @samp{matrix}@tie{}(2).
+ If no value is provided,
+ then @samp{scalar} is assumed.
+ All unknown strings will yield a value of @samp{-1}.@footnote{
+ That's not to say that @tame{} can't support an arbitrary number
+ of dimensions;
+ this syntax just doesn't provide that utility.}
+-->
+<function name="_symtable:str-to-dim" as="xs:integer">
+ <param name="str" as="xs:string?" />
+
+ <choose>
+ <when test="empty( $str ) or ( $str = 'scalar' )">
+ <sequence select="0" />
+ </when>
+
+ <when test="$str = 'vector'">
+ <sequence select="1" />
+ </when>
+
+ <when test="$str = 'matrix'">
+ <sequence select="2" />
+ </when>
+
+ <otherwise>
+ <sequence select="-1" />
+ </otherwise>
+ </choose>
+</function>
+
+
+<!--
@node Symbol Types
@section Symbol Types
@@ -249,6 +284,7 @@
@menu
+ * Parameters: Parameter Symbols. @code{param}
* Templates: Template Symbols. @code{tpl}
* Program Metadata: Program Metadata Symbols. @code{meta}
@end menu
@@ -256,6 +292,57 @@
<!--
+ @node Parameter Symbols
+ @subsection Parameter Symbols
+
+ Global parameters define all inputs to the program.
+-->
+
+
+<!--
+ Produce a @code{param} symbol with the following attributes:
+
+ @table @code
+ @item name
+ Name of the parameter as provided by @pkgns{param/@@name}.
+
+ @item type
+ The datatype defining the parameter's domain,
+ as provided by @pkgns{param/@@type}.
+
+ @item dim
+ Numeric dimension converted from its string representation in
+ @pkgns{param/@@set}.@footnote{
+ The attribute name @pkgns{param/@@set} is unfortunate and simply
+ incorrect terminology with how it is used.
+ It will be changed in the future.}
+
+ @item desc
+ Description as provided by @pkgns{param/@@desc}.
+
+ @item tex
+ TeX symbol used when rendering parameter in an equation.
+
+ @item keep
+ Always @samp{true} to ensure that the symbol is retained after
+ linking.
+ @end table
+-->
+<template match="lv:param" mode="preproc:symtable" priority="5">
+ <variable name="dim" as="xs:integer"
+ select="_symtable:str-to-dim( @set )" />
+
+ <preproc:sym type="param"
+ name="{@name}"
+ dim="{$dim}"
+ desc="{@desc}"
+ dtype="{@type}"
+ tex="{@sym}"
+ keep="true" />
+</template>
+
+
+<!--
@node Template Symbols
@subsection Template Symbols
diff --git a/test/symtable/symbols.xspec b/test/symtable/symbols.xspec
index d4dbdd8..d7135f7 100644
--- a/test/symtable/symbols.xspec
+++ b/test/symtable/symbols.xspec
@@ -29,6 +29,77 @@
stylesheet="../../src/symtable/symbols.xsl">
+ <scenario label="lv:param">
+ <context mode="preproc:symtable">
+ <lv:param name="foo_bar"
+ type="footype"
+ desc="Vector param"
+ set="vector" />
+
+ <lv:param name="tex_param"
+ type="tex"
+ desc="Matrix param with TeX"
+ set="matrix"
+ sym="\tex" />
+
+ <lv:param name="scalar_param"
+ type="bar"
+ desc="Scalar param (implicit)" />
+
+ <lv:param name="scalar_param_explicit"
+ type="bar"
+ set="scalar"
+ desc="Scalar param (explicit)" />
+
+ <lv:param name="unknown_dim"
+ type="wtf"
+ set="calabi-yau"
+ desc="Unknown dimension" />
+ </context>
+
+ <expect label="derives symbol data from param">
+ <preproc:sym type="param"
+ name="foo_bar"
+ dim="1"
+ desc="Vector param"
+ dtype="footype"
+ tex=""
+ keep="true" />
+
+ <preproc:sym type="param"
+ name="tex_param"
+ dim="2"
+ desc="Matrix param with TeX"
+ dtype="tex"
+ tex="\tex"
+ keep="true" />
+
+ <preproc:sym type="param"
+ name="scalar_param"
+ dim="0"
+ desc="Scalar param (implicit)"
+ dtype="bar"
+ tex=""
+ keep="true" />
+
+ <preproc:sym type="param"
+ name="scalar_param_explicit"
+ dim="0"
+ desc="Scalar param (explicit)"
+ dtype="bar"
+ tex=""
+ keep="true" />
+
+ <preproc:sym type="param"
+ name="unknown_dim"
+ dim="-1"
+ desc="Unknown dimension"
+ dtype="wtf"
+ tex=""
+ keep="true" />
+ </expect>
+ </scenario>
+
<scenario label="lv:template">
<context mode="preproc:symtable">
<lv:template name="_foo_"