mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-18 09:24:42 -04:00
Merge branch 'globalVars'
This commit is contained in:
commit
040c5e689e
@ -69,6 +69,7 @@ for (i:=0;i<sh;i++) {
|
|||||||
addWire(x-1,i+5,x-1,2);
|
addWire(x-1,i+5,x-1,2);
|
||||||
addWire(x-1,2,x,2);
|
addWire(x-1,2,x,2);
|
||||||
}
|
}
|
||||||
|
global.shift:=sh;
|
||||||
|
|
||||||
o:=addComponent("Out",sh*5+2,0);
|
o:=addComponent("Out",sh*5+2,0);
|
||||||
o.Bits=args.dataBits;
|
o.Bits=args.dataBits;
|
||||||
@ -86,7 +87,7 @@ o.Label="Out";</string>
|
|||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>generic</string>
|
<string>generic</string>
|
||||||
<string>this.Bits=bitsNeededFor(args.dataBits)-1;</string>
|
<string>this.Bits=global.shift;</string>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="-60" y="100"/>
|
<pos x="-60" y="100"/>
|
||||||
@ -100,9 +101,8 @@ o.Label="Out";</string>
|
|||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>generic</string>
|
<string>generic</string>
|
||||||
<string>sh:=bitsNeededFor(args.dataBits)-1;
|
<string>this.'Input Splitting'=""+global.shift;
|
||||||
this.'Input Splitting'=""+sh;
|
this.'Output Splitting'="1*"+global.shift;</string>
|
||||||
this.'Output Splitting'="1*"+sh;</string>
|
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Output Splitting</string>
|
<string>Output Splitting</string>
|
||||||
|
@ -37,6 +37,7 @@ public class ResolveGenerics {
|
|||||||
*/
|
*/
|
||||||
public static final String GEN_ARGS_KEY = "genArgs";
|
public static final String GEN_ARGS_KEY = "genArgs";
|
||||||
private static final String SETTINGS_KEY = "settings";
|
private static final String SETTINGS_KEY = "settings";
|
||||||
|
private static final String GLOBALS_KEY = "global";
|
||||||
private final HashMap<String, Statement> map;
|
private final HashMap<String, Statement> map;
|
||||||
private final HashMap<Args, CircuitHolder> circuitMap;
|
private final HashMap<Args, CircuitHolder> circuitMap;
|
||||||
private final Circuit circuit;
|
private final Circuit circuit;
|
||||||
@ -128,7 +129,25 @@ public class ResolveGenerics {
|
|||||||
ArrayList<VisualElement> newComponents = new ArrayList<>();
|
ArrayList<VisualElement> newComponents = new ArrayList<>();
|
||||||
ArrayList<Wire> newWires = new ArrayList<>();
|
ArrayList<Wire> newWires = new ArrayList<>();
|
||||||
|
|
||||||
for (VisualElement ve : c.getElements()) {
|
Globals globals = new Globals();
|
||||||
|
for (VisualElement ve : c.getElements())
|
||||||
|
if (ve.equalsDescription(GenericCode.DESCRIPTION)) {
|
||||||
|
handleVisualElement(c, ve, args, newComponents, newWires, globals);
|
||||||
|
globals.lock(); // allow write only in first code component
|
||||||
|
}
|
||||||
|
globals.lock(); // allow write only in code components
|
||||||
|
for (VisualElement ve : c.getElements())
|
||||||
|
if (!ve.equalsDescription(GenericCode.DESCRIPTION))
|
||||||
|
handleVisualElement(c, ve, args, newComponents, newWires, globals);
|
||||||
|
|
||||||
|
c.add(newWires);
|
||||||
|
for (VisualElement ve : newComponents)
|
||||||
|
c.add(ve);
|
||||||
|
|
||||||
|
return new CircuitHolder(c, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleVisualElement(Circuit c, VisualElement ve, Args args, ArrayList<VisualElement> newComponents, ArrayList<Wire> newWires, Globals globals) throws ElementNotFoundException, NodeException {
|
||||||
ElementAttributes elementAttributes = ve.getElementAttributes();
|
ElementAttributes elementAttributes = ve.getElementAttributes();
|
||||||
String gen = elementAttributes.get(Keys.GENERIC).trim();
|
String gen = elementAttributes.get(Keys.GENERIC).trim();
|
||||||
try {
|
try {
|
||||||
@ -138,6 +157,7 @@ public class ResolveGenerics {
|
|||||||
boolean isCustom = elementTypeDescription instanceof ElementTypeDescriptionCustom;
|
boolean isCustom = elementTypeDescription instanceof ElementTypeDescriptionCustom;
|
||||||
Statement genS = getStatement(gen);
|
Statement genS = getStatement(gen);
|
||||||
Context mod = createContext(c, newComponents, newWires, args)
|
Context mod = createContext(c, newComponents, newWires, args)
|
||||||
|
.declareVar(GLOBALS_KEY, globals)
|
||||||
.declareVar("args", args);
|
.declareVar("args", args);
|
||||||
if (isCustom) {
|
if (isCustom) {
|
||||||
mod.declareFunc("setCircuit", new SetCircuitFunc(ve));
|
mod.declareFunc("setCircuit", new SetCircuitFunc(ve));
|
||||||
@ -152,12 +172,6 @@ public class ResolveGenerics {
|
|||||||
throw new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", ve, gen), e);
|
throw new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", ve, gen), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.add(newWires);
|
|
||||||
for (VisualElement ve : newComponents)
|
|
||||||
c.add(ve);
|
|
||||||
|
|
||||||
return new CircuitHolder(c, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Context createContext(Circuit circuit, ArrayList<VisualElement> newComponents, ArrayList<Wire> newWires, Args args) throws NodeException {
|
private Context createContext(Circuit circuit, ArrayList<VisualElement> newComponents, ArrayList<Wire> newWires, Args args) throws NodeException {
|
||||||
try {
|
try {
|
||||||
@ -310,7 +324,7 @@ public class ResolveGenerics {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key.equals(Context.BASE_FILE_KEY) && !key.equals(SETTINGS_KEY)) {
|
if (!key.equals(Context.BASE_FILE_KEY) && !key.equals(SETTINGS_KEY) && !key.equals(GLOBALS_KEY)) {
|
||||||
contentSet.add(key);
|
contentSet.add(key);
|
||||||
sb.append(key).append(":=");
|
sb.append(key).append(":=");
|
||||||
if (val instanceof String) {
|
if (val instanceof String) {
|
||||||
@ -435,4 +449,26 @@ public class ResolveGenerics {
|
|||||||
return new SubstituteLibrary.AllowSetAttributes(elementAttributes);
|
return new SubstituteLibrary.AllowSetAttributes(elementAttributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class Globals implements HGSMap {
|
||||||
|
private final HashMap<String, Object> map = new HashMap<>();
|
||||||
|
private boolean writeEnable = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hgsMapPut(String key, Object val) throws HGSEvalException {
|
||||||
|
if (writeEnable)
|
||||||
|
map.put(key, val);
|
||||||
|
else
|
||||||
|
throw new HGSEvalException(Lang.get("err_writeInCodeComponentsOnly"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object hgsMapGet(String key) throws HGSEvalException {
|
||||||
|
return map.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lock() {
|
||||||
|
writeEnable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1210,7 +1210,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
|||||||
</string>
|
</string>
|
||||||
<string name="err_multipleGenericInitCodes">Mehrere Initialisierungscodes für die generischen Elemente.</string>
|
<string name="err_multipleGenericInitCodes">Mehrere Initialisierungscodes für die generischen Elemente.</string>
|
||||||
<string name="err_inGenericInitCode">Fehler bei der Analyse des generischen Initialisierungscodes.</string>
|
<string name="err_inGenericInitCode">Fehler bei der Analyse des generischen Initialisierungscodes.</string>
|
||||||
|
<string name="err_writeInCodeComponentsOnly">Globale Variablen können nur in Code-Komponenten beschrieben werden.</string>
|
||||||
|
|
||||||
<string name="err_vgaModeNotDetected_N">Videomodus wurde nicht erkannt ({0})</string>
|
<string name="err_vgaModeNotDetected_N">Videomodus wurde nicht erkannt ({0})</string>
|
||||||
<string name="err_ROM_noFileGivenToLoad">Es ist kein Dateiname für das automatische Neuladen verfügbar!</string>
|
<string name="err_ROM_noFileGivenToLoad">Es ist kein Dateiname für das automatische Neuladen verfügbar!</string>
|
||||||
|
@ -1199,6 +1199,7 @@
|
|||||||
</string>
|
</string>
|
||||||
<string name="err_multipleGenericInitCodes">Multiple initialization codes for the generic elements.</string>
|
<string name="err_multipleGenericInitCodes">Multiple initialization codes for the generic elements.</string>
|
||||||
<string name="err_inGenericInitCode">Error in the analysis of the generic initialization code.</string>
|
<string name="err_inGenericInitCode">Error in the analysis of the generic initialization code.</string>
|
||||||
|
<string name="err_writeInCodeComponentsOnly">Global variables can only be written in code components.</string>
|
||||||
|
|
||||||
<string name="err_ROM_noFileGivenToLoad">There is no file name available for the automatic reload!</string>
|
<string name="err_ROM_noFileGivenToLoad">There is no file name available for the automatic reload!</string>
|
||||||
<string name="err_virtualSignal_N_DeclaredTwiceInLine_N">Virtual signal {0} declared twice in line {1}!</string>
|
<string name="err_virtualSignal_N_DeclaredTwiceInLine_N">Virtual signal {0} declared twice in line {1}!</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user