mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-19 11:49:05 +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,98 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.expression;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.definitions.ParsedFunctionArgument;
|
||||
import stanhebben.zenscript.statements.Statement;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeAny;
|
||||
import stanhebben.zenscript.type.ZenTypeFunction;
|
||||
import stanhebben.zenscript.type.ZenTypeNative;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class ExpressionFunction extends Expression {
|
||||
private final List<ParsedFunctionArgument> arguments;
|
||||
private final ZenType returnType;
|
||||
private final Statement[] statements;
|
||||
|
||||
private final ZenTypeFunction functionType;
|
||||
|
||||
public ExpressionFunction(ZenPosition position, List<ParsedFunctionArgument> arguments, ZenType returnType, Statement[] statements) {
|
||||
super(position);
|
||||
|
||||
this.arguments = arguments;
|
||||
this.returnType = returnType;
|
||||
this.statements = statements;
|
||||
|
||||
ZenType[] argumentTypes = new ZenType[arguments.size()];
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
argumentTypes[i] = arguments.get(i).getType();
|
||||
}
|
||||
functionType = new ZenTypeFunction(returnType, argumentTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
|
||||
if (type instanceof ZenTypeNative) {
|
||||
ZenTypeNative nativeType = (ZenTypeNative) type;
|
||||
Class nativeClass = nativeType.getNativeClass();
|
||||
if (nativeClass.isInterface() && nativeClass.getMethods().length == 1) {
|
||||
// functional interface
|
||||
Method method = nativeClass.getMethods()[0];
|
||||
if (returnType != ZenTypeAny.INSTANCE
|
||||
&& !returnType.canCastImplicit(environment.getType(method.getGenericReturnType()), environment)) {
|
||||
environment.error(position, "return type not compatible");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
if (arguments.size() != method.getParameterTypes().length) {
|
||||
environment.error(position, "number of arguments incorrect");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
ZenType argumentType = environment.getType(method.getGenericParameterTypes()[i]);
|
||||
if (arguments.get(i).getType() != ZenTypeAny.INSTANCE
|
||||
&& !argumentType.canCastImplicit(arguments.get(i).getType(), environment)) {
|
||||
environment.error(position, "argument " + i + " doesn't match");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
}
|
||||
|
||||
return new ExpressionJavaLambda(
|
||||
position,
|
||||
nativeClass,
|
||||
arguments,
|
||||
statements,
|
||||
environment.getType(nativeClass));
|
||||
} else {
|
||||
environment.error(position, type.toString() + " is not a functional interface");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
} else {
|
||||
environment.error(position, "Cannot cast a function literal to " + type.toString());
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType() {
|
||||
return functionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(boolean result, IEnvironmentMethod environment) {
|
||||
// TODO: implement
|
||||
throw new UnsupportedOperationException("not yet implemented");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user