mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-17 10:55:04 +00:00
Added projects and basic build scripts. Project for scripting engine, API, Main 1.7 version and one for each mod supported in 1.7.
This commit is contained in:
1 parent
219106f392
commit
38b78ce305
281 files changed
+25090
-49
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package stanhebben.zenscript.expression;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeAny;
|
||||
import stanhebben.zenscript.type.ZenTypeArrayBasic;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class ExpressionArray extends Expression {
|
||||
private final Expression[] contents;
|
||||
private final ZenTypeArrayBasic type;
|
||||
|
||||
public ExpressionArray(ZenPosition position, Expression... contents) {
|
||||
super(position);
|
||||
|
||||
this.contents = contents;
|
||||
type = new ZenTypeArrayBasic(ZenTypeAny.INSTANCE);
|
||||
}
|
||||
|
||||
public ExpressionArray(ZenPosition position, Expression[] contents, ZenTypeArrayBasic type) {
|
||||
super(position);
|
||||
this.contents = contents;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
|
||||
if (type instanceof ZenTypeArrayBasic) {
|
||||
ZenTypeArrayBasic arrayType = (ZenTypeArrayBasic) type;
|
||||
Expression[] newContents = new Expression[contents.length];
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
newContents[i] = contents[i].cast(position, environment, arrayType.getBaseType());
|
||||
}
|
||||
|
||||
return new ExpressionArray(getPosition(), newContents, arrayType);
|
||||
} else if (this.type.canCastImplicit(type, environment)) {
|
||||
return this.type.cast(position, environment, this, type);
|
||||
} else {
|
||||
environment.error(position, "cannot cast " + this.type + " to " + type);
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(boolean result, IEnvironmentMethod environment) {
|
||||
Type baseType = type.getBaseType().toASMType();
|
||||
|
||||
MethodOutput output = environment.getOutput();
|
||||
output.constant(contents.length);
|
||||
output.newArray(baseType);
|
||||
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
output.dup();
|
||||
output.constant(i);
|
||||
contents[i].compile(result, environment);
|
||||
output.arrayStore(baseType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user