small bug-fix
This commit is contained in:
@@ -598,8 +598,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (DeclarationDescriptor descriptor : closureCodegen.closure.keySet()) {
|
for (DeclarationDescriptor descriptor : closureCodegen.closure.keySet()) {
|
||||||
final Type sharedVarType = getSharedVarType(descriptor);
|
Type sharedVarType = getSharedVarType(descriptor);
|
||||||
consArgTypes.add(sharedVarType != null ? sharedVarType : state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getOutType()));
|
if(sharedVarType == null)
|
||||||
|
sharedVarType = state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getOutType());
|
||||||
|
consArgTypes.add(sharedVarType);
|
||||||
final EnclosedValueDescriptor valueDescriptor = closureCodegen.closure.get(descriptor);
|
final EnclosedValueDescriptor valueDescriptor = closureCodegen.closure.get(descriptor);
|
||||||
valueDescriptor.getOuterValue().put(sharedVarType, v);
|
valueDescriptor.getOuterValue().put(sharedVarType, v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,7 +342,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
Map<DeclarationDescriptor, EnclosedValueDescriptor> closure = context.closure.closure;
|
Map<DeclarationDescriptor, EnclosedValueDescriptor> closure = context.closure.closure;
|
||||||
int k = 0;
|
int k = 0;
|
||||||
for (DeclarationDescriptor varDescr : closure.keySet()) {
|
for (DeclarationDescriptor varDescr : closure.keySet()) {
|
||||||
final Type sharedVarType = context.closure.exprContext.getSharedVarType(varDescr);
|
Type sharedVarType = context.closure.exprContext.getSharedVarType(varDescr);
|
||||||
|
if(sharedVarType == null) {
|
||||||
|
sharedVarType = state.getTypeMapper().mapType(((VariableDescriptor) varDescr).getOutType());
|
||||||
|
}
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
iv.load(firstClosureIndex + k, StackValue.refType(sharedVarType));
|
iv.load(firstClosureIndex + k, StackValue.refType(sharedVarType));
|
||||||
iv.putfield(state.getTypeMapper().jvmName(descriptor, OwnerKind.IMPLEMENTATION), "$" + (k+1), sharedVarType.getDescriptor());
|
iv.putfield(state.getTypeMapper().jvmName(descriptor, OwnerKind.IMPLEMENTATION), "$" + (k+1), sharedVarType.getDescriptor());
|
||||||
|
|||||||
@@ -119,6 +119,12 @@ public class LabelResolver {
|
|||||||
else if (declarationDescriptor instanceof FunctionDescriptor) {
|
else if (declarationDescriptor instanceof FunctionDescriptor) {
|
||||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) declarationDescriptor;
|
FunctionDescriptor functionDescriptor = (FunctionDescriptor) declarationDescriptor;
|
||||||
thisReceiver = functionDescriptor.getReceiverParameter();
|
thisReceiver = functionDescriptor.getReceiverParameter();
|
||||||
|
if(!thisReceiver.exists()) {
|
||||||
|
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
||||||
|
if(containingDeclaration instanceof ClassDescriptor) {
|
||||||
|
thisReceiver = ((ClassDescriptor)containingDeclaration).getImplicitReceiver();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException(); // TODO
|
||||||
|
|||||||
@@ -1,18 +1,83 @@
|
|||||||
namespace jet.collections.iterator
|
namespace jet.collections.iterator
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException
|
||||||
|
|
||||||
trait IIterator<out T> {
|
trait IIterator<out T> {
|
||||||
fun next() : T
|
fun next() : T
|
||||||
val hasNext : Boolean
|
val hasNext : Boolean
|
||||||
|
|
||||||
|
inline fun <R> foldLeft(init: R, operation: fun(accumulated: R, element: T) : R) : R {
|
||||||
|
while(hasNext)
|
||||||
|
init = operation(init, next())
|
||||||
|
return init
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <R> foldLeft(init: R, operation: fun(accumulated: R, index: Int, element: T) : R) : R {
|
||||||
|
var k = 0
|
||||||
|
while(hasNext)
|
||||||
|
init = operation(init, k++, next())
|
||||||
|
return init
|
||||||
|
}
|
||||||
|
|
||||||
inline fun foreach(operation: fun(element: T) : Unit) = while(hasNext) operation(next())
|
inline fun foreach(operation: fun(element: T) : Unit) = while(hasNext) operation(next())
|
||||||
|
|
||||||
|
inline fun foreach(operation: fun(index: Int, element: T) : Unit) : Unit {
|
||||||
|
var k = 0
|
||||||
|
while(hasNext)
|
||||||
|
operation(k++, next())
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <R> map(transform: fun(element: T) : R) : IIterator<R> {
|
inline fun <R> map(transform: fun(element: T) : R) : IIterator<R> {
|
||||||
val that = this
|
|
||||||
return object : IIterator<R> {
|
return object : IIterator<R> {
|
||||||
override fun next() : R = transform(that.next())
|
override fun next() : R = transform(this@map.next())
|
||||||
|
|
||||||
override val hasNext : Boolean
|
override val hasNext : Boolean
|
||||||
get() = that.hasNext
|
get() = this@map.hasNext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun plus(other: IIterator<T>) : IIterator<T> =
|
||||||
|
object : IIterator<T> {
|
||||||
|
override fun next() : T = if(this@plus.hasNext) this@plus.next() else other.next()
|
||||||
|
|
||||||
|
override val hasNext : Boolean
|
||||||
|
get() = this@plus.hasNext || other.hasNext
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun filter(condition: fun(element: T) : Boolean) : IIterator<T> {
|
||||||
|
return object : IIterator<T> {
|
||||||
|
private var _next : T = null
|
||||||
|
private var _lookedAhead : Boolean = false
|
||||||
|
private var _hasNext : Boolean = false
|
||||||
|
|
||||||
|
private fun lookAhead() : Boolean {
|
||||||
|
if(!_lookedAhead) {
|
||||||
|
_lookedAhead = true
|
||||||
|
while(this@filter.hasNext) {
|
||||||
|
_next = this@filter.next()
|
||||||
|
if(condition(_next)) {
|
||||||
|
_hasNext = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _hasNext
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun next() : T {
|
||||||
|
lookAhead()
|
||||||
|
_lookedAhead = false
|
||||||
|
if(_hasNext) {
|
||||||
|
val res = _next
|
||||||
|
_next = null
|
||||||
|
_hasNext = false
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
throw NoSuchElementException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val hasNext : Boolean
|
||||||
|
get() = lookAhead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user