From f58db128753fd4c3c06ff979c6981e5239fc6578 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 25 Jun 2023 21:18:44 -0400 Subject: detect circular dependencies --- fractiform.js | 17 +++++++++++------ 1 file 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) { -- cgit v1.2.3