-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,089 additions
and
475 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
package leekscript.common; | ||
|
||
import leekscript.compiler.JavaWriter; | ||
|
||
public class IntervalType extends Type { | ||
|
||
private final Type type; | ||
|
||
public IntervalType(Type type) { | ||
this(type, false); | ||
} | ||
|
||
public IntervalType() { | ||
super("interval", "t", "IntervalLeekValue", "IntervalLeekValue", "new IntervalLeekValue()"); | ||
public IntervalType(Type type, boolean infinite) { | ||
super(infinite ? "Interval<infinite>" : type == Type.VOID ? "Interval<empty>" : type == Type.ANY ? "Interval" : "Interval<" + type.toString() + ">", "t", "IntervalLeekValue", "IntervalLeekValue", type == Type.INT ? "new IntegerIntervalLeekValue()" : "new RealIntervalLeekValue()"); | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public Type element() { | ||
public CastType accepts(Type type) { | ||
if (type instanceof IntervalType at) { | ||
var cast = this.type.accepts(at.type); | ||
if (cast.ordinal() >= CastType.SAFE_DOWNCAST.ordinal()) return CastType.UNSAFE_DOWNCAST; | ||
return cast; | ||
} | ||
return super.accepts(type); | ||
} | ||
|
||
@Override | ||
public Type key() { | ||
return Type.INT; | ||
} | ||
|
||
@Override | ||
public Type element() { | ||
return type; | ||
} | ||
|
||
public boolean canBeIterable() { | ||
return true; | ||
} | ||
|
||
public boolean isIterable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getJavaPrimitiveName(int version) { | ||
return type == Type.ANY ? "IntervalLeekValue" : type == Type.INT ? "IntegerIntervalLeekValue" : "RealIntervalLeekValue"; | ||
} | ||
|
||
@Override | ||
public String getJavaName(int version) { | ||
return type == Type.ANY ? "IntervalLeekValue" : type == Type.INT ? "IntegerIntervalLeekValue" : "RealIntervalLeekValue"; | ||
} | ||
|
||
@Override | ||
public String getDefaultValue(JavaWriter writer, int version) { | ||
return type == Type.INT ? "new IntegerIntervalLeekValue(" + writer.getAIThis() + ")" : "new RealIntervalLeekValue(" + writer.getAIThis() + ")"; | ||
} | ||
} |
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
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.