-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix default constructors in classes + supported them for subclasses
- Implemented super calls
- Loading branch information
1 parent
768f1f8
commit f325e2f
Showing
34 changed files
with
321 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...el/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/BoundSuperCallable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.openzen.zenscript.codemodel.compilation.impl; | ||
|
||
import org.openzen.zencode.shared.CodePosition; | ||
import org.openzen.zenscript.codemodel.compilation.*; | ||
import org.openzen.zenscript.codemodel.expression.Expression; | ||
import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; | ||
import org.openzen.zenscript.codemodel.type.TypeID; | ||
|
||
import java.math.MathContext; | ||
|
||
public class BoundSuperCallable implements CompilingCallable { | ||
private final ExpressionCompiler compiler; | ||
private final InstanceCallable method; | ||
private final Expression target; | ||
private final TypeID[] typeArguments; | ||
|
||
public BoundSuperCallable(ExpressionCompiler compiler, InstanceCallable method, Expression target, TypeID[] typeArguments) { | ||
this.compiler = compiler; | ||
this.method = method; | ||
this.target = target; | ||
this.typeArguments = typeArguments; | ||
} | ||
|
||
@Override | ||
public Expression call(CodePosition position, CompilingExpression[] arguments) { | ||
MatchedCallArguments<InstanceCallableMethod> matched = MatchedCallArguments.match(compiler, position, method.overloads, null, typeArguments, arguments); | ||
return matched.eval(compiler.at(position), (builder, method, args) -> builder.callSuper((MethodInstance) method, target, args)); | ||
} | ||
|
||
@Override | ||
public CastedExpression casted(CodePosition position, CastedEval cast, CompilingExpression[] arguments) { | ||
MatchedCallArguments<InstanceCallableMethod> matched = MatchedCallArguments.match(compiler, position, method.overloads, cast.type, typeArguments, arguments); | ||
return matched.cast(compiler.at(position), cast, (builder, method, args) -> builder.callSuper((MethodInstance) method, target, args)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallSuperExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.openzen.zenscript.codemodel.expression; | ||
|
||
import org.openzen.zencode.shared.CodePosition; | ||
import org.openzen.zenscript.codemodel.constant.CompileTimeConstant; | ||
import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; | ||
|
||
import java.util.Optional; | ||
|
||
public class CallSuperExpression extends Expression { | ||
public final Expression target; | ||
public final MethodInstance method; | ||
public final CallArguments arguments; | ||
|
||
public CallSuperExpression(CodePosition position, Expression target, MethodInstance method, CallArguments arguments) { | ||
super(position, method.getHeader().getReturnType(), multiThrow(position, arguments.arguments)); | ||
|
||
this.target = target; | ||
this.method = method; | ||
this.arguments = arguments; | ||
} | ||
|
||
@Override | ||
public <T> T accept(ExpressionVisitor<T> visitor) { | ||
return visitor.visitCallSuper(this); | ||
} | ||
|
||
@Override | ||
public <C, R> R accept(C context, ExpressionVisitorWithContext<C, R> visitor) { | ||
return visitor.visitCallSuper(context, this); | ||
} | ||
|
||
@Override | ||
public Expression transform(ExpressionTransformer transformer) { | ||
Expression tTarget = target.transform(transformer); | ||
CallArguments tArguments = arguments.transform(transformer); | ||
return tTarget == target && tArguments == arguments | ||
? this | ||
: new CallSuperExpression(position, tTarget, method, tArguments); | ||
} | ||
|
||
@Override | ||
public Optional<CompileTimeConstant> evaluate() { | ||
CompileTimeConstant[] arguments = new CompileTimeConstant[this.arguments.arguments.length]; | ||
for (int i = 0; i < arguments.length; i++) { | ||
Optional<CompileTimeConstant> argument = this.arguments.arguments[i].evaluate(); | ||
if (argument.isPresent()) { | ||
arguments[i] = argument.get(); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
return method.method.evaluate(this.arguments.typeArguments, arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.