use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class IOverloadable method getOverloadPriority.
default int getOverloadPriority() {
final Annotation annotation = this.getAnnotation(Types.OVERLOADPRIORITY_CLASS);
if (annotation == null) {
return 0;
}
final IValue value = annotation.getArguments().getFirst();
return value == null ? OverloadPriority.DEFAULT_PRIORITY : value.intValue();
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class StatementList method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
if (this.valueCount <= 0) {
return Types.isVoid(type) ? this : null;
}
context = context.push(this);
final IValue value = this.values[this.valueCount - 1];
if (Types.isVoid(type) && !value.isStatement()) {
final IValue applyStatementCall = resolveApplyStatement(markers, context, value);
if (applyStatementCall != null) {
this.returnType = type;
this.values[this.valueCount - 1] = applyStatementCall;
return this;
}
}
final IValue typed = TypeChecker.convertValue(value, type, typeContext, markers, context, RETURN_MARKER_SUPPLIER);
context.pop();
if (typed != null) {
this.values[this.valueCount - 1] = typed;
this.returnType = typed.getType();
}
return this;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class StatementList method resolveApplyStatement.
private static IValue resolveApplyStatement(MarkerList markers, IContext context, IValue resolvedValue) {
final ArgumentList arguments = new ArgumentList(resolvedValue);
final IValue implicitValue = context.resolveImplicit(null);
if (implicitValue != null) {
final IValue call = resolveApplyStatement(markers, context, arguments, implicitValue);
if (call != null) {
return call;
}
}
return resolveApplyStatement(markers, context, arguments, null);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class CompleteCommand method execute.
@Override
public void execute(DyvilREPL repl, String argument) {
final IContext context = repl.getContext().getContext();
if (argument == null) {
// REPL Variables
this.printREPLMembers(repl, "");
return;
}
final int dotIndex = argument.lastIndexOf('.');
if (dotIndex <= 0) {
// REPL Variable Completions
this.printREPLMembers(repl, Qualifier.qualify(argument));
return;
}
final String expression = argument.substring(0, dotIndex);
final String memberStart = Qualifier.qualify(argument.substring(dotIndex + 1));
final MarkerList markers = new MarkerList(Markers.INSTANCE);
final TokenList tokens = new DyvilLexer(markers, DyvilSymbols.INSTANCE).tokenize(expression);
new ParserManager(DyvilSymbols.INSTANCE, tokens.iterator(), markers).parse(new ExpressionParser((IValue value) -> {
value.resolveTypes(markers, context);
value = value.resolve(markers, context);
value.checkTypes(markers, context);
if (!markers.isEmpty()) {
// Print Errors, if any
final boolean colors = repl.getCompiler().config.useAnsiColors();
final StringBuilder buffer = new StringBuilder();
markers.log(new LineSource(expression), buffer, colors);
repl.getOutput().println(buffer);
}
try {
this.printCompletions(repl, memberStart, value);
} catch (Throwable throwable) {
throwable.printStackTrace(repl.getErrorOutput());
}
}));
}
Aggregations