Merge branch 'master' into 1.15
# Conflicts: # src/main/java/carpet/script/CarpetExpression.java
This commit is contained in:
commit
7fae5c92cf
20 files changed
+553
-138
No files matched your search
@@ -2,12 +2,12 @@ package carpet.script.value;
|
||||
|
||||
public interface ContainerValueInterface
|
||||
{
|
||||
public Value put(Value where, Value value);
|
||||
default Value put(Value where, Value value, Value conditions)
|
||||
boolean put(Value where, Value value);
|
||||
default boolean put(Value where, Value value, Value conditions)
|
||||
{
|
||||
return put(where, value);
|
||||
}
|
||||
public Value get(Value where);
|
||||
public boolean has(Value where);
|
||||
public Value delete(Value where);
|
||||
Value get(Value where);
|
||||
boolean has(Value where);
|
||||
boolean delete(Value where);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.ExpressionException;
|
||||
|
||||
public abstract class FrameworkValue extends Value
|
||||
{
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
throw new ExpressionException("Scarpet language component cannot be used");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean()
|
||||
{
|
||||
throw new ExpressionException("Scarpet language component cannot be used");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value clone()
|
||||
{
|
||||
throw new ExpressionException("Scarpet language component cannot be used");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
throw new UnsupportedOperationException("Scarpet language component cannot be used as map key");
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,13 @@ import carpet.script.exception.ExpressionException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FunctionSignatureValue extends Value
|
||||
public class FunctionSignatureValue extends FrameworkValue
|
||||
{
|
||||
private String identifier;
|
||||
private List<String> arguments;
|
||||
private List<String> globals;
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
throw new ExpressionException("Function "+identifier+" is not defined yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean()
|
||||
{
|
||||
throw new ExpressionException("Function "+identifier+" is not defined yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value clone()
|
||||
{
|
||||
throw new ExpressionException("Function "+identifier+" is not defined yet");
|
||||
}
|
||||
public FunctionSignatureValue(String name, List<String> args, List<String> globals)
|
||||
{
|
||||
this.identifier = name;
|
||||
@@ -43,11 +27,7 @@ public class FunctionSignatureValue extends Value
|
||||
}
|
||||
public List<String> getGlobals() {return globals;}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
throw new UnsupportedOperationException("function signature value cannot be used as map key");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package carpet.script.value;
|
||||
|
||||
public class LContainerValue extends FrameworkValue
|
||||
{
|
||||
private ContainerValueInterface container;
|
||||
private Value address;
|
||||
|
||||
public LContainerValue(ContainerValueInterface c, Value v)
|
||||
{
|
||||
container = c;
|
||||
address = v;
|
||||
}
|
||||
|
||||
public ContainerValueInterface getContainer() {return container; }
|
||||
public Value getAddress() {return address; }
|
||||
}
|
||||
@@ -306,7 +306,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value put(Value where, Value value, Value conditionValue)
|
||||
public boolean put(Value where, Value value, Value conditionValue)
|
||||
{
|
||||
String condition = conditionValue.getString();
|
||||
if (condition.equalsIgnoreCase("insert"))
|
||||
@@ -319,11 +319,12 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value put(Value ind, Value value)
|
||||
public boolean put(Value ind, Value value)
|
||||
{
|
||||
return put(ind, value, true, false);
|
||||
}
|
||||
private Value put(Value ind, Value value, boolean replace, boolean extend)
|
||||
|
||||
private boolean put(Value ind, Value value, boolean replace, boolean extend)
|
||||
{
|
||||
if (ind == Value.NULL)
|
||||
{
|
||||
@@ -335,12 +336,14 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
{
|
||||
items.add(value);
|
||||
}
|
||||
return items.get(items.size()-1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int numitems = items.size();
|
||||
int index = (int) NumericValue.asNumber(ind).getLong();
|
||||
if (!(ind instanceof NumericValue))
|
||||
return false;
|
||||
int index = (int)((NumericValue) ind).getLong();
|
||||
if (index < 0)
|
||||
{
|
||||
long range = abs(index) / numitems;
|
||||
@@ -350,7 +353,8 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
if (replace)
|
||||
{
|
||||
while (index >= items.size()) items.add(Value.NULL);
|
||||
return items.set(index, value);
|
||||
items.set(index, value);
|
||||
return true;
|
||||
}
|
||||
while (index > items.size()) items.add(Value.NULL);
|
||||
|
||||
@@ -359,11 +363,10 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
Iterable<Value> iterable = ((AbstractListValue) value)::iterator;
|
||||
List<Value> appendix = StreamSupport.stream( iterable.spliterator(), false).collect(Collectors.toList());
|
||||
items.addAll(index, appendix );
|
||||
return items.get(index+appendix.size()-1);
|
||||
return true;
|
||||
}
|
||||
items.add(index, value);
|
||||
return value;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,14 +389,16 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value delete(Value where)
|
||||
public boolean delete(Value where)
|
||||
{
|
||||
long index = NumericValue.asNumber(where).getLong();
|
||||
if (!(where instanceof NumericValue) || items.isEmpty()) return false;
|
||||
long index = ((NumericValue) where).getLong();
|
||||
int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
index = index % numitems;
|
||||
return items.remove((int)index);
|
||||
items.remove((int)index);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -177,21 +177,17 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value delete(Value where)
|
||||
public boolean delete(Value where)
|
||||
{
|
||||
Value ret = map.remove(where);
|
||||
if (ret == null)
|
||||
return Value.NULL;
|
||||
return ret;
|
||||
return ret != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value put(Value key, Value value)
|
||||
public boolean put(Value key, Value value)
|
||||
{
|
||||
Value ret = map.put(key, value);
|
||||
if (ret == null)
|
||||
return Value.NULL;
|
||||
return ret;
|
||||
return ret != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -191,7 +191,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
|
||||
private Tag getTag()
|
||||
public Tag getTag()
|
||||
{
|
||||
if (nbtTag == null)
|
||||
nbtTag = nbtSupplier.get();
|
||||
@@ -210,7 +210,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
{
|
||||
if (o instanceof NBTSerializableValue)
|
||||
return getTag().equals(((NBTSerializableValue) o).getTag());
|
||||
return super.equals((Value)o);
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,13 +240,13 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value put(Value where, Value value)
|
||||
public boolean put(Value where, Value value)
|
||||
{
|
||||
return put(where, value, new StringValue("replace"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value put(Value where, Value value, Value conditions)
|
||||
public boolean put(Value where, Value value, Value conditions)
|
||||
{
|
||||
/// WIP
|
||||
|
||||
@@ -272,14 +272,15 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (modifiedTag != null)
|
||||
{
|
||||
replaceTag(modifiedTag);
|
||||
return true;
|
||||
}
|
||||
return this;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -412,13 +413,13 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value delete(Value where)
|
||||
public boolean delete(Value where)
|
||||
{
|
||||
NbtPathArgumentType.NbtPath path = cachePath(where.getString());
|
||||
Tag tag = getTag().copy();
|
||||
int removed = path.remove(tag);
|
||||
if (removed > 0) replaceTag(tag);
|
||||
return new NumericValue(removed);
|
||||
return removed > 0;
|
||||
}
|
||||
|
||||
public static class InventoryLocator
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
return getString().compareTo(o.getString());
|
||||
}
|
||||
|
||||
@Override // for hashmap key access
|
||||
@Override // for hashmap key access, and == operator
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
if (o instanceof Value)
|
||||
@@ -124,12 +124,6 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
return false;
|
||||
}
|
||||
|
||||
// for general use
|
||||
public boolean equals(final Value o)
|
||||
{
|
||||
return this.compareTo(o)==0;
|
||||
}
|
||||
|
||||
public void assertAssignable()
|
||||
{
|
||||
if (boundVariable == null || boundVariable.startsWith("_"))
|
||||
|
||||
Reference in new issue
Block a user