diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index 3d674335c81..947cf407491 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -60,15 +60,15 @@ public class JetTypeMapper { public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1"); public static final Type TYPE_ITERATOR = Type.getObjectType("jet/Iterator"); public static final Type TYPE_INT_RANGE = Type.getObjectType("jet/IntRange"); - public static final Type TYPE_SHARED_VAR = Type.getObjectType("jet/refs/SharedVar$Object"); - public static final Type TYPE_SHARED_INT = Type.getObjectType("jet/refs/SharedVar$Int"); - public static final Type TYPE_SHARED_DOUBLE = Type.getObjectType("jet/refs/SharedVar$Double"); - public static final Type TYPE_SHARED_FLOAT = Type.getObjectType("jet/refs/SharedVar$Float"); - public static final Type TYPE_SHARED_BYTE = Type.getObjectType("jet/refs/SharedVar$Byte"); - public static final Type TYPE_SHARED_SHORT = Type.getObjectType("jet/refs/SharedVar$Short"); - public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/refs/SharedVar$Char"); - public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/refs/SharedVar$Long"); - public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/refs/SharedVar$Boolean"); + public static final Type TYPE_SHARED_VAR = Type.getObjectType("jet/runtime/SharedVar$Object"); + public static final Type TYPE_SHARED_INT = Type.getObjectType("jet/runtime/SharedVar$Int"); + public static final Type TYPE_SHARED_DOUBLE = Type.getObjectType("jet/runtime/SharedVar$Double"); + public static final Type TYPE_SHARED_FLOAT = Type.getObjectType("jet/runtime/SharedVar$Float"); + public static final Type TYPE_SHARED_BYTE = Type.getObjectType("jet/runtime/SharedVar$Byte"); + public static final Type TYPE_SHARED_SHORT = Type.getObjectType("jet/runtime/SharedVar$Short"); + public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char"); + public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long"); + public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean"); public JetTypeMapper(JetStandardLibrary standardLibrary, BindingContext bindingContext) { this.standardLibrary = standardLibrary; @@ -461,7 +461,10 @@ public class JetTypeMapper { parameterTypes.add(type); } for (ValueParameterDescriptor parameter : parameters) { - final Type type = mapType(parameter.getOutType()); + Type type = mapType(parameter.getOutType()); + if(parameter.isVararg()) { + type = Type.getType("[" + type.getDescriptor()); + } valueParameterTypes.add(type); parameterTypes.add(type); } @@ -559,7 +562,13 @@ public class JetTypeMapper { parameterTypes.add(mapType(receiver.getType())); } for (ValueParameterDescriptor parameter : parameters) { - parameterTypes.add(mapType(parameter.getOutType())); + if(parameter.isVararg()) { + Type type = mapType(parameter.getOutType()); + type = Type.getType("[" + type.getDescriptor()); + parameterTypes.add(type); + } + else + parameterTypes.add(mapType(parameter.getOutType())); } Type returnType = mapReturnType(f.getReturnType()); return new Method(name, returnType, parameterTypes.toArray(new Type[parameterTypes.size()])); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java index c61130a7b15..902026b2014 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java @@ -31,31 +31,31 @@ public class ArrayIterator implements IntrinsicMethod { JetStandardLibrary standardLibrary = codegen.getState().getStandardLibrary(); if(containingDeclaration.equals(standardLibrary.getArray())) { codegen.generateTypeInfo(funDescriptor.getReturnType().getArguments().get(0).getType()); - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([Ljava/lang/Object;Ljet/typeinfo/TypeInfo;)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;Ljet/typeinfo/TypeInfo;)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getByteArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([B)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([B)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getShortArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([S)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([S)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getIntArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([I)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([I)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getLongArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([J)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([J)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getFloatArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([F)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([F)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getDoubleArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([D)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([D)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getCharArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([C)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([C)Ljet/Iterator;"); } else if(containingDeclaration.equals(standardLibrary.getBooleanArrayClass())) { - v.invokestatic("jet/arrays/ArrayIterator", "iterator", "([Z)Ljet/Iterator;"); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Z)Ljet/Iterator;"); } else { throw new UnsupportedOperationException(containingDeclaration.toString()); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 80f8d5b1b0f..5880ad7fc20 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -118,18 +118,26 @@ public class JetFlowInformationProvider { Pseudocode pseudocode = pseudocodeMap.get(subroutine); assert pseudocode != null; - SubroutineEnterInstruction enterInstruction = pseudocode.getEnterInstruction(); - Set visited = new HashSet(); - collectReachable(enterInstruction, visited, null); - - for (Instruction instruction : pseudocode.getInstructions()) { - if (!visited.contains(instruction) && - instruction instanceof JetElementInstruction && + for (Instruction deadInstruction : pseudocode.getDeadInstructions()) { + if (deadInstruction instanceof JetElementInstruction && // TODO : do {return} while (1 > a) - !(instruction instanceof ReadUnitValueInstruction)) { - unreachableElements.add(((JetElementInstruction) instruction).getElement()); + !(deadInstruction instanceof ReadUnitValueInstruction)) { + unreachableElements.add(((JetElementInstruction) deadInstruction).getElement()); } } + +// SubroutineEnterInstruction enterInstruction = pseudocode.getEnterInstruction(); +// Set visited = new HashSet(); +// collectReachable(enterInstruction, visited, null); +// +// for (Instruction instruction : pseudocode.getInstructions()) { +// if (!visited.contains(instruction) && +// instruction instanceof JetElementInstruction && +// // TODO : do {return} while (1 > a) +// !(instruction instanceof ReadUnitValueInstruction)) { +// unreachableElements.add(((JetElementInstruction) instruction).getElement()); +// } +// } } // public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { // Instruction dominatorInstruction = representativeInstructions.get(dominator); @@ -175,17 +183,17 @@ public class JetFlowInformationProvider { // } // } - private boolean collectReachable(Instruction current, Set visited, @Nullable Instruction lookFor) { - if (!visited.add(current)) return false; - if (current == lookFor) return true; - - for (Instruction nextInstruction : current.getNextInstructions()) { - if (collectReachable(nextInstruction, visited, lookFor)) { - return true; - } - } - return false; - } +// private boolean collectReachable(Instruction current, Set visited, @Nullable Instruction lookFor) { +// if (!visited.add(current)) return false; +// if (current == lookFor) return true; +// +// for (Instruction nextInstruction : current.getNextInstructions()) { +// if (collectReachable(nextInstruction, visited, lookFor)) { +// return true; +// } +// } +// return false; +// } // private void processPreviousInstructions(Instruction previousFor, final Set visited, final Collection returnedExpressions, final Collection elementsReturningUnit) { // if (!visited.add(previousFor)) return; @@ -248,20 +256,29 @@ public class JetFlowInformationProvider { // } // } - private Map traverseInstructionGraphUntilFactsStabilization(Pseudocode pseudocode, InstructionsMergeHandler instructionsMergeHandler, D initialDataValue, boolean straightDirection) { + private Map traverseInstructionGraphUntilFactsStabilization( + Pseudocode pseudocode, + InstructionsMergeHandler instructionsMergeHandler, + D initialDataValue, + D initialDataValueForEnterInstruction, + boolean straightDirection) { Map dataMap = Maps.newHashMap(); initializeDataMap(dataMap, pseudocode, initialDataValue); + dataMap.put(pseudocode.getEnterInstruction(), initialDataValueForEnterInstruction); boolean[] changed = new boolean[1]; changed[0] = true; while (changed[0]) { changed[0] = false; - traverseSubGraph(pseudocode, instructionsMergeHandler, Collections.emptyList(), straightDirection, dataMap, changed); + traverseSubGraph(pseudocode, instructionsMergeHandler, Collections.emptyList(), straightDirection, dataMap, changed, false); } return dataMap; } - private void initializeDataMap(Map dataMap, Pseudocode pseudocode, D initialDataValue) { + private void initializeDataMap( + Map dataMap, + Pseudocode pseudocode, + D initialDataValue) { List instructions = pseudocode.getInstructions(); for (Instruction instruction : instructions) { dataMap.put(instruction, initialDataValue); @@ -271,10 +288,19 @@ public class JetFlowInformationProvider { } } - private void traverseSubGraph(Pseudocode pseudocode, InstructionsMergeHandler instructionsMergeHandler, Collection previousSubGraphInstructions, boolean straightDirection, Map dataMap, boolean[] changed) { + private void traverseSubGraph( + Pseudocode pseudocode, + InstructionsMergeHandler instructionsMergeHandler, + Collection previousSubGraphInstructions, + boolean straightDirection, + Map dataMap, + boolean[] changed, + boolean isLocal) { List instructions = pseudocode.getInstructions(); SubroutineEnterInstruction enterInstruction = pseudocode.getEnterInstruction(); for (Instruction instruction : instructions) { + if (!isLocal && instruction instanceof SubroutineEnterInstruction) continue; + Collection allPreviousInstructions; Collection previousInstructions = straightDirection ? instruction.getPreviousInstructions() @@ -290,7 +316,7 @@ public class JetFlowInformationProvider { if (instruction instanceof LocalDeclarationInstruction) { Pseudocode subroutinePseudocode = ((LocalDeclarationInstruction) instruction).getBody(); - traverseSubGraph(subroutinePseudocode, instructionsMergeHandler, previousInstructions, straightDirection, dataMap, changed); + traverseSubGraph(subroutinePseudocode, instructionsMergeHandler, previousInstructions, straightDirection, dataMap, changed, true); } D previousDataValue = dataMap.get(instruction); @@ -299,7 +325,7 @@ public class JetFlowInformationProvider { for (Instruction previousInstruction : allPreviousInstructions) { incomingEdgesData.add(dataMap.get(previousInstruction)); } - D mergedData = instructionsMergeHandler.merge(instruction, previousDataValue, incomingEdgesData); + D mergedData = instructionsMergeHandler.merge(instruction, incomingEdgesData); if (!mergedData.equals(previousDataValue)) { changed[0] = true; dataMap.put(instruction, mergedData); @@ -312,80 +338,203 @@ public class JetFlowInformationProvider { assert pseudocode != null; Collection instructions = pseudocode.getInstructions(); - InstructionsMergeHandler> instructionsMergeHandler = new InstructionsMergeHandler>() { + InstructionsMergeHandler> instructionsMergeHandler = new InstructionsMergeHandler>() { @Override - public Set merge(Instruction instruction, Set previousDataValue, Collection> incomingEdgesData) { - Set initializedVariables = Sets.newHashSet(); - initializedVariables.addAll(previousDataValue); - for (Set edgeDataValue : incomingEdgesData) { - initializedVariables.addAll(edgeDataValue); + public Map merge( + Instruction instruction, + Collection> incomingEdgesData) { + + Set variablesInScope = Sets.newHashSet(); + for (Map edgePointsMap : incomingEdgesData) { + variablesInScope.addAll(edgePointsMap.keySet()); } - if (instruction instanceof WriteValueInstruction) { - DeclarationDescriptor descriptor = null; - JetElement lValue = ((WriteValueInstruction) instruction).getlValue(); - if (lValue instanceof JetProperty) { - descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, lValue); - } - else if (lValue instanceof JetSimpleNameExpression) { - descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) lValue); - } - else if (lValue instanceof JetParameter) { - descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, lValue); - } - if (descriptor instanceof LocalVariableDescriptor) { - initializedVariables.add((LocalVariableDescriptor) descriptor); + Map pointsMap = Maps.newHashMap(); + for (LocalVariableDescriptor variable : variablesInScope) { + Set edgesDataForVariable = Sets.newHashSet(); + for (Map edgePointsMap : incomingEdgesData) { + InitializationPoints points = edgePointsMap.get(variable); + if (points != null) { + edgesDataForVariable.add(points); + } } + pointsMap.put(variable, new InitializationPoints(edgesDataForVariable)); } - return initializedVariables; + + if (instruction instanceof WriteValueInstruction) { + LocalVariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction); +// DeclarationDescriptor descriptor = null; +// JetElement lValue = ((WriteValueInstruction) instruction).getlValue(); +// if (lValue instanceof JetProperty || lValue instanceof JetParameter) { +// descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, lValue); +// } +// else if (lValue instanceof JetSimpleNameExpression) { +// descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) lValue); +// } +// if (descriptor instanceof LocalVariableDescriptor) { +// LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; + InitializationPoints initializationAtThisPoint = new InitializationPoints(((WriteValueInstruction) instruction).getElement()); + pointsMap.put(variableDescriptor, initializationAtThisPoint); +// } + } + + return pointsMap; } }; - Map> dataMap = traverseInstructionGraphUntilFactsStabilization(pseudocode, instructionsMergeHandler, Collections.emptySet(), true); - InstructionDataAnalyzer instructionDataAnalyzer = new InstructionDataAnalyzer>() { + + Set localVariables = collectAllLocalVariables(pseudocode); + Map initialMapForStartInstruction = Maps.newHashMap(); + InitializationPoints initialPoints = new InitializationPoints(); + for (LocalVariableDescriptor variable : localVariables) { + initialMapForStartInstruction.put(variable, initialPoints); + } + Map> dataMap = + traverseInstructionGraphUntilFactsStabilization(pseudocode, instructionsMergeHandler, Collections.emptyMap(), initialMapForStartInstruction, true); + + InstructionDataAnalyzer> instructionDataAnalyzer = new InstructionDataAnalyzer>() { @Override - public void analyze(Instruction instruction, Map> dataMap) { - Set initializedVariables = dataMap.get(instruction); + public void analyze(Instruction instruction, Map> dataMap) { + Map variablesData = dataMap.get(instruction); if (instruction instanceof ReadValueInstruction) { + LocalVariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction); JetElement element = ((ReadValueInstruction) instruction).getElement(); - if (element instanceof JetSimpleNameExpression) { - DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element); - if (descriptor instanceof LocalVariableDescriptor) { - if (!initializedVariables.contains(descriptor)) { - trace.report(Errors.UNINITIALIZED_VARIABLE.on((JetSimpleNameExpression) element, descriptor)); - } + if (element instanceof JetSimpleNameExpression && variableDescriptor != null) { +// DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element); +// if (descriptor instanceof LocalVariableDescriptor) { + InitializationPoints initializationPoints = variablesData.get(variableDescriptor); + assert initializationPoints != null; + if (initializationPoints.canBeUninitialized) { + trace.report(Errors.UNINITIALIZED_VARIABLE.on((JetSimpleNameExpression) element, variableDescriptor)); } +// } } } else if (instruction instanceof WriteValueInstruction) { - JetElement element = ((WriteValueInstruction) instruction).getElement(); - if (element instanceof JetSimpleNameExpression) { - DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element); - if (descriptor instanceof LocalVariableDescriptor) { - if (initializedVariables.contains(descriptor) && ((LocalVariableDescriptor) descriptor).isVar()) { - trace.report(Errors.VAL_REASSIGNMENT.on((JetSimpleNameExpression) element, descriptor)); - } + JetElement element = ((WriteValueInstruction) instruction).getlValue(); + LocalVariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction); + if (element instanceof JetSimpleNameExpression && variableDescriptor != null) { +// DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element); +// if (descriptor instanceof LocalVariableDescriptor) { + InitializationPoints initializationPoints = variablesData.get(variableDescriptor); + assert initializationPoints != null; + if (initializationPoints.hasPossibleInitializers() && !variableDescriptor.isVar()) { + trace.report(Errors.VAL_REASSIGNMENT.on((JetSimpleNameExpression) element, variableDescriptor)); } +// } } - } + } } }; - traverseInstructionGraphAndReportErrors(instructions, dataMap, instructionDataAnalyzer); + traverseAndAnalyzeInstructionGraph(instructions, dataMap, instructionDataAnalyzer); } - private void traverseInstructionGraphAndReportErrors(Collection instructions, Map> dataMap, InstructionDataAnalyzer> instructionDataAnalyzer) { + @Nullable + private LocalVariableDescriptor extractVariableDescriptorIfAny(Instruction instruction) { + LocalVariableDescriptor variableDescriptor = null; + if (instruction instanceof ReadValueInstruction) { + JetElement element = ((ReadValueInstruction) instruction).getElement(); + if (element instanceof JetSimpleNameExpression) { + DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element); + if (descriptor instanceof LocalVariableDescriptor) { + variableDescriptor = (LocalVariableDescriptor) descriptor; + } + } + } + else if (instruction instanceof WriteValueInstruction) { + DeclarationDescriptor descriptor = null; + JetElement lValue = ((WriteValueInstruction) instruction).getlValue(); + if (lValue instanceof JetProperty || lValue instanceof JetParameter) { + descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, lValue); + } + else if (lValue instanceof JetSimpleNameExpression) { + descriptor = trace.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) lValue); + } + if (descriptor instanceof LocalVariableDescriptor) { + variableDescriptor = (LocalVariableDescriptor) descriptor; + } + } + return variableDescriptor; + } + + private Set collectAllLocalVariables(Pseudocode pseudocode) { + final Set localVariables = Sets.newHashSet(); + InstructionDataAnalyzer analyzer = new InstructionDataAnalyzer() { + @Override + public void analyze(Instruction instruction, Map dataMap) { + LocalVariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction); + if (variableDescriptor != null) { + localVariables.add(variableDescriptor); + } + } + }; + traverseAndAnalyzeInstructionGraph(pseudocode.getInstructions(), Collections.emptyMap(), analyzer); + return localVariables; + } + + private void traverseAndAnalyzeInstructionGraph(Collection instructions, Map dataMap, InstructionDataAnalyzer instructionDataAnalyzer) { for (Instruction instruction : instructions) { if (instruction instanceof LocalDeclarationInstruction) { - traverseInstructionGraphAndReportErrors(((LocalDeclarationInstruction) instruction).getBody().getInstructions(), dataMap, instructionDataAnalyzer); + traverseAndAnalyzeInstructionGraph(((LocalDeclarationInstruction) instruction).getBody().getInstructions(), dataMap, instructionDataAnalyzer); } instructionDataAnalyzer.analyze(instruction, dataMap); } } interface InstructionsMergeHandler { - D merge(Instruction instruction, D previousDataValue, Collection incomingEdgesData); + D merge(Instruction instruction, Collection incomingEdgesData); } interface InstructionDataAnalyzer { void analyze(Instruction instruction, Map dataMap); } -} + + private static class InitializationPoints { + private Set possiblePoints = Sets.newHashSet(); + private boolean canBeUninitialized; + + public InitializationPoints() { + canBeUninitialized = true; + } + + public InitializationPoints(JetElement element) { + canBeUninitialized = false; + possiblePoints.add(element); + } + + public InitializationPoints(Set edgesData) { + canBeUninitialized = false; + for (InitializationPoints edgeData : edgesData) { + if (edgeData.canBeUninitialized) { + canBeUninitialized = true; + } + possiblePoints.addAll(edgeData.possiblePoints); + } + } + + public boolean hasPossibleInitializers() { + return !possiblePoints.isEmpty(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof InitializationPoints)) return false; + + InitializationPoints that = (InitializationPoints) o; + + if (canBeUninitialized != that.canBeUninitialized) return false; + if (possiblePoints != null ? !possiblePoints.equals(that.possiblePoints) : that.possiblePoints != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = possiblePoints != null ? possiblePoints.hashCode() : 0; + result = 31 * result + (canBeUninitialized ? 1 : 0); + return result; + } + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java index 65fadb3b5a3..07179794241 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java @@ -12,6 +12,7 @@ import java.util.LinkedHashSet; public abstract class InstructionImpl implements Instruction { private Pseudocode owner; private final Collection previousInstructions = new LinkedHashSet(); + protected boolean isDead = false; protected InstructionImpl() { } @@ -42,4 +43,11 @@ public abstract class InstructionImpl implements Instruction { return target; } + public void die() { + isDead = true; + } + + public boolean isDead() { + return isDead; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java index 9a7f0087050..630199c91e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java @@ -1,5 +1,7 @@ package org.jetbrains.jet.lang.cfg.pseudocode; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.cfg.Label; @@ -77,6 +79,17 @@ public class Pseudocode { public List getInstructions() { return instructions; } + + @NotNull + public List getDeadInstructions() { + List deadInstructions = Lists.newArrayList(); + for (Instruction instruction : instructions) { + if (((InstructionImpl)instruction).isDead()) { + deadInstructions.add(instruction); + } + } + return deadInstructions; + } @Deprecated //for tests only public List getLabels() { @@ -166,6 +179,26 @@ public class Pseudocode { } }); } + removeDeadInstructions(); + } + + private void removeDeadInstructions() { + boolean hasRemovedInstruction = true; + Collection processedInstructions = Sets.newHashSet(); + while (hasRemovedInstruction) { + hasRemovedInstruction = false; + for (Instruction instruction : instructions) { + if (!(instruction instanceof SubroutineEnterInstruction || instruction instanceof SubroutineExitInstruction) && + instruction.getPreviousInstructions().isEmpty() && !processedInstructions.contains(instruction)) { + hasRemovedInstruction = true; + for (Instruction nextInstruction : instruction.getNextInstructions()) { + nextInstruction.getPreviousInstructions().remove(instruction); + } + ((InstructionImpl)instruction).die(); + processedInstructions.add(instruction); + } + } + } } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 4f4cfb16e36..ede21587970 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -142,7 +142,7 @@ public interface Errors { }; PsiElementOnlyDiagnosticFactory3 VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT); - PsiElementOnlyDiagnosticFactory1 UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be uninitialized", NAME); + PsiElementOnlyDiagnosticFactory1 UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME); PsiElementOnlyDiagnosticFactory1 VAL_REASSIGNMENT = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Val can not be reassigned", NAME); SimpleDiagnosticFactory UNREACHABLE_CODE = SimpleDiagnosticFactory.create(ERROR, "Unreachable code"); diff --git a/compiler/testData/cfg/Finally.instructions b/compiler/testData/cfg/Finally.instructions index 652eed75a12..8500acbd625 100644 --- a/compiler/testData/cfg/Finally.instructions +++ b/compiler/testData/cfg/Finally.instructions @@ -41,12 +41,12 @@ l0: jf(l3) NEXT:[read (Unit), r(2)] PREV:[r(2 > 3)] r(2) NEXT:[ret l1] PREV:[jf(l3)] ret l1 NEXT:[] PREV:[r(2)] - jmp(l4) NEXT:[r(2)] PREV:[] +* jmp(l4) NEXT:[r(2)] PREV:[] l3: read (Unit) NEXT:[r(2)] PREV:[jf(l3)] l2: l4: - r(2) NEXT:[] PREV:[jmp?(l2), jmp(l4), read (Unit)] + r(2) NEXT:[] PREV:[jmp?(l2), read (Unit)] l1: NEXT:[] PREV:[ret l1, r(2)] error: @@ -67,12 +67,12 @@ l3: r(2 > 3) NEXT:[jf(l5)] PREV:[r(>)] jf(l5) NEXT:[read (Unit), ret l4] PREV:[r(2 > 3)] ret l4 NEXT:[] PREV:[jf(l5)] - jmp(l6) NEXT:[] PREV:[] +* jmp(l6) NEXT:[] PREV:[] l5: read (Unit) NEXT:[] PREV:[jf(l5)] l4: l6: - NEXT:[] PREV:[ret l4, jmp(l6), read (Unit)] + NEXT:[] PREV:[ret l4, read (Unit)] error: NEXT:[] PREV:[] ===================== @@ -113,12 +113,12 @@ l3: r(2 > 3) NEXT:[jf(l5)] PREV:[r(>)] jf(l5) NEXT:[read (Unit), ret l4] PREV:[r(2 > 3)] ret l4 NEXT:[] PREV:[jf(l5)] - jmp(l6) NEXT:[] PREV:[] +* jmp(l6) NEXT:[] PREV:[] l5: read (Unit) NEXT:[] PREV:[jf(l5)] l4: l6: - NEXT:[] PREV:[ret l4, jmp(l6), read (Unit)] + NEXT:[] PREV:[ret l4, read (Unit)] error: NEXT:[] PREV:[] ===================== @@ -145,12 +145,12 @@ l2: jf(l5) NEXT:[read (Unit), r(2)] PREV:[r(2 > 3)] r(2) NEXT:[ret l3] PREV:[jf(l5)] ret l3 NEXT:[] PREV:[r(2)] - jmp(l6) NEXT:[r(2)] PREV:[] +* jmp(l6) NEXT:[r(2)] PREV:[] l5: read (Unit) NEXT:[r(2)] PREV:[jf(l5)] l4: l6: - r(2) NEXT:[] PREV:[jmp?(l4), jmp(l6), read (Unit)] + r(2) NEXT:[] PREV:[jmp?(l4), read (Unit)] l3: NEXT:[] PREV:[ret l3, r(2)] error: @@ -197,12 +197,12 @@ l2: jf(l5) NEXT:[read (Unit), r(2)] PREV:[r(2 > 3)] r(2) NEXT:[ret l3] PREV:[jf(l5)] ret l3 NEXT:[] PREV:[r(2)] - jmp(l6) NEXT:[r(2)] PREV:[] +* jmp(l6) NEXT:[r(2)] PREV:[] l5: read (Unit) NEXT:[r(2)] PREV:[jf(l5)] l4: l6: - r(2) NEXT:[] PREV:[jmp?(l4), jmp(l6), read (Unit)] + r(2) NEXT:[] PREV:[jmp?(l4), read (Unit)] l3: NEXT:[] PREV:[ret l3, r(2)] error: @@ -238,12 +238,12 @@ l4: jf(l7) NEXT:[read (Unit), r(2)] PREV:[r(2 > 3)] r(2) NEXT:[jmp(l3)] PREV:[jf(l7)] jmp(l3) NEXT:[read (Unit)] PREV:[r(2)] - jmp(l8) NEXT:[r(2)] PREV:[] +* jmp(l8) NEXT:[r(2)] PREV:[] l7: read (Unit) NEXT:[r(2)] PREV:[jf(l7)] l6: l8: - r(2) NEXT:[jmp(l2)] PREV:[jmp?(l6), jmp(l8), read (Unit)] + r(2) NEXT:[jmp(l2)] PREV:[jmp?(l6), read (Unit)] jmp(l2) NEXT:[r(true)] PREV:[r(2)] l3: read (Unit) NEXT:[] PREV:[jf(l3), jmp(l3)] @@ -282,11 +282,11 @@ l5: r(2 > 3) NEXT:[jf(l7)] PREV:[r(>)] jf(l7) NEXT:[read (Unit), jmp(l4)] PREV:[r(2 > 3)] jmp(l4) NEXT:[read (Unit)] PREV:[jf(l7)] - jmp(l8) NEXT:[jmp(l3)] PREV:[] +* jmp(l8) NEXT:[jmp(l3)] PREV:[] l7: read (Unit) NEXT:[jmp(l3)] PREV:[jf(l7)] l8: - jmp(l3) NEXT:[r(true)] PREV:[jmp(l8), read (Unit)] + jmp(l3) NEXT:[r(true)] PREV:[read (Unit)] l4: read (Unit) NEXT:[r(5)] PREV:[jf(l4), jmp(l4)] r(5) NEXT:[r(2)] PREV:[read (Unit)] @@ -326,11 +326,11 @@ l5: r(2 > 3) NEXT:[jf(l7)] PREV:[r(>)] jf(l7) NEXT:[read (Unit), jmp(l4)] PREV:[r(2 > 3)] jmp(l4) NEXT:[read (Unit)] PREV:[jf(l7)] - jmp(l8) NEXT:[jmp(l3)] PREV:[] +* jmp(l8) NEXT:[jmp(l3)] PREV:[] l7: read (Unit) NEXT:[jmp(l3)] PREV:[jf(l7)] l8: - jmp(l3) NEXT:[r(true)] PREV:[jmp(l8), read (Unit)] + jmp(l3) NEXT:[r(true)] PREV:[read (Unit)] l4: read (Unit) NEXT:[r(2)] PREV:[jf(l4), jmp(l4)] l2: @@ -374,12 +374,12 @@ l5: jf(l7) NEXT:[read (Unit), r(2)] PREV:[r(2 > 3)] r(2) NEXT:[jmp(l4)] PREV:[jf(l7)] jmp(l4) NEXT:[jmp?(l6)] PREV:[r(2)] - jmp(l8) NEXT:[r(2)] PREV:[] +* jmp(l8) NEXT:[r(2)] PREV:[] l7: read (Unit) NEXT:[r(2)] PREV:[jf(l7)] l6: l8: - r(2) NEXT:[jmp?(l4)] PREV:[jmp?(l6), jmp(l8), read (Unit)] + r(2) NEXT:[jmp?(l4)] PREV:[jmp?(l6), read (Unit)] jmp?(l4) NEXT:[jmp?(l6), read (Unit)] PREV:[r(2)] l2: read (Unit) NEXT:[] PREV:[jmp?(l2), jmp?(l4)] @@ -422,11 +422,11 @@ l6: r(2 > 3) NEXT:[jf(l7)] PREV:[r(>)] jf(l7) NEXT:[read (Unit), jmp(l5)] PREV:[r(2 > 3)] jmp(l5) NEXT:[r(1)] PREV:[jf(l7)] - jmp(l8) NEXT:[jmp?(l5)] PREV:[] +* jmp(l8) NEXT:[jmp?(l5)] PREV:[] l7: read (Unit) NEXT:[jmp?(l5)] PREV:[jf(l7)] l8: - jmp?(l5) NEXT:[r(1), read (Unit)] PREV:[jmp(l8), read (Unit)] + jmp?(l5) NEXT:[r(1), read (Unit)] PREV:[read (Unit)] l3: read (Unit) NEXT:[r(5)] PREV:[jmp?(l3), jmp?(l5)] r(5) NEXT:[r(2)] PREV:[read (Unit)] @@ -470,11 +470,11 @@ l6: r(2 > 3) NEXT:[jf(l7)] PREV:[r(>)] jf(l7) NEXT:[read (Unit), jmp(l5)] PREV:[r(2 > 3)] jmp(l5) NEXT:[r(1)] PREV:[jf(l7)] - jmp(l8) NEXT:[jmp?(l5)] PREV:[] +* jmp(l8) NEXT:[jmp?(l5)] PREV:[] l7: read (Unit) NEXT:[jmp?(l5)] PREV:[jf(l7)] l8: - jmp?(l5) NEXT:[r(1), read (Unit)] PREV:[jmp(l8), read (Unit)] + jmp?(l5) NEXT:[r(1), read (Unit)] PREV:[read (Unit)] l3: read (Unit) NEXT:[r(2)] PREV:[jmp?(l3), jmp?(l5)] l2: @@ -500,12 +500,12 @@ l0: r(1) NEXT:[r(2)] PREV:[jmp?(l2)] r(2) NEXT:[ret(*) l1] PREV:[r(1)] ret(*) l1 NEXT:[] PREV:[r(2)] - ret(*) l1 NEXT:[] PREV:[] +* ret(*) l1 NEXT:[] PREV:[] l2: r(2) NEXT:[ret(*) l1] PREV:[jmp?(l2)] ret(*) l1 NEXT:[] PREV:[r(2)] l1: - NEXT:[] PREV:[ret(*) l1, ret(*) l1, ret(*) l1] + NEXT:[] PREV:[ret(*) l1, ret(*) l1] error: NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/For.instructions b/compiler/testData/cfg/For.instructions new file mode 100644 index 00000000000..4e19aac83c9 --- /dev/null +++ b/compiler/testData/cfg/For.instructions @@ -0,0 +1,40 @@ +== t1 == +fun t1() { + for (i in 1..2) { + doSmth(i) + } +} +--------------------- +l0: + NEXT:[r(1)] PREV:[] + r(1) NEXT:[r(2)] PREV:[] + r(2) NEXT:[r(..)] PREV:[r(1)] + r(..) NEXT:[r(1..2)] PREV:[r(2)] + r(1..2) NEXT:[w(i)] PREV:[r(..)] + w(i) NEXT:[jmp?(l2)] PREV:[r(1..2)] +l3: + jmp?(l2) NEXT:[read (Unit), r(i)] PREV:[w(i)] +l4: +l5: + r(i) NEXT:[r(doSmth)] PREV:[jmp?(l2), jmp?(l4)] + r(doSmth) NEXT:[r(doSmth(i))] PREV:[r(i)] + r(doSmth(i)) NEXT:[jmp?(l4)] PREV:[r(doSmth)] + jmp?(l4) NEXT:[r(i), read (Unit)] PREV:[r(doSmth(i))] +l2: + read (Unit) NEXT:[] PREV:[jmp?(l2), jmp?(l4)] +l1: + NEXT:[] PREV:[read (Unit)] +error: + NEXT:[] PREV:[] +===================== +== doSmth == +fun doSmth(i: Int) {} +--------------------- +l0: + NEXT:[read (Unit)] PREV:[] + read (Unit) NEXT:[] PREV:[] +l1: + NEXT:[] PREV:[read (Unit)] +error: + NEXT:[] PREV:[] +===================== diff --git a/compiler/testData/cfg/For.jet b/compiler/testData/cfg/For.jet new file mode 100644 index 00000000000..35dab23bf0c --- /dev/null +++ b/compiler/testData/cfg/For.jet @@ -0,0 +1,7 @@ +fun t1() { + for (i in 1..2) { + doSmth(i) + } +} + +fun doSmth(i: Int) {} diff --git a/compiler/testData/cfg/If.instructions b/compiler/testData/cfg/If.instructions new file mode 100644 index 00000000000..d075477d559 --- /dev/null +++ b/compiler/testData/cfg/If.instructions @@ -0,0 +1,98 @@ +== t1 == +fun t1(b: Boolean) { + var u: String + if (b) { + u = "s" + } + doSmth(u) + + var r: String + if (b) { + r = "s" + } + else { + r = "t" + } + doSmth(r) +} +--------------------- +l0: + NEXT:[r(b)] PREV:[] + r(b) NEXT:[jf(l2)] PREV:[] + jf(l2) NEXT:[read (Unit), r("s")] PREV:[r(b)] + r("s") NEXT:[w(u)] PREV:[jf(l2)] + w(u) NEXT:[jmp(l3)] PREV:[r("s")] + jmp(l3) NEXT:[r(u)] PREV:[w(u)] +l2: + read (Unit) NEXT:[r(u)] PREV:[jf(l2)] +l3: + r(u) NEXT:[r(doSmth)] PREV:[jmp(l3), read (Unit)] + r(doSmth) NEXT:[r(doSmth(u))] PREV:[r(u)] + r(doSmth(u)) NEXT:[r(b)] PREV:[r(doSmth)] + r(b) NEXT:[jf(l4)] PREV:[r(doSmth(u))] + jf(l4) NEXT:[r("t"), r("s")] PREV:[r(b)] + r("s") NEXT:[w(r)] PREV:[jf(l4)] + w(r) NEXT:[jmp(l5)] PREV:[r("s")] + jmp(l5) NEXT:[r(r)] PREV:[w(r)] +l4: + r("t") NEXT:[w(r)] PREV:[jf(l4)] + w(r) NEXT:[r(r)] PREV:[r("t")] +l5: + r(r) NEXT:[r(doSmth)] PREV:[jmp(l5), w(r)] + r(doSmth) NEXT:[r(doSmth(r))] PREV:[r(r)] + r(doSmth(r)) NEXT:[] PREV:[r(doSmth)] +l1: + NEXT:[] PREV:[r(doSmth(r))] +error: + NEXT:[] PREV:[] +===================== +== t2 == +fun t2(b: Boolean) { + val i = 3 + if (b) { + return; + } + doSmth(i) + if (i is Int) { + return; + } +} +--------------------- +l0: + NEXT:[r(3)] PREV:[] + r(3) NEXT:[w(i)] PREV:[] + w(i) NEXT:[r(b)] PREV:[r(3)] + r(b) NEXT:[jf(l2)] PREV:[w(i)] + jf(l2) NEXT:[read (Unit), ret l1] PREV:[r(b)] + ret l1 NEXT:[] PREV:[jf(l2)] +* jmp(l3) NEXT:[r(i)] PREV:[] +l2: + read (Unit) NEXT:[r(i)] PREV:[jf(l2)] +l3: + r(i) NEXT:[r(doSmth)] PREV:[read (Unit)] + r(doSmth) NEXT:[r(doSmth(i))] PREV:[r(i)] + r(doSmth(i)) NEXT:[r(i)] PREV:[r(doSmth)] + r(i) NEXT:[r(i is Int)] PREV:[r(doSmth(i))] + r(i is Int) NEXT:[jf(l4)] PREV:[r(i)] + jf(l4) NEXT:[read (Unit), ret l1] PREV:[r(i is Int)] + ret l1 NEXT:[] PREV:[jf(l4)] +* jmp(l5) NEXT:[] PREV:[] +l4: + read (Unit) NEXT:[] PREV:[jf(l4)] +l1: +l5: + NEXT:[] PREV:[ret l1, ret l1, read (Unit)] +error: + NEXT:[] PREV:[] +===================== +== doSmth == +fun doSmth(s: String) {} +--------------------- +l0: + NEXT:[read (Unit)] PREV:[] + read (Unit) NEXT:[] PREV:[] +l1: + NEXT:[] PREV:[read (Unit)] +error: + NEXT:[] PREV:[] +===================== diff --git a/compiler/testData/cfg/If.jet b/compiler/testData/cfg/If.jet new file mode 100644 index 00000000000..26e9276b66d --- /dev/null +++ b/compiler/testData/cfg/If.jet @@ -0,0 +1,31 @@ +fun t1(b: Boolean) { + var u: String + if (b) { + u = "s" + } + doSmth(u) + + var r: String + if (b) { + r = "s" + } + else { + r = "t" + } + doSmth(r) +} + +fun t2(b: Boolean) { + val i = 3 + if (b) { + return; + } + doSmth(i) + if (i is Int) { + return; + } +} + +fun doSmth(s: String) {} + + diff --git a/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions b/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions index c0e4641ad03..bdad7a8566b 100644 --- a/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions +++ b/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions @@ -34,17 +34,17 @@ l0: NEXT:[ret l1] PREV:[] l2: l4: - ret l1 NEXT:[] PREV:[, jt(l2)] + ret l1 NEXT:[] PREV:[] l5: - r(1) NEXT:[r(0)] PREV:[] - r(0) NEXT:[r(>)] PREV:[r(1)] - r(>) NEXT:[r(1 > 0)] PREV:[r(0)] - r(1 > 0) NEXT:[jt(l2)] PREV:[r(>)] - jt(l2) NEXT:[read (Unit), ret l1] PREV:[r(1 > 0)] +* r(1) NEXT:[r(0)] PREV:[] +* r(0) NEXT:[r(>)] PREV:[] +* r(>) NEXT:[r(1 > 0)] PREV:[] +* r(1 > 0) NEXT:[jt(l2)] PREV:[] +* jt(l2) NEXT:[read (Unit), ret l1] PREV:[] l3: - read (Unit) NEXT:[] PREV:[jt(l2)] +* read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[ret l1, read (Unit)] + NEXT:[] PREV:[ret l1] error: NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/checker/Unresolved.jet b/compiler/testData/checker/Unresolved.jet index 9e361861010..2d56e915eb7 100644 --- a/compiler/testData/checker/Unresolved.jet +++ b/compiler/testData/checker/Unresolved.jet @@ -22,8 +22,9 @@ fun testUnresolved() { //TODO for (j in collection) { - val i: Int = j - j += 1 + var i: Int = j + i += 1 + foo1(j) } } diff --git a/compiler/testData/checker/regression/AssignmentsUnderOperators.jet b/compiler/testData/checker/regression/AssignmentsUnderOperators.jet index 5a7c24b7fd0..2acdbfdd984 100644 --- a/compiler/testData/checker/regression/AssignmentsUnderOperators.jet +++ b/compiler/testData/checker/regression/AssignmentsUnderOperators.jet @@ -1,5 +1,5 @@ fun test() { - val a : Any? = null + var a : Any? = null if (a is Any) else a = null; while (a is Any) a = null while (true) a = null diff --git a/compiler/testData/checker/regression/Jet183-1.jet b/compiler/testData/checker/regression/Jet183-1.jet index 37c72d83ef6..0199cd9fcb3 100644 --- a/compiler/testData/checker/regression/Jet183-1.jet +++ b/compiler/testData/checker/regression/Jet183-1.jet @@ -12,7 +12,7 @@ abstract enum class ProtocolState { fun box(): String { - val x: ProtocolState = ProtocolState.WAITING + var x: ProtocolState = ProtocolState.WAITING x = x.signal() if (x != ProtocolState.TALKING) return "fail 1" x = x.signal() diff --git a/compiler/testData/checkerWithErrorTypes/full/FlowAnalyseVariables.jet b/compiler/testData/checkerWithErrorTypes/full/FlowAnalyseVariables.jet new file mode 100644 index 00000000000..81a49d26b02 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/full/FlowAnalyseVariables.jet @@ -0,0 +1,99 @@ +namespace uninitialized_vals { + +fun t1(b : Boolean) { + val v : Int + if (v == 0) {} + + var u: String + if (b) { + u = "s" + } + doSmth(u) + + var r: String + if (b) { + r = "s" + } + else { + r = "tg" + } + doSmth(r) + + var t: String + if (b) + doSmth(t) + else + t = "ss" + doSmth(t) + + val i = 3 + doSmth(i) + if (b) { + return; + } + doSmth(i) + if (i is Int) { + return; + } +} + +fun t2() { + val s = "ss" + + for (i in 0..2) { + doSmth(s) + } +} + +fun doSmth(s: String) {} +fun doSmth(i: Int) {} + +} + +namespace reassigned_vals { + +fun t1() { + val a : Int = 1 + a = 2 + + var b : Int = 1 + b = 3 +} + +abstract enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + } + + TALKING { + override fun signal() = ProtocolState.WAITING + } + + abstract fun signal() : ProtocolState +} + +fun t2() { + val x: ProtocolState = ProtocolState.WAITING + x = x.signal() + x = x.signal() +} + +fun t3() { + val x = 1 + x += 2 + val y = 3 + y *= 4 + var z = 5 + z -= y +} + +fun t4() { + for (i in 0..2) { + i += 1 + fun t5() { + i += 3 + } + } +} + +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet b/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet index 646a38f5b89..68b1803449f 100644 --- a/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet +++ b/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet @@ -176,23 +176,23 @@ fun testFunctionLiterals() { } val endsWithAssignment = { () : Int => - val x = 1 + var x = 1 x = 333 } val endsWithReAssignment = { () : Int => - val x = 1 + var x = 1 x += 333 } val endsWithFunDeclaration : fun() : String = { - val x = 1 + var x = 1 x = 333 fun meow() : Unit {} } val endsWithObjectDeclaration : fun() : Int = { - val x = 1 + var x = 1 x = 333 object A {} } diff --git a/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet b/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet index 48ea2a58e4d..9bd749a8372 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet @@ -22,8 +22,9 @@ fun testUnresolved() { //TODO for (j in collection) { - val i: Int = j - j += 1 + var i: Int = j + i += 1 + foo1(j) } } diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet b/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet index 5a7c24b7fd0..2acdbfdd984 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet @@ -1,5 +1,5 @@ fun test() { - val a : Any? = null + var a : Any? = null if (a is Any) else a = null; while (a is Any) a = null while (true) a = null diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet b/compiler/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet index 37c72d83ef6..0199cd9fcb3 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet @@ -12,7 +12,7 @@ abstract enum class ProtocolState { fun box(): String { - val x: ProtocolState = ProtocolState.WAITING + var x: ProtocolState = ProtocolState.WAITING x = x.signal() if (x != ProtocolState.TALKING) return "fail 1" x = x.signal() diff --git a/compiler/testData/codegen/classes/overloadPlusAssign.jet b/compiler/testData/codegen/classes/overloadPlusAssign.jet index 21459ecff1e..5247973e8d6 100644 --- a/compiler/testData/codegen/classes/overloadPlusAssign.jet +++ b/compiler/testData/codegen/classes/overloadPlusAssign.jet @@ -17,7 +17,7 @@ class ArrayWrapper() { } fun box(): String { - val v1 = ArrayWrapper() + var v1 = ArrayWrapper() val v2 = ArrayWrapper() v1.add("foo") v2.add("bar") diff --git a/compiler/testData/codegen/classes/overloadPlusAssignReturn.jet b/compiler/testData/codegen/classes/overloadPlusAssignReturn.jet index 28fb9af2652..42671b9f138 100644 --- a/compiler/testData/codegen/classes/overloadPlusAssignReturn.jet +++ b/compiler/testData/codegen/classes/overloadPlusAssignReturn.jet @@ -20,7 +20,7 @@ class ArrayWrapper() { } fun box(): String { - val v1 = ArrayWrapper() + var v1 = ArrayWrapper() val v2 = ArrayWrapper() v1.add("foo") val v3 = v1 diff --git a/compiler/testData/codegen/classes/overloadPlusToPlusAssign.jet b/compiler/testData/codegen/classes/overloadPlusToPlusAssign.jet index e81515821b0..c5236b0ace4 100644 --- a/compiler/testData/codegen/classes/overloadPlusToPlusAssign.jet +++ b/compiler/testData/codegen/classes/overloadPlusToPlusAssign.jet @@ -20,7 +20,7 @@ class ArrayWrapper() { } fun box(): String { - val v1 = ArrayWrapper() + var v1 = ArrayWrapper() val v2 = ArrayWrapper() v1.add("foo") val v3 = v1 diff --git a/compiler/testData/codegen/controlStructures/forIntRange.jet b/compiler/testData/codegen/controlStructures/forIntRange.jet index 0fe391123eb..d215a925bb9 100644 --- a/compiler/testData/codegen/controlStructures/forIntRange.jet +++ b/compiler/testData/codegen/controlStructures/forIntRange.jet @@ -4,7 +4,7 @@ fun box() : String { a[1] = "b" a[2] = "c" - val result = 0 + var result = 0 for(i in a.indices) { result += i } diff --git a/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java b/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java index 4fa45ef3ed8..b9efa562bcf 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java +++ b/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java @@ -107,11 +107,15 @@ public class JetControlFlowTest extends JetTestCaseBase { //check edges directions Collection instructions = pseudocode.getInstructions(); for (Instruction instruction : instructions) { - for (Instruction nextInstruction : instruction.getNextInstructions()) { - assertTrue("instruction: " + instruction + " next: " + nextInstruction, nextInstruction.getPreviousInstructions().contains(instruction)); - } - for (Instruction prevInstruction : instruction.getPreviousInstructions()) { - assertTrue("instruction: " + instruction + " prev: " + prevInstruction, prevInstruction.getNextInstructions().contains(instruction)); + if (!((InstructionImpl) instruction).isDead()) { + for (Instruction nextInstruction : instruction.getNextInstructions()) { + assertTrue("instruction '" + instruction + "' has '" + nextInstruction + "' among next instructions list, but not vice versa", + nextInstruction.getPreviousInstructions().contains(instruction)); + } + for (Instruction prevInstruction : instruction.getPreviousInstructions()) { + assertTrue("instruction '" + instruction + "' has '" + prevInstruction + "' among previous instructions list, but not vice versa", + prevInstruction.getNextInstructions().contains(instruction)); + } } } } @@ -150,13 +154,14 @@ public class JetControlFlowTest extends JetTestCaseBase { private static String formatInstruction(Instruction instruction, int maxLength) { String[] parts = instruction.toString().split("\n"); + String prefix = ((InstructionImpl)instruction).isDead() ? "* " : " "; if (parts.length == 1) { - return " " + String.format("%1$-" + maxLength + "s", instruction); + return prefix + String.format("%1$-" + maxLength + "s", instruction); } StringBuilder sb = new StringBuilder(); for (int i = 0, partsLength = parts.length; i < partsLength; i++) { String part = parts[i]; - sb.append(" ").append(String.format("%1$-" + maxLength + "s", part)); + sb.append(prefix).append(String.format("%1$-" + maxLength + "s", part)); if (i < partsLength - 1) sb.append("\n"); } return sb.toString(); @@ -210,7 +215,9 @@ public class JetControlFlowTest extends JetTestCaseBase { } } else { - maxLength = instuctionText.length(); + if (instuctionText.length() > maxLength) { + maxLength = instuctionText.length(); + } } } String instructionListText = formatInstructionList(instruction.getNextInstructions()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java index 5c4167442fa..5be2b30adca 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java @@ -268,7 +268,7 @@ public class NamespaceGenTest extends CodegenTestCase { } public void testStringPlusEq() throws Exception { - loadText("fun foo(s: String) : String { val result = s; result += s; return result; } "); + loadText("fun foo(s: String) : String { var result = s; result += s; return result; } "); System.out.println(generateToText()); final Method main = generateFunction(); assertEquals("JarJar", main.invoke(null, "Jar")); diff --git a/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java b/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java new file mode 100644 index 00000000000..9dca1094568 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java @@ -0,0 +1,29 @@ +package org.jetbrains.jet.codegen; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * @author alex.tkachman + */ +public class VarArgTest extends CodegenTestCase { + public void testStringArray () throws InvocationTargetException, IllegalAccessException { + /* + loadText("fun test(vararg ts: String) = ts"); + System.out.println(generateToText()); + final Method main = generateFunction(); + Object[] args = {"mama", "papa"}; + assertTrue(args == main.invoke(null, args)); + */ + } + + public void testIntArray () throws InvocationTargetException, IllegalAccessException { + /* + loadText("fun test(vararg ts: Int) = ts"); + System.out.println(generateToText()); + final Method main = generateFunction(); + int[] args = {3, 4}; + assertTrue(args == main.invoke(null, args)); + */ + } +} diff --git a/examples/src/collections/Iterator.kt b/examples/src/collections/Iterator.kt index 8fedf34a2d9..0e8bfac5277 100644 --- a/examples/src/collections/Iterator.kt +++ b/examples/src/collections/Iterator.kt @@ -2,6 +2,19 @@ namespace jet.collections import java.util.NoSuchElementException +trait Iterator { + fun next() : T + val hasNext : Boolean + + fun map(transform: fun(element: T) : R) : Iterator = + object : Iterator { + override fun next() : R = transform(this@map.next()) + + override val hasNext : Boolean + get() = this@map.hasNext + } +} + trait ISized { val size : Int } @@ -16,6 +29,29 @@ trait ISet : Iterable, ISized { fun contains(item : T) : Boolean } +trait IList : Iterable, ISized { + fun get(index : Int) : T + + fun iterator() : Iterator = + object Iterator { + var index = 0 + + override fun next() : T = get(index++) + + override val hasNext : Boolean + get() = index < size + } + + fun toArray() : Array = Array(size) { index => get(index) } +} + +fun Array.asList() : IList = object IList { + override val size + get() = this@Array.size + + override fun get(index: Int) = this@asList[index] +} + fun Iterator.foreach(operation: fun(element: T) : Unit) : Unit = while(hasNext) operation(next()) fun Iterator.foreach(operation: fun(index: Int, element: T) : Unit) : Unit { diff --git a/stdlib/src/jet/ExtensionFunction1.java b/stdlib/src/jet/ExtensionFunction1.java index 2a75a41acf6..3036473a0f6 100644 --- a/stdlib/src/jet/ExtensionFunction1.java +++ b/stdlib/src/jet/ExtensionFunction1.java @@ -1,19 +1,19 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class ExtensionFunction1 extends DefaultJetObject{ +public abstract class ExtensionFunction1 extends DefaultJetObject { protected ExtensionFunction1(TypeInfo typeInfo) { super(typeInfo); } - public abstract R invoke(E receiver, D d); + public abstract R invoke(E receiver, D1 d1); @Override public String toString() { - return "{E.(d: D) : R}"; + return "{E.(d1: D1) : R)}"; } } + diff --git a/stdlib/src/jet/ExtensionFunction10.java b/stdlib/src/jet/ExtensionFunction10.java new file mode 100644 index 00000000000..a840c84675c --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction10.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction10 extends DefaultJetObject { + protected ExtensionFunction10(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction11.java b/stdlib/src/jet/ExtensionFunction11.java new file mode 100644 index 00000000000..161a2635dfc --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction11.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction11 extends DefaultJetObject { + protected ExtensionFunction11(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction12.java b/stdlib/src/jet/ExtensionFunction12.java new file mode 100644 index 00000000000..286b76250f8 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction12.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction12 extends DefaultJetObject { + protected ExtensionFunction12(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction13.java b/stdlib/src/jet/ExtensionFunction13.java new file mode 100644 index 00000000000..6e498216343 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction13.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction13 extends DefaultJetObject { + protected ExtensionFunction13(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction14.java b/stdlib/src/jet/ExtensionFunction14.java new file mode 100644 index 00000000000..129899f7d23 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction14.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction14 extends DefaultJetObject { + protected ExtensionFunction14(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction15.java b/stdlib/src/jet/ExtensionFunction15.java new file mode 100644 index 00000000000..650b4597b3c --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction15.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction15 extends DefaultJetObject { + protected ExtensionFunction15(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction16.java b/stdlib/src/jet/ExtensionFunction16.java new file mode 100644 index 00000000000..782911bb1b6 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction16.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction16 extends DefaultJetObject { + protected ExtensionFunction16(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction17.java b/stdlib/src/jet/ExtensionFunction17.java new file mode 100644 index 00000000000..9a690ecc852 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction17.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction17 extends DefaultJetObject { + protected ExtensionFunction17(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction18.java b/stdlib/src/jet/ExtensionFunction18.java new file mode 100644 index 00000000000..ed7fed24fdc --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction18.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction18 extends DefaultJetObject { + protected ExtensionFunction18(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction19.java b/stdlib/src/jet/ExtensionFunction19.java new file mode 100644 index 00000000000..2db3e66aaa2 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction19.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction19 extends DefaultJetObject { + protected ExtensionFunction19(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction2.java b/stdlib/src/jet/ExtensionFunction2.java index a7ffa19687a..bf5ccd43d4e 100644 --- a/stdlib/src/jet/ExtensionFunction2.java +++ b/stdlib/src/jet/ExtensionFunction2.java @@ -1,11 +1,10 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class ExtensionFunction2 extends DefaultJetObject{ +public abstract class ExtensionFunction2 extends DefaultJetObject { protected ExtensionFunction2(TypeInfo typeInfo) { super(typeInfo); } @@ -14,6 +13,7 @@ public abstract class ExtensionFunction2 extends DefaultJetObjec @Override public String toString() { - return "{E.(d1: D1, d2: D2) : R}"; + return "{E.(d1: D1, d2: D2) : R)}"; } } + diff --git a/stdlib/src/jet/ExtensionFunction20.java b/stdlib/src/jet/ExtensionFunction20.java new file mode 100644 index 00000000000..f3466d13499 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction20.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction20 extends DefaultJetObject { + protected ExtensionFunction20(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction21.java b/stdlib/src/jet/ExtensionFunction21.java new file mode 100644 index 00000000000..43f7bb1bde0 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction21.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction21 extends DefaultJetObject { + protected ExtensionFunction21(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20, D21 d21); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20, d21: D21) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction22.java b/stdlib/src/jet/ExtensionFunction22.java new file mode 100644 index 00000000000..04296ce8b0e --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction22.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction22 extends DefaultJetObject { + protected ExtensionFunction22(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20, D21 d21, D22 d22); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20, d21: D21, d22: D22) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction3.java b/stdlib/src/jet/ExtensionFunction3.java index 54dd96f5f32..8c5518f8c4c 100644 --- a/stdlib/src/jet/ExtensionFunction3.java +++ b/stdlib/src/jet/ExtensionFunction3.java @@ -1,11 +1,10 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class ExtensionFunction3 extends DefaultJetObject{ +public abstract class ExtensionFunction3 extends DefaultJetObject { protected ExtensionFunction3(TypeInfo typeInfo) { super(typeInfo); } @@ -14,6 +13,7 @@ public abstract class ExtensionFunction3 extends DefaultJetOb @Override public String toString() { - return "{E.(d1: D1, d2: D2, d3: D3) : R}"; + return "{E.(d1: D1, d2: D2, d3: D3) : R)}"; } } + diff --git a/stdlib/src/jet/ExtensionFunction4.java b/stdlib/src/jet/ExtensionFunction4.java new file mode 100644 index 00000000000..67f85720049 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction4.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction4 extends DefaultJetObject { + protected ExtensionFunction4(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction5.java b/stdlib/src/jet/ExtensionFunction5.java new file mode 100644 index 00000000000..702db6aa429 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction5.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction5 extends DefaultJetObject { + protected ExtensionFunction5(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction6.java b/stdlib/src/jet/ExtensionFunction6.java new file mode 100644 index 00000000000..b5be7b846a3 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction6.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction6 extends DefaultJetObject { + protected ExtensionFunction6(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction7.java b/stdlib/src/jet/ExtensionFunction7.java new file mode 100644 index 00000000000..2e854e49b25 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction7.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction7 extends DefaultJetObject { + protected ExtensionFunction7(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction8.java b/stdlib/src/jet/ExtensionFunction8.java new file mode 100644 index 00000000000..d633773ea78 --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction8.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction8 extends DefaultJetObject { + protected ExtensionFunction8(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8) : R)}"; + } +} + diff --git a/stdlib/src/jet/ExtensionFunction9.java b/stdlib/src/jet/ExtensionFunction9.java new file mode 100644 index 00000000000..1c65840d5ae --- /dev/null +++ b/stdlib/src/jet/ExtensionFunction9.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class ExtensionFunction9 extends DefaultJetObject { + protected ExtensionFunction9(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(E receiver, D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9); + + @Override + public String toString() { + return "{E.(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function0.java b/stdlib/src/jet/Function0.java index 67515b604e1..81d32b0b281 100644 --- a/stdlib/src/jet/Function0.java +++ b/stdlib/src/jet/Function0.java @@ -5,8 +5,13 @@ package jet; import jet.typeinfo.TypeInfo; -public abstract class Function0 extends DefaultJetObject { - protected Function0(TypeInfo typeInfo) { +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; + +public abstract class Function0 extends DefaultJetObject { + protected Function0(TypeInfo typeInfo) { super(typeInfo); } @@ -16,4 +21,68 @@ public abstract class Function0 extends DefaultJetObject { public String toString() { return "{() : R}"; } + +// public static void main(String[] args) throws IOException { +// for(int i = 1; i <= 22; i++) { +// PrintStream out = new PrintStream(new File("/Development/Dev.Git/jet/stdlib/src/jet/Function" + i + ".java")); +// out.print("/*\n" + +// " * @author alex.tkachman\n" + +// " */\n" + +// "package jet;\n" + +// "\n" + +// "import jet.typeinfo.TypeInfo;\n" + +// "public abstract class Function" + i + "<"); +// for(int k = 1; k <= i; k++) +// out.print("D" + k + ", "); +// out.println("R> extends DefaultJetObject {\n" + +// " protected Function" + i + "(TypeInfo typeInfo) {\n" + +// " super(typeInfo);\n" + +// " }"); +// +// out.print("\n public abstract R invoke("); +// for(int k = 1; k <= i; k++) +// out.print("D" + k + " d" + k + (k != i ? ", " : ");\n\n")); +// +// out.println(" @Override\n" + +// " public String toString() {"); +// out.print(" return \"{("); +// for(int k = 1; k <= i; k++) +// out.print("d" + k + ": D" + k + (k != i ? ", " : ") : R)}\";\n")); +// out.println(" }"); +// +// out.println("}\n"); +// out.close(); +// } +// +// for(int i = 1; i <= 22; i++) { +// PrintStream out = new PrintStream(new File("/Development/Dev.Git/jet/stdlib/src/jet/ExtensionFunction" + i + ".java")); +// out.print("/*\n" + +// " * @author alex.tkachman\n" + +// " */\n" + +// "package jet;\n" + +// "\n" + +// "import jet.typeinfo.TypeInfo;\n" + +// "public abstract class ExtensionFunction" + i + " extends DefaultJetObject {\n" + +// " protected ExtensionFunction" + i + "(TypeInfo typeInfo) {\n" + +// " super(typeInfo);\n" + +// " }"); +// +// out.print("\n public abstract R invoke(E receiver, "); +// for(int k = 1; k <= i; k++) +// out.print("D" + k + " d" + k + (k != i ? ", " : ");\n\n")); +// +// out.println(" @Override\n" + +// " public String toString() {"); +// out.print(" return \"{E.("); +// for(int k = 1; k <= i; k++) +// out.print("d" + k + ": D" + k + (k != i ? ", " : ") : R)}\";\n")); +// out.println(" }"); +// +// out.println("}\n"); +// out.close(); +// } +// } } diff --git a/stdlib/src/jet/Function1.java b/stdlib/src/jet/Function1.java index 345a47cb0a2..3991ba51dd7 100644 --- a/stdlib/src/jet/Function1.java +++ b/stdlib/src/jet/Function1.java @@ -1,19 +1,19 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class Function1 extends DefaultJetObject { +public abstract class Function1 extends DefaultJetObject { protected Function1(TypeInfo typeInfo) { super(typeInfo); } - public abstract R invoke(D d); + public abstract R invoke(D1 d1); @Override public String toString() { - return "{(d: D) : R}"; + return "{(d1: D1) : R)}"; } } + diff --git a/stdlib/src/jet/Function10.java b/stdlib/src/jet/Function10.java new file mode 100644 index 00000000000..3d5633fe157 --- /dev/null +++ b/stdlib/src/jet/Function10.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function10 extends DefaultJetObject { + protected Function10(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function11.java b/stdlib/src/jet/Function11.java new file mode 100644 index 00000000000..23ae003d045 --- /dev/null +++ b/stdlib/src/jet/Function11.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function11 extends DefaultJetObject { + protected Function11(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function12.java b/stdlib/src/jet/Function12.java new file mode 100644 index 00000000000..5e7d39422c2 --- /dev/null +++ b/stdlib/src/jet/Function12.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function12 extends DefaultJetObject { + protected Function12(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function13.java b/stdlib/src/jet/Function13.java new file mode 100644 index 00000000000..fe41e408dc6 --- /dev/null +++ b/stdlib/src/jet/Function13.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function13 extends DefaultJetObject { + protected Function13(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function14.java b/stdlib/src/jet/Function14.java new file mode 100644 index 00000000000..9c678ede552 --- /dev/null +++ b/stdlib/src/jet/Function14.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function14 extends DefaultJetObject { + protected Function14(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function15.java b/stdlib/src/jet/Function15.java new file mode 100644 index 00000000000..9bbc6b85394 --- /dev/null +++ b/stdlib/src/jet/Function15.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function15 extends DefaultJetObject { + protected Function15(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function16.java b/stdlib/src/jet/Function16.java new file mode 100644 index 00000000000..7e401a94242 --- /dev/null +++ b/stdlib/src/jet/Function16.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function16 extends DefaultJetObject { + protected Function16(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function17.java b/stdlib/src/jet/Function17.java new file mode 100644 index 00000000000..2c75ba63d76 --- /dev/null +++ b/stdlib/src/jet/Function17.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function17 extends DefaultJetObject { + protected Function17(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function18.java b/stdlib/src/jet/Function18.java new file mode 100644 index 00000000000..1c95e9e8e39 --- /dev/null +++ b/stdlib/src/jet/Function18.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function18 extends DefaultJetObject { + protected Function18(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function19.java b/stdlib/src/jet/Function19.java new file mode 100644 index 00000000000..8f8d5a030a3 --- /dev/null +++ b/stdlib/src/jet/Function19.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function19 extends DefaultJetObject { + protected Function19(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function2.java b/stdlib/src/jet/Function2.java index 170b1969d0e..21f32978e29 100644 --- a/stdlib/src/jet/Function2.java +++ b/stdlib/src/jet/Function2.java @@ -1,11 +1,10 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class Function2 extends DefaultJetObject { +public abstract class Function2 extends DefaultJetObject { protected Function2(TypeInfo typeInfo) { super(typeInfo); } @@ -14,6 +13,7 @@ public abstract class Function2 extends DefaultJetObject { @Override public String toString() { - return "{(d1: D1, d2: D2) : R}"; + return "{(d1: D1, d2: D2) : R)}"; } } + diff --git a/stdlib/src/jet/Function20.java b/stdlib/src/jet/Function20.java new file mode 100644 index 00000000000..cdf5b11a16e --- /dev/null +++ b/stdlib/src/jet/Function20.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function20 extends DefaultJetObject { + protected Function20(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function21.java b/stdlib/src/jet/Function21.java new file mode 100644 index 00000000000..c213b6079b7 --- /dev/null +++ b/stdlib/src/jet/Function21.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function21 extends DefaultJetObject { + protected Function21(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20, D21 d21); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20, d21: D21) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function22.java b/stdlib/src/jet/Function22.java new file mode 100644 index 00000000000..6aacfa26e84 --- /dev/null +++ b/stdlib/src/jet/Function22.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function22 extends DefaultJetObject { + protected Function22(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9, D10 d10, D11 d11, D12 d12, D13 d13, D14 d14, D15 d15, D16 d16, D17 d17, D18 d18, D19 d19, D20 d20, D21 d21, D22 d22); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9, d10: D10, d11: D11, d12: D12, d13: D13, d14: D14, d15: D15, d16: D16, d17: D17, d18: D18, d19: D19, d20: D20, d21: D21, d22: D22) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function3.java b/stdlib/src/jet/Function3.java index 54380062e6e..ffecf8c9ad1 100644 --- a/stdlib/src/jet/Function3.java +++ b/stdlib/src/jet/Function3.java @@ -1,11 +1,10 @@ /* - * @author max + * @author alex.tkachman */ package jet; import jet.typeinfo.TypeInfo; - -public abstract class Function3 extends DefaultJetObject{ +public abstract class Function3 extends DefaultJetObject { protected Function3(TypeInfo typeInfo) { super(typeInfo); } @@ -14,6 +13,7 @@ public abstract class Function3 extends DefaultJetObject{ @Override public String toString() { - return "{(d1: D1, d2: D2, d3: D3) : R}"; + return "{(d1: D1, d2: D2, d3: D3) : R)}"; } } + diff --git a/stdlib/src/jet/Function4.java b/stdlib/src/jet/Function4.java new file mode 100644 index 00000000000..31fc584ad8f --- /dev/null +++ b/stdlib/src/jet/Function4.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function4 extends DefaultJetObject { + protected Function4(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function5.java b/stdlib/src/jet/Function5.java new file mode 100644 index 00000000000..85655ac1e7e --- /dev/null +++ b/stdlib/src/jet/Function5.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function5 extends DefaultJetObject { + protected Function5(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function6.java b/stdlib/src/jet/Function6.java new file mode 100644 index 00000000000..bf4dfadf09d --- /dev/null +++ b/stdlib/src/jet/Function6.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function6 extends DefaultJetObject { + protected Function6(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function7.java b/stdlib/src/jet/Function7.java new file mode 100644 index 00000000000..ef3691024d4 --- /dev/null +++ b/stdlib/src/jet/Function7.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function7 extends DefaultJetObject { + protected Function7(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function8.java b/stdlib/src/jet/Function8.java new file mode 100644 index 00000000000..0b261a57dfb --- /dev/null +++ b/stdlib/src/jet/Function8.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function8 extends DefaultJetObject { + protected Function8(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8) : R)}"; + } +} + diff --git a/stdlib/src/jet/Function9.java b/stdlib/src/jet/Function9.java new file mode 100644 index 00000000000..5334531aa97 --- /dev/null +++ b/stdlib/src/jet/Function9.java @@ -0,0 +1,19 @@ +/* + * @author alex.tkachman + */ +package jet; + +import jet.typeinfo.TypeInfo; +public abstract class Function9 extends DefaultJetObject { + protected Function9(TypeInfo typeInfo) { + super(typeInfo); + } + + public abstract R invoke(D1 d1, D2 d2, D3 d3, D4 d4, D5 d5, D6 d6, D7 d7, D8 d8, D9 d9); + + @Override + public String toString() { + return "{(d1: D1, d2: D2, d3: D3, d4: D4, d5: D5, d6: D6, d7: D7, d8: D8, d9: D9) : R)}"; + } +} + diff --git a/stdlib/src/jet/arrays/ArrayIterator.java b/stdlib/src/jet/runtime/ArrayIterator.java similarity index 98% rename from stdlib/src/jet/arrays/ArrayIterator.java rename to stdlib/src/jet/runtime/ArrayIterator.java index 79f3bd2a15a..3b57a17636a 100644 --- a/stdlib/src/jet/arrays/ArrayIterator.java +++ b/stdlib/src/jet/runtime/ArrayIterator.java @@ -1,13 +1,10 @@ -package jet.arrays; +package jet.runtime; import jet.Iterator; import jet.JetObject; import jet.typeinfo.TypeInfo; import jet.typeinfo.TypeInfoProjection; -import java.lang.reflect.GenericArrayType; -import java.util.Arrays; - /** * @author alex.tkachman */ diff --git a/stdlib/src/jet/refs/SharedVar.java b/stdlib/src/jet/runtime/SharedVar.java similarity index 96% rename from stdlib/src/jet/refs/SharedVar.java rename to stdlib/src/jet/runtime/SharedVar.java index 0bd99c66965..e0bc9e93d14 100644 --- a/stdlib/src/jet/refs/SharedVar.java +++ b/stdlib/src/jet/runtime/SharedVar.java @@ -1,4 +1,4 @@ -package jet.refs; +package jet.runtime; public final class SharedVar { public static final class Object {