Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-16 14:56:32 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-19 15:21:14 -0500
commit0c020b736d8d46f18e2e671d7b928e146db5572e (patch)
tree22afa40d5ae4299993f1ca204b0bdd5d36836a9d
parent7f26db41b211694530acb5c3cd881c14e508b7df (diff)
downloadtame-0c020b736d8d46f18e2e671d7b928e146db5572e.tar.gz
tame-0c020b736d8d46f18e2e671d7b928e146db5572e.tar.bz2
tame-0c020b736d8d46f18e2e671d7b928e146db5572e.zip
Produce consts as part of rater object
-rw-r--r--src/current/compiler/fragments.xsl6
-rw-r--r--src/current/compiler/js.xsl36
2 files changed, 28 insertions, 14 deletions
diff --git a/src/current/compiler/fragments.xsl b/src/current/compiler/fragments.xsl
index 23dcae9..8fee167 100644
--- a/src/current/compiler/fragments.xsl
+++ b/src/current/compiler/fragments.xsl
@@ -128,7 +128,11 @@
<xsl:variable name="pkg" as="element( lv:package )"
select="root(.)" />
- <xsl:apply-templates select="$pkg/lv:const[ @name=$name ]" mode="compile" />
+ <xsl:apply-templates mode="compile"
+ select="$pkg/lv:const[ @name=$name ],
+ $pkg/lv:typedef//lv:item[ @name=$name ]">
+ <xsl:with-param name="as-const" select="true()" />
+ </xsl:apply-templates>
</xsl:template>
<xsl:template match="preproc:sym[ @type='tpl' ]" mode="preproc:compile-fragments" priority="5">
diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl
index 6674140..95541cd 100644
--- a/src/current/compiler/js.xsl
+++ b/src/current/compiler/js.xsl
@@ -65,18 +65,11 @@
<!-- to store debug information for equations (we have to put this out here
so that functions also have access to it...yes, it's stateful, yes it's
bullshit, but oh well) -->
- <text>var debug = {};</text>
<text>var consts = {};</text>
+ <text>var debug = {};</text>
<text>var params = {};</text>
<text>var types = {};</text>
<text>var meta = {};</text>
- <!--
- <value-of select="$compiler:nl" />
- <apply-templates
- select="root(.)//lv:const[ .//lv:item or preproc:iou ]"
- mode="compile" />
- -->
-
</template>
@@ -162,7 +155,6 @@
<text>premium: ( Math.round( args.___yield * 100 ) / 100 ), </text>
<text>classes: classes, </text>
<text>vars: args, </text>
- <text>consts: consts, </text>
<text>reqParams: req_params, </text>
<text>debug: debug </text>
<text>}; </text>
@@ -174,6 +166,7 @@
<text>'; </text>
<text>rater.meta = meta;</text>
+ <text>rater.consts = consts;</text>
<!-- provide classification -> yields mapping -->
<value-of select="$compiler:nl" />
@@ -383,6 +376,9 @@
@return property representing a specific value
-->
<template match="lv:enum/lv:item" mode="compile">
+ <param name="as-const" as="xs:boolean"
+ select="false()" />
+
<!-- determine enumerated value -->
<variable name="value">
<choose>
@@ -398,9 +394,10 @@
</variable>
<!-- we are only interest in its value; its constant is an internal value -->
- <text>'</text>
- <value-of select="$value" />
- <text>': true</text>
+ <sequence select="if ( $as-const ) then
+ concat( 'consts[''', @name, '''] = ', $value, ';' )
+ else
+ concat( '''', $value, ''': true' )" />
</template>
@@ -412,7 +409,7 @@
@return JS object assignment for constant set values
-->
-<template mode="compile" priority="1"
+<template mode="compile" priority="2"
match="lv:const[ element() or @values ]">
<text>consts['</text>
<value-of select="@name" />
@@ -449,6 +446,19 @@
<!--
+ Falls back to scalar constants
+-->
+<template mode="compile" priority="1"
+ match="lv:const">
+ <text>consts['</text>
+ <value-of select="@name" />
+ <text>'] = </text>
+ <value-of select="@value" />
+ <text>;</text>
+</template>
+
+
+<!--
Produce sequence of sets
Sets are used to group together items in a matrix. A set can be