Skip to content

Commit

Permalink
Merge pull request #480 from StoneCypher/DocFromSm
Browse files Browse the repository at this point in the history
Document .from and sm, fixes StoneCypher/fsl#784, fixes StoneCypher/fsl#785
  • Loading branch information
StoneCypher committed May 22, 2022
2 parents eac57da + 22230f0 commit fdb3369
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 101 deletions.
14 changes: 7 additions & 7 deletions benchmark/results/general.chart.html
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1653229181730" width="16" height="9"></canvas>
<canvas id="chart1653232384200" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1653229181730 = document
.getElementById('chart1653229181730')
const ctx1653232384200 = document
.getElementById('chart1653232384200')
.getContext('2d')
const chart1653229181730 = new Chart(ctx1653229181730, {
const chart1653232384200 = new Chart(ctx1653232384200, {
type: 'bar',
data: {
labels: ["Blind cycle a traffic light 500 times by transition","Blind cycle a traffic light 500 times by action","Blind cycle a basic-hooked traffic light 500 times by transition","Blind cycle a named-hooked traffic light 500 times by transition","Blind cycle an any-transition traffic light 500 times by transition","Blind cycle an exit hooked traffic light 500 times by transition","Blind cycle an enter hooked traffic light 500 times by transition","Blind cycle a standard-transition hooked light by transition","Blind cycle a main-transition hooked light by transition","Blind cycle a force-transition hooked light by transition","Blind cycle a traffic light 500 times by action","Blind cycle a basic-hooked traffic light 500 times by action","Blind cycle a named-hooked traffic light 500 times by action","Blind cycle an any-action traffic light 500 times by action","Blind cycle a global-action traffic light 500 times by action","Blind cycle an exit hooked traffic light 500 times by action","Blind cycle an enter hooked traffic light 500 times by action","Blind cycle a standard transition tl 500 times by action","Blind cycle a main transition tl 500 times by action","Blind cycle a forced transition tl 500 times by action","Kitchen Sink 500 times"],
datasets: [
{
data: [5701,13401,1267,6011,5885,5992,6010,6244,5639,28217,14110,1506,1341,10736,10142,8748,8607,62153,62285,53459,8986],
backgroundColor: ["hsl(10.980000000000006, 85%, 55%)","hsl(25.823999999999995, 85%, 55%)","hsl(2.4360000000000017, 85%, 55%)","hsl(11.580000000000007, 85%, 55%)","hsl(11.340000000000003, 85%, 55%)","hsl(11.544000000000006, 85%, 55%)","hsl(11.580000000000007, 85%, 55%)","hsl(12.023999999999994, 85%, 55%)","hsl(10.859999999999996, 85%, 55%)","hsl(54.35999999999999, 85%, 55%)","hsl(27.180000000000007, 85%, 55%)","hsl(2.904000000000002, 85%, 55%)","hsl(2.5800000000000067, 85%, 55%)","hsl(20.68799999999999, 85%, 55%)","hsl(19.536, 85%, 55%)","hsl(16.859999999999996, 85%, 55%)","hsl(16.583999999999993, 85%, 55%)","hsl(119.748, 85%, 55%)","hsl(120, 85%, 55%)","hsl(102.996, 85%, 55%)","hsl(17.31600000000001, 85%, 55%)"],
borderColor: ["hsl(10.980000000000006, 85%, 55%)","hsl(25.823999999999995, 85%, 55%)","hsl(2.4360000000000017, 85%, 55%)","hsl(11.580000000000007, 85%, 55%)","hsl(11.340000000000003, 85%, 55%)","hsl(11.544000000000006, 85%, 55%)","hsl(11.580000000000007, 85%, 55%)","hsl(12.023999999999994, 85%, 55%)","hsl(10.859999999999996, 85%, 55%)","hsl(54.35999999999999, 85%, 55%)","hsl(27.180000000000007, 85%, 55%)","hsl(2.904000000000002, 85%, 55%)","hsl(2.5800000000000067, 85%, 55%)","hsl(20.68799999999999, 85%, 55%)","hsl(19.536, 85%, 55%)","hsl(16.859999999999996, 85%, 55%)","hsl(16.583999999999993, 85%, 55%)","hsl(119.748, 85%, 55%)","hsl(120, 85%, 55%)","hsl(102.996, 85%, 55%)","hsl(17.31600000000001, 85%, 55%)"],
data: [5760,13492,1405,6785,6263,6265,6121,6475,6396,26127,14498,1637,1493,11425,11722,10085,10236,69588,68338,68222,9737],
backgroundColor: ["hsl(9.936000000000002, 85%, 55%)","hsl(23.268, 85%, 55%)","hsl(2.4239999999999955, 85%, 55%)","hsl(11.700000000000001, 85%, 55%)","hsl(10.799999999999999, 85%, 55%)","hsl(10.799999999999999, 85%, 55%)","hsl(10.559999999999995, 85%, 55%)","hsl(11.159999999999997, 85%, 55%)","hsl(11.027999999999999, 85%, 55%)","hsl(45.059999999999995, 85%, 55%)","hsl(24.996, 85%, 55%)","hsl(2.819999999999993, 85%, 55%)","hsl(2.5800000000000067, 85%, 55%)","hsl(19.704, 85%, 55%)","hsl(20.208000000000002, 85%, 55%)","hsl(17.387999999999995, 85%, 55%)","hsl(17.65199999999999, 85%, 55%)","hsl(120, 85%, 55%)","hsl(117.84, 85%, 55%)","hsl(117.64800000000001, 85%, 55%)","hsl(16.787999999999993, 85%, 55%)"],
borderColor: ["hsl(9.936000000000002, 85%, 55%)","hsl(23.268, 85%, 55%)","hsl(2.4239999999999955, 85%, 55%)","hsl(11.700000000000001, 85%, 55%)","hsl(10.799999999999999, 85%, 55%)","hsl(10.799999999999999, 85%, 55%)","hsl(10.559999999999995, 85%, 55%)","hsl(11.159999999999997, 85%, 55%)","hsl(11.027999999999999, 85%, 55%)","hsl(45.059999999999995, 85%, 55%)","hsl(24.996, 85%, 55%)","hsl(2.819999999999993, 85%, 55%)","hsl(2.5800000000000067, 85%, 55%)","hsl(19.704, 85%, 55%)","hsl(20.208000000000002, 85%, 55%)","hsl(17.387999999999995, 85%, 55%)","hsl(17.65199999999999, 85%, 55%)","hsl(120, 85%, 55%)","hsl(117.84, 85%, 55%)","hsl(117.64800000000001, 85%, 55%)","hsl(16.787999999999993, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
130 changes: 65 additions & 65 deletions benchmark/results/general.json
@@ -1,138 +1,138 @@
{
"name": "General performance suite",
"date": "2022-05-22T14:19:41.730Z",
"date": "2022-05-22T15:13:04.200Z",
"version": "1.2.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 5701,
"margin": 1.73,
"percentSlower": 90.85
"ops": 5760,
"margin": 2.55,
"percentSlower": 91.72
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 13401,
"margin": 2.31,
"percentSlower": 78.48
"ops": 13492,
"margin": 2.32,
"percentSlower": 80.61
},
{
"name": "Blind cycle a basic-hooked traffic light 500 times by transition",
"ops": 1267,
"margin": 6.55,
"percentSlower": 97.97
"ops": 1405,
"margin": 0.56,
"percentSlower": 97.98
},
{
"name": "Blind cycle a named-hooked traffic light 500 times by transition",
"ops": 6011,
"margin": 7.53,
"percentSlower": 90.35
"ops": 6785,
"margin": 0.84,
"percentSlower": 90.25
},
{
"name": "Blind cycle an any-transition traffic light 500 times by transition",
"ops": 5885,
"margin": 2.9,
"percentSlower": 90.55
"ops": 6263,
"margin": 1.32,
"percentSlower": 91
},
{
"name": "Blind cycle an exit hooked traffic light 500 times by transition",
"ops": 5992,
"margin": 1.29,
"percentSlower": 90.38
"ops": 6265,
"margin": 0.88,
"percentSlower": 91
},
{
"name": "Blind cycle an enter hooked traffic light 500 times by transition",
"ops": 6010,
"margin": 1.18,
"percentSlower": 90.35
"ops": 6121,
"margin": 1.14,
"percentSlower": 91.2
},
{
"name": "Blind cycle a standard-transition hooked light by transition",
"ops": 6244,
"margin": 0.82,
"percentSlower": 89.98
"ops": 6475,
"margin": 1,
"percentSlower": 90.7
},
{
"name": "Blind cycle a main-transition hooked light by transition",
"ops": 5639,
"margin": 7.84,
"percentSlower": 90.95
"ops": 6396,
"margin": 0.96,
"percentSlower": 90.81
},
{
"name": "Blind cycle a force-transition hooked light by transition",
"ops": 28217,
"margin": 2.53,
"percentSlower": 54.7
"ops": 26127,
"margin": 0.79,
"percentSlower": 62.45
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 14110,
"margin": 0.69,
"percentSlower": 77.35
"ops": 14498,
"margin": 0.62,
"percentSlower": 79.17
},
{
"name": "Blind cycle a basic-hooked traffic light 500 times by action",
"ops": 1506,
"margin": 6.16,
"percentSlower": 97.58
"ops": 1637,
"margin": 1.07,
"percentSlower": 97.65
},
{
"name": "Blind cycle a named-hooked traffic light 500 times by action",
"ops": 1341,
"margin": 5.11,
"ops": 1493,
"margin": 0.35,
"percentSlower": 97.85
},
{
"name": "Blind cycle an any-action traffic light 500 times by action",
"ops": 10736,
"margin": 1.13,
"percentSlower": 82.76
"ops": 11425,
"margin": 0.75,
"percentSlower": 83.58
},
{
"name": "Blind cycle a global-action traffic light 500 times by action",
"ops": 10142,
"margin": 5.76,
"percentSlower": 83.72
"ops": 11722,
"margin": 1.4,
"percentSlower": 83.16
},
{
"name": "Blind cycle an exit hooked traffic light 500 times by action",
"ops": 8748,
"margin": 6.73,
"percentSlower": 85.95
"ops": 10085,
"margin": 0.86,
"percentSlower": 85.51
},
{
"name": "Blind cycle an enter hooked traffic light 500 times by action",
"ops": 8607,
"margin": 8.46,
"percentSlower": 86.18
"ops": 10236,
"margin": 0.77,
"percentSlower": 85.29
},
{
"name": "Blind cycle a standard transition tl 500 times by action",
"ops": 62153,
"margin": 1.29,
"percentSlower": 0.21
"ops": 69588,
"margin": 0.68,
"percentSlower": 0
},
{
"name": "Blind cycle a main transition tl 500 times by action",
"ops": 62285,
"margin": 0.92,
"percentSlower": 0
"ops": 68338,
"margin": 1.42,
"percentSlower": 1.8
},
{
"name": "Blind cycle a forced transition tl 500 times by action",
"ops": 53459,
"margin": 8.74,
"percentSlower": 14.17
"ops": 68222,
"margin": 0.72,
"percentSlower": 1.96
},
{
"name": "Kitchen Sink 500 times",
"ops": 8986,
"margin": 2.37,
"percentSlower": 85.57
"ops": 9737,
"margin": 0.83,
"percentSlower": 86.01
}
],
"fastest": {
"name": "Blind cycle a main transition tl 500 times by action",
"index": 18
"name": "Blind cycle a standard transition tl 500 times by action",
"index": 17
},
"slowest": {
"name": "Blind cycle a basic-hooked traffic light 500 times by transition",
Expand Down
41 changes: 39 additions & 2 deletions dist/es6/jssm.d.ts
Expand Up @@ -82,13 +82,15 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
* operator `sm`, and mostly falls back to `.from` when needing to parse
* strings dynamically instead of from template literals.
*
* Operator {@link sm}:
*
* ```typescript
* import { sm } from './jssm';
*
* const switch = sm`on <=> off;`;
* ```
*
* &hellip; or &hellip;
* Method {@link from}:
*
* ```typescript
* import * as jssm from './jssm';
Expand Down Expand Up @@ -131,13 +133,15 @@ declare function wrap_parse(input: string, options?: Object): any;
* operator `sm`, and mostly falls back to `.from` when needing to parse
* strings dynamically instead of from template literals.
*
* Operator {@link sm}:
*
* ```typescript
* import { sm } from './jssm';
*
* const switch = sm`on <=> off;`;
* ```
*
* &hellip; or &hellip;
* Method {@link from}:
*
* ```typescript
* import * as jssm from './jssm';
Expand Down Expand Up @@ -281,6 +285,39 @@ declare class Machine<mDT> {
instance_name(): string | undefined;
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
}
/*********
*
* Create a state machine from a template string. This is one of the two main
* paths for working with JSSM, alongside {@link from}.
*
* Use this method when you want to work directly and conveniently with a
* constant template expression. Use `.from` when you want to pull from
* dynamic strings.
*
*
* ```typescript
* import * as jssm from './jssm';
*
* const switch = jssm.from('on <=> off;');
* ```
*
*/
declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
/*********
*
* Create a state machine from an implementation string. This is one of the
* two main paths for working with JSSM, alongside {@link sm}.
*
* Use this method when you want to conveniently pull a state machine from a
* string dynamically. Use operator `sm` when you just want to work with a
* template expression.
*
* ```typescript
* import * as jssm from './jssm';
*
* const switch = jssm.from('on <=> off;');
* ```
*
*/
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors };
41 changes: 39 additions & 2 deletions dist/es6/jssm.js
Expand Up @@ -253,13 +253,15 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
* operator `sm`, and mostly falls back to `.from` when needing to parse
* strings dynamically instead of from template literals.
*
* Operator {@link sm}:
*
* ```typescript
* import { sm } from './jssm';
*
* const switch = sm`on <=> off;`;
* ```
*
* &hellip; or &hellip;
* Method {@link from}:
*
* ```typescript
* import * as jssm from './jssm';
Expand Down Expand Up @@ -376,13 +378,15 @@ function compile_rule_handler(rule) {
* operator `sm`, and mostly falls back to `.from` when needing to parse
* strings dynamically instead of from template literals.
*
* Operator {@link sm}:
*
* ```typescript
* import { sm } from './jssm';
*
* const switch = sm`on <=> off;`;
* ```
*
* &hellip; or &hellip;
* Method {@link from}:
*
* ```typescript
* import * as jssm from './jssm';
Expand Down Expand Up @@ -1195,6 +1199,23 @@ class Machine {
return sm(template_strings, ...remainder);
}
}
/*********
*
* Create a state machine from a template string. This is one of the two main
* paths for working with JSSM, alongside {@link from}.
*
* Use this method when you want to work directly and conveniently with a
* constant template expression. Use `.from` when you want to pull from
* dynamic strings.
*
*
* ```typescript
* import * as jssm from './jssm';
*
* const switch = jssm.from('on <=> off;');
* ```
*
*/
function sm(template_strings, ...remainder /* , arguments */) {
// foo`a${1}b${2}c` will come in as (['a','b','c'],1,2)
// this includes when a and c are empty strings
Expand All @@ -1208,6 +1229,22 @@ function sm(template_strings, ...remainder /* , arguments */) {
/* eslint-enable prefer-rest-params */
)));
}
/*********
*
* Create a state machine from an implementation string. This is one of the
* two main paths for working with JSSM, alongside {@link sm}.
*
* Use this method when you want to conveniently pull a state machine from a
* string dynamically. Use operator `sm` when you just want to work with a
* template expression.
*
* ```typescript
* import * as jssm from './jssm';
*
* const switch = jssm.from('on <=> off;');
* ```
*
*/
function from(MachineAsString, ExtraConstructorFields) {
const to_decorate = make(MachineAsString);
if (ExtraConstructorFields !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/es6/version.js
@@ -1,2 +1,2 @@
const version = "5.65.3";
const version = "5.65.4";
export { version };
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

0 comments on commit fdb3369

Please sign in to comment.