2022-05-02 11:59:43 -04:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2016-08-24 09:43:05 -04:00
|
|
|
<!--
|
2016-08-24 10:19:11 -04:00
|
|
|
Compile standalone JavaScript program suitable for execution
|
|
|
|
|
2023-01-17 23:09:25 -05:00
|
|
|
Copyright (C) 2014-2023 Ryan Specialty, LLC.
|
2016-08-24 10:19:11 -04:00
|
|
|
|
|
|
|
This file is part of TAME.
|
|
|
|
|
|
|
|
TAME is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>.
|
2016-08-24 09:43:05 -04:00
|
|
|
-->
|
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
<stylesheet version="2.0"
|
|
|
|
xmlns="http://www.w3.org/1999/XSL/Transform"
|
|
|
|
xmlns:lv="http://www.lovullo.com/rater"
|
|
|
|
xmlns:lvp="http://www.lovullo.com"
|
|
|
|
xmlns:lvm="http://www.lovullo.com/rater/map"
|
|
|
|
xmlns:lvmc="http://www.lovullo.com/rater/map/compiler"
|
|
|
|
xmlns:c="http://www.lovullo.com/calc"
|
|
|
|
xmlns:l="http://www.lovullo.com/rater/linker"
|
|
|
|
xmlns:compiler="http://www.lovullo.com/rater/compiler"
|
|
|
|
xmlns:calc-compiler="http://www.lovullo.com/calc/compiler"
|
|
|
|
xmlns:util="http://www.lovullo.com/util"
|
|
|
|
xmlns:ext="http://www.lovullo.com/ext"
|
|
|
|
xmlns:preproc="http://www.lovullo.com/rater/preproc">
|
|
|
|
|
|
|
|
|
2020-01-13 16:41:06 -05:00
|
|
|
<output method="text" />
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
<include href="include/dslc-base.xsl" />
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- compiler -> JS -->
|
2019-02-07 14:36:17 -05:00
|
|
|
<include href="compiler/map.xsl" />
|
2020-02-24 15:08:56 -05:00
|
|
|
<include href="compiler/js.xsl" />
|
2019-02-07 14:36:17 -05:00
|
|
|
<include href="include/depgen.xsl" />
|
2020-02-24 15:08:56 -05:00
|
|
|
<include href="include/preproc/symtable.xsl" />
|
|
|
|
<include href="include/util.xsl" />
|
|
|
|
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- path to program XML -->
|
2019-02-07 14:36:17 -05:00
|
|
|
<param name="path-program-ui" />
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
<template match="/" priority="5">
|
2016-08-24 09:43:05 -04:00
|
|
|
<!-- the rater itself -->
|
2019-02-07 14:36:17 -05:00
|
|
|
<text>var rater = </text>
|
2020-01-13 16:41:06 -05:00
|
|
|
<!-- (moved from linker during TAMER POC linker) -->
|
|
|
|
<call-template name="compiler:entry" />
|
|
|
|
<call-template name="compiler:classifier" />
|
2020-01-15 16:32:46 -05:00
|
|
|
<value-of disable-output-escaping="yes" select="/lv:package/l:static/text()" />
|
2020-01-13 16:41:06 -05:00
|
|
|
<call-template name="compiler:entry-rater" />
|
2019-02-07 14:36:17 -05:00
|
|
|
<value-of disable-output-escaping="yes" select="/lv:package/l:exec/text()" />
|
|
|
|
<text>; </text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2020-01-13 16:41:06 -05:00
|
|
|
<!--(moved from linker during TAMER POC linker) -->
|
|
|
|
<call-template name="compiler:exit-rater">
|
|
|
|
<with-param name="name" select="/*/@name" />
|
|
|
|
<with-param name="symbols" select="/*/l:dep/preproc:sym" />
|
|
|
|
<with-param name="mapfrom" select="/*/l:map-from/l:from" />
|
|
|
|
</call-template>
|
|
|
|
<call-template name="compiler:static" />
|
|
|
|
|
2016-08-24 09:43:05 -04:00
|
|
|
<!-- maps may or may not exist -->
|
2019-02-07 14:36:17 -05:00
|
|
|
<variable name="map" select="/lv:package/l:map-exec" />
|
|
|
|
<variable name="retmap" select="/lv:package/l:retmap-exec" />
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- store a reference to the mapper in rater.fromMap() -->
|
2023-04-28 16:40:26 -04:00
|
|
|
<text>rater.fromMap=function(input,callback){</text>
|
|
|
|
<text>var output={};</text>
|
|
|
|
<value-of disable-output-escaping="yes" select="$map/text()" />
|
|
|
|
<text>callback(output);}; </text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- return map -->
|
2023-04-28 16:40:26 -04:00
|
|
|
<text>rater._retmap=function(input,callback){</text>
|
|
|
|
<text>var output={};</text>
|
|
|
|
<value-of disable-output-escaping="yes" select="$retmap/text()" />
|
|
|
|
<text>callback(output);}; </text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- we'll export a version that automatically performs the mapping -->
|
2020-01-28 13:57:42 -05:00
|
|
|
<text>module.exports = function( args_base, _canterm ) { </text>
|
2019-02-07 14:36:17 -05:00
|
|
|
<text>var ret; rater.fromMap( args_base, function( args ) {</text>
|
|
|
|
<text>
|
2020-01-28 13:57:42 -05:00
|
|
|
var rater_result = rater( args, _canterm );
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
// perf counter
|
|
|
|
var start = ( new Date() ).getTime();
|
|
|
|
|
|
|
|
rater._retmap( rater_result.vars, function( result )
|
|
|
|
{
|
|
|
|
// add the final premium
|
|
|
|
result.premium = rater_result.premium;
|
|
|
|
result.__classes = rater_result.classes;
|
|
|
|
|
|
|
|
// process the rating worksheet
|
|
|
|
try
|
|
|
|
{
|
|
|
|
result.__worksheet = process_worksheet(
|
|
|
|
rater.worksheet,
|
|
|
|
rater_result.vars,
|
2018-02-26 10:39:03 -05:00
|
|
|
rater.consts,
|
2016-08-24 09:43:05 -04:00
|
|
|
rater_result.debug,
|
|
|
|
rater_result.premium
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch ( e )
|
|
|
|
{
|
|
|
|
result.__worksheet = [ 'Failed: ' + e.message ];
|
|
|
|
}
|
|
|
|
ret = result;
|
|
|
|
} );
|
|
|
|
|
|
|
|
// add performance data
|
|
|
|
var end = ( new Date() ).getTime(),
|
|
|
|
time = ( ( new Date() ).getTime() - start );
|
|
|
|
|
|
|
|
ret.__perf = {
|
|
|
|
time: {
|
|
|
|
start: start,
|
|
|
|
end: end,
|
|
|
|
total: time
|
|
|
|
}
|
|
|
|
};
|
2019-02-07 14:36:17 -05:00
|
|
|
</text>
|
|
|
|
<text>} );</text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
<text>return ret;</text>
|
|
|
|
<text>}; </text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
<text>
|
2016-08-24 09:43:05 -04:00
|
|
|
function process_worksheet( worksheet, vars, consts, debug, premium )
|
|
|
|
{
|
|
|
|
var ret = {};
|
|
|
|
|
|
|
|
for ( var name in worksheet )
|
|
|
|
{
|
|
|
|
var data = Array.prototype.slice.call( worksheet[ name ] ),
|
|
|
|
disp = data[0],
|
|
|
|
calc = data[1],
|
|
|
|
always = data[2];
|
|
|
|
|
|
|
|
ret[ name ] = [
|
|
|
|
disp,
|
|
|
|
process_wdisplay_set( [calc], vars, consts, debug ),
|
|
|
|
|
|
|
|
( ( name === 'yield' )
|
|
|
|
? premium
|
|
|
|
: ( vars[ name ] || consts[ name ] )
|
|
|
|
),
|
|
|
|
|
|
|
|
( always === 'true' )
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_wdisplay( data, vars, consts, debug )
|
|
|
|
{
|
|
|
|
if ( data === null )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var name = data[ 0 ],
|
|
|
|
desc = data[ 1 ],
|
|
|
|
sub = data[ 2 ],
|
|
|
|
val = data[ 3 ]; // may not exist
|
|
|
|
|
|
|
|
return [
|
|
|
|
name,
|
|
|
|
desc,
|
|
|
|
process_wdisplay_set( sub, vars, consts, debug ),
|
|
|
|
val || process_wval( name, desc, vars, consts, debug )
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function process_wval( type, desc, vars, consts, debug )
|
|
|
|
{
|
|
|
|
if ( desc.runtime )
|
|
|
|
{
|
|
|
|
type = 'runtime';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case 'apply':
|
|
|
|
case 'cases':
|
|
|
|
case 'case':
|
|
|
|
case 'otherwise':
|
|
|
|
case 'runtime':
|
|
|
|
return ( debug[ desc._id ] );
|
|
|
|
|
|
|
|
case 'value-of':
|
|
|
|
return ( vars[ desc.name ] || consts[ desc.name ] );
|
|
|
|
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function process_wdisplay_set( sub, vars, consts, debug )
|
|
|
|
{
|
|
|
|
var ret = [],
|
|
|
|
i = sub.length;
|
|
|
|
|
|
|
|
while ( i-- )
|
|
|
|
{
|
|
|
|
if ( sub[ i ] === undefined )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret[ i ] = process_wdisplay( sub[ i ], vars, consts, debug );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-02-07 14:36:17 -05:00
|
|
|
</text>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
|
|
|
<!-- expose the raw, unmapped rater -->
|
2019-02-07 14:36:17 -05:00
|
|
|
<text>module.exports.rater = rater;</text>
|
|
|
|
</template>
|
2016-08-24 09:43:05 -04:00
|
|
|
|
2019-02-07 14:36:17 -05:00
|
|
|
</stylesheet>
|