Skip to content

Commit

Permalink
Begin work on an integer pool for CInt
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Oct 22, 2018
1 parent 430960a commit 3d6d5af
Show file tree
Hide file tree
Showing 53 changed files with 389 additions and 277 deletions.
32 changes: 16 additions & 16 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public Construct item(MCItemStack is, Target t) {

CArray ret = CArray.GetAssociativeArray(t);
ret.set("name", new CString(is.getType().getName(), t), t);
ret.set("qty", new CInt(is.getAmount(), t), t);
ret.set("qty", CInt.getFromPool(is.getAmount(), t), t);
ret.set("meta", itemMeta(is, t), t);
return ret;
}
Expand Down Expand Up @@ -413,7 +413,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
ma.set("display", display, t);
ma.set("lore", lore, t);
ma.set("enchants", enchants(meta.getEnchants(), t), t);
ma.set("repair", new CInt(meta.getRepairCost(), t), t);
ma.set("repair", CInt.getFromPool(meta.getRepairCost(), t), t);

Set<MCItemFlag> itemFlags = meta.getItemFlags();
CArray flagArray = new CArray(t);
Expand All @@ -425,7 +425,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
ma.set("flags", flagArray, t);

if(is.getType().getMaxDurability() > 0) {
ma.set("damage", new CInt(meta.getDamage(), t), t);
ma.set("damage", CInt.getFromPool(meta.getDamage(), t), t);
ma.set("unbreakable", CBoolean.get(meta.isUnbreakable()), t);
}

Expand Down Expand Up @@ -458,11 +458,11 @@ public Construct itemMeta(MCItemStack is, Target t) {
} else if(bs instanceof MCCreatureSpawner) {
MCCreatureSpawner mccs = (MCCreatureSpawner) bs;
ma.set("spawntype", mccs.getSpawnedType().name());
ma.set("delay", new CInt(mccs.getDelay(), t), t);
ma.set("delay", CInt.getFromPool(mccs.getDelay(), t), t);
} else if(bs instanceof MCBrewingStand) {
MCBrewingStand brewStand = (MCBrewingStand) bs;
ma.set("brewtime", new CInt(brewStand.getBrewingTime(), t), t);
ma.set("fuel", new CInt(brewStand.getFuelLevel(), t), t);
ma.set("brewtime", CInt.getFromPool(brewStand.getBrewingTime(), t), t);
ma.set("fuel", CInt.getFromPool(brewStand.getFuelLevel(), t), t);
MCBrewerInventory inv = brewStand.getInventory();
CArray invData = CArray.GetAssociativeArray(t);
if(inv.getFuel().getAmount() != 0) {
Expand All @@ -483,8 +483,8 @@ public Construct itemMeta(MCItemStack is, Target t) {
ma.set("inventory", invData, t);
} else if(bs instanceof MCFurnace) {
MCFurnace furnace = (MCFurnace) bs;
ma.set("burntime", new CInt(furnace.getBurnTime(), t), t);
ma.set("cooktime", new CInt(furnace.getCookTime(), t), t);
ma.set("burntime", CInt.getFromPool(furnace.getBurnTime(), t), t);
ma.set("cooktime", CInt.getFromPool(furnace.getCookTime(), t), t);
MCFurnaceInventory inv = furnace.getInventory();
CArray invData = CArray.GetAssociativeArray(t);
if(inv.getResult().getAmount() != 0) {
Expand All @@ -509,7 +509,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
} else if(meta instanceof MCFireworkMeta) {
MCFireworkMeta mcfm = (MCFireworkMeta) meta;
CArray firework = CArray.GetAssociativeArray(t);
firework.set("strength", new CInt(mcfm.getStrength(), t), t);
firework.set("strength", CInt.getFromPool(mcfm.getStrength(), t), t);
CArray fe = new CArray(t);
for(MCFireworkEffect effect : mcfm.getEffects()) {
fe.push(fireworkEffect(effect, t), t);
Expand Down Expand Up @@ -585,7 +585,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
ma.set("color", color(mapcolor, t), t);
}
if(mm.hasMapId()) {
ma.set("mapid", new CInt(mm.getMapId(), t), t);
ma.set("mapid", CInt.getFromPool(mm.getMapId(), t), t);
} else {
ma.set("mapid", CNull.NULL, t);
}
Expand Down Expand Up @@ -1015,9 +1015,9 @@ public AbstractCREException exception(CArray exception, Target t) throws ClassNo
*/
public CArray color(MCColor color, Target t) {
CArray ca = CArray.GetAssociativeArray(t);
ca.set("r", new CInt(color.getRed(), t), t);
ca.set("g", new CInt(color.getGreen(), t), t);
ca.set("b", new CInt(color.getBlue(), t), t);
ca.set("r", CInt.getFromPool(color.getRed(), t), t);
ca.set("g", CInt.getFromPool(color.getGreen(), t), t);
ca.set("b", CInt.getFromPool(color.getBlue(), t), t);
return ca;
}

Expand Down Expand Up @@ -1164,7 +1164,7 @@ public CArray enchants(Map<MCEnchantment, Integer> map, Target t) {
for(Map.Entry<MCEnchantment, Integer> entry : map.entrySet()) {
CArray enchant = CArray.GetAssociativeArray(t);
enchant.set("etype", new CString(entry.getKey().getName(), t), t);
enchant.set("elevel", new CInt(entry.getValue(), t), t);
enchant.set("elevel", CInt.getFromPool(entry.getValue(), t), t);
ret.set(entry.getKey().getKey(), enchant, t);
}
return ret;
Expand Down Expand Up @@ -1208,8 +1208,8 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
CArray ea = CArray.GetAssociativeArray(t);
for(MCLivingEntity.MCEffect eff : effectList) {
CArray effect = CArray.GetAssociativeArray(t);
effect.set("id", new CInt(eff.getPotionEffectType().getId(), t), t);
effect.set("strength", new CInt(eff.getStrength(), t), t);
effect.set("id", CInt.getFromPool(eff.getPotionEffectType().getId(), t), t);
effect.set("strength", CInt.getFromPool(eff.getStrength(), t), t);
effect.set("seconds", new CDouble(eff.getTicksRemaining() / 20.0, t), t);
effect.set("ambient", CBoolean.get(eff.isAmbient()), t);
effect.set("particles", CBoolean.get(eff.hasParticles()), t);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/laytonsmith/core/Static.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static <T extends Construct> T getObject(Construct construct, Target t, C
public static CNumber getNumber(Number number, Target t) {
long longValue = number.longValue();
double doubleValue = number.doubleValue();
return longValue == doubleValue ? new CInt(longValue, t) : new CDouble(doubleValue, t);
return longValue == doubleValue ? CInt.getFromPool(longValue, t) : new CDouble(doubleValue, t);
}

/**
Expand Down Expand Up @@ -487,20 +487,20 @@ public static Construct resolveConstruct(String val, Target t) throws ConfigRunt
}
if(VALID_HEX.matcher(val).matches()) {
//Hex number
return new CInt(Long.parseLong(val.substring(2), 16), t);
return CInt.getFromPool(Long.parseLong(val.substring(2), 16), t);
}
if(INVALID_BINARY.matcher(val).matches()) {
throw new CREFormatException("Binary numbers must only contain digits 0 and 1, but \"" + val + "\" was found.", t);
}
if(VALID_BINARY.matcher(val).matches()) {
//Binary number
return new CInt(Long.parseLong(val.substring(2), 2), t);
return CInt.getFromPool(Long.parseLong(val.substring(2), 2), t);
}
if(INVALID_OCTAL.matcher(val).matches()) {
throw new CREFormatException("Octal numbers must only contain digits 0-7, but \"" + val + "\" was found.", t);
}
if(VALID_OCTAL.matcher(val).matches()) {
return new CInt(Long.parseLong(val.substring(2), 8), t);
return CInt.getFromPool(Long.parseLong(val.substring(2), 8), t);
}
if(INVALID_DECIMAL.matcher(val).matches()) {
throw new CREFormatException("Decimal numbers must only contain digits, but \"" + val + "\" was found.", t);
Expand All @@ -509,7 +509,7 @@ public static Construct resolveConstruct(String val, Target t) throws ConfigRunt
return new CDecimal(val.substring(2), t);
}
try {
return new CInt(Long.parseLong(val), t);
return CInt.getFromPool(Long.parseLong(val), t);
} catch (NumberFormatException e) {
try {
if(!(val.contains(" ") || val.contains("\t"))) {
Expand Down Expand Up @@ -1328,7 +1328,7 @@ public static Construct getMSObject(Object object, Target t) {
} else if(object instanceof Boolean) {
return CBoolean.get((boolean) object);
} else if((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer) || (object instanceof Long)) {
return new CInt((long) object, t);
return CInt.getFromPool((long) object, t);
} else if((object instanceof Float) || (object instanceof Double)) {
return new CDouble((double) object, t);
} else if(object instanceof Character) {
Expand Down Expand Up @@ -1366,21 +1366,21 @@ public String getString(CResource res) {
short[] array = (short[]) object;
CArray r = new CArray(t);
for(short s : array) {
r.push(new CInt(s, t), t);
r.push(CInt.getFromPool(s, t), t);
}
return r;
} else if(object instanceof int[]) {
int[] array = (int[]) object;
CArray r = new CArray(t);
for(int i : array) {
r.push(new CInt(i, t), t);
r.push(CInt.getFromPool(i, t), t);
}
return r;
} else if(object instanceof long[]) {
long[] array = (long[]) object;
CArray r = new CArray(t);
for(long l : array) {
r.push(new CInt(l, t), t);
r.push(CInt.getFromPool(l, t), t);
}
return r;
} else if(object instanceof float[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private Construct resolveIdentifier(Token t) throws ConfigCompileException {
case DOUBLE:
return new CDouble(t.val(), t.getTarget());
case INTEGER:
return new CInt(t.val(), t.getTarget());
return CInt.getFromPool(t.val(), t.getTarget());
default:
throw new ConfigCompileException("Unexpected identifier? Found '" + t.val() + "' but was not any expected value.", t.getTarget());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private static Construct tokenToConstruct(Token t) {
return new CBareString(t.val(), t.getTarget());
}
if(t.type == Token.TType.INTEGER) {
return new CInt(Long.parseLong(t.val()), t.getTarget());
return CInt.getFromPool(Long.parseLong(t.val()), t.getTarget());
}
if(t.type == Token.TType.DOUBLE) {
return new CDouble(Double.parseDouble(t.val()), t.getTarget());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/laytonsmith/core/constructs/CArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public Set<Construct> keySet() {
if(!associativeMode) {
set = new LinkedHashSet<>(array.size());
for(int i = 0; i < array.size(); i++) {
set.add(new CInt(i, Target.UNKNOWN));
set.add(CInt.getFromPool(i, Target.UNKNOWN));
}
} else {
set = new LinkedHashSet<>(associativeArray.size());
Expand Down Expand Up @@ -368,7 +368,7 @@ public void set(Construct index, Construct c, Target t) {
}

public final void set(int index, Construct c, Target t) {
this.set(new CInt(index, t), c, t);
this.set(CInt.getFromPool(index, t), c, t);
}

/* Shortcuts */
Expand Down Expand Up @@ -409,12 +409,12 @@ public Construct get(Construct index, Target t) {
}

public final Construct get(long index, Target t) {
return this.get(new CInt(index, t), t);
return this.get(CInt.getFromPool(index, t), t);
}

@Override
public final Construct get(int index, Target t) {
return this.get(new CInt(index, t), t);
return this.get(CInt.getFromPool(index, t), t);
}

@Override
Expand Down Expand Up @@ -471,7 +471,7 @@ public CArray indexesOf(Construct value) {
} else {
for(int i = 0; i < array.size(); i++) {
if(BasicLogic.equals.doEquals(array.get(i), value)) {
ret.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN);
ret.push(CInt.getFromPool(i, Target.UNKNOWN), Target.UNKNOWN);
}
}
}
Expand Down Expand Up @@ -643,7 +643,7 @@ private String normalizeConstruct(Construct c) {
* @return
*/
public Construct remove(int i) {
return remove(new CInt(i, Target.UNKNOWN));
return remove(CInt.getFromPool(i, Target.UNKNOWN));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/laytonsmith/core/constructs/CByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public Set<Construct> keySet() {
public Construct get(Construct index, Target t) throws ConfigRuntimeException {
int i = Static.getInt32(index, t);
byte b = getByte(i);
return new CInt(b, t);
return CInt.getFromPool(b, t);
}

@Override
Expand Down Expand Up @@ -556,7 +556,7 @@ public void set(Construct index, Construct c, Target t) {
public Construct get(Construct index, Target t) {
int i = Static.getInt32(index, t);
try {
return new CInt(backing[i], t);
return CInt.getFromPool(backing[i], t);
} catch (ArrayIndexOutOfBoundsException e) {
throw new CRERangeException("Index out of range. Found " + i + ", but array length is only " + backing.length, t);
}
Expand Down
Loading

0 comments on commit 3d6d5af

Please sign in to comment.