Hex/bin logic number support
This commit is contained in:
@@ -189,17 +189,28 @@ public class LAssembler{
|
|||||||
return putConst("___" + symbol, symbol.substring(1, symbol.length() - 1).replace("\\n", "\n")).id;
|
return putConst("___" + symbol, symbol.substring(1, symbol.length() - 1).replace("\\n", "\n")).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//remove spaces for non-strings
|
||||||
|
symbol = symbol.replace(' ', '_');
|
||||||
|
|
||||||
try{
|
try{
|
||||||
double value = Double.parseDouble(symbol);
|
double value = parseDouble(symbol);
|
||||||
if(Double.isNaN(value) || Double.isInfinite(value)) value = 0;
|
if(Double.isNaN(value) || Double.isInfinite(value)) value = 0;
|
||||||
|
|
||||||
//this creates a hidden const variable with the specified value
|
//this creates a hidden const variable with the specified value
|
||||||
String key = "___" + value;
|
return putConst("___" + value, value).id;
|
||||||
return putConst(key, value).id;
|
|
||||||
}catch(NumberFormatException e){
|
}catch(NumberFormatException e){
|
||||||
return putVar(symbol).id;
|
return putVar(symbol).id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double parseDouble(String symbol) throws NumberFormatException{
|
||||||
|
//parse hex/binary syntax
|
||||||
|
if(symbol.startsWith("0b")) return Long.parseLong(symbol.substring(2), 2);
|
||||||
|
if(symbol.startsWith("0x")) return Long.parseLong(symbol.substring(2), 16);
|
||||||
|
|
||||||
|
return Double.parseDouble(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
/** Adds a constant value by name. */
|
/** Adds a constant value by name. */
|
||||||
public BVar putConst(String name, Object value){
|
public BVar putConst(String name, Object value){
|
||||||
BVar var = putVar(name);
|
BVar var = putVar(name);
|
||||||
|
|||||||
@@ -491,7 +491,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
|||||||
selected = null;
|
selected = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user