- Rewrote the whole damn typecasting system. Now uses a more flexible and more structure casting rule system.

- Improved function literals. Function recipes are a thing!
- Added mirrored shaped recipes
- Fixed a few "any" type - related errors
- Added environment to the bracket handlers. Breaks existing bracket handlers!!
- Turned JavaMethod into an interface. Can now be used both for existing methods and generated ones. Makes a few things simpler :)
- Added creative and adventure getters to player info
This commit is contained in:
Stan Hebben committed 2014-08-20 11:59:49 +02:00
1 parent c67ad22270
commit 154c2242f9
172 files changed
+5400 -2134

No files matched your search

+12 -1
View File
@@ -9,7 +9,9 @@
<name must-exist="no">runClient</name>
</task-names>
<task-args/>
<task-jvm-args/>
<task-jvm-args>
<arg>-Xdebug</arg>
</task-jvm-args>
</task>
<task>
<display-name>run</display-name>
@@ -22,5 +24,14 @@
<arg>-Dfml.coreMods.load=minetweaker.mc172.transformer.MineTweakerTransformer</arg>
</task-jvm-args>
</task>
<task>
<display-name>run.single</display-name>
<non-blocking>no</non-blocking>
<task-names>
<name must-exist="no">${project}:runClient</name>
</task-names>
<task-args/>
<task-jvm-args/>
</task>
</built-in-tasks>
</gradle-project-properties>
@@ -1,6 +1,7 @@
package minetweaker;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
@@ -23,8 +24,9 @@ public interface IBracketHandler {
*
* If the series of tokens is unrecognized, this method should return null.
*
* @param environment global compilation environment
* @param tokens token stream to be detected
* @return the resolved symbol, or null
*/
public IZenSymbol resolve(List<Token> tokens);
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens);
}
@@ -29,6 +29,7 @@ import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
import stanhebben.zenscript.symbols.SymbolJavaStaticGetter;
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
/**
@@ -333,7 +334,7 @@ public class MineTweakerAPI {
* @return corresponding symbol
*/
public static IZenSymbol getJavaStaticMethodSymbol(Class cls, String name, Class... arguments) {
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
return new SymbolJavaStaticMethod(method);
}
@@ -347,7 +348,7 @@ public class MineTweakerAPI {
* @return corresponding symbol
*/
public static IZenSymbol getJavaStaticGetterSymbol(Class cls, String name) {
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
return new SymbolJavaStaticGetter(method);
}
@@ -379,7 +380,7 @@ public class MineTweakerAPI {
* @param arguments argument types
* @return java method
*/
public static JavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
public static IJavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
}
}
@@ -6,7 +6,6 @@
package minetweaker.api.player;
import java.util.List;
import minetweaker.api.chat.IChatMessage;
import minetweaker.api.data.IData;
import minetweaker.api.item.IItemStack;
@@ -53,5 +52,12 @@ public interface IPlayer {
@ZenGetter("currentItem")
public IItemStack getCurrentItem();
@ZenGetter("creative")
public boolean isCreative();
@ZenGetter("adventure")
public boolean isAdventure();
// not an exposed method. risks abuse
public void openBrowser(String url);
}
@@ -28,28 +28,26 @@ public interface IRecipeManager {
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param mirrored indicates if the mirrored recipe should be valid too (optional)
* @param function recipe function (optional)
*/
@ZenMethod
public void addShaped(
IItemStack output,
IIngredient[][] ingredients,
@Optional boolean mirrored);
@Optional IRecipeFunction function);
/**
* Adds a shaped recipe.
* Adds a mirrored shaped recipe.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param function recipe function (optional)
* @param mirrored indicates if the mirrored recipe should be valid too (optional)
*/
@ZenMethod
public void addShaped(
public void addShapedMirrored(
IItemStack output,
IIngredient[][] ingredients,
IRecipeFunction function,
@Optional boolean mirrored);
@Optional IRecipeFunction function);
/**
* Adds a shapeless recipe.
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import minetweaker.IBracketHandler;
@@ -35,6 +36,7 @@ import stanhebben.zenscript.symbols.SymbolPackage;
import stanhebben.zenscript.symbols.SymbolType;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeNative;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -105,9 +107,9 @@ public class GlobalRegistry {
}
}
public static IZenSymbol resolveBracket(List<Token> tokens) {
public static IZenSymbol resolveBracket(IEnvironmentGlobal environment, List<Token> tokens) {
for (IBracketHandler handler : bracketHandlers) {
IZenSymbol symbol = handler.resolve(tokens);
IZenSymbol symbol = handler.resolve(environment, tokens);
if (symbol != null) {
return symbol;
}
@@ -117,7 +119,7 @@ public class GlobalRegistry {
}
public static IZenSymbol getStaticFunction(Class cls, String name, Class... arguments) {
JavaMethod method = JavaMethod.get(types, cls, name, arguments);
IJavaMethod method = JavaMethod.get(types, cls, name, arguments);
if (method == null) return null;
return new SymbolJavaStaticMethod(method);
}
@@ -180,8 +182,8 @@ public class GlobalRegistry {
}
@Override
public IZenSymbol getBracketed(List<Token> tokens) {
return resolveBracket(tokens);
public IZenSymbol getBracketed(IEnvironmentGlobal environment, List<Token> tokens) {
return resolveBracket(environment, tokens);
}
@Override
@@ -266,5 +268,15 @@ public class GlobalRegistry {
public void warning(ZenPosition position, String message) {
MineTweakerAPI.logWarning(position.toString() + " > " + message);
}
@Override
public Set<String> getClassNames() {
return classes.keySet();
}
@Override
public byte[] getClass(String name) {
return classes.get(name);
}
}
}
@@ -36,6 +36,8 @@ import stanhebben.zenscript.parser.ParseException;
* @author Stan Hebben
*/
public class MTTweaker implements ITweaker {
private static final boolean DEBUG = true;
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
@@ -61,8 +63,9 @@ public class MTTweaker implements ITweaker {
}
action.apply();
actions.add(action);
}
actions.add(action);
}
@Override
@@ -148,7 +151,7 @@ public class MTTweaker implements ITweaker {
try {
String filename = script.getGroupName();
System.out.println("MineTweaker: Loading " + filename);
compileScripts(filename, files, environmentGlobal);
compileScripts(filename, files, environmentGlobal, DEBUG);
// execute scripts
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
@@ -59,7 +59,7 @@ public class MCItemBlock implements IBlock {
@Override
public boolean matches(IBlock block) {
if (getDefinition() != block.getDefinition()) {
/*if (getDefinition() != block.getDefinition()) {
System.out.println("Different block");
return false;
}
@@ -74,11 +74,11 @@ public class MCItemBlock implements IBlock {
return false;
}
return true;
return true;*/
/* return getDefinition() == block.getDefinition()
return getDefinition() == block.getDefinition()
&& (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta())
&& (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData())));*/
&& (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData())));
}
@Override
@@ -18,14 +18,15 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize;
import net.minecraft.item.Item;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.ZenTokener;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -64,8 +65,8 @@ public class ItemBracketHandler implements IBracketHandler {
}
private final IZenSymbol symbolAny;
private final JavaMethod method;
private final JavaMethod method2;
private final IJavaMethod method;
private final IJavaMethod method2;
public ItemBracketHandler() {
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(
@@ -82,7 +83,7 @@ public class ItemBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
// any symbol
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
return symbolAny;
@@ -111,30 +112,17 @@ public class ItemBracketHandler implements IBracketHandler {
}
}
return find(tokens, fromIndex, toIndex, meta);
return find(environment, tokens, fromIndex, toIndex, meta);
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
/*StringBuilder test = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
if (i > startIndex) {
test.append(' ');
}
test.append(token.getValue());
test.append(" (");
test.append(token.getType());
test.append(")");
}
System.out.println("Find " + test);*/
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex, int meta) {
if (endIndex == startIndex + 1 && tokens.get(startIndex).getType() == ZenTokener.T_INTVALUE) {
int id = Integer.parseInt(tokens.get(startIndex).getValue());
if (id < 0 || id > Item.itemsList.length || Item.itemsList[id] == null) {
return null;
}
return new ItemReferenceSymbolId(id, meta);
return new ItemReferenceSymbolId(environment, id, meta);
}
StringBuilder valueBuilder = new StringBuilder();
@@ -144,25 +132,28 @@ public class ItemBracketHandler implements IBracketHandler {
}
if (itemNames.containsKey(valueBuilder.toString())) {
return new ItemReferenceSymbol(valueBuilder.toString(), meta);
return new ItemReferenceSymbol(environment, valueBuilder.toString(), meta);
}
return null;
}
private class ItemReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
private final int meta;
public ItemReferenceSymbol(String name, int meta) {
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
this.environment = environment;
this.name = name;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name),
new ExpressionInt(position, meta, ZenType.INT));
@@ -170,18 +161,21 @@ public class ItemBracketHandler implements IBracketHandler {
}
private class ItemReferenceSymbolId implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final int id;
private final int meta;
public ItemReferenceSymbolId(int id, int meta) {
public ItemReferenceSymbolId(IEnvironmentGlobal environment, int id, int meta) {
this.environment = environment;
this.id = id;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method2,
new ExpressionInt(position, id, ZenType.INT),
new ExpressionInt(position, meta, ZenType.INT));
@@ -9,11 +9,13 @@ import minetweaker.runtime.GlobalRegistry;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -33,17 +35,17 @@ public class LiquidBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
@@ -52,29 +54,32 @@ public class LiquidBracketHandler implements IBracketHandler {
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
if (fluid != null) {
return new LiquidReferenceSymbol(valueBuilder.toString());
return new LiquidReferenceSymbol(environment, valueBuilder.toString());
}
return null;
}
private class LiquidReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public LiquidReferenceSymbol(String name) {
public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = JavaMethod.get(
IJavaMethod method = JavaMethod.get(
GlobalRegistry.getTypeRegistry(),
LiquidBracketHandler.class,
"getLiquid",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -12,11 +12,13 @@ import minetweaker.annotations.BracketHandler;
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
import minetweaker.api.oredict.IOreDictEntry;
import minetweaker.runtime.GlobalRegistry;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -31,43 +33,46 @@ public class OreBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
valueBuilder.append(token.getValue());
}
return new OreReferenceSymbol(valueBuilder.toString());
return new OreReferenceSymbol(environment, valueBuilder.toString());
}
private class OreReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public OreReferenceSymbol(String name) {
public OreReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = JavaMethod.get(
IJavaMethod method = JavaMethod.get(
GlobalRegistry.getTypeRegistry(),
OreBracketHandler.class,
"getOre",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -94,6 +94,16 @@ public class MCPlayer implements IPlayer {
return MineTweakerMC.getIItemStack(player.getCurrentEquippedItem());
}
@Override
public boolean isCreative() {
return player.capabilities.isCreativeMode;
}
@Override
public boolean isAdventure() {
return !player.capabilities.allowEdit;
}
@Override
public void openBrowser(String url) {
if (player instanceof EntityPlayerMP) {
@@ -75,15 +75,13 @@ public class MCRecipeManager implements IRecipeManager {
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, boolean mirrored) {
addShaped(output, ingredients, null, mirrored);
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, null, false);
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, null, true);
}
@Override
@@ -383,4 +381,10 @@ public class MCRecipeManager implements IRecipeManager {
return true;
}
private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
}
}
@@ -85,6 +85,16 @@ public class ServerPlayer implements IPlayer {
return null;
}
@Override
public boolean isCreative() {
return true;
}
@Override
public boolean isAdventure() {
return false;
}
@Override
public void openBrowser(String url) {
if (Desktop.isDesktopSupported()) {
@@ -11,14 +11,15 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.ZenTokener;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -35,14 +36,14 @@ public class IC2BracketHandler implements IBracketHandler {
return getIItemStack(stack);
}
private final JavaMethod method;
private final IJavaMethod method;
public IC2BracketHandler() {
method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class);
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() >= 5) {
if (tokens.get(0).getValue().equals("ic2")
&& tokens.get(1).getValue().equals("-")
@@ -64,7 +65,7 @@ public class IC2BracketHandler implements IBracketHandler {
MineTweakerAPI.logError("Not a valid IC2 item: " + name);
return null;
} else {
return new ItemReferenceSymbol(name, meta);
return new ItemReferenceSymbol(environment, name, meta);
}
} else {
return null;
@@ -79,18 +80,21 @@ public class IC2BracketHandler implements IBracketHandler {
// #############################
private class ItemReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
private final int meta;
public ItemReferenceSymbol(String name, int meta) {
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
this.environment = environment;
this.name = name;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name),
new ExpressionInt(position, meta, ZenType.INT));
@@ -133,39 +133,30 @@ public class Harvester {
@Override
public boolean canBeHarvested(World world, Map<String, Boolean> map, int x, int y, int z) {
System.out.println("canBeHarvested start");
for (TweakerHarvestable harvestable : harvestables) {
if (harvestable.block.matches(MineTweakerMC.getBlock(world, x, y, z)))
return true;
}
System.out.println("canBeHarvested end");
return false;
}
@Override
public List<ItemStack> getDrops(World world, Random random, Map<String, Boolean> map, int x, int y, int z) {
System.out.println("getDrops start");
IBlock block = MineTweakerMC.getBlock(world, x, y, z);
for (TweakerHarvestable harvestable : harvestables) {
if (harvestable.block.matches(block)) {
if (harvestable.possibleDrops == null) {
Block mcBlock = ((MCBlockDefinition) block.getDefinition()).getInternalBlock();
List<ItemStack> result = mcBlock.getBlockDropped(world, x, y, z, block.getMeta(), 0);
//return Collections.EMPTY_LIST;
System.out.println("getDrops end");
return result;
} else {
List<ItemStack> result = Arrays.asList(MineTweakerMC.getItemStacks(WeightedItemStack.pickRandomDrops(random, harvestable.possibleDrops)));
System.out.println("getDrops end");
return result;
}
}
}
System.out.println("getDrops end");
return Collections.EMPTY_LIST;
}
@@ -19,14 +19,15 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize;
import net.minecraft.item.Item;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.ZenTokener;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -55,7 +56,7 @@ public class ItemBracketHandler implements IBracketHandler {
}
private final IZenSymbol symbolAny;
private final JavaMethod method;
private final IJavaMethod method;
public ItemBracketHandler() {
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
@@ -66,7 +67,7 @@ public class ItemBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
// any symbol
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
return symbolAny;
@@ -95,10 +96,10 @@ public class ItemBracketHandler implements IBracketHandler {
}
}
return find(tokens, fromIndex, toIndex, meta);
return find(environment, tokens, fromIndex, toIndex, meta);
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex, int meta) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
@@ -107,25 +108,28 @@ public class ItemBracketHandler implements IBracketHandler {
String itemName = valueBuilder.toString();
if (itemNames.containsKey(itemName)) {
return new ItemReferenceSymbol(itemName, meta);
return new ItemReferenceSymbol(environment, itemName, meta);
}
return null;
}
private class ItemReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
private final int meta;
public ItemReferenceSymbol(String name, int meta) {
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
this.environment = environment;
this.name = name;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name),
new ExpressionInt(position, meta, ZenType.INT));
@@ -9,11 +9,13 @@ import minetweaker.runtime.GlobalRegistry;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -33,17 +35,17 @@ public class LiquidBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
@@ -52,29 +54,32 @@ public class LiquidBracketHandler implements IBracketHandler {
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
if (fluid != null) {
return new LiquidReferenceSymbol(valueBuilder.toString());
return new LiquidReferenceSymbol(environment, valueBuilder.toString());
}
return null;
}
private class LiquidReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public LiquidReferenceSymbol(String name) {
public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = JavaMethod.get(
IJavaMethod method = JavaMethod.get(
GlobalRegistry.getTypeRegistry(),
LiquidBracketHandler.class,
"getLiquid",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -12,11 +12,13 @@ import minetweaker.annotations.BracketHandler;
import minetweaker.mc1710.oredict.MCOreDictEntry;
import minetweaker.api.oredict.IOreDictEntry;
import minetweaker.runtime.GlobalRegistry;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -31,43 +33,46 @@ public class OreBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
valueBuilder.append(token.getValue());
}
return new OreReferenceSymbol(valueBuilder.toString());
return new OreReferenceSymbol(environment, valueBuilder.toString());
}
private class OreReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public OreReferenceSymbol(String name) {
public OreReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = JavaMethod.get(
IJavaMethod method = JavaMethod.get(
GlobalRegistry.getTypeRegistry(),
OreBracketHandler.class,
"getOre",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -95,6 +95,16 @@ public class MCPlayer implements IPlayer {
return MineTweakerMC.getIItemStack(player.getCurrentEquippedItem());
}
@Override
public boolean isCreative() {
return player.capabilities.isCreativeMode;
}
@Override
public boolean isAdventure() {
return !player.capabilities.allowEdit;
}
@Override
public void openBrowser(String url) {
if (player instanceof EntityPlayerMP) {
@@ -75,15 +75,13 @@ public class MCRecipeManager implements IRecipeManager {
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, boolean mirrored) {
addShaped(output, ingredients, null, mirrored);
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, function, false);
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, function, true);
}
@Override
@@ -365,6 +363,12 @@ public class MCRecipeManager implements IRecipeManager {
return null;
}
}
private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
}
private static boolean matches(Object input, IIngredient ingredient) {
if ((input == null) != (ingredient == null)) {
@@ -86,6 +86,16 @@ public class ServerPlayer implements IPlayer {
return null;
}
@Override
public boolean isCreative() {
return true;
}
@Override
public boolean isAdventure() {
return false;
}
@Override
public void openBrowser(String url) {
if (Desktop.isDesktopSupported()) {
@@ -11,14 +11,15 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.ZenTokener;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -35,14 +36,14 @@ public class IC2BracketHandler implements IBracketHandler {
return getIItemStack(stack);
}
private final JavaMethod method;
private final IJavaMethod method;
public IC2BracketHandler() {
method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class);
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() >= 5) {
if (tokens.get(0).getValue().equals("ic2")
&& tokens.get(1).getValue().equals("-")
@@ -64,7 +65,7 @@ public class IC2BracketHandler implements IBracketHandler {
MineTweakerAPI.logError("Not a valid IC2 item: " + name);
return null;
} else {
return new ItemReferenceSymbol(name, meta);
return new ItemReferenceSymbol(environment, name, meta);
}
} else {
return null;
@@ -79,18 +80,21 @@ public class IC2BracketHandler implements IBracketHandler {
// #############################
private class ItemReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
private final int meta;
public ItemReferenceSymbol(String name, int meta) {
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
this.environment = environment;
this.name = name;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name),
new ExpressionInt(position, meta, ZenType.INT));
@@ -19,14 +19,15 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize;
import net.minecraft.item.Item;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.ZenTokener;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -55,7 +56,7 @@ public class ItemBracketHandler implements IBracketHandler {
}
private final IZenSymbol symbolAny;
private final JavaMethod method;
private final IJavaMethod method;
public ItemBracketHandler() {
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
@@ -66,7 +67,7 @@ public class ItemBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
// any symbol
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
return symbolAny;
@@ -95,10 +96,10 @@ public class ItemBracketHandler implements IBracketHandler {
}
}
return find(tokens, fromIndex, toIndex, meta);
return find(environment, tokens, fromIndex, toIndex, meta);
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex, int meta) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
@@ -107,25 +108,28 @@ public class ItemBracketHandler implements IBracketHandler {
String itemName = valueBuilder.toString();
if (itemNames.containsKey(itemName)) {
return new ItemReferenceSymbol(itemName, meta);
return new ItemReferenceSymbol(environment, itemName, meta);
}
return null;
}
private class ItemReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
private final int meta;
public ItemReferenceSymbol(String name, int meta) {
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
this.environment = environment;
this.name = name;
this.meta = meta;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name),
new ExpressionInt(position, meta, ZenType.INT));
@@ -9,11 +9,13 @@ import minetweaker.runtime.GlobalRegistry;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -33,17 +35,17 @@ public class LiquidBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
@@ -52,29 +54,32 @@ public class LiquidBracketHandler implements IBracketHandler {
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
if (fluid != null) {
return new LiquidReferenceSymbol(valueBuilder.toString());
return new LiquidReferenceSymbol(environment, valueBuilder.toString());
}
return null;
}
private class LiquidReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public LiquidReferenceSymbol(String name) {
public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = JavaMethod.get(
IJavaMethod method = JavaMethod.get(
GlobalRegistry.getTypeRegistry(),
LiquidBracketHandler.class,
"getLiquid",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -12,12 +12,13 @@ import minetweaker.MineTweakerAPI;
import minetweaker.annotations.BracketHandler;
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
import minetweaker.api.oredict.IOreDictEntry;
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -31,42 +32,45 @@ public class OreBracketHandler implements IBracketHandler {
}
@Override
public IZenSymbol resolve(List<Token> tokens) {
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
return find(tokens, 2, tokens.size());
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
valueBuilder.append(token.getValue());
}
return new OreReferenceSymbol(valueBuilder.toString());
return new OreReferenceSymbol(environment, valueBuilder.toString());
}
private class OreReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public OreReferenceSymbol(String name) {
public OreReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
JavaMethod method = MineTweakerAPI.getJavaMethod(
IJavaMethod method = MineTweakerAPI.getJavaMethod(
OreBracketHandler.class,
"getOre",
String.class);
return new ExpressionJavaCallStatic(
return new ExpressionCallStatic(
position,
environment,
method,
new ExpressionString(position, name));
}
@@ -96,6 +96,16 @@ public class MCPlayer implements IPlayer {
return MineTweakerMC.getIItemStack(player.getCurrentEquippedItem());
}
@Override
public boolean isCreative() {
return player.capabilities.isCreativeMode;
}
@Override
public boolean isAdventure() {
return !player.capabilities.allowEdit;
}
@Override
public void openBrowser(String url) {
if (player instanceof EntityPlayerMP) {
@@ -73,17 +73,15 @@ public class MCRecipeManager implements IRecipeManager {
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
return toRemove.size();
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, boolean mirrored) {
addShaped(output, ingredients, null, mirrored);
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, function, false);
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
addShaped(output, ingredients, function, true);
}
@Override
@@ -383,4 +381,10 @@ public class MCRecipeManager implements IRecipeManager {
return true;
}
private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
}
}
@@ -86,6 +86,16 @@ public class ServerPlayer implements IPlayer {
return null;
}
@Override
public boolean isCreative() {
return true;
}
@Override
public boolean isAdventure() {
return false;
}
@Override
public void openBrowser(String url) {
if (Desktop.isDesktopSupported()) {
@@ -7,8 +7,7 @@
package stanhebben.zenscript;
import java.util.List;
import stanhebben.zenscript.IZenErrorLogger;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.TypeRegistry;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
@@ -24,7 +23,7 @@ public interface IZenCompileEnvironment {
public IZenSymbol getDollar(String name);
public IZenSymbol getBracketed(List<Token> tokens);
public IZenSymbol getBracketed(IEnvironmentGlobal environment, List<Token> tokens);
public TypeRegistry getTypeRegistry();
@@ -17,16 +17,21 @@ import stanhebben.zenscript.annotations.ZenMethodStatic;
import stanhebben.zenscript.annotations.ZenOperator;
import stanhebben.zenscript.annotations.ZenSetter;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.compiler.ITypeRegistry;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.expand.ZenExpandCaster;
import stanhebben.zenscript.type.expand.ZenExpandMember;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.ZenNativeOperator;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
import stanhebben.zenscript.value.IAny;
/**
* Type expansions provide additional members for existing types. They can
@@ -77,7 +82,7 @@ public class TypeExpansion {
for (Annotation annotation : method.getAnnotations()) {
if (annotation instanceof ZenCaster) {
checkStatic(method);
casters.add(new ZenExpandCaster(new JavaMethod(cls, method, types)));
casters.add(new ZenExpandCaster(new JavaMethod(method, types)));
} else if (annotation instanceof ZenGetter) {
checkStatic(method);
ZenGetter getterAnnotation = (ZenGetter) annotation;
@@ -86,7 +91,7 @@ public class TypeExpansion {
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember(type, name));
}
members.get(name).setGetter(new JavaMethod(cls, method, types));
members.get(name).setGetter(new JavaMethod(method, types));
} else if (annotation instanceof ZenSetter) {
checkStatic(method);
ZenSetter setterAnnotation = (ZenSetter) annotation;
@@ -95,7 +100,7 @@ public class TypeExpansion {
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember(type, name));
}
members.get(name).setSetter(new JavaMethod(cls, method, types));
members.get(name).setSetter(new JavaMethod(method, types));
} else if (annotation instanceof ZenOperator) {
checkStatic(method);
ZenOperator operatorAnnotation = (ZenOperator) annotation;
@@ -107,7 +112,7 @@ public class TypeExpansion {
} else {
unaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
new JavaMethod(method, types)));
}
break;
case ADD:
@@ -128,7 +133,7 @@ public class TypeExpansion {
} else {
binaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
new JavaMethod(method, types)));
}
break;
case INDEXSET:
@@ -137,7 +142,7 @@ public class TypeExpansion {
} else {
trinaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
new JavaMethod(method, types)));
}
break;
}
@@ -150,7 +155,7 @@ public class TypeExpansion {
if (!members.containsKey(methodName)) {
members.put(methodName, new ZenExpandMember(type, methodName));
}
members.get(methodName).addMethod(new JavaMethod(cls, method, types));
members.get(methodName).addMethod(new JavaMethod(method, types));
} else if (annotation instanceof ZenMethodStatic) {
checkStatic(method);
ZenMethodStatic methodAnnotation = (ZenMethodStatic) annotation;
@@ -160,12 +165,24 @@ public class TypeExpansion {
if (!staticMembers.containsKey(methodName)) {
staticMembers.put(methodName, new ZenExpandMember(type, methodName));
}
staticMembers.get(methodName).addMethod(new JavaMethod(cls, method, types));
staticMembers.get(methodName).addMethod(new JavaMethod(method, types));
}
}
}
}
/**
* Registers all casting rules to the given delegate.
*
* @param environment compilation environment
* @param rules target delegate
*/
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules) {
for (ZenExpandCaster caster : casters) {
caster.constructCastingRules(environment, rules);
}
}
/**
* Retrieves a caster from this expansion. May return null if no suitable
* caster was available.
@@ -209,7 +226,7 @@ public class TypeExpansion {
OperatorType operator) {
for (ZenNativeOperator op : unaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, value);
return new ExpressionCallStatic(position, environment, op.getMethod(), value);
}
}
@@ -235,7 +252,7 @@ public class TypeExpansion {
OperatorType operator) {
for (ZenNativeOperator op : binaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, left, right);
return new ExpressionCallStatic(position, environment, op.getMethod(), left, right);
}
}
@@ -263,7 +280,7 @@ public class TypeExpansion {
OperatorType operator) {
for (ZenNativeOperator op : trinaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, first, second, third);
return new ExpressionCallStatic(position, environment, op.getMethod(), first, second, third);
}
}
@@ -312,6 +329,7 @@ public class TypeExpansion {
public void compileAnyCast(ZenType type, MethodOutput output, IEnvironmentGlobal environment, int localValue, int localClass) {
if (type == null)
throw new IllegalArgumentException("type cannot be null");
Type asmType = type.toASMType();
if (asmType == null) {
throw new RuntimeException("type has no asm type");
@@ -340,7 +358,8 @@ public class TypeExpansion {
output.ifEQ(skip);
output.load(type.toASMType(), localValue);
caster.compile(output);
output.invokeStatic(casterAny, "rtAs", "(Ljava/lang/Class;)Z");
output.loadObject(localClass);
output.invokeStatic(casterAny, "rtAs", "(" + caster.getTarget().getSignature() + "Ljava/lang/Class;)Ljava/lang/Object;");
output.returnType(caster.getTarget().toASMType());
output.label(skip);
}
@@ -374,6 +393,25 @@ public class TypeExpansion {
}
}
public boolean compileAnyUnary(MethodOutput output, OperatorType type, IEnvironmentMethod environment) {
for (ZenNativeOperator operator : unaryOperators) {
if (operator.getOperator() == type) {
ZenType returnType = operator.getMethod().getReturnType();
output.loadObject(0);
operator.getMethod().invokeStatic(output);
output.invokeStatic(
returnType.getAnyClassName(environment),
"valueOf",
"(" + returnType.getSignature() + ")" + ZenType.ANY.getSignature());
output.returnObject();
return true;
}
}
return false;
}
// #######################
// ### Private methods ###
// #######################
@@ -50,8 +50,9 @@ public class ZenModule {
* @param mainFileName main filename (used for debug info)
* @param scripts scripts to compile
* @param environmentGlobal global compile environment
* @param debug enable debug mode (outputs classes to generated directory)
*/
public static void compileScripts(String mainFileName, List<ZenParsedFile> scripts, IEnvironmentGlobal environmentGlobal) {
public static void compileScripts(String mainFileName, List<ZenParsedFile> scripts, IEnvironmentGlobal environmentGlobal, boolean debug) {
ClassWriter clsMain = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
clsMain.visitSource(mainFileName, null);
@@ -117,6 +118,7 @@ public class ZenModule {
if (script.getStatements().size() > 0) {
MethodOutput scriptOutput = new MethodOutput(clsScript, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "__script__", "()V", null, null);
IEnvironmentMethod functionMethod = new EnvironmentMethod(scriptOutput, environmentScript);
//scriptOutput.enableDebug();
scriptOutput.start();
for (Statement statement : script.getStatements()) {
statement.compile(functionMethod);
@@ -143,6 +145,28 @@ public class ZenModule {
constructor.visitMaxs(0, 0);
constructor.visitEnd();
// debug: output classes
if (debug) {
try {
File outputDir = new File("generated");
outputDir.mkdir();
for (String className : environmentGlobal.getClassNames()) {
File outputFile = new File(outputDir, className.replace('.', '/') + ".class");
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
FileOutputStream output = new FileOutputStream(outputFile);
output.write(environmentGlobal.getClass(className));
output.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
environmentGlobal.putClass("__ZenMain__", clsMain.toByteArray());
}
@@ -176,7 +200,7 @@ public class ZenModule {
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
files.add(file);
compileScripts(filename, files, environmentGlobal);
compileScripts(filename, files, environmentGlobal, false);
// debug: output classes
File outputDir = new File("generated");
@@ -238,18 +262,7 @@ public class ZenModule {
}
String filename = file.getName();
compileScripts(filename, files, environmentGlobal);
// debug: output classes
File outputDir = new File("generated");
outputDir.mkdir();
for (Map.Entry<String, byte[]> entry : classes.entrySet()) {
File outputFile = new File(outputDir, entry.getKey().replace('.', '/') + ".class");
FileOutputStream output = new FileOutputStream(outputFile);
output.write(entry.getValue());
output.close();
}
compileScripts(filename, files, environmentGlobal, true);
return new ZenModule(classes, baseClassLoader);
}
@@ -126,7 +126,7 @@ public class ZenParsedFile {
}
functions.put(function.getName(), function);
} else {
statements.add(Statement.read(tokener, environmentScript));
statements.add(Statement.read(tokener, environmentScript, null));
}
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.compiler;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassVisitor;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -90,4 +91,14 @@ public class EnvironmentClass implements IEnvironmentClass {
public void warning(ZenPosition position, String message) {
global.warning(position, message);
}
@Override
public Set<String> getClassNames() {
return global.getClassNames();
}
@Override
public byte[] getClass(String name) {
return global.getClass(name);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.compiler;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import stanhebben.zenscript.IZenErrorLogger;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -103,4 +104,14 @@ public class EnvironmentGlobal implements IEnvironmentGlobal {
local.put(name, value);
}
}
@Override
public Set<String> getClassNames() {
return classes.keySet();
}
@Override
public byte[] getClass(String name) {
return classes.get(name);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.compiler;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassVisitor;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -107,4 +108,14 @@ public class EnvironmentMethod implements IEnvironmentMethod {
public void putValue(String name, IZenSymbol value) {
local.put(name, value);
}
@Override
public Set<String> getClassNames() {
return environment.getClassNames();
}
@Override
public byte[] getClass(String name) {
return environment.getClass(name);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.compiler;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassVisitor;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -106,4 +107,14 @@ public class EnvironmentScope implements IEnvironmentMethod {
public void warning(ZenPosition position, String message) {
outer.warning(position, message);
}
@Override
public Set<String> getClassNames() {
return outer.getClassNames();
}
@Override
public byte[] getClass(String name) {
return outer.getClass(name);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.compiler;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import stanhebben.zenscript.IZenCompileEnvironment;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -86,4 +87,14 @@ public class EnvironmentScript implements IEnvironmentGlobal {
public void warning(ZenPosition position, String message) {
parent.warning(position, message);
}
@Override
public Set<String> getClassNames() {
return parent.getClassNames();
}
@Override
public byte[] getClass(String name) {
return parent.getClass(name);
}
}
@@ -6,6 +6,7 @@
package stanhebben.zenscript.compiler;
import java.util.Set;
import stanhebben.zenscript.IZenErrorLogger;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.expression.partial.IPartialExpression;
@@ -26,6 +27,10 @@ public interface IEnvironmentGlobal extends ITypeRegistry, IZenErrorLogger {
public boolean containsClass(String name);
public Set<String> getClassNames();
public byte[] getClass(String name);
public void putClass(String name, byte[] data);
public IPartialExpression getValue(String name, ZenPosition position);
@@ -67,7 +67,7 @@ public class ParsedFunction {
ArrayList<Statement> statementsAL = new ArrayList<Statement>();
while (parser.optional(T_ACLOSE) == null) {
statementsAL.add(Statement.read(parser, environment));
statementsAL.add(Statement.read(parser, environment, type));
}
statements = statementsAL.toArray(new Statement[statementsAL.size()]);
}
@@ -8,13 +8,13 @@ import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.expression.ParsedExpression;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeBool;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.ZenPosition;
public abstract class Expression implements IPartialExpression {
public static final Expression parse(ZenTokener parser, IEnvironmentMethod environment) {
public static final Expression parse(ZenTokener parser, IEnvironmentMethod environment, ZenType predictedType) {
return ParsedExpression.read(parser, environment)
.compile(environment)
.compile(environment, predictedType)
.eval(environment);
}
@@ -28,13 +28,17 @@ public abstract class Expression implements IPartialExpression {
return position;
}
public abstract ZenType getType();
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (getType() == type) {
return this;
} else {
return getType().cast(position, environment, this, type);
ICastingRule castingRule = getType().getCastingRule(type, environment);
if (castingRule == null) {
environment.error(position, "Cannot cast " + this.getType() + " to " + type);
return new ExpressionInvalid(position, type);
} else {
return new ExpressionAs(position, this, castingRule);
}
}
}
@@ -77,6 +81,11 @@ public abstract class Expression implements IPartialExpression {
return getType().call(position, environment, this, values);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return getType().predictCallTypes(numArguments);
}
@Override
public IZenSymbol toSymbol() {
return null;
@@ -5,8 +5,8 @@ import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeAny;
import stanhebben.zenscript.type.ZenTypeArrayBasic;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
@@ -14,21 +14,19 @@ public class ExpressionArray extends Expression {
private final Expression[] contents;
private final ZenTypeArrayBasic type;
public ExpressionArray(ZenPosition position, Expression... contents) {
public ExpressionArray(ZenPosition position, ZenTypeArrayBasic type, Expression... contents) {
super(position);
this.contents = contents;
type = new ZenTypeArrayBasic(ZenTypeAny.INSTANCE);
}
public ExpressionArray(ZenPosition position, Expression[] contents, ZenTypeArrayBasic type) {
super(position);
this.contents = contents;
this.type = type;
}
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (this.type.equals(type)) {
return this;
}
if (type instanceof ZenTypeArrayBasic) {
ZenTypeArrayBasic arrayType = (ZenTypeArrayBasic) type;
Expression[] newContents = new Expression[contents.length];
@@ -36,12 +34,15 @@ public class ExpressionArray extends Expression {
newContents[i] = contents[i].cast(position, environment, arrayType.getBaseType());
}
return new ExpressionArray(getPosition(), newContents, arrayType);
} else if (this.type.canCastImplicit(type, environment)) {
return this.type.cast(position, environment, this, type);
return new ExpressionArray(getPosition(), arrayType, newContents);
} else {
environment.error(position, "cannot cast " + this.type + " to " + type);
return new ExpressionInvalid(position, type);
ICastingRule castingRule = this.type.getCastingRule(type, environment);
if (castingRule == null) {
environment.error(position, "cannot cast " + this.type + " to " + type);
return new ExpressionInvalid(position, type);
} else {
return new ExpressionAs(position, this, castingRule);
}
}
}
@@ -3,34 +3,46 @@ package stanhebben.zenscript.expression;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.ZenPosition;
public class ExpressionAs extends Expression {
private final Expression value;
private final ZenType type;
private final ICastingRule castingRule;
public ExpressionAs(ZenPosition position, Expression value, ZenType type) {
public ExpressionAs(ZenPosition position, Expression value, ICastingRule castingRule) {
super(position);
this.value = value;
this.type = type;
this.castingRule = castingRule;
}
@Override
/*@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
return this.type.cast(position, environment, this, type);
}
if (castingRule.getResultingType().equals(type)) {
return this;
}
ICastingRule newCastingRule = type.getCastingRule(type, environment);
if (newCastingRule == null) {
environment.error(position, "Cannot cast " + getType() + " to " + type);
return new ExpressionInvalid(position, type);
} else {
return new ExpressionAs(position, this, newCastingRule);
}
}*/
@Override
public ZenType getType() {
return type;
return castingRule.getResultingType();
}
@Override
public void compile(boolean result, IEnvironmentMethod environment) {
value.compile(result, environment);
if (result) {
value.getType().compileCast(getPosition(), environment, type);
castingRule.compile(environment);
}
}
}
@@ -30,7 +30,7 @@ public class ExpressionBool extends Expression {
if (type == ZenType.BOOL) {
return this;
} else {
return ZenType.BOOL.cast(position, environment, this, type);
return super.cast(position, environment, type);
}
}
@@ -6,8 +6,10 @@
package stanhebben.zenscript.expression;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
@@ -16,18 +18,19 @@ import stanhebben.zenscript.util.ZenPosition;
*
* @author Stanneke
*/
public class ExpressionJavaCallStatic extends Expression {
private final JavaMethod method;
public class ExpressionCallStatic extends Expression {
private final IJavaMethod method;
private final Expression[] arguments;
public ExpressionJavaCallStatic(
public ExpressionCallStatic(
ZenPosition position,
JavaMethod method,
IEnvironmentGlobal environment,
IJavaMethod method,
Expression... arguments) {
super(position);
this.method = method;
this.arguments = arguments;
this.arguments = JavaMethod.rematch(position, method, environment, arguments);
}
@Override
@@ -43,7 +46,7 @@ public class ExpressionJavaCallStatic extends Expression {
argument.compile(true, environment);
}
output.invokeStatic(method);
method.invokeStatic(output);
if (method.getReturnType() != ZenType.VOID && !result) {
output.pop(method.getReturnType().isLarge());
@@ -6,8 +6,10 @@
package stanhebben.zenscript.expression;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -15,15 +17,16 @@ import stanhebben.zenscript.util.ZenPosition;
*
* @author Stanneke
*/
public class ExpressionJavaCallVirtual extends Expression {
private final JavaMethod method;
public class ExpressionCallVirtual extends Expression {
private final IJavaMethod method;
private final Expression receiver;
private final Expression[] arguments;
public ExpressionJavaCallVirtual(
public ExpressionCallVirtual(
ZenPosition position,
JavaMethod method,
IEnvironmentGlobal environment,
IJavaMethod method,
Expression receiver,
Expression... arguments) {
super(position);
@@ -31,7 +34,7 @@ public class ExpressionJavaCallVirtual extends Expression {
this.method = method;
this.receiver = receiver;
this.arguments = arguments;
this.arguments = JavaMethod.rematch(position, method, environment, arguments);
}
@Override
@@ -47,7 +50,7 @@ public class ExpressionJavaCallVirtual extends Expression {
argument.compile(true, environment);
}
environment.getOutput().invoke(method);
method.invokeVirtual(environment.getOutput());
if (method.getReturnType() != ZenType.VOID && !result) {
environment.getOutput().pop(method.getReturnType().isLarge());
}
@@ -25,11 +25,11 @@ import stanhebben.zenscript.util.ZenPosition;
public class ExpressionFunction extends Expression {
private final List<ParsedFunctionArgument> arguments;
private final ZenType returnType;
private final Statement[] statements;
private final List<Statement> statements;
private final ZenTypeFunction functionType;
public ExpressionFunction(ZenPosition position, List<ParsedFunctionArgument> arguments, ZenType returnType, Statement[] statements) {
public ExpressionFunction(ZenPosition position, List<ParsedFunctionArgument> arguments, ZenType returnType, List<Statement> statements) {
super(position);
System.out.println("Function expression: " + arguments.size() + " arguments");
@@ -95,6 +95,7 @@ public class ExpressionFunction extends Expression {
@Override
public void compile(boolean result, IEnvironmentMethod environment) {
// TODO: implement
// TODO: make sure the function is compiled properly
throw new UnsupportedOperationException("not yet implemented");
}
}
@@ -7,10 +7,8 @@
package stanhebben.zenscript.expression;
import org.objectweb.asm.Label;
import stanhebben.zenscript.compiler.EnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.compiler.EnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeAny;
import stanhebben.zenscript.util.ZenPosition;
@@ -32,6 +30,8 @@ public class ExpressionInvalid extends Expression {
super(position);
this.type = type;
//throw new RuntimeException("Constructing invalid expression");
}
@Override
@@ -1,59 +0,0 @@
/*
* 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 stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stanneke
*/
public class ExpressionJavaCallStaticGenerated extends Expression {
private final String target;
private final String name;
private final String descriptor;
private final ZenType returnZType;
private final Expression[] arguments;
public ExpressionJavaCallStaticGenerated(
ZenPosition position,
String target, String name, String descriptor,
ZenType returnZType,
Expression... arguments) {
super(position);
this.target = target;
this.name = name;
this.descriptor = descriptor;
this.returnZType = returnZType;
this.arguments = arguments;
}
@Override
public ZenType getType() {
return returnZType;
}
@Override
public void compile(boolean result, IEnvironmentMethod environment) {
MethodOutput output = environment.getOutput();
for (Expression argument : arguments) {
argument.compile(true, environment);
}
output.invokeStatic(target, name, descriptor);
if (!descriptor.endsWith("V") && !result) {
output.pop();
}
}
}
@@ -30,7 +30,7 @@ import static stanhebben.zenscript.util.ZenTypeUtil.internal;
public class ExpressionJavaLambda extends Expression {
private final Class interfaceClass;
private final List<ParsedFunctionArgument> arguments;
private final Statement[] statements;
private final List<Statement> statements;
private final ZenType type;
@@ -38,7 +38,7 @@ public class ExpressionJavaLambda extends Expression {
ZenPosition position,
Class interfaceClass,
List<ParsedFunctionArgument> arguments,
Statement[] statements,
List<Statement> statements,
ZenType type) {
super(position);
@@ -7,25 +7,17 @@ import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeAny;
import stanhebben.zenscript.type.ZenTypeAssociative;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
import static stanhebben.zenscript.util.ZenTypeUtil.internal;
public class ExpressionTable extends Expression {
public class ExpressionMap extends Expression {
private final Expression[] keys;
private final Expression[] values;
private final ZenTypeAssociative type;
public ExpressionTable(ZenPosition position, Expression[] keys, Expression[] values) {
super(position);
this.keys = keys;
this.values = values;
type = new ZenTypeAssociative(ZenTypeAny.INSTANCE, ZenTypeAny.INSTANCE);
}
public ExpressionTable(ZenPosition position, Expression[] keys, Expression[] values, ZenTypeAssociative type) {
public ExpressionMap(ZenPosition position, Expression[] keys, Expression[] values, ZenTypeAssociative type) {
super(position);
this.keys = keys;
@@ -69,22 +61,29 @@ public class ExpressionTable extends Expression {
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (this.type.equals(type)) {
return this;
}
if (type instanceof ZenTypeAssociative) {
ZenTypeAssociative keyType = (ZenTypeAssociative) type;
ZenTypeAssociative associativeType = (ZenTypeAssociative) type;
Expression[] newKeys = new Expression[keys.length];
Expression[] newValues = new Expression[values.length];
for (int i = 0; i < keys.length; i++) {
newKeys[i] = keys[i].cast(position, environment, keyType.getKeyType());
newValues[i] = values[i].cast(position, environment, keyType.getValueType());
newKeys[i] = keys[i].cast(position, environment, associativeType.getKeyType());
newValues[i] = values[i].cast(position, environment, associativeType.getValueType());
}
return new ExpressionTable(getPosition(), newKeys, newValues, keyType);
} else if (this.type.canCastImplicit(type, environment)) {
return this.type.cast(position, environment, this, type);
return new ExpressionMap(getPosition(), newKeys, newValues, associativeType);
} else {
environment.error(position, "cannot cast " + this.type + " to " + type);
return new ExpressionInvalid(position, type);
ICastingRule castingRule = this.type.getCastingRule(type, environment);
if (castingRule == null) {
environment.error(position, "cannot cast " + this.type + " to " + type);
return new ExpressionInvalid(position, type);
} else {
return new ExpressionAs(position, this, castingRule);
}
}
}
}
@@ -17,7 +17,7 @@ public class ExpressionOrOr extends Expression {
@Override
public ZenType getType() {
return a.getType(); // TODO: combine both types
return a.getType();
}
@Override
@@ -26,7 +26,11 @@ public interface IPartialExpression {
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values);
public ZenType[] predictCallTypes(int numArguments);
public IZenSymbol toSymbol();
public ZenType getType();
public ZenType toType(IEnvironmentGlobal environment);
}
@@ -57,8 +57,18 @@ public class PartialJavaClass implements IPartialExpression {
return new SymbolJavaClass(cls);
}
@Override
public ZenType getType() {
return null;
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
return environment.getType(cls);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return new ZenType[numArguments];
}
}
@@ -55,11 +55,21 @@ public class PartialLocal implements IPartialExpression {
return variable.getType().call(position, environment, eval(environment), values);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return variable.getType().predictCallTypes(numArguments);
}
@Override
public IZenSymbol toSymbol() {
return variable;
}
@Override
public ZenType getType() {
return variable.getType();
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
environment.error(position, "not a valid type");
@@ -57,11 +57,21 @@ public class PartialPackage implements IPartialExpression {
return new ExpressionInvalid(position);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return new ZenType[numArguments];
}
@Override
public IZenSymbol toSymbol() {
return null; // not supposed to be used as symbol
}
@Override
public ZenType getType() {
return null;
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
environment.error(position, "not a valid type");
@@ -6,14 +6,16 @@
package stanhebben.zenscript.expression.partial;
import java.util.Arrays;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.ExpressionJavaCallStaticGenerated;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.symbols.SymbolZenStaticMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -67,7 +69,12 @@ public class PartialStaticGenerated implements IPartialExpression {
arguments[i] = values[i].cast(position, environment, argumentTypes[i]);
}
return new ExpressionJavaCallStaticGenerated(position, owner, method, signature, returnType, arguments);
return new ExpressionCallStatic(position, environment, JavaMethod.getStatic(owner, method, returnType, argumentTypes), arguments);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return Arrays.copyOf(argumentTypes, numArguments);
}
@Override
@@ -75,6 +82,11 @@ public class PartialStaticGenerated implements IPartialExpression {
return new SymbolZenStaticMethod(owner, method, signature, argumentTypes, returnType);
}
@Override
public ZenType getType() {
return returnType;
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
environment.error(position, "not a valid type");
@@ -9,11 +9,12 @@ package stanhebben.zenscript.expression.partial;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.symbols.SymbolJavaStaticGetter;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -22,16 +23,16 @@ import stanhebben.zenscript.util.ZenPosition;
*/
public class PartialStaticGetter implements IPartialExpression {
private final ZenPosition position;
private final JavaMethod method;
private final IJavaMethod method;
public PartialStaticGetter(ZenPosition position, JavaMethod method) {
public PartialStaticGetter(ZenPosition position, IJavaMethod method) {
this.position = position;
this.method = method;
}
@Override
public Expression eval(IEnvironmentGlobal environment) {
return method.callStatic(position, environment);
return new ExpressionCallStatic(position, environment, method);
}
@Override
@@ -51,11 +52,21 @@ public class PartialStaticGetter implements IPartialExpression {
return new ExpressionInvalid(position);
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return new ZenType[numArguments];
}
@Override
public IZenSymbol toSymbol() {
return new SymbolJavaStaticGetter(method);
}
@Override
public ZenType getType() {
return method.getReturnType();
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
environment.error(position, "not a valid type");
@@ -6,14 +6,16 @@
package stanhebben.zenscript.expression.partial;
import java.util.Arrays;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -22,9 +24,9 @@ import stanhebben.zenscript.util.ZenPosition;
*/
public class PartialStaticMethod implements IPartialExpression {
private final ZenPosition position;
private final JavaMethod method;
private final IJavaMethod method;
public PartialStaticMethod(ZenPosition position, JavaMethod method) {
public PartialStaticMethod(ZenPosition position, IJavaMethod method) {
this.position = position;
this.method = method;
}
@@ -50,18 +52,28 @@ public class PartialStaticMethod implements IPartialExpression {
@Override
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
if (method.accepts(environment, values)) {
return method.callStatic(position, environment, values);
return new ExpressionCallStatic(position, environment, method, values);
} else {
environment.error(position, "parameter count mismatch");
return new ExpressionInvalid(position, method.getReturnType());
}
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return Arrays.copyOf(method.getParameterTypes(), numArguments);
}
@Override
public IZenSymbol toSymbol() {
return new SymbolJavaStaticMethod(method);
}
@Override
public ZenType getType() {
return method.getReturnType();
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
return ZenType.ANY;
@@ -55,6 +55,16 @@ public class PartialType implements IPartialExpression {
public IZenSymbol toSymbol() {
return new SymbolType(type);
}
@Override
public ZenType getType() {
return null; // not an expression
}
@Override
public ZenType[] predictCallTypes(int numArguments) {
return new ZenType[numArguments];
}
@Override
public ZenType toType(IEnvironmentGlobal environment) {
@@ -65,13 +65,10 @@ public class NFA {
Partial[] partials = new Partial[regexp.length];
for (int i = 0; i < regexp.length; i++) {
//System.out.println("Processing regexp " + i + ": " + regexp[i]);
partials[i] = processRegExp(new CharStream(regexp[i]));
partials[i].head.setFinal(finals[i]);
initial.addTransition(partials[i].tailLabel, partials[i].tail);
}
//System.out.println("NFA generated");
}
/**
@@ -230,7 +230,6 @@ public class TokenStream implements Iterator<Token> {
if (nextChar < 0 && value.length() == 0) {
return; // happens on comments at the end of files
}
//System.out.println("Value: " + value.length() + " characters: " + value);
throw new TokenException(file, line, lineOffset, (char)nextChar);
}
} catch (IOException ex) {
@@ -17,7 +17,6 @@ import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.definitions.ParsedFunctionArgument;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionFloat;
import stanhebben.zenscript.expression.ExpressionFunction;
import stanhebben.zenscript.expression.ExpressionInt;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.parser.ParseException;
@@ -331,7 +330,6 @@ public abstract class ParsedExpression {
}*/
case T_ID:
return new ParsedExpressionVariable(position, parser.next().getValue());
// TODO: implement function values
case T_FUNCTION:
// function (argname, argname, ...) { ...contents... }
parser.next();
@@ -360,18 +358,14 @@ public abstract class ParsedExpression {
parser.required(T_AOPEN, "{ expected");
Statement[] statements;
if (parser.optional(T_ACLOSE) != null) {
statements = new Statement[0];
} else {
ArrayList<Statement> statementsAL = new ArrayList<Statement>();
List<Statement> statements = new ArrayList<Statement>();
if (parser.optional(T_ACLOSE) == null) {
while (parser.optional(T_ACLOSE) == null) {
statementsAL.add(Statement.read(parser, environment));
statements.add(Statement.read(parser, environment, returnType));
}
statements = statementsAL.toArray(new Statement[statementsAL.size()]);
}
return new ParsedExpressionValue(position, new ExpressionFunction(position, arguments, returnType, statements));
return new ParsedExpressionFunction(position, returnType, arguments, statements);
case T_LT: {
Token start = parser.next();
List<Token> tokens = new ArrayList<Token>();
@@ -380,7 +374,7 @@ public abstract class ParsedExpression {
tokens.add(next);
next = parser.next();
}
IZenSymbol resolved = parser.getEnvironment().getBracketed(tokens);
IZenSymbol resolved = parser.getEnvironment().getBracketed(environment, tokens);
if (resolved == null) {
StringBuilder builder = new StringBuilder();
builder.append('<');
@@ -397,7 +391,7 @@ public abstract class ParsedExpression {
} else {
return new ParsedExpressionValue(
start.getPosition(),
parser.getEnvironment().getBracketed(tokens).instance(start.getPosition()));
parser.getEnvironment().getBracketed(environment, tokens).instance(start.getPosition()));
}
}
case T_SQBROPEN: {
@@ -431,7 +425,7 @@ public abstract class ParsedExpression {
}
}
return new ParsedExpressionTable(position, keys, values);
return new ParsedExpressionMap(position, keys, values);
}
}
case T_TRUE:
@@ -463,9 +457,9 @@ public abstract class ParsedExpression {
return position;
}
public abstract IPartialExpression compile(IEnvironmentMethod environment);
public abstract IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType);
public Expression compileKey(IEnvironmentMethod environment) {
return compile(environment).eval(environment);
public Expression compileKey(IEnvironmentMethod environment, ZenType predictedType) {
return compile(environment, predictedType).eval(environment);
}
}
@@ -7,8 +7,9 @@
package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.ExpressionOrOr;
import stanhebben.zenscript.expression.ExpressionAndAnd;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -27,10 +28,10 @@ public class ParsedExpressionAndAnd extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
return new ExpressionOrOr(
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionAndAnd(
getPosition(),
left.compile(environment).eval(environment),
right.compile(environment).eval(environment));
left.compile(environment, predictedType).eval(environment),
right.compile(environment, predictedType).eval(environment));
}
}
@@ -10,7 +10,12 @@ import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionArray;
import stanhebben.zenscript.expression.ExpressionAs;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeArray;
import stanhebben.zenscript.type.ZenTypeArrayBasic;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -27,20 +32,52 @@ public class ParsedExpressionArray extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
ZenType predictedBaseType = null;
ZenTypeArrayBasic arrayType = ZenType.ANYARRAY;
ICastingRule castingRule = null;
if (predictedType instanceof ZenTypeArray) {
predictedBaseType = ((ZenTypeArray) predictedType).getBaseType();
if (predictedType instanceof ZenTypeArrayBasic) {
// TODO: allow any kind of array type
arrayType = (ZenTypeArrayBasic) predictedType;
}
} else {
// find any[] caster that casts to the given type
castingRule = ZenType.ANYARRAY.getCastingRule(predictedType, environment);
if (castingRule != null) {
if (castingRule.getInputType() instanceof ZenTypeArray) {
predictedBaseType = ((ZenTypeArray) castingRule.getInputType()).getBaseType();
if (castingRule.getInputType() instanceof ZenTypeArrayBasic) {
// TODO: allow any kind of array type
arrayType = (ZenTypeArrayBasic) castingRule.getInputType();
}
} else {
environment.error(getPosition(), "Invalid caster - any[] caster but input type is not an array");
castingRule = null;
}
}
}
Expression[] cContents = new Expression[contents.size()];
for (int i = 0; i < contents.size(); i++) {
cContents[i] = contents.get(i).compile(environment).eval(environment);
cContents[i] = contents.get(i).compile(environment, predictedBaseType).eval(environment);
}
Expression result = new ExpressionArray(getPosition(), arrayType, cContents);
if (castingRule != null) {
return new ExpressionAs(getPosition(), result, castingRule);
} else {
return result;
}
return new ExpressionArray(getPosition(), cContents);
}
@Override
public Expression compileKey(IEnvironmentMethod environment) {
public Expression compileKey(IEnvironmentMethod environment, ZenType predictedType) {
if (contents.size() == 1 && contents.get(0) instanceof ParsedExpressionVariable) {
return contents.get(0).compile(environment).eval(environment);
return contents.get(0).compile(environment, predictedType).eval(environment);
} else {
return compile(environment).eval(environment);
return compile(environment, predictedType).eval(environment);
}
}
}
@@ -8,6 +8,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -26,10 +27,10 @@ public class ParsedExpressionAssign extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
IPartialExpression cLeft = left.compile(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
IPartialExpression cLeft = left.compile(environment, predictedType);
return cLeft
.assign(getPosition(), environment,
right.compile(environment).eval(environment));
right.compile(environment, cLeft.getType()).eval(environment));
}
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -30,9 +31,10 @@ public class ParsedExpressionBinary extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cLeft = left.compile(environment).eval(environment);
Expression cRight = right.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: make better predictions
Expression cLeft = left.compile(environment, predictedType).eval(environment);
Expression cRight = right.compile(environment, predictedType).eval(environment);
return cLeft.getType().binary(getPosition(), environment, cLeft, cRight, operator);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.ExpressionBool;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -25,7 +26,7 @@ public class ParsedExpressionBool extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionBool(getPosition(), value);
}
}
@@ -10,6 +10,7 @@ import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -26,13 +27,15 @@ public class ParsedExpressionCall extends ParsedExpression {
this.receiver = receiver;
this.arguments = arguments;
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
IPartialExpression cReceiver = receiver.compile(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
IPartialExpression cReceiver = receiver.compile(environment, null);
ZenType[] predictedTypes = cReceiver.predictCallTypes(arguments.size());
Expression[] cArguments = new Expression[arguments.size()];
for (int i = 0; i < cArguments.length; i++) {
IPartialExpression cArgument = arguments.get(i).compile(environment);
IPartialExpression cArgument = arguments.get(i).compile(environment, predictedTypes[i]);
cArguments[i] = cArgument.eval(environment);
}
@@ -27,9 +27,9 @@ public class ParsedExpressionCast extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return value
.compile(environment)
.compile(environment, type)
.eval(environment)
.cast(getPosition(), environment, type);
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.CompareType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -34,9 +35,9 @@ public class ParsedExpressionCompare extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cLeft = left.compile(environment).eval(environment);
Expression cRight = right.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
Expression cLeft = left.compile(environment, null).eval(environment);
Expression cRight = right.compile(environment, null).eval(environment);
return cLeft.getType().compare(getPosition(), environment, cLeft, cRight, type);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.ExpressionConditional;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -29,11 +30,11 @@ public class ParsedExpressionConditional extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionConditional(
getPosition(),
condition.compile(environment).eval(environment),
ifThen.compile(environment).eval(environment),
ifElse.compile(environment).eval(environment));
condition.compile(environment, ZenType.BOOL).eval(environment),
ifThen.compile(environment, predictedType).eval(environment),
ifElse.compile(environment, predictedType).eval(environment));
}
}
@@ -0,0 +1,83 @@
/*
* 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.parser.expression;
import java.lang.reflect.Method;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.definitions.ParsedFunctionArgument;
import stanhebben.zenscript.expression.ExpressionFunction;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.ExpressionJavaLambda;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.statements.Statement;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeAny;
import stanhebben.zenscript.type.ZenTypeNative;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stan
*/
public class ParsedExpressionFunction extends ParsedExpression {
private final ZenType returnType;
private final List<ParsedFunctionArgument> arguments;
private final List<Statement> statements;
public ParsedExpressionFunction(ZenPosition position, ZenType returnType, List<ParsedFunctionArgument> arguments, List<Statement> statements) {
super(position);
this.returnType = returnType;
this.arguments = arguments;
this.statements = statements;
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
if (predictedType != null && predictedType instanceof ZenTypeNative) {
System.out.println("Known predicted function type: " + predictedType);
ZenTypeNative nativeType = (ZenTypeNative) predictedType;
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(getPosition(), "return type not compatible");
return new ExpressionInvalid(getPosition());
}
if (arguments.size() != method.getParameterTypes().length) {
environment.error(getPosition(), "number of arguments incorrect");
return new ExpressionInvalid(getPosition());
}
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(getPosition(), "argument " + i + " doesn't match");
return new ExpressionInvalid(getPosition());
}
}
return new ExpressionJavaLambda(
getPosition(),
nativeClass,
arguments,
statements,
environment.getType(nativeClass));
} else {
environment.error(getPosition(), predictedType.toString() + " is not a functional interface");
return new ExpressionInvalid(getPosition());
}
} else {
System.out.println("No known predicted type");
return new ExpressionFunction(getPosition(), arguments, returnType, statements);
}
}
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -28,9 +29,10 @@ public class ParsedExpressionIndex extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cValue = value.compile(environment).eval(environment);
Expression cIndex = index.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: improve type prediction for this
Expression cValue = value.compile(environment, null).eval(environment);
Expression cIndex = index.compile(environment, null).eval(environment);
return cValue.getType().binary(getPosition(), environment, cValue, cIndex, OperatorType.INDEXGET);
}
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -30,10 +31,11 @@ public class ParsedExpressionIndexSet extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cValue = value.compile(environment).eval(environment);
Expression cIndex = index.compile(environment).eval(environment);
Expression cSetValue = setValue.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: improve prediction in this expression
Expression cValue = value.compile(environment, null).eval(environment);
Expression cIndex = index.compile(environment, null).eval(environment);
Expression cSetValue = setValue.compile(environment, null).eval(environment);
return cValue.getType().trinary(getPosition(), environment, cValue, cIndex, cSetValue,OperatorType.INDEXSET);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -21,7 +22,7 @@ public class ParsedExpressionInvalid extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
return new ExpressionInvalid(getPosition());
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionInvalid(getPosition(), predictedType == null ? ZenType.ANY : predictedType);
}
}
@@ -0,0 +1,79 @@
/*
* 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.parser.expression;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionAs;
import stanhebben.zenscript.expression.ExpressionMap;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeAssociative;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stanneke
*/
public class ParsedExpressionMap extends ParsedExpression {
private final List<ParsedExpression> keys;
private final List<ParsedExpression> values;
public ParsedExpressionMap(
ZenPosition position,
List<ParsedExpression> keys,
List<ParsedExpression> values) {
super(position);
this.keys = keys;
this.values = values;
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
ZenType predictedKeyType = null;
ZenType predictedValueType = null;
ICastingRule castingRule = null;
ZenTypeAssociative mapType = ZenType.ANYMAP;
if (predictedType instanceof ZenTypeAssociative) {
ZenTypeAssociative inputType = (ZenTypeAssociative) predictedType;
predictedKeyType = inputType.getKeyType();
predictedValueType = inputType.getValueType();
mapType = inputType;
} else {
castingRule = ZenType.ANYMAP.getCastingRule(predictedType, environment);
if (castingRule != null) {
if (castingRule.getInputType() instanceof ZenTypeAssociative) {
ZenTypeAssociative inputType = (ZenTypeAssociative) castingRule.getInputType();
predictedKeyType = inputType.getKeyType();
predictedValueType = inputType.getValueType();
mapType = inputType;
} else {
environment.error(getPosition(), "Caster found for any[any] but its input is not an associative array");
}
}
}
Expression[] cKeys = new Expression[keys.size()];
Expression[] cValues = new Expression[values.size()];
for (int i = 0; i < keys.size(); i++) {
cKeys[i] = keys.get(i).compileKey(environment, predictedKeyType);
cValues[i] = values.get(i).compile(environment, predictedValueType).eval(environment);
}
Expression result = new ExpressionMap(getPosition(), cKeys, cValues, mapType);
if (castingRule != null) {
return new ExpressionAs(getPosition(), result, castingRule);
} else {
return result;
}
}
}
@@ -8,6 +8,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -26,7 +27,7 @@ public class ParsedExpressionMember extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
return value.compile(environment).getMember(getPosition(), environment, member);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return value.compile(environment, null).getMember(getPosition(), environment, member);
}
}
@@ -9,6 +9,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.ExpressionNull;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -21,7 +22,7 @@ public class ParsedExpressionNull extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionNull(getPosition());
}
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -30,12 +31,13 @@ public class ParsedExpressionOpAssign extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cLeft = left.compile(environment).eval(environment);
Expression cRight = right.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: validate if the prediction rules are sound
Expression cLeft = left.compile(environment, predictedType).eval(environment);
Expression cRight = right.compile(environment, cLeft.getType()).eval(environment);
Expression value = cLeft.getType().binary(getPosition(), environment, cLeft, cRight, operator);
return left.compile(environment).assign(getPosition(), environment, value);
return left.compile(environment, predictedType).assign(getPosition(), environment, value);
}
}
@@ -7,8 +7,10 @@
package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionOrOr;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -27,10 +29,23 @@ public class ParsedExpressionOrOr extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
Expression cLeft = left.compile(environment, predictedType).eval(environment);
Expression cRight = right.compile(environment, predictedType).eval(environment);
ZenType type;
if (cRight.getType().canCastImplicit(cLeft.getType(), environment)) {
type = cLeft.getType();
} else if (cLeft.getType().canCastImplicit(cRight.getType(), environment)) {
type = cRight.getType();
} else {
environment.error(getPosition(), "These types could not be unified: " + cLeft.getType() + " and " + cRight.getType());
type = ZenType.ANY;
}
return new ExpressionOrOr(
getPosition(),
left.compile(environment).eval(environment),
right.compile(environment).eval(environment));
cLeft.cast(getPosition(), environment, type),
cRight.cast(getPosition(), environment, type));
}
}
@@ -1,46 +0,0 @@
/*
* 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.parser.expression;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionTable;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stanneke
*/
public class ParsedExpressionTable extends ParsedExpression {
private final List<ParsedExpression> keys;
private final List<ParsedExpression> values;
public ParsedExpressionTable(
ZenPosition position,
List<ParsedExpression> keys,
List<ParsedExpression> values) {
super(position);
this.keys = keys;
this.values = values;
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression[] cKeys = new Expression[keys.size()];
Expression[] cValues = new Expression[values.size()];
for (int i = 0; i < keys.size(); i++) {
cKeys[i] = keys.get(i).compileKey(environment);
cValues[i] = values.get(i).compile(environment).eval(environment);
}
return new ExpressionTable(getPosition(), cKeys, cValues);
}
}
@@ -10,6 +10,7 @@ import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -28,8 +29,9 @@ public class ParsedExpressionUnary extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
Expression cValue = value.compile(environment).eval(environment);
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
// TODO: improve type predictions?
Expression cValue = value.compile(environment, predictedType).eval(environment);
return cValue.getType().unary(getPosition(), environment, cValue, operator);
}
}
@@ -8,6 +8,7 @@ package stanhebben.zenscript.parser.expression;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -26,7 +27,7 @@ public class ParsedExpressionValue extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
return value;
}
}
@@ -11,6 +11,7 @@ import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -27,18 +28,24 @@ public class ParsedExpressionVariable extends ParsedExpression {
}
@Override
public IPartialExpression compile(IEnvironmentMethod environment) {
public IPartialExpression compile(IEnvironmentMethod environment, ZenType predictedType) {
IPartialExpression result = environment.getValue(name, getPosition());
if (result == null) {
environment.error(getPosition(), "could not find " + name);
return new ExpressionInvalid(getPosition());
// enable usage of static members of the same type as the predicted type (eg. enum values)
IPartialExpression member = predictedType.getStaticMember(getPosition(), environment, name);
if (member == null || member.getType().getCastingRule(predictedType, environment) == null) {
environment.error(getPosition(), "could not find " + name);
return new ExpressionInvalid(getPosition());
} else {
return member;
}
} else {
return result;
}
}
@Override
public Expression compileKey(IEnvironmentMethod environment) {
public Expression compileKey(IEnvironmentMethod environment, ZenType predictedType) {
return new ExpressionString(getPosition(), name);
}
}
@@ -13,14 +13,14 @@ import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
public abstract class Statement {
public static Statement read(ZenTokener parser, IEnvironmentGlobal environment) {
public static Statement read(ZenTokener parser, IEnvironmentGlobal environment, ZenType returnType) {
Token next = parser.peek();
switch (next.getType()) {
case T_AOPEN: {
Token t = parser.next();
ArrayList<Statement> statements = new ArrayList<Statement>();
while (parser.optional(T_ACLOSE) == null) {
statements.add(read(parser, environment));
statements.add(read(parser, environment, returnType));
}
return new StatementBlock(t.getPosition(), statements);
}
@@ -28,7 +28,7 @@ public abstract class Statement {
parser.next();
ParsedExpression expression = ParsedExpression.read(parser, environment);
parser.required(T_SEMICOLON, "; expected");
return new StatementReturn(next.getPosition(), expression);
return new StatementReturn(next.getPosition(), returnType, expression);
}
case T_VAR:
case T_VAL: {
@@ -49,10 +49,10 @@ public abstract class Statement {
case T_IF: {
Token t = parser.next();
ParsedExpression expression = ParsedExpression.read(parser, environment);
Statement onIf = read(parser, environment);
Statement onIf = read(parser, environment, returnType);
Statement onElse = null;
if (parser.optional(T_ELSE) != null) {
onElse = read(parser, environment);
onElse = read(parser, environment, returnType);
}
return new StatementIf(t.getPosition(), expression, onIf, onElse);
}
@@ -68,7 +68,7 @@ public abstract class Statement {
parser.required(T_IN, "in expected");
ParsedExpression source = ParsedExpression.read(parser, environment);
Statement content = read(parser, environment);
Statement content = read(parser, environment, null);
return new StatementForeach(
t.getPosition(),
names.toArray(new String[names.size()]),
@@ -16,7 +16,7 @@ public class StatementExpression extends Statement {
@Override
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
expression.compile(environment)
expression.compile(environment, null)
.eval(environment)
.compile(false, environment);
}
@@ -26,7 +26,7 @@ public class StatementForeach extends Statement {
@Override
public void compile(IEnvironmentMethod environment) {
Expression cList = list.compile(environment).eval(environment);
Expression cList = list.compile(environment, ZenType.ANYARRAY).eval(environment);
ZenType listType = cList.getType();
IZenIterator iterator = listType.makeIterator(varnames.length, environment);
@@ -5,7 +5,6 @@ import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.parser.expression.ParsedExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeBool;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
@@ -26,7 +25,7 @@ public class StatementIf extends Statement {
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
Expression cCondition = condition.compile(environment).eval(environment);
Expression cCondition = condition.compile(environment, ZenType.BOOL).eval(environment);
ZenType expressionType = cCondition.getType();
if (expressionType.canCastImplicit(ZenType.BOOL, environment)) {
Label labelEnd = new Label();
@@ -4,14 +4,17 @@ import org.objectweb.asm.Type;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.parser.expression.ParsedExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.ZenPosition;
public class StatementReturn extends Statement {
private final ZenType returnType;
private final ParsedExpression expression;
public StatementReturn(ZenPosition position, ParsedExpression expression) {
public StatementReturn(ZenPosition position, ZenType returnType, ParsedExpression expression) {
super(position);
this.returnType = returnType;
this.expression = expression;
}
@@ -31,7 +34,7 @@ public class StatementReturn extends Statement {
if (expression == null) {
environment.getOutput().ret();
} else {
Expression cExpression = expression.compile(environment).eval(environment);
Expression cExpression = expression.compile(environment, returnType).eval(environment);
cExpression.compile(true, environment);
Type returnType = cExpression.getType().toASMType();
@@ -39,7 +39,7 @@ public class StatementVar extends Statement {
Expression cInitializer = initializer == null
? null
: initializer.compile(environment).eval(environment);
: initializer.compile(environment, type).eval(environment);
ZenType cType = type == null ? (cInitializer == null ? ZenTypeAny.INSTANCE : cInitializer.getType()) : type;
SymbolLocal symbol = new SymbolLocal(cType, isFinal);
@@ -8,7 +8,7 @@ package stanhebben.zenscript.symbols;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.expression.partial.PartialStaticGetter;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -16,9 +16,9 @@ import stanhebben.zenscript.util.ZenPosition;
* @author Stanneke
*/
public class SymbolJavaStaticGetter implements IZenSymbol {
private final JavaMethod method;
private final IJavaMethod method;
public SymbolJavaStaticGetter(JavaMethod method) {
public SymbolJavaStaticGetter(IJavaMethod method) {
this.method = method;
}
@@ -8,7 +8,7 @@ package stanhebben.zenscript.symbols;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.expression.partial.PartialStaticMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -16,9 +16,9 @@ import stanhebben.zenscript.util.ZenPosition;
* @author Stanneke
*/
public class SymbolJavaStaticMethod implements IZenSymbol {
private final JavaMethod method;
private final IJavaMethod method;
public SymbolJavaStaticMethod(JavaMethod method) {
public SymbolJavaStaticMethod(IJavaMethod method) {
this.method = method;
}
@@ -1,6 +1,8 @@
package stanhebben.zenscript.type;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.Type;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.ZenTokener;
@@ -12,22 +14,38 @@ import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.parser.ParseException;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingRuleDelegateMap;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.expand.ZenExpandCaster;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
import static stanhebben.zenscript.util.ZenTypeUtil.EMPTY_REGISTRY;
public abstract class ZenType {
public static final ZenTypeAny ANY = ZenTypeAny.INSTANCE;
public static final ZenTypeBool BOOL = new ZenTypeBool();
public static final ZenTypeBoolObject BOOLOBJECT = ZenTypeBoolObject.INSTANCE;
public static final ZenTypeByte BYTE = ZenTypeByte.INSTANCE;
public static final ZenTypeByteObject BYTEOBJECT = ZenTypeByteObject.INSTANCE;
public static final ZenTypeShort SHORT = ZenTypeShort.INSTANCE;
public static final ZenTypeShortObject SHORTOBJECT = ZenTypeShortObject.INSTANCE;
public static final ZenTypeInt INT = ZenTypeInt.INSTANCE;
public static final ZenTypeIntObject INTOBJECT = ZenTypeIntObject.INSTANCE;
public static final ZenTypeLong LONG = ZenTypeLong.INSTANCE;
public static final ZenTypeLongObject LONGOBJECT = ZenTypeLongObject.INSTANCE;
public static final ZenTypeFloat FLOAT = ZenTypeFloat.INSTANCE;
public static final ZenTypeFloatObject FLOATOBJECT = ZenTypeFloatObject.INSTANCE;
public static final ZenTypeDouble DOUBLE = ZenTypeDouble.INSTANCE;
public static final ZenTypeDoubleObject DOUBLEOBJECT = ZenTypeDoubleObject.INSTANCE;
public static final ZenTypeString STRING = ZenTypeString.INSTANCE;
public static final ZenTypeVoid VOID = ZenTypeVoid.INSTANCE;
public static final ZenTypeNull NULL = ZenTypeNull.INSTANCE;
public static final ZenTypeArrayBasic ANYARRAY = new ZenTypeArrayBasic(ANY);
public static final ZenTypeAssociative ANYMAP = new ZenTypeAssociative(ANY, ANY);
public static final int NUM_BYTE = 1;
public static final int NUM_SHORT = 2;
public static final int NUM_INT = 3;
@@ -35,6 +53,54 @@ public abstract class ZenType {
public static final int NUM_FLOAT = 5;
public static final int NUM_DOUBLE = 6;
protected static final IJavaMethod BOOL_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "valueOf", boolean.class);
protected static final IJavaMethod BYTE_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Byte.class, "valueOf", byte.class);
protected static final IJavaMethod SHORT_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Short.class, "valueOf", short.class);
protected static final IJavaMethod INT_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Integer.class, "valueOf", int.class);
protected static final IJavaMethod LONG_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Long.class, "valueOf", long.class);
protected static final IJavaMethod FLOAT_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Float.class, "valueOf", float.class);
protected static final IJavaMethod DOUBLE_VALUEOF = JavaMethod.get(EMPTY_REGISTRY, Double.class, "valueOf", double.class);
protected static final IJavaMethod BOOL_VALUE = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "booleanValue");
protected static final IJavaMethod BYTE_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "byteValue");
protected static final IJavaMethod SHORT_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "shortValue");
protected static final IJavaMethod INT_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "intValue");
protected static final IJavaMethod LONG_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "longValue");
protected static final IJavaMethod FLOAT_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "floatValue");
protected static final IJavaMethod DOUBLE_VALUE = JavaMethod.get(EMPTY_REGISTRY, Number.class, "doubleValue");
protected static final IJavaMethod BOOL_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "toString", boolean.class);
protected static final IJavaMethod BYTE_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Byte.class, "toString", byte.class);
protected static final IJavaMethod SHORT_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Short.class, "toString", short.class);
protected static final IJavaMethod INT_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Integer.class, "toString", int.class);
protected static final IJavaMethod LONG_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Long.class, "toString", long.class);
protected static final IJavaMethod FLOAT_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Float.class, "toString", float.class);
protected static final IJavaMethod DOUBLE_TOSTRING_STATIC = JavaMethod.get(EMPTY_REGISTRY, Double.class, "toString", double.class);
protected static final IJavaMethod BOOL_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "toString");
protected static final IJavaMethod BYTE_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Byte.class, "toString");
protected static final IJavaMethod SHORT_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Short.class, "toString");
protected static final IJavaMethod INT_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Integer.class, "toString");
protected static final IJavaMethod LONG_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Long.class, "toString");
protected static final IJavaMethod FLOAT_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Float.class, "toString");
protected static final IJavaMethod DOUBLE_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Double.class, "toString");
protected static final IJavaMethod PARSE_BOOL = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "parseBoolean", String.class);
protected static final IJavaMethod PARSE_BYTE = JavaMethod.get(EMPTY_REGISTRY, Byte.class, "parseByte", String.class);
protected static final IJavaMethod PARSE_SHORT = JavaMethod.get(EMPTY_REGISTRY, Short.class, "parseShort", String.class);
protected static final IJavaMethod PARSE_INT = JavaMethod.get(EMPTY_REGISTRY, Integer.class, "parseInt", String.class);
protected static final IJavaMethod PARSE_LONG = JavaMethod.get(EMPTY_REGISTRY, Long.class, "parseLong", String.class);
protected static final IJavaMethod PARSE_FLOAT = JavaMethod.get(EMPTY_REGISTRY, Float.class, "parseFloat", String.class);
protected static final IJavaMethod PARSE_DOUBLE = JavaMethod.get(EMPTY_REGISTRY, Double.class, "parseDouble", String.class);
protected static final IJavaMethod PARSE_BOOL_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_BYTE_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Byte.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_SHORT_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Short.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_INT_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Integer.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_LONG_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Long.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_FLOAT_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Float.class, "valueOf", String.class);
protected static final IJavaMethod PARSE_DOUBLE_OBJECT = JavaMethod.get(EMPTY_REGISTRY, Double.class, "valueOf", String.class);
public static ZenType parse(String type, IEnvironmentGlobal environment) {
try {
ZenTokener parser = new ZenTokener(type, environment.getEnvironment());
@@ -99,7 +165,6 @@ public abstract class ZenType {
}
if (partial != null) {
base = partial.toType(environment);
System.out.println("Parsed type " + base.getName());
}
break;
default:
@@ -118,6 +183,8 @@ public abstract class ZenType {
return base;
}
private Map<ZenType, ICastingRule> castingRules = null;
public abstract Expression unary(
ZenPosition position,
IEnvironmentGlobal environment,
@@ -163,15 +230,35 @@ public abstract class ZenType {
Expression receiver,
Expression... arguments);
public abstract Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type);
public ZenType[] predictCallTypes(int numArguments) {
return new ZenType[numArguments];
}
public abstract void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters);
public abstract IZenIterator makeIterator(
int numValues,
IEnvironmentMethod methodOutput);
public abstract boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment);
public ICastingRule getCastingRule(ZenType type, IEnvironmentGlobal environment) {
if (castingRules == null) {
castingRules = new HashMap<ZenType, ICastingRule>();
constructCastingRules(environment, new CastingRuleDelegateMap(castingRules), true);
}
return castingRules.get(type);
}
public final boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
if (equals(type))
return true;
return getCastingRule(type, environment) != null;
}
public abstract boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment);
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
return canCastImplicit(type, environment);
}
public abstract Class toJavaClass();
@@ -183,7 +270,17 @@ public abstract class ZenType {
public abstract boolean isPointer();
public abstract void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type);
public final void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
if (equals(type))
return;
ICastingRule castingRule = getCastingRule(type, environment);
if (castingRule != null) {
castingRule.compile(environment);
} else {
throw new RuntimeException("Cannot cast " + getName() + " to " + type.getName());
}
}
public abstract String getAnyClassName(IEnvironmentGlobal environment);
@@ -251,6 +348,13 @@ public abstract class ZenType {
return null;
}
protected void constructExpansionCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules) {
TypeExpansion expansion = environment.getExpansion(getName());
if (expansion != null) {
expansion.constructCastingRules(environment, rules);
}
}
protected Expression castExpansion(
ZenPosition position,
IEnvironmentGlobal environment,
@@ -1,24 +1,30 @@
package stanhebben.zenscript.type;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import stanhebben.zenscript.annotations.CompareType;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionAs;
import stanhebben.zenscript.expression.ExpressionCompareGeneric;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.ExpressionJavaCallVirtual;
import stanhebben.zenscript.expression.ExpressionCallVirtual;
import stanhebben.zenscript.expression.ExpressionNull;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingAnyBool;
import stanhebben.zenscript.type.casting.CastingAnyByte;
import stanhebben.zenscript.type.casting.CastingAnyDouble;
import stanhebben.zenscript.type.casting.CastingAnyFloat;
import stanhebben.zenscript.type.casting.CastingAnyInt;
import stanhebben.zenscript.type.casting.CastingAnyLong;
import stanhebben.zenscript.type.casting.CastingAnyShort;
import stanhebben.zenscript.type.casting.CastingAnyString;
import stanhebben.zenscript.type.casting.CastingRuleAnyAs;
import stanhebben.zenscript.type.casting.CastingRuleNullableStaticMethod;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.natives.JavaMethod;
import static stanhebben.zenscript.util.AnyClassWriter.*;
import stanhebben.zenscript.util.MethodCompiler;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
import stanhebben.zenscript.value.IAny;
@@ -30,205 +36,6 @@ import stanhebben.zenscript.value.IAny;
public class ZenTypeAny extends ZenType {
public static final ZenTypeAny INSTANCE = new ZenTypeAny();
private static final Map<String, MethodCompiler> CASTERS;
static {
CASTERS = new HashMap<String, MethodCompiler>();
CASTERS.put("bool", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asBool", boolean.class);
}
});
CASTERS.put("byte", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asByte", byte.class);
}
});
CASTERS.put("short", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asShort", short.class);
}
});
CASTERS.put("int", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asInt", int.class);
}
});
CASTERS.put("long", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asLong", long.class);
}
});
CASTERS.put("float", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asFloat", float.class);
}
});
CASTERS.put("double", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
output.invokeInterface(IAny.class, "asDouble", double.class);
}
});
CASTERS.put("string", new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asString", String.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Boolean.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asBool", boolean.class);
output.invokeStatic(Boolean.class, "valueOf", Boolean.class, boolean.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Byte.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asByte", boolean.class);
output.invokeStatic(Byte.class, "valueOf", Byte.class, byte.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Short.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asShort", short.class);
output.invokeStatic(Short.class, "valueOf", Short.class, short.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Integer.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asInt", int.class);
output.invokeStatic(Integer.class, "valueOf", Integer.class, int.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Long.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asLong", long.class);
output.invokeStatic(Long.class, "valueOf", Long.class, long.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Float.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asFloat", float.class);
output.invokeStatic(Float.class, "valueOf", Float.class, float.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(Double.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asDouble", double.class);
output.invokeStatic(Double.class, "valueOf", Double.class, double.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
CASTERS.put(String.class.getName(), new MethodCompiler() {
@Override
public void compile(MethodOutput output) {
Label lblNull = new Label();
Label lblAfter = new Label();
output.dup();
output.ifNull(lblNull);
output.invokeInterface(IAny.class, "asString", String.class);
output.goTo(lblAfter);
output.label(lblNull);
output.pop();
output.aConstNull();
output.label(lblAfter);
}
});
}
private ZenTypeAny() {}
@Override
@@ -247,12 +54,40 @@ public class ZenTypeAny extends ZenType {
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
return null; // TODO: handle iteration on any-values
}
@Override
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
return true;
public ICastingRule getCastingRule(ZenType type, IEnvironmentGlobal environment) {
ICastingRule base = super.getCastingRule(type, environment);
if (base == null) {
return new CastingRuleAnyAs(type);
} else {
return base;
}
}
@Override
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters) {
rules.registerCastingRule(BOOL, CastingAnyBool.INSTANCE);
rules.registerCastingRule(BOOLOBJECT, new CastingRuleNullableStaticMethod(BOOL_VALUEOF, CastingAnyBool.INSTANCE));
rules.registerCastingRule(BYTE, CastingAnyByte.INSTANCE);
rules.registerCastingRule(BYTEOBJECT, new CastingRuleNullableStaticMethod(BYTE_VALUEOF, CastingAnyByte.INSTANCE));
rules.registerCastingRule(SHORT, CastingAnyShort.INSTANCE);
rules.registerCastingRule(SHORTOBJECT, new CastingRuleNullableStaticMethod(SHORT_VALUEOF, CastingAnyShort.INSTANCE));
rules.registerCastingRule(INT, CastingAnyInt.INSTANCE);
rules.registerCastingRule(INTOBJECT, new CastingRuleNullableStaticMethod(INT_VALUEOF, CastingAnyInt.INSTANCE));
rules.registerCastingRule(LONG, CastingAnyLong.INSTANCE);
rules.registerCastingRule(LONGOBJECT, new CastingRuleNullableStaticMethod(LONG_VALUEOF, CastingAnyLong.INSTANCE));
rules.registerCastingRule(FLOAT, CastingAnyFloat.INSTANCE);
rules.registerCastingRule(FLOATOBJECT, new CastingRuleNullableStaticMethod(FLOAT_VALUEOF, CastingAnyFloat.INSTANCE));
rules.registerCastingRule(DOUBLE, CastingAnyDouble.INSTANCE);
rules.registerCastingRule(DOUBLEOBJECT, new CastingRuleNullableStaticMethod(DOUBLE_VALUEOF, CastingAnyDouble.INSTANCE));
rules.registerCastingRule(STRING, CastingAnyString.INSTANCE);
if (followCasters) {
constructExpansionCastingRules(environment, rules);
}
}
@Override
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
return true;
@@ -282,26 +117,14 @@ public class ZenTypeAny extends ZenType {
public boolean isPointer() {
return true;
}
@Override
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType toType) {
if (CASTERS.containsKey(toType.getName())) {
CASTERS.get(toType.getName()).compile(environment.getOutput());
} else {
if (!compileCastExpansion(position, environment, toType)) {
environment.getOutput().constant(toType);
environment.getOutput().invokeInterface(IAny.class, "as", Class.class, Object.class);
}
}
}
@Override
public Expression unary(ZenPosition position, IEnvironmentGlobal environment, Expression value, OperatorType operator) {
switch (operator) {
case NEG:
return new ExpressionJavaCallVirtual(position, METHOD_NEG, value);
return new ExpressionCallVirtual(position, environment, METHOD_NEG, value);
case NOT:
return new ExpressionJavaCallVirtual(position, METHOD_NOT, value);
return new ExpressionCallVirtual(position, environment, METHOD_NOT, value);
default:
return new ExpressionInvalid(position, ZenTypeAny.INSTANCE);
}
@@ -311,33 +134,33 @@ public class ZenTypeAny extends ZenType {
public Expression binary(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, OperatorType operator) {
switch (operator) {
case ADD:
return new ExpressionJavaCallVirtual(position, METHOD_ADD, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_ADD, left, right.cast(position, environment, ANY));
case CAT:
return new ExpressionJavaCallVirtual(position, METHOD_CAT, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_CAT, left, right.cast(position, environment, ANY));
case SUB:
return new ExpressionJavaCallVirtual(position, METHOD_SUB, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_SUB, left, right.cast(position, environment, ANY));
case MUL:
return new ExpressionJavaCallVirtual(position, METHOD_MUL, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_MUL, left, right.cast(position, environment, ANY));
case DIV:
return new ExpressionJavaCallVirtual(position, METHOD_DIV, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_DIV, left, right.cast(position, environment, ANY));
case MOD:
return new ExpressionJavaCallVirtual(position, METHOD_MOD, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_MOD, left, right.cast(position, environment, ANY));
case AND:
return new ExpressionJavaCallVirtual(position, METHOD_AND, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_AND, left, right.cast(position, environment, ANY));
case OR:
return new ExpressionJavaCallVirtual(position, METHOD_OR, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_OR, left, right.cast(position, environment, ANY));
case XOR:
return new ExpressionJavaCallVirtual(position, METHOD_XOR, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_XOR, left, right.cast(position, environment, ANY));
case CONTAINS:
return new ExpressionJavaCallVirtual(position, METHOD_CONTAINS, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_CONTAINS, left, right.cast(position, environment, ANY));
case INDEXGET:
return new ExpressionJavaCallVirtual(position, METHOD_INDEXGET, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_INDEXGET, left, right.cast(position, environment, ANY));
case RANGE:
return new ExpressionJavaCallVirtual(position, METHOD_RANGE, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_RANGE, left, right.cast(position, environment, ANY));
case COMPARE:
return new ExpressionJavaCallVirtual(position, METHOD_COMPARETO, left, right.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_COMPARETO, left, right.cast(position, environment, ANY));
case MEMBERGETTER:
return new ExpressionJavaCallVirtual(position, METHOD_MEMBERGET, left, right.cast(position, environment, STRING));
return new ExpressionCallVirtual(position, environment, METHOD_MEMBERGET, left, right.cast(position, environment, STRING));
default:
return new ExpressionInvalid(position, ANY);
}
@@ -347,9 +170,9 @@ public class ZenTypeAny extends ZenType {
public Expression trinary(ZenPosition position, IEnvironmentGlobal environment, Expression first, Expression second, Expression third, OperatorType operator) {
switch (operator) {
case INDEXSET:
return new ExpressionJavaCallVirtual(position, METHOD_INDEXSET, first, second.cast(position, environment, ANY), third.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_INDEXSET, first, second.cast(position, environment, ANY), third.cast(position, environment, ANY));
case MEMBERSETTER:
return new ExpressionJavaCallVirtual(position, METHOD_MEMBERSET, first, second.cast(position, environment, STRING), third.cast(position, environment, ANY));
return new ExpressionCallVirtual(position, environment, METHOD_MEMBERSET, first, second.cast(position, environment, STRING), third.cast(position, environment, ANY));
default:
return new ExpressionInvalid(position, ANY);
}
@@ -357,9 +180,12 @@ public class ZenTypeAny extends ZenType {
@Override
public Expression compare(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, CompareType type) {
Expression comparator = JavaMethod
.get(environment, IAny.class, "compareTo", IAny.class)
.callVirtual(position, environment, left, right);
Expression comparator = new ExpressionCallVirtual(
position,
environment,
JavaMethod.get(environment, IAny.class, "compareTo", IAny.class),
left,
right);
return new ExpressionCompareGeneric(
position,
@@ -369,20 +195,21 @@ public class ZenTypeAny extends ZenType {
@Override
public Expression call(ZenPosition position, IEnvironmentGlobal environment, Expression receiver, Expression... arguments) {
return JavaMethod
.get(environment, IAny.class, "call", IAny[].class)
.callVirtual(position, environment, receiver, arguments);
return new ExpressionCallVirtual(
position,
environment,
JavaMethod.get(environment, IAny.class, "call", IAny[].class),
receiver,
arguments);
}
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
if (type.equals(this)) return value;
if (canCastExpansion(environment, type)) {
return castExpansion(position, environment, value, type);
} else {
return new ExpressionAs(position, value, type);
public ZenType[] predictCallTypes(int numArguments) {
ZenType[] result = new ZenType[numArguments];
for (int i = 0; i < result.length; i++) {
result[i] = ANY;
}
return result;
}
@Override
@@ -44,19 +44,6 @@ public abstract class ZenTypeArray extends ZenType {
return name;
}
@Override
public final boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
if (equals(type) || canCastExpansion(environment, type)) {
return true;
}
if (type instanceof ZenTypeArray) {
return base.canCastImplicit(((ZenTypeArray) type).base, environment);
}
return false;
}
@Override
public final boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
return equals(type) || canCastExpansion(environment, type);
@@ -1,7 +1,5 @@
package stanhebben.zenscript.type;
import java.util.Arrays;
import java.util.List;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
@@ -11,6 +9,11 @@ import stanhebben.zenscript.expression.ExpressionArrayGet;
import stanhebben.zenscript.expression.ExpressionArrayLength;
import stanhebben.zenscript.expression.ExpressionArraySet;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingRuleArrayArray;
import stanhebben.zenscript.type.casting.CastingRuleArrayList;
import stanhebben.zenscript.type.casting.CastingRuleDelegateArray;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
@@ -41,12 +44,32 @@ public class ZenTypeArrayBasic extends ZenTypeArray {
}
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
if (equals(type)) return value;
return castExpansion(position, environment, value, type);
public ICastingRule getCastingRule(ZenType type, IEnvironmentGlobal environment) {
ICastingRule base = super.getCastingRule(type, environment);
if (base == null && getBaseType() == ANY && type instanceof ZenTypeArray) {
ZenType toBaseType = ((ZenTypeArray)type).getBaseType();
if (type instanceof ZenTypeArrayBasic) {
return new CastingRuleArrayArray(ANY.getCastingRule(toBaseType, environment), this, (ZenTypeArrayBasic) type);
} else if (type instanceof ZenTypeArrayList) {
return new CastingRuleArrayList(ANY.getCastingRule(toBaseType, environment), this, (ZenTypeArrayList) type);
} else {
throw new RuntimeException("Invalid array type: " + type);
}
} else {
return base;
}
}
@Override
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters) {
ICastingRuleDelegate arrayRules = new CastingRuleDelegateArray(rules, this);
getBaseType().constructCastingRules(environment, arrayRules, followCasters);
if (followCasters) {
constructExpansionCastingRules(environment, rules);
}
}
@Override
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
if (numValues == 1) {
@@ -71,7 +94,7 @@ public class ZenTypeArrayBasic extends ZenTypeArray {
@Override
public Class toJavaClass() {
try {
return Class.forName("[" + getBaseType().toJavaClass().getName());
return Class.forName("[L" + getBaseType().toJavaClass().getName() + ";");
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
@@ -81,68 +104,7 @@ public class ZenTypeArrayBasic extends ZenTypeArray {
public String getSignature() {
return "[" + getBaseType().getSignature();
}
@Override
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType toClass) {
MethodOutput output = environment.getOutput();
if (compileCastExpansion(position, environment, toClass)) {
// OK
} else if (toClass instanceof ZenTypeArrayList) {
// convert array to list
// Arrays.asList(value);
output.invokeStatic(Arrays.class, "asList", List.class, Object[].class);
} else if (toClass instanceof ZenTypeArrayBasic) {
// convert elements
if (toClass.equals(this)) {
// do nothing
} else {
ZenType component = ((ZenTypeArrayBasic) toClass).getBaseType();
Type componentType = component.toASMType();
int result = output.local(componentType);
output.dup();
output.arrayLength();
output.newArray(componentType);
output.storeObject(result);
output.iConst0();
Label lbl = new Label();
output.label(lbl);
// stack: original index
output.dupX1();
output.dupX1();
output.arrayLoad(componentType);
// stack: original index value
getBaseType().compileCast(position, environment, toClass);
output.loadObject(result);
output.dupX2();
output.dupX2();
output.arrayStore(componentType);
output.pop();
// stack: original index
output.iConst1();
output.iAdd();
output.dupX1();
output.arrayLength();
output.ifICmpGE(lbl);
output.pop();
output.pop();
output.loadObject(result);
}
} else {
// TODO: error
}
}
@Override
public IPartialExpression getMemberLength(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value) {
return new ExpressionArrayLength(position, value.eval(environment));
@@ -7,15 +7,15 @@
package stanhebben.zenscript.type;
import java.util.List;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingRuleDelegateList;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.iterator.IteratorIterable;
import stanhebben.zenscript.type.iterator.IteratorList;
import stanhebben.zenscript.util.MethodOutput;
import stanhebben.zenscript.util.ZenPosition;
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
@@ -38,12 +38,15 @@ public class ZenTypeArrayList extends ZenTypeArray {
}
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
if (equals(type)) return value;
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters) {
ICastingRuleDelegate arrayRules = new CastingRuleDelegateList(rules, this);
getBaseType().constructCastingRules(environment, arrayRules, followCasters);
return castExpansion(position, environment, value, type);
if (followCasters) {
constructExpansionCastingRules(environment, rules);
}
}
@Override
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
if (numValues == 1) {
@@ -74,74 +77,16 @@ public class ZenTypeArrayList extends ZenTypeArray {
public String getSignature() {
return signature(List.class);
}
@Override
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
MethodOutput output = environment.getOutput();
if (equals(type)) {
return;
}
if (compileCastExpansion(position, environment, type)) {
// OK
} else if (type instanceof ZenTypeArrayList) {
// TODO: implement
} else if (type instanceof ZenTypeArrayBasic) {
// convert elements
ZenType component = ((ZenTypeArrayBasic) type).getBaseType();
Type componentType = component.toASMType();
Type baseType = getBaseType().toASMType();
int result = output.local(componentType);
output.dup();
output.arrayLength();
output.newArray(baseType);
output.storeObject(result);
output.iConst0();
Label lbl = new Label();
output.label(lbl);
// stack: original index
output.dupX1();
output.dupX1();
output.arrayLoad(componentType);
// stack: original index value
getBaseType().compileCast(position, environment, type);
output.loadObject(result);
output.dupX2();
output.dupX2();
output.arrayStore(baseType);
output.pop();
// stack: original index
output.iConst1();
output.iAdd();
output.dupX1();
output.arrayLength();
output.ifICmpGE(lbl);
output.pop();
output.pop();
output.loadObject(result);
} else {
// TODO: error
}
}
@Override
public Expression indexGet(ZenPosition position, IEnvironmentGlobal environment, Expression array, Expression index) {
// TODO: implement
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Expression indexSet(ZenPosition position, IEnvironmentGlobal environment, Expression array, Expression index, Expression value) {
// TODO: implement
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@@ -22,6 +22,9 @@ import stanhebben.zenscript.expression.ExpressionMapSize;
import stanhebben.zenscript.expression.ExpressionNull;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingRuleMap;
import stanhebben.zenscript.type.casting.ICastingRule;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.iterator.IteratorMap;
import stanhebben.zenscript.type.iterator.IteratorMapKeys;
import stanhebben.zenscript.util.ZenPosition;
@@ -32,24 +35,39 @@ import static stanhebben.zenscript.util.ZenTypeUtil.signature;
* @author Stanneke
*/
public class ZenTypeAssociative extends ZenType {
private final ZenType base;
private final ZenType key;
private final ZenType valueType;
private final ZenType keyType;
private final String name;
public ZenTypeAssociative(ZenType base, ZenType key) {
this.base = base;
this.key = key;
public ZenTypeAssociative(ZenType valueType, ZenType keyType) {
this.valueType = valueType;
this.keyType = keyType;
name = base.getName() + "[" + key.getName() + "]";
name = valueType.getName() + "[" + keyType.getName() + "]";
}
public ZenType getValueType() {
return base;
return valueType;
}
public ZenType getKeyType() {
return key;
return keyType;
}
@Override
public ICastingRule getCastingRule(ZenType type, IEnvironmentGlobal environment) {
ICastingRule base = super.getCastingRule(type, environment);
if (base == null && type instanceof ZenTypeAssociative && keyType == ANY && valueType == ANY) {
ZenTypeAssociative aType = (ZenTypeAssociative) type;
return new CastingRuleMap(
ANY.getCastingRule(aType.keyType, environment),
ANY.getCastingRule(aType.valueType, environment),
this,
aType);
} else {
return base;
}
}
@Override
@@ -71,9 +89,9 @@ public class ZenTypeAssociative extends ZenType {
@Override
public Expression binary(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, OperatorType operator) {
if (operator == OperatorType.CONTAINS) {
return new ExpressionMapContains(position, left, right.cast(position, environment, key));
return new ExpressionMapContains(position, left, right.cast(position, environment, keyType));
} else if (operator == OperatorType.INDEXGET) {
return new ExpressionMapIndexGet(position, left, right.cast(position, environment, key));
return new ExpressionMapIndexGet(position, left, right.cast(position, environment, keyType));
} else {
Expression result = binaryExpansion(position, environment, left, right, operator);
if (result == null) {
@@ -91,8 +109,8 @@ public class ZenTypeAssociative extends ZenType {
return new ExpressionMapIndexSet(
position,
first,
second.cast(position, environment, key),
third.cast(position, environment, base));
second.cast(position, environment, keyType),
third.cast(position, environment, valueType));
} else {
Expression result = trinaryExpansion(position, environment, first, second, third, operator);
if (result == null) {
@@ -119,16 +137,16 @@ public class ZenTypeAssociative extends ZenType {
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
if (name.equals("length")) {
return new ExpressionMapSize(position, value.eval(environment));
} else if (STRING.canCastImplicit(key, environment)) {
} else if (STRING.canCastImplicit(keyType, environment)) {
return new ExpressionMapIndexGet(
position,
value.eval(environment),
new ExpressionString(position, name).cast(position, environment, key));
new ExpressionString(position, name).cast(position, environment, keyType));
} else {
IPartialExpression result = memberExpansion(position, environment, value.eval(environment), name);
if (result == null) {
environment.error(position, "this array is not indexable with strings");
return new ExpressionInvalid(position, base);
return new ExpressionInvalid(position, valueType);
} else {
return result;
}
@@ -153,14 +171,12 @@ public class ZenTypeAssociative extends ZenType {
}
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
if (type == this) {
return value;
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters) {
if (followCasters) {
constructExpansionCastingRules(environment, rules);
}
return castExpansion(position, environment, value, type);
}
@Override
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
if (numValues == 1) {
@@ -172,11 +188,6 @@ public class ZenTypeAssociative extends ZenType {
}
}
@Override
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
return type == this || canCastAssociative(type, environment) || canCastExpansion(environment, type);
}
@Override
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
return type == this || canCastAssociative(type, environment) || canCastExpansion(environment, type);
@@ -207,15 +218,6 @@ public class ZenTypeAssociative extends ZenType {
return true;
}
@Override
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
if (equals(type)) {
// nothing to do
} else if (!compileCastExpansion(position, environment, type)) {
environment.error(position, "cannot cast " + this + " to " + type);
}
}
@Override
public String getName() {
return name;
@@ -13,12 +13,14 @@ import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionArithmeticBinary;
import stanhebben.zenscript.expression.ExpressionArithmeticCompare;
import stanhebben.zenscript.expression.ExpressionArithmeticUnary;
import stanhebben.zenscript.expression.ExpressionAs;
import stanhebben.zenscript.expression.ExpressionBool;
import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import static stanhebben.zenscript.type.ZenType.BYTE;
import static stanhebben.zenscript.type.ZenType.STRING;
import stanhebben.zenscript.type.casting.CastingRuleStaticMethod;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.AnyClassWriter;
import static stanhebben.zenscript.util.AnyClassWriter.METHOD_ASBOOL;
import static stanhebben.zenscript.util.AnyClassWriter.METHOD_ASBYTE;
@@ -33,7 +35,6 @@ import static stanhebben.zenscript.util.ZenTypeUtil.signature;
import stanhebben.zenscript.value.IAny;
public class ZenTypeBool extends ZenType {
//private static final JavaMethod BOOL_TOSTRING = JavaMethod.get(EMPTY_REGISTRY, Boolean.class, "toString", boolean.class);
private static final String ANY_NAME = "any/AnyBool";
private static final String ANY_NAME_2 = "any.AnyBool";
private static final String ANY_NAME_DESC = "Lany/AnyBool;";
@@ -44,18 +45,31 @@ public class ZenTypeBool extends ZenType {
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
return null;
}
@Override
public void constructCastingRules(IEnvironmentGlobal environment, ICastingRuleDelegate rules, boolean followCasters) {
rules.registerCastingRule(STRING, new CastingRuleStaticMethod(BOOL_TOSTRING_STATIC));
rules.registerCastingRule(BOOLOBJECT, new CastingRuleStaticMethod(BOOL_VALUEOF));
rules.registerCastingRule(ANY, new CastingRuleStaticMethod(JavaMethod.getStatic(
getAnyClassName(environment), "valueOf", ANY, BOOL
)));
if (followCasters) {
constructExpansionCastingRules(environment, rules);
}
}
/*@Override
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
return type == BOOL || type == ANY || type == ZenTypeString.INSTANCE || canCastExpansion(environment, type);
}
}*/
@Override
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
return type == BOOL || type == ANY || type == ZenTypeString.INSTANCE || canCastExpansion(environment, type);
return canCastImplicit(type, environment);
}
@Override
/*@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
if (type == BOOL || type == ZenTypeBoolObject.INSTANCE || type == STRING || type == ANY) {
return new ExpressionAs(position, value, type);
@@ -64,7 +78,7 @@ public class ZenTypeBool extends ZenType {
} else {
return new ExpressionAs(position, value, type);
}
}
}*/
@Override
public Class toJavaClass() {
@@ -140,7 +154,7 @@ public class ZenTypeBool extends ZenType {
environment.error(position, "cannot call a boolean value");
return new ExpressionInvalid(position, ZenTypeAny.INSTANCE);
}
@Override
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
IPartialExpression result = memberExpansion(position, environment, value.eval(environment), name);
@@ -168,7 +182,7 @@ public class ZenTypeBool extends ZenType {
return false;
}
@Override
/*@Override
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
if (type == this) {
// nothing to do
@@ -181,7 +195,7 @@ public class ZenTypeBool extends ZenType {
} else if (!compileCastExpansion(position, environment, type)) {
environment.error(position, "Cannot compile bool to " + type);
}
}
}*/
@Override
public String getName() {
@@ -321,7 +335,7 @@ public class ZenTypeBool extends ZenType {
getValue(output);
output.invokeVirtual(StringBuilder.class, "append", StringBuilder.class, boolean.class);
output.loadObject(1);
output.invoke(METHOD_ASSTRING);
METHOD_ASSTRING.invokeVirtual(output);
output.invokeVirtual(StringBuilder.class, "append", StringBuilder.class, String.class);
output.invokeVirtual(StringBuilder.class, "toString", String.class);
output.invokeStatic(STRING.getAnyClassName(environment), "valueOf", "(Ljava/lang/String;)" + signature(IAny.class));
@@ -349,7 +363,7 @@ public class ZenTypeBool extends ZenType {
output.dup();
getValue(output);
output.loadObject(1);
output.invoke(METHOD_ASBOOL);
METHOD_ASBOOL.invokeVirtual(output);
output.iAnd();
valueOf(output);
output.returnObject();
@@ -361,7 +375,7 @@ public class ZenTypeBool extends ZenType {
output.dup();
getValue(output);
output.loadObject(1);
output.invoke(METHOD_ASBOOL);
METHOD_ASBOOL.invokeVirtual(output);
output.iOr();
valueOf(output);
output.returnObject();
@@ -373,7 +387,7 @@ public class ZenTypeBool extends ZenType {
output.dup();
getValue(output);
output.loadObject(1);
output.invoke(METHOD_ASBYTE);
METHOD_ASBYTE.invokeVirtual(output);
output.iXor();
valueOf(output);
output.returnObject();
@@ -388,7 +402,7 @@ public class ZenTypeBool extends ZenType {
public void defineCompareTo(MethodOutput output) {
getValue(output);
output.loadObject(1);
output.invoke(METHOD_ASBOOL);
METHOD_ASBOOL.invokeVirtual(output);
output.iSub();
output.returnInt();
}
Loaded 100 of 172 files, more files were not shown because too many files have changed in this diff. Show more