Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/current/calc.xsd10
-rw-r--r--src/current/compiler/js-calc.xsl24
-rw-r--r--src/current/include/preproc/expand.xsl40
-rw-r--r--src/current/include/preproc/macros.xsl2
-rw-r--r--src/current/include/preproc/symtable.xsl5
5 files changed, 75 insertions, 6 deletions
diff --git a/src/current/calc.xsd b/src/current/calc.xsd
index 9ff9f67..c5b9572 100644
--- a/src/current/calc.xsd
+++ b/src/current/calc.xsd
@@ -235,6 +235,16 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
+
+ <xs:attribute name="dim" type="xs:string">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+ Specify the dimension of each index of the generator result.
+ Disables casting and truncating with @precision if greater
+ than 0 or 'scaler'. This expands into c:sum/@dim.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
diff --git a/src/current/compiler/js-calc.xsl b/src/current/compiler/js-calc.xsl
index f760fbc..219c8a4 100644
--- a/src/current/compiler/js-calc.xsl
+++ b/src/current/compiler/js-calc.xsl
@@ -36,6 +36,7 @@
-->
<stylesheet version="2.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.lovullo.com/calc"
xmlns:lv="http://www.lovullo.com/rater"
xmlns:preproc="http://www.lovullo.com/rater/preproc"
@@ -187,6 +188,9 @@
</choose>
</variable>
+ <variable name="dim" as="xs:integer"
+ select="if ( @dim ) then @dim else 0" />
+
<!-- introduce scope both to encapsulate values and so we can insert this as
part of a larger expression (will return a value) -->
<text>( function() {</text>
@@ -245,7 +249,12 @@
<value-of select="$value" />
<text> ) {</text>
- <text>var result = +(+( </text>
+ <text>var result = </text>
+ <!-- if caller wants to yield a vector, don't cast -->
+ <sequence select="if ( not( $dim gt 0 ) ) then
+ '+(+( '
+ else
+ '(( '" />
<choose>
<!-- if there are child nodes, use that as the summand/expression -->
<when test="./c:*">
@@ -260,9 +269,16 @@
<text>]</text>
</otherwise>
</choose>
- <text> )).toFixed(</text>
- <value-of select="$precision" />
- <text>);</text>
+ <text> ))</text>
+
+ <!-- if caller wants to yield a vector, don't truncate -->
+ <if test="not( $dim gt 0 )">
+ <text>.toFixed(</text>
+ <value-of select="$precision" />
+ <text>)</text>
+ </if>
+
+ <text>;</text>
<!-- if generating a set, store this result -->
<if test="@generates">
diff --git a/src/current/include/preproc/expand.xsl b/src/current/include/preproc/expand.xsl
index f023df1..c43fcc2 100644
--- a/src/current/include/preproc/expand.xsl
+++ b/src/current/include/preproc/expand.xsl
@@ -123,6 +123,46 @@
<!--
+ Translate dimension aliases (e.g. scaler, vector, matrix) into respective
+ numeric representations.
+-->
+<xsl:template mode="preproc:expand" priority="8"
+ match="c:*[ @dim
+ and not( string( @dim ) castable as xs:integer ) ]">
+ <xsl:copy>
+ <xsl:sequence select="@*" />
+
+ <!-- replace dim with numeric -->
+ <xsl:attribute name="dim">
+ <xsl:choose>
+ <xsl:when test="@dim = 'scaler' or @dim = ''">
+ <xsl:sequence select="0" />
+ </xsl:when>
+
+ <xsl:when test="@dim = 'vector'">
+ <xsl:sequence select="1" />
+ </xsl:when>
+
+ <xsl:when test="@dim = 'matrix'">
+ <xsl:sequence select="2" />
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:message terminate="yes"
+ select="concat(
+ '!!! [preproc] error: ',
+ 'unknown dimension alias ''',
+ @dim, '''' )" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+
+ <xsl:sequence select="node()" />
+ </xsl:copy>
+</xsl:template>
+
+
+<!--
Give let's a name so that they may be easily referenced uniquely
-->
<xsl:template match="c:let[ not( @name ) ]" mode="preproc:expand" priority="5">
diff --git a/src/current/include/preproc/macros.xsl b/src/current/include/preproc/macros.xsl
index e58f247..234632f 100644
--- a/src/current/include/preproc/macros.xsl
+++ b/src/current/include/preproc/macros.xsl
@@ -402,7 +402,7 @@
<xsl:sequence select="./lv:class" />
- <c:sum of="_CMATCH_" index="{@index}" sym="{@gensym}">
+ <c:sum of="_CMATCH_" index="{@index}" sym="{@gensym}" dim="{@dim}">
<!-- copy @generates, if it exists (has the benefit of copying nothing
if it does not exist) -->
<xsl:sequence select="@generates" />
diff --git a/src/current/include/preproc/symtable.xsl b/src/current/include/preproc/symtable.xsl
index 432c3ab..7635c9a 100644
--- a/src/current/include/preproc/symtable.xsl
+++ b/src/current/include/preproc/symtable.xsl
@@ -688,9 +688,12 @@
<xsl:template match="c:*[ @generates ]" mode="preproc:symtable" priority="5">
<xsl:variable name="parent" select="ancestor::lv:rate" />
+ <xsl:variable name="dim" as="xs:integer"
+ select="if ( @dim ) then @dim else 1" />
+
<preproc:sym name="{@generates}"
parent="{$parent/@yields}"
- type="gen" dtype="float" dim="1" desc="{@desc}" tex="{@sym}" />
+ type="gen" dtype="float" dim="{$dim}" desc="{@desc}" tex="{@sym}" />
<xsl:apply-templates mode="preproc:symtable" />
</xsl:template>