use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class IValue method fromObject.
static IValue fromObject(Object o) {
if (o == null) {
return new NullValue();
}
Class c = o.getClass();
if (c == Character.class) {
return new CharValue(null, o.toString(), true);
} else if (c == Boolean.class) {
return new BooleanValue((Boolean) o);
} else if (c == Integer.class) {
return new IntValue((Integer) o);
} else if (c == Long.class) {
return new LongValue((Long) o);
} else if (c == Float.class) {
return new FloatValue((Float) o);
} else if (c == Double.class) {
return new DoubleValue((Double) o);
} else if (c == String.class) {
return new StringValue((String) o);
} else if (c == int[].class) {
final ArrayExpr valueList = new ArrayExpr();
final ArgumentList values = valueList.getValues();
valueList.setElementType(Types.INT);
for (int i : (int[]) o) {
values.add(new IntValue(i));
}
return valueList;
} else if (c == long[].class) {
final ArrayExpr valueList = new ArrayExpr();
final ArgumentList values = valueList.getValues();
valueList.setElementType(Types.LONG);
for (long l : (long[]) o) {
values.add(new LongValue(l));
}
return valueList;
} else if (c == float[].class) {
final ArrayExpr valueList = new ArrayExpr();
final ArgumentList values = valueList.getValues();
valueList.setElementType(Types.FLOAT);
for (float f : (float[]) o) {
values.add(new FloatValue(f));
}
return valueList;
} else if (c == double[].class) {
final ArrayExpr valueList = new ArrayExpr();
final ArgumentList values = valueList.getValues();
valueList.setElementType(Types.DOUBLE);
for (double d : (double[]) o) {
values.add(new DoubleValue(d));
}
return valueList;
} else if (c == dyvilx.tools.asm.Type.class) {
dyvilx.tools.asm.Type type = (dyvilx.tools.asm.Type) o;
return new ClassOperator(Types.fromASMType(type));
}
return null;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class MapExpr method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
if (!Types.isSuperClass(type, MapType.MapTypes.IMMUTABLE_MAP_CLASS.getClassType())) {
final Annotation annotation = type.getTheClass().getAnnotation(LazyTypes.MAP_CONVERTIBLE_CLASS);
if (annotation == null) {
return null;
}
// [ x : y, ... ] -> Type(x : y, ...))
final int size = this.keys.size();
final ArgumentList arguments = new ArgumentList(size);
for (int i = 0; i < size; i++) {
arguments.add(new ColonOperator(this.keys.get(i), this.values.get(i)));
}
return new LiteralConversion(this, annotation, arguments).withType(type, typeContext, markers, context);
}
final int size = this.keys.size();
final IType keyType = this.keyType = Types.resolveTypeSafely(type, MapType.MapTypes.KEY_VARIABLE);
final IType valueType = this.valueType = Types.resolveTypeSafely(type, MapType.MapTypes.VALUE_VARIABLE);
for (int i = 0; i < size; i++) {
final IValue key = TypeChecker.convertValue(this.keys.get(i), keyType, typeContext, markers, context, KEY_MARKER_SUPPLIER);
this.keys.set(i, key);
final IValue value = TypeChecker.convertValue(this.values.get(i), valueType, typeContext, markers, context, VALUE_MARKER_SUPPLIER);
this.values.set(i, value);
}
return this;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ApplyAccess method resolve.
@Override
public IValue resolve(MarkerList markers, IContext context) {
// -> with(x..., { statements })
if (this.arguments.size() == 1 && this.receiver instanceof ICall) {
final ICall call = (ICall) this.receiver;
IValue argument = this.arguments.getFirst();
if (argument instanceof Closure) {
argument = argument.resolve(markers, context);
final ArgumentList oldArgs = call.getArguments();
call.resolveReceiver(markers, context);
call.resolveArguments(markers, context);
call.setArguments(oldArgs.appended(null, argument));
final IValue resolvedCall = call.resolveCall(markers, context, false);
if (resolvedCall != null) {
return resolvedCall;
}
// Revert
call.setArguments(oldArgs);
this.receiver = call.resolveCall(markers, context, true);
return this.resolveCall(markers, context, true);
}
}
return super.resolve(markers, context);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ApplyAccess method toCompoundAssignment.
@Override
public IValue toCompoundAssignment(IValue rhs, SourcePosition position, MarkerList markers, IContext context, SideEffectHelper helper) {
// x(y...) (op)= z
// -> x(y...) = x(y...) (op) z
// note that x and y... are each only evaluated once
final IValue applyReceiver = helper.processValue(this.receiver);
final ArgumentList applyArguments = helper.processArguments(this.arguments);
this.arguments = applyArguments;
this.receiver = applyReceiver;
return new ApplyAssignment(position, applyReceiver, applyArguments, rhs).resolveCall(markers, context, true);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ICall method toLambda.
default IValue toLambda(MarkerList markers, IContext context, int wildcards) {
SourcePosition position = this.getPosition();
final IParameter[] parameters = new IParameter[wildcards];
for (int i = 0; i < wildcards; i++) {
parameters[i] = new CodeParameter(null, position, Name.fromRaw("wildcard$" + i), Types.UNKNOWN, new AttributeList());
}
int parIndex = 0;
final IValue receiver = this.getReceiver();
if (receiver != null && receiver.isPartialWildcard()) {
this.setReceiver(receiver.withLambdaParameter(parameters[parIndex++]));
}
final ArgumentList arguments = this.getArguments();
for (int i = 0, size = arguments.size(); i < size; i++) {
final IValue argument = arguments.get(i, null);
if (argument.isPartialWildcard()) {
arguments.set(i, null, argument.withLambdaParameter(parameters[parIndex++]));
}
}
final LambdaExpr lambdaExpr = new LambdaExpr(position, parameters, wildcards);
lambdaExpr.setImplicitParameters(true);
lambdaExpr.setValue(this);
return lambdaExpr.resolve(markers, context);
}
Aggregations