From 292b2ec7184a269ead0603ec2f3065a07fd1d102 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sun, 3 Jan 2021 17:34:29 +0100 Subject: [PATCH] fixes an issue with generic code loading files --- .../digital/draw/library/ResolveGenerics.java | 20 +++++++++++-------- .../de/neemann/digital/hdl/hgs/Context.java | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java b/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java index 0f7042407..fa4141155 100644 --- a/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java +++ b/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java @@ -57,8 +57,7 @@ public class ResolveGenerics { if (!gen.isEmpty()) { boolean isCustom = library.getElementType(ve.getElementName(), ve.getElementAttributes()).isCustom(); Statement genS = getStatement(gen); - Context mod = new Context(); - mod.declareVar(Context.BASE_FILE_KEY, circuit.getOrigin().getPath()); + Context mod = publishCircuitPath(new Context(), circuit); if (isCustom) { mod.declareVar("args", args) .declareFunc("setCircuit", new SetCircuitFunc(ve)); @@ -79,6 +78,16 @@ public class ResolveGenerics { return new CircuitHolder(c, args); } + private Context publishCircuitPath(Context context, Circuit circuit) throws NodeException { + try { + if (circuit.getOrigin() != null) + context.declareVar(Context.BASE_FILE_KEY, circuit.getOrigin().getPath()); + return context; + } catch (HGSEvalException e) { + throw new NodeException("error setting the base filename", e); + } + } + private Args createArgs(VisualElement visualElement, Circuit circuit) throws NodeException { Context context; if (visualElement != null) { @@ -96,12 +105,7 @@ public class ResolveGenerics { } } } else { - context = new Context(); - try { - context.declareVar(Context.BASE_FILE_KEY, circuit.getOrigin().getPath()); - } catch (HGSEvalException e) { - throw new NodeException("error setting the base filename", e); - } + context = publishCircuitPath(new Context(), circuit); List g = circuit.getElements(v -> v.equalsDescription(GenericInitCode.DESCRIPTION) && v.getElementAttributes().get(Keys.ENABLED)); if (g.size() == 0) throw new NodeException(Lang.get("err_noGenericInitCode")); diff --git a/src/main/java/de/neemann/digital/hdl/hgs/Context.java b/src/main/java/de/neemann/digital/hdl/hgs/Context.java index 7964789a5..fe8664c05 100644 --- a/src/main/java/de/neemann/digital/hdl/hgs/Context.java +++ b/src/main/java/de/neemann/digital/hdl/hgs/Context.java @@ -631,7 +631,7 @@ public class Context implements HGSMap { File hexFile = fileLocator.locate(); if (hexFile == null) - throw new HGSEvalException("file " + name + " not found!"); + throw new HGSEvalException("File " + name + " not found! Is circuit saved?"); try { DataField dataField = Importer.read(hexFile, dataBits);