diff --git a/src/main/dig/generic/barrelShifter/barrelShifter.dig b/src/main/dig/generic/barrelShifter/barrelShifter.dig
index 96dba8991..77c271512 100644
--- a/src/main/dig/generic/barrelShifter/barrelShifter.dig
+++ b/src/main/dig/generic/barrelShifter/barrelShifter.dig
@@ -86,25 +86,28 @@
generic
- dataBits:=16;
-shiftBits:=int(4);
-circuit:="shift-fixed-left-inc.dig";
-if (isPresent(args)) {
+ if (isPresent(args)) {
if (args.dir="right") {
- circuit="shift-fixed-right-inc.dig";
+ export circuit:="shift-fixed-right-inc.dig";
} else {
if (args.dir="arith") {
- circuit="shift-fixed-arith-right-inc.dig";
+ export circuit:="shift-fixed-arith-right-inc.dig";
} else {
- if (args.dir!="left") {
+ if (args.dir="left") {
+ export circuit:="shift-fixed-left-inc.dig";
+ } else {
panic("only \"left\", \"right\" or \"arith\" is allowed as direction, not \""+args.dir+"\"!");
}
}
}
- dataBits=args.dataBits;
- shiftBits=bitsNeededFor(args.dataBits-1);
+ export shiftBits:=bitsNeededFor(args.dataBits-1);
+} else {
+ // used if circuit is started as the main circuit
+ export circuit:="shift-fixed-left-inc.dig";
+ export dataBits:=16;
+ export shiftBits:=int(4);
}
diff --git a/src/main/dig/generic/barrelShifter/shift-inc.dig b/src/main/dig/generic/barrelShifter/shift-inc.dig
index 534259d0b..11263a654 100644
--- a/src/main/dig/generic/barrelShifter/shift-inc.dig
+++ b/src/main/dig/generic/barrelShifter/shift-inc.dig
@@ -13,12 +13,13 @@
generic
- dataBits:=16;
-shift:=8;
-if (isPresent(args)) {
- dataBits = args.dataBits;
- shift = 1<<(args.shiftBits-1);
+ if (isPresent(args)) {
+ export shift := 1<<(args.shiftBits-1);
setCircuit(args.circuit);
+} else {
+ // used if circuit is started as the main circuit
+ export dataBits:=16;
+ export shift:=8;
}
@@ -97,18 +98,18 @@ if (isPresent(args)) {
generic
- dataBits:=16;
-shiftBits:=3;
-circuit:="shift-fixed-left-inc.dig";
-if (isPresent(args)) {
- dataBits = args.dataBits;
+ if (isPresent(args)) {
if (args.shiftBits=2) {
export shift := 1;
setCircuit(args.circuit);
} else {
- shiftBits = args.shiftBits-1;
- circuit=args.circuit;
+ export shiftBits := args.shiftBits-1;
}
+} else {
+ // used if circuit is started as the main circuit
+ export dataBits:=16;
+ export shiftBits:=3;
+ export circuit:="shift-fixed-left-inc.dig";
}
diff --git a/src/main/dig/generic/gray/GrayCounter.dig b/src/main/dig/generic/gray/GrayCounter.dig
index dbbf462b1..844185588 100644
--- a/src/main/dig/generic/gray/GrayCounter.dig
+++ b/src/main/dig/generic/gray/GrayCounter.dig
@@ -138,9 +138,7 @@ ist als drei.}}
generic
inBits:=2;
-bits:=3;
if (isPresent(args)) {
- bits=args.bits;
if (args.bits>3) {
setCircuit("GrayNode-inc.dig");
}
diff --git a/src/main/dig/generic/gray/GrayNode-inc.dig b/src/main/dig/generic/gray/GrayNode-inc.dig
index 155da0385..48d7d5513 100644
--- a/src/main/dig/generic/gray/GrayNode-inc.dig
+++ b/src/main/dig/generic/gray/GrayNode-inc.dig
@@ -107,14 +107,13 @@
generic
- inBits:=3;
-bits:=4;
-if (isPresent(args)) {
- inBits = args.inBits+1;
- bits=args.bits;
+ if (isPresent(args)) {
+ export inBits := args.inBits+1;
if (args.inBits<args.bits-2) {
setCircuit("GrayNode-inc.dig");
}
+} else {
+ export inBits:=3;
}
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 8154f4361..71c616990 100644
--- a/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java
+++ b/src/main/java/de/neemann/digital/draw/library/ResolveGenerics.java
@@ -69,7 +69,7 @@ public class ResolveGenerics {
Statement genS = getStatement(gen);
if (isCustom) {
Context mod = new Context()
- .declareVar("args", args)
+ .declareVar("args", new ArgsGetter(args))
.declareFunc("setCircuit", new Function(1) {
@Override
protected Object f(Object... args) {
@@ -81,7 +81,7 @@ public class ResolveGenerics {
ve.setGenericArgs(mod);
} else {
Context mod = new Context()
- .declareVar("args", args)
+ .declareVar("args", new ArgsGetter(args))
.declareVar("this", new SubstituteLibrary.AllowSetAttributes(ve.getElementAttributes()));
genS.execute(mod);
}
@@ -104,4 +104,23 @@ public class ResolveGenerics {
return genS;
}
+ private static final class ArgsGetter implements HGSMap {
+ private final Context args;
+
+ private ArgsGetter(Context args) {
+ this.args = args;
+ }
+
+ @Override
+ public Object hgsMapGet(String key) throws HGSEvalException {
+ Object v = args.hgsMapGet(key);
+ if (v == null) {
+ Object a = args.hgsMapGet("args");
+ if (a instanceof HGSMap) {
+ return ((HGSMap) a).hgsMapGet(key);
+ }
+ }
+ return v;
+ }
+ }
}
diff --git a/src/main/java/de/neemann/digital/hdl/hgs/Parser.java b/src/main/java/de/neemann/digital/hdl/hgs/Parser.java
index ad7f5021f..9bfcf4ad7 100644
--- a/src/main/java/de/neemann/digital/hdl/hgs/Parser.java
+++ b/src/main/java/de/neemann/digital/hdl/hgs/Parser.java
@@ -175,7 +175,7 @@ public class Parser {
return lino(c -> ref.declareVar(c, initVal.value(c)));
case EQUAL:
if (export)
- throw newParserException("export not allowed here!");
+ throw newParserException("export is only allowed at variable declaration!");
final Expression val = parseExpression();
if (isRealStatement) expect(SEMICOLON);
return lino(c -> {
@@ -187,18 +187,18 @@ public class Parser {
case ADD:
expect(ADD);
if (export)
- throw newParserException("export not allowed here!");
+ throw newParserException("export is only allowed at variable declaration!");
if (isRealStatement) expect(SEMICOLON);
return lino(c -> ref.set(c, Value.toLong(ref.get(c)) + 1));
case SUB:
expect(SUB);
if (export)
- throw newParserException("export not allowed here!");
+ throw newParserException("export is only allowed at variable declaration!");
if (isRealStatement) expect(SEMICOLON);
return lino(c -> ref.set(c, Value.toLong(ref.get(c)) - 1));
case SEMICOLON:
if (export)
- throw newParserException("export not allowed here!");
+ throw newParserException("export is only allowed at variable declaration!");
return lino(ref::get);
default:
throw newUnexpectedToken(refToken);