From 02dd2eae1a75fc81e1658b63fd5f585ab3affa2e Mon Sep 17 00:00:00 2001 From: Joseph Abbey Date: Tue, 1 Nov 2022 13:59:47 +0000 Subject: [PATCH] prevent creating signals, etc. with the same name --- examples/button_driven.vhdl | 14 +++++-- examples/button_driven.vhdl.sbd | 2 +- scratch-vhdl-vscode/media/main.js | 64 ++++++++++++++++++------------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/examples/button_driven.vhdl b/examples/button_driven.vhdl index 197a05d..fc9467a 100644 --- a/examples/button_driven.vhdl +++ b/examples/button_driven.vhdl @@ -1,10 +1,18 @@ library ieee; use ieee.std_logic_1164.all; +entity button_driven is + port( + clk : in std_logic; + reset : in std_logic; + incr : in std_logic; + buttons : in std_logic_vector(3 downto 0); + leds : out std_logic_vector(3 downto 0) + ); +end entity; - -architecture scratch of led4_button4 is +architecture scratch of button_driven is constant button_tab_c : natural := 1; @@ -15,7 +23,7 @@ begin process(clk) begin if rising_edge(clk) then - if reset = '0' then + if reset = '1' then leds <= "0000"; else -- If any buttons are pressed, set leds to buttons. diff --git a/examples/button_driven.vhdl.sbd b/examples/button_driven.vhdl.sbd index 17ded2c..8e9192e 100644 --- a/examples/button_driven.vhdl.sbd +++ b/examples/button_driven.vhdl.sbd @@ -1 +1 @@ -{"blocks":{"languageVersion":0,"blocks":[{"type":"process","id":"avqozk~ylO6~9`OoO-tF","x":388,"y":13,"extraState":{"depCount":1},"fields":{"1":{"id":"u;Fa!BiTi{j_018wO)36"}},"inputs":{"body":{"block":{"type":"controls_if","id":"7)2aH8jQ`CxLSWy}UAgr","inputs":{"IF0":{"block":{"type":"logic_rising_edge","id":"0QWfBso?I$XYQ8@mej5}","fields":{"dep":{"id":"u;Fa!BiTi{j_018wO)36"}}}},"DO0":{"block":{"type":"controls_if","id":"|iCK:,3?*n,e{^9zO]%y","extraState":{"hasElse":true},"inputs":{"IF0":{"block":{"type":"logic_compare","id":"B=Og_Cm*AO)T}CKQAZXF","fields":{"OP":"EQ"},"inputs":{"A":{"block":{"type":"variables_get","id":"Db8Ohuaw7PUe(HOT?d:%","fields":{"VAR":{"id":"k={!]s@w*z5TAx~}`{9)"}}}},"B":{"block":{"type":"value_std_logic","id":"HV[(76@,1o#o|NIyg{4L","fields":{"VALUE":0}}}}}},"DO0":{"block":{"type":"variables_set","id":"#+9/+hoAZ#@$}Xj@UfWf","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"value_std_logic_vector","id":"e;wxzA`Gn*})l|hu!d,}","fields":{"VALUE":"0000"}}}}}},"ELSE":{"block":{"type":"controls_if","id":"G-`MW2Q19@O:3dI$@8i`","icons":{"comment":{"text":"If any buttons are pressed, set leds to buttons.","pinned":false,"height":107,"width":387}},"inputs":{"IF0":{"block":{"type":"logic_operation_vector","id":"16BmZIO|$qr(z+1]f618","fields":{"OPERATION":"or"},"inputs":{"LIST":{"block":{"type":"variables_get","id":".*yYPrudmb_BZ;n|H]a2","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}},"DO0":{"block":{"type":"variables_set","id":"@2+PU)j0,=F_cLpfwji{","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"variables_get","id":".+(dqWRY[l/0K@ZwWi6E","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"clk","id":"u;Fa!BiTi{j_018wO)36"},{"name":"reset","id":"k={!]s@w*z5TAx~}`{9)"},{"name":"incr","id":"-N/%|Yb*ua~LIYg|RDXz"},{"name":"buttons","id":"xiS/W8KC[SjitA9:_W,%"},{"name":"leds","id":"j]MA]3Vu=zr|cCG^O7mG"}],"signals":{}} \ No newline at end of file +{"blocks":{"languageVersion":0,"blocks":[{"type":"process","id":"avqozk~ylO6~9`OoO-tF","x":388,"y":13,"extraState":{"depCount":1},"fields":{"1":{"id":"u;Fa!BiTi{j_018wO)36"}},"inputs":{"body":{"block":{"type":"controls_if","id":"7)2aH8jQ`CxLSWy}UAgr","inputs":{"IF0":{"block":{"type":"logic_rising_edge","id":"0QWfBso?I$XYQ8@mej5}","fields":{"dep":{"id":"u;Fa!BiTi{j_018wO)36"}}}},"DO0":{"block":{"type":"controls_if","id":"|iCK:,3?*n,e{^9zO]%y","extraState":{"hasElse":true},"inputs":{"IF0":{"block":{"type":"logic_compare","id":"B=Og_Cm*AO)T}CKQAZXF","fields":{"OP":"EQ"},"inputs":{"A":{"block":{"type":"variables_get","id":"Db8Ohuaw7PUe(HOT?d:%","fields":{"VAR":{"id":"k={!]s@w*z5TAx~}`{9)"}}}},"B":{"block":{"type":"value_std_logic","id":"HV[(76@,1o#o|NIyg{4L","fields":{"VALUE":1}}}}}},"DO0":{"block":{"type":"variables_set","id":"#+9/+hoAZ#@$}Xj@UfWf","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"value_std_logic_vector","id":"e;wxzA`Gn*})l|hu!d,}","fields":{"VALUE":"0000"}}}}}},"ELSE":{"block":{"type":"controls_if","id":"G-`MW2Q19@O:3dI$@8i`","icons":{"comment":{"text":"If any buttons are pressed, set leds to buttons.","pinned":false,"height":107,"width":387}},"inputs":{"IF0":{"block":{"type":"logic_operation_vector","id":"16BmZIO|$qr(z+1]f618","fields":{"OPERATION":"or"},"inputs":{"LIST":{"block":{"type":"variables_get","id":".*yYPrudmb_BZ;n|H]a2","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}},"DO0":{"block":{"type":"variables_set","id":"@2+PU)j0,=F_cLpfwji{","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"variables_get","id":".+(dqWRY[l/0K@ZwWi6E","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"clk","id":"u;Fa!BiTi{j_018wO)36"},{"name":"reset","id":"k={!]s@w*z5TAx~}`{9)"},{"name":"incr","id":"-N/%|Yb*ua~LIYg|RDXz"},{"name":"buttons","id":"xiS/W8KC[SjitA9:_W,%"},{"name":"leds","id":"j]MA]3Vu=zr|cCG^O7mG"}],"signals":{}} \ No newline at end of file diff --git a/scratch-vhdl-vscode/media/main.js b/scratch-vhdl-vscode/media/main.js index f218177..6751f53 100644 --- a/scratch-vhdl-vscode/media/main.js +++ b/scratch-vhdl-vscode/media/main.js @@ -1099,6 +1099,8 @@ document.addEventListener('DOMContentLoaded', function () { weight: -1, }); + const notExists = (n) => !(entity.entity.hasOwnProperty(n) || signals.hasOwnProperty(n) || constants.hasOwnProperty(n) || aliases.hasOwnProperty(n)); + Blockly.ContextMenuRegistry.registry.register({ displayText: "Add port", preconditionFn() { @@ -1106,15 +1108,17 @@ document.addEventListener('DOMContentLoaded', function () { }, callback() { prompt("New port name: ").then((n) => { - prompt("New port direction: ").then((d) => { - prompt("New port type: ").then((t) => { - entity.entity[n] = [d, t]; - vscode.postMessage({ - type: "updateEntity", - body: JSON.stringify(entity) + if (notExists(n)) + prompt("New port direction: ").then((d) => { + prompt("New port type: ").then((t) => { + entity.entity[n] = [d, t]; + vscode.postMessage({ + type: "updateEntity", + body: JSON.stringify(entity) + }); }); }); - }); + else this.callback() }); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE, @@ -1189,16 +1193,18 @@ document.addEventListener('DOMContentLoaded', function () { }, callback() { prompt("New constant name: ").then((n) => { - prompt("New constant type: ").then((t) => { - prompt("New constant value: ").then((v) => { - entity.constants = entity.constants || {}; - entity.constants[n] = [t, v]; - vscode.postMessage({ - type: "updateEntity", - body: JSON.stringify(entity) + if (notExists(n)) + prompt("New constant type: ").then((t) => { + prompt("New constant value: ").then((v) => { + entity.constants = entity.constants || {}; + entity.constants[n] = [t, v]; + vscode.postMessage({ + type: "updateEntity", + body: JSON.stringify(entity) + }); }); }); - }); + else this.callback() }); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE, @@ -1231,14 +1237,16 @@ document.addEventListener('DOMContentLoaded', function () { }, callback() { prompt("New alias name: ").then((n) => { - prompt("New alias value: ").then((v) => { - entity.aliases = entity.aliases || {}; - entity.aliases[n] = v; - vscode.postMessage({ - type: "updateEntity", - body: JSON.stringify(entity) + if (notExists(n)) + prompt("New alias value: ").then((v) => { + entity.aliases = entity.aliases || {}; + entity.aliases[n] = v; + vscode.postMessage({ + type: "updateEntity", + body: JSON.stringify(entity) + }); }); - }); + else this.callback() }); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE, @@ -1279,12 +1287,14 @@ document.addEventListener('DOMContentLoaded', function () { old(...args); if (!args[2] && args[0] == "CREATE_VARIABLE") { ws.removeButtonCallback("CREATE_VARIABLE"); - ws.registerButtonCallback("CREATE_VARIABLE", (d) => { + ws.registerButtonCallback("CREATE_VARIABLE", function c(d) { prompt("New variable name: ").then((n) => { - prompt("New variable type: ").then((t) => { - d.getTargetWorkspace().createVariable(n); - signals[n] = t; - }); + if (notExists(n)) + prompt("New variable type: ").then((t) => { + d.getTargetWorkspace().createVariable(n); + signals[n] = t; + }); + else c(d); }); }, true); }