summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-06-25 21:18:44 -0400
committerpommicket <pommicket@gmail.com>2023-06-25 21:18:44 -0400
commitf58db128753fd4c3c06ff979c6981e5239fc6578 (patch)
treecdf4fc314f245196dbc964a43e152da271b3d037
parent8c75c92a912f48e2a8ed4a3e1647a9217605888e (diff)
detect circular dependencies
-rw-r--r--fractiform.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/fractiform.js b/fractiform.js
index df86a2b..ad47cb9 100644
--- a/fractiform.js
+++ b/fractiform.js
@@ -2,10 +2,6 @@
/*
TODO:
-- prev controls:
- - wrap?
- - filter
-- detect circular dependencies
- detect duplicate widget names
*/
@@ -494,6 +490,7 @@ class GLSLGenerationState {
constructor(widgets) {
this.widgets = widgets;
this.code = [];
+ this.computing_inputs = {};
this.variable = 0;
}
@@ -607,11 +604,19 @@ class GLSLGenerationState {
if (dot !== -1) {
input = input.substr(0, dot);
}
- let widget = this.widgets['-' + input];
+ let esc_input = '-' + input; // prevent wacky stuff if input is an Object built-in
+ let widget = this.widgets[esc_input];
if (widget === undefined) {
return {error: 'cannot find ' + input};
}
- return this.compute_widget_output(widget, field);
+
+ if (esc_input in this.computing_inputs) {
+ return {error: 'circular dependency at ' + input};
+ }
+ this.computing_inputs[esc_input] = true;
+ let value = this.compute_widget_output(widget, field);
+ delete this.computing_inputs[esc_input];
+ return value;
}
compute_widget_output(widget, output) {