Produce consts as part of rater object

master
Mike Gerwitz 2018-02-16 14:56:32 -05:00
parent 7f26db41b2
commit 0c020b736d
2 changed files with 28 additions and 14 deletions

View File

@ -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">

View File

@ -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" />
@ -448,6 +445,19 @@
</template>
<!--
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