Skip to content

Commit

Permalink
Merge pull request #471 from StoneCypher/ImproveErrorsAndCreateInstan…
Browse files Browse the repository at this point in the history
…ceNamesAndMakeFrom

Adds instance names, fixes StoneCypher/fsl#428; puts them in errors, fixes StoneCypher/fsl#429; multiplexes errors, fixes StoneCypher/fsl#739; makes .from, fixes StoneCypher/fsl#753
  • Loading branch information
StoneCypher committed May 15, 2022
2 parents 6e2e7f8 + 94a26af commit 4c208fc
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 232 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -62,8 +62,8 @@ What if integration with the outside was straightforward?

```javascript
const MTL = sm`Red 'next' -> Green 'next' -> Yellow 'next' -> Red;` // MTL = More Traffic Lights
.hook('Red', 'Green', () => console.log('GO GO GO')) // node will jump the gun when you hit return, though
.hook_entry('Red', () => console.log('STOP')); // so put it on one line in node
.hook('Red', 'Green', () => log('GO GO GO') ) // node will jump the gun when you hit return, though
.hook_entry('Red', () => log('STOP') ); // so put it on one line in node

log( MTL.state() ); // 'Red'

Expand Down
14 changes: 7 additions & 7 deletions benchmark/results/general.chart.html
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1652464721425" width="16" height="9"></canvas>
<canvas id="chart1652584461536" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1652464721425 = document
.getElementById('chart1652464721425')
const ctx1652584461536 = document
.getElementById('chart1652584461536')
.getContext('2d')
const chart1652464721425 = new Chart(ctx1652464721425, {
const chart1652584461536 = new Chart(ctx1652584461536, {
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: [6757,13692,1364,6584,6342,6051,6263,6366,6223,26829,13675,1571,1421,10754,10816,9742,9640,66446,66115,67410,9346],
backgroundColor: ["hsl(12.023999999999994, 85%, 55%)","hsl(24.372000000000003, 85%, 55%)","hsl(2.4239999999999955, 85%, 55%)","hsl(11.723999999999995, 85%, 55%)","hsl(11.291999999999994, 85%, 55%)","hsl(10.776000000000005, 85%, 55%)","hsl(11.148000000000009, 85%, 55%)","hsl(11.327999999999998, 85%, 55%)","hsl(11.076000000000004, 85%, 55%)","hsl(47.76, 85%, 55%)","hsl(24.348000000000006, 85%, 55%)","hsl(2.795999999999998, 85%, 55%)","hsl(2.531999999999999, 85%, 55%)","hsl(19.140000000000004, 85%, 55%)","hsl(19.259999999999998, 85%, 55%)","hsl(17.340000000000003, 85%, 55%)","hsl(17.159999999999997, 85%, 55%)","hsl(118.28399999999999, 85%, 55%)","hsl(117.696, 85%, 55%)","hsl(120, 85%, 55%)","hsl(16.632, 85%, 55%)"],
borderColor: ["hsl(12.023999999999994, 85%, 55%)","hsl(24.372000000000003, 85%, 55%)","hsl(2.4239999999999955, 85%, 55%)","hsl(11.723999999999995, 85%, 55%)","hsl(11.291999999999994, 85%, 55%)","hsl(10.776000000000005, 85%, 55%)","hsl(11.148000000000009, 85%, 55%)","hsl(11.327999999999998, 85%, 55%)","hsl(11.076000000000004, 85%, 55%)","hsl(47.76, 85%, 55%)","hsl(24.348000000000006, 85%, 55%)","hsl(2.795999999999998, 85%, 55%)","hsl(2.531999999999999, 85%, 55%)","hsl(19.140000000000004, 85%, 55%)","hsl(19.259999999999998, 85%, 55%)","hsl(17.340000000000003, 85%, 55%)","hsl(17.159999999999997, 85%, 55%)","hsl(118.28399999999999, 85%, 55%)","hsl(117.696, 85%, 55%)","hsl(120, 85%, 55%)","hsl(16.632, 85%, 55%)"],
data: [7270,14513,1456,6975,6568,6458,6104,6557,6608,25042,14323,1598,1505,11689,11799,10311,9944,62101,68655,68495,9192],
backgroundColor: ["hsl(12.708000000000004, 85%, 55%)","hsl(25.368000000000002, 85%, 55%)","hsl(2.5440000000000054, 85%, 55%)","hsl(12.191999999999997, 85%, 55%)","hsl(11.483999999999993, 85%, 55%)","hsl(11.291999999999994, 85%, 55%)","hsl(10.668000000000001, 85%, 55%)","hsl(11.459999999999997, 85%, 55%)","hsl(11.544000000000006, 85%, 55%)","hsl(43.775999999999996, 85%, 55%)","hsl(25.032, 85%, 55%)","hsl(2.795999999999998, 85%, 55%)","hsl(2.6279999999999974, 85%, 55%)","hsl(20.436, 85%, 55%)","hsl(20.627999999999997, 85%, 55%)","hsl(18.023999999999997, 85%, 55%)","hsl(17.376000000000005, 85%, 55%)","hsl(108.54, 85%, 55%)","hsl(120, 85%, 55%)","hsl(119.72399999999999, 85%, 55%)","hsl(16.068, 85%, 55%)"],
borderColor: ["hsl(12.708000000000004, 85%, 55%)","hsl(25.368000000000002, 85%, 55%)","hsl(2.5440000000000054, 85%, 55%)","hsl(12.191999999999997, 85%, 55%)","hsl(11.483999999999993, 85%, 55%)","hsl(11.291999999999994, 85%, 55%)","hsl(10.668000000000001, 85%, 55%)","hsl(11.459999999999997, 85%, 55%)","hsl(11.544000000000006, 85%, 55%)","hsl(43.775999999999996, 85%, 55%)","hsl(25.032, 85%, 55%)","hsl(2.795999999999998, 85%, 55%)","hsl(2.6279999999999974, 85%, 55%)","hsl(20.436, 85%, 55%)","hsl(20.627999999999997, 85%, 55%)","hsl(18.023999999999997, 85%, 55%)","hsl(17.376000000000005, 85%, 55%)","hsl(108.54, 85%, 55%)","hsl(120, 85%, 55%)","hsl(119.72399999999999, 85%, 55%)","hsl(16.068, 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-13T17:58:41.425Z",
"date": "2022-05-15T03:14:21.536Z",
"version": "1.2.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 6757,
"margin": 1.85,
"percentSlower": 89.98
"ops": 7270,
"margin": 1.32,
"percentSlower": 89.41
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 13692,
"margin": 1.2,
"percentSlower": 79.69
"ops": 14513,
"margin": 0.53,
"percentSlower": 78.86
},
{
"name": "Blind cycle a basic-hooked traffic light 500 times by transition",
"ops": 1364,
"margin": 1.44,
"percentSlower": 97.98
"ops": 1456,
"margin": 0.89,
"percentSlower": 97.88
},
{
"name": "Blind cycle a named-hooked traffic light 500 times by transition",
"ops": 6584,
"margin": 2.82,
"percentSlower": 90.23
"ops": 6975,
"margin": 1.15,
"percentSlower": 89.84
},
{
"name": "Blind cycle an any-transition traffic light 500 times by transition",
"ops": 6342,
"margin": 1.36,
"percentSlower": 90.59
"ops": 6568,
"margin": 1.9,
"percentSlower": 90.43
},
{
"name": "Blind cycle an exit hooked traffic light 500 times by transition",
"ops": 6051,
"margin": 1.22,
"percentSlower": 91.02
"ops": 6458,
"margin": 0.74,
"percentSlower": 90.59
},
{
"name": "Blind cycle an enter hooked traffic light 500 times by transition",
"ops": 6263,
"margin": 0.99,
"percentSlower": 90.71
"ops": 6104,
"margin": 3.63,
"percentSlower": 91.11
},
{
"name": "Blind cycle a standard-transition hooked light by transition",
"ops": 6366,
"margin": 1.17,
"percentSlower": 90.56
"ops": 6557,
"margin": 0.88,
"percentSlower": 90.45
},
{
"name": "Blind cycle a main-transition hooked light by transition",
"ops": 6223,
"margin": 1.39,
"percentSlower": 90.77
"ops": 6608,
"margin": 0.92,
"percentSlower": 90.38
},
{
"name": "Blind cycle a force-transition hooked light by transition",
"ops": 26829,
"margin": 0.79,
"percentSlower": 60.2
"ops": 25042,
"margin": 0.67,
"percentSlower": 63.52
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 13675,
"margin": 1.26,
"percentSlower": 79.71
"ops": 14323,
"margin": 0.77,
"percentSlower": 79.14
},
{
"name": "Blind cycle a basic-hooked traffic light 500 times by action",
"ops": 1571,
"margin": 1.02,
"ops": 1598,
"margin": 3.15,
"percentSlower": 97.67
},
{
"name": "Blind cycle a named-hooked traffic light 500 times by action",
"ops": 1421,
"margin": 0.76,
"percentSlower": 97.89
"ops": 1505,
"margin": 0.6,
"percentSlower": 97.81
},
{
"name": "Blind cycle an any-action traffic light 500 times by action",
"ops": 10754,
"margin": 1.18,
"percentSlower": 84.05
"ops": 11689,
"margin": 0.95,
"percentSlower": 82.97
},
{
"name": "Blind cycle a global-action traffic light 500 times by action",
"ops": 10816,
"margin": 2.49,
"percentSlower": 83.95
"ops": 11799,
"margin": 0.71,
"percentSlower": 82.81
},
{
"name": "Blind cycle an exit hooked traffic light 500 times by action",
"ops": 9742,
"margin": 1.05,
"percentSlower": 85.55
"ops": 10311,
"margin": 0.91,
"percentSlower": 84.98
},
{
"name": "Blind cycle an enter hooked traffic light 500 times by action",
"ops": 9640,
"margin": 0.78,
"percentSlower": 85.7
"ops": 9944,
"margin": 1.25,
"percentSlower": 85.52
},
{
"name": "Blind cycle a standard transition tl 500 times by action",
"ops": 66446,
"margin": 0.86,
"percentSlower": 1.43
"ops": 62101,
"margin": 2.65,
"percentSlower": 9.55
},
{
"name": "Blind cycle a main transition tl 500 times by action",
"ops": 66115,
"margin": 1.06,
"percentSlower": 1.92
"ops": 68655,
"margin": 0.84,
"percentSlower": 0
},
{
"name": "Blind cycle a forced transition tl 500 times by action",
"ops": 67410,
"margin": 0.78,
"percentSlower": 0
"ops": 68495,
"margin": 0.62,
"percentSlower": 0.23
},
{
"name": "Kitchen Sink 500 times",
"ops": 9346,
"margin": 2.42,
"percentSlower": 86.14
"ops": 9192,
"margin": 1.33,
"percentSlower": 86.61
}
],
"fastest": {
"name": "Blind cycle a forced transition tl 500 times by action",
"index": 19
"name": "Blind cycle a main transition tl 500 times by action",
"index": 18
},
"slowest": {
"name": "Blind cycle a basic-hooked traffic light 500 times by transition",
Expand Down
7 changes: 5 additions & 2 deletions dist/es6/jssm.d.ts
Expand Up @@ -30,6 +30,7 @@ declare class Machine<mDT> {
_fsl_version?: string;
_raw_state_declaration?: Array<Object>;
_state_declarations: Map<StateType, JssmStateDeclaration>;
_instance_name: string;
_graph_layout: JssmLayout;
_dot_preamble: string;
_arrange_declaration: Array<Array<StateType>>;
Expand All @@ -54,7 +55,7 @@ declare class Machine<mDT> {
_main_transition_hook: HookHandler | undefined;
_forced_transition_hook: HookHandler | undefined;
_any_transition_hook: HookHandler | undefined;
constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout }: JssmGenericConfig<mDT>);
constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name }: JssmGenericConfig<mDT>);
_new_state(state_config: JssmGenericState): StateType;
state(): StateType;
state_is_final(whichState: StateType): boolean;
Expand Down Expand Up @@ -124,7 +125,9 @@ declare class Machine<mDT> {
valid_action(action: StateType, _newData?: mDT): boolean;
valid_transition(newState: StateType, _newData?: mDT): boolean;
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
instance_name(): string | undefined;
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
}
declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key };
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 };

0 comments on commit 4c208fc

Please sign in to comment.