Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
3ad5e74a
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3ad5e74a
编写于
11月 02, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
multi-index array expressions and related fixes
上级
532af263
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
220 addition
and
101 deletion
+220
-101
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
...kend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+79
-62
compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
...ackend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
+2
-1
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
.../backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
+3
-0
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
...ler/backend/src/org/jetbrains/jet/codegen/StackValue.java
+76
-37
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
...d/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
+1
-1
compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
+59
-0
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
3ad5e74a
此差异已折叠。
点击以展开。
compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
浏览文件 @
3ad5e74a
...
...
@@ -81,9 +81,10 @@ public class FunctionCodegen {
ExpressionCodegen
codegen
=
new
ExpressionCodegen
(
mv
,
frameMap
,
jvmSignature
.
getReturnType
(),
context
,
state
);
Type
[]
argTypes
=
jvmSignature
.
getArgumentTypes
();
int
add
=
functionDescriptor
.
getReceiverParameter
().
exists
()
?
state
.
getTypeMapper
().
mapType
(
functionDescriptor
.
getReceiverParameter
().
getType
()).
getSize
()
:
0
;
for
(
int
i
=
0
;
i
<
paramDescrs
.
size
();
i
++)
{
ValueParameterDescriptor
parameter
=
paramDescrs
.
get
(
i
);
frameMap
.
enter
(
parameter
,
argTypes
[
i
].
getSize
());
frameMap
.
enter
(
parameter
,
argTypes
[
i
+
add
].
getSize
());
}
for
(
final
TypeParameterDescriptor
typeParameterDescriptor
:
typeParameters
)
{
...
...
compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
浏览文件 @
3ad5e74a
...
...
@@ -547,6 +547,9 @@ public class JetTypeMapper {
}
public
CallableMethod
mapToCallableMethod
(
FunctionDescriptor
functionDescriptor
,
OwnerKind
kind
)
{
if
(
functionDescriptor
==
null
)
return
null
;
final
DeclarationDescriptor
functionParent
=
functionDescriptor
.
getContainingDeclaration
();
final
List
<
Type
>
valueParameterTypes
=
new
ArrayList
<
Type
>();
Method
descriptor
=
mapSignature
(
functionDescriptor
.
getOriginal
(),
valueParameterTypes
,
kind
);
...
...
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
3ad5e74a
...
...
@@ -38,7 +38,7 @@ public abstract class StackValue {
throw
new
UnsupportedOperationException
(
"cannot store to value "
+
this
);
}
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
public
void
dupReceiver
(
InstructionAdapter
v
)
{
}
public
void
condJump
(
Label
label
,
boolean
jumpIfFalse
,
InstructionAdapter
v
)
{
...
...
@@ -84,8 +84,8 @@ public abstract class StackValue {
return
new
ArrayElement
(
type
,
unbox
);
}
public
static
StackValue
collectionElement
(
Type
type
,
CallableMethod
getter
,
CallableMethod
setter
)
{
return
new
CollectionElement
(
type
,
getter
,
setter
);
public
static
StackValue
collectionElement
(
Type
type
,
CallableMethod
getter
,
CallableMethod
setter
,
FrameMap
frame
)
{
return
new
CollectionElement
(
type
,
getter
,
setter
,
frame
);
}
public
static
StackValue
field
(
Type
type
,
String
owner
,
String
name
,
boolean
isStatic
)
{
...
...
@@ -456,24 +456,21 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
if
(
below
==
1
)
{
v
.
dup2X1
();
}
else
{
v
.
dup2
();
// array and index
}
public
void
dupReceiver
(
InstructionAdapter
v
)
{
v
.
dup2
();
// array and index
}
}
private
static
class
CollectionElement
extends
StackValue
{
private
final
CallableMethod
getter
;
private
final
CallableMethod
setter
;
private
final
FrameMap
frame
;
public
CollectionElement
(
Type
type
,
CallableMethod
getter
,
CallableMethod
setter
)
{
public
CollectionElement
(
Type
type
,
CallableMethod
getter
,
CallableMethod
setter
,
FrameMap
frame
)
{
super
(
type
);
this
.
getter
=
getter
;
this
.
setter
=
setter
;
this
.
frame
=
frame
;
}
@Override
...
...
@@ -494,14 +491,71 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
if
(
below
==
1
)
{
v
.
dup2X1
();
public
void
dupReceiver
(
InstructionAdapter
v
)
{
int
size
=
calcSize
();
if
(
size
==
2
)
{
v
.
dup2
();
// collection and index
}
else
{
v
.
dup2
();
// collection and index
Method
signature
=
getter
.
getSignature
();
Type
[]
argumentTypes
=
signature
.
getArgumentTypes
();
int
firstIndex
=
frame
.
enterTemp
();
int
lastIndex
=
firstIndex
;
frame
.
leaveTemp
();
for
(
int
i
=
argumentTypes
.
length
-
1
;
i
>=
0
;
i
--)
{
int
sz
=
argumentTypes
[
i
].
getSize
();
frame
.
enterTemp
(
sz
);
lastIndex
+=
sz
;
v
.
store
(
lastIndex
-
sz
,
argumentTypes
[
i
]);
}
if
(
getter
.
getInvokeOpcode
()
!=
Opcodes
.
INVOKESTATIC
)
{
frame
.
enterTemp
();
lastIndex
++;
v
.
store
(
lastIndex
-
1
,
JetTypeMapper
.
TYPE_OBJECT
);
}
firstIndex
=
lastIndex
;
int
curIndex
=
lastIndex
;
if
(
getter
.
getInvokeOpcode
()
!=
Opcodes
.
INVOKESTATIC
)
{
v
.
load
(
curIndex
-
1
,
JetTypeMapper
.
TYPE_OBJECT
);
curIndex
--;
}
for
(
int
i
=
0
;
i
!=
argumentTypes
.
length
;
i
++)
{
int
sz
=
argumentTypes
[
i
].
getSize
();
v
.
load
(
curIndex
-
sz
,
argumentTypes
[
i
]);
curIndex
-=
sz
;
}
curIndex
=
firstIndex
;
if
(
getter
.
getInvokeOpcode
()
!=
Opcodes
.
INVOKESTATIC
)
{
v
.
load
(
curIndex
-
1
,
JetTypeMapper
.
TYPE_OBJECT
);
curIndex
--;
}
for
(
int
i
=
0
;
i
!=
argumentTypes
.
length
;
i
++)
{
int
sz
=
argumentTypes
[
i
].
getSize
();
v
.
load
(
curIndex
-
sz
,
argumentTypes
[
i
]);
curIndex
-=
sz
;
}
frame
.
leaveTemp
(
size
);
}
}
private
int
calcSize
()
{
assert
getter
!=
null
;
int
size
=
getter
.
getInvokeOpcode
()
==
Opcodes
.
INVOKESTATIC
?
0
:
1
;
Method
signature
=
getter
.
getSignature
();
Type
[]
argumentTypes
=
signature
.
getArgumentTypes
();
for
(
int
i
=
0
;
i
!=
argumentTypes
.
length
;
++
i
)
size
+=
argumentTypes
[
i
].
getSize
();
return
size
;
}
}
...
...
@@ -523,14 +577,9 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
public
void
dupReceiver
(
InstructionAdapter
v
)
{
if
(!
isStatic
)
{
if
(
below
==
1
)
{
v
.
dupX1
();
}
else
{
v
.
dup
();
}
v
.
dup
();
}
}
...
...
@@ -557,7 +606,7 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
public
void
dupReceiver
(
InstructionAdapter
v
)
{
}
@Override
...
...
@@ -607,14 +656,9 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
public
void
dupReceiver
(
InstructionAdapter
v
)
{
if
(!
isStatic
)
{
if
(
below
==
1
)
{
v
.
dupX1
();
}
else
{
v
.
dup
();
}
v
.
dup
();
}
}
}
...
...
@@ -716,13 +760,8 @@ public abstract class StackValue {
}
@Override
public
void
dupReceiver
(
InstructionAdapter
v
,
int
below
)
{
if
(
below
==
1
)
{
v
.
dupX1
();
}
else
{
v
.
dup
();
}
public
void
dupReceiver
(
InstructionAdapter
v
)
{
v
.
dup
();
}
@Override
...
...
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
浏览文件 @
3ad5e74a
...
...
@@ -32,7 +32,7 @@ public class Increment implements IntrinsicMethod {
}
}
StackValue
value
=
codegen
.
genQualified
(
receiver
,
operand
);
value
.
dupReceiver
(
v
,
0
);
value
.
dupReceiver
(
v
);
value
.
put
(
expectedType
,
v
);
if
(
expectedType
==
Type
.
LONG_TYPE
)
{
v
.
lconst
(
myDelta
);
...
...
compiler/tests/org/jetbrains/jet/codegen/ArrayGenTest.java
浏览文件 @
3ad5e74a
...
...
@@ -107,4 +107,63 @@ public class ArrayGenTest extends CodegenTestCase {
Method
foo
=
generateFunction
();
assertTrue
((
Integer
)
foo
.
invoke
(
null
)
==
12
);
}
public
void
testCollectionAssignGetMultiIndex
()
throws
Exception
{
loadText
(
"import java.util.ArrayList\n"
+
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n"
+
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n"
+
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
(
foo
.
invoke
(
null
).
equals
(
"57"
));
}
public
void
testArrayGetAssignMultiIndex
()
throws
Exception
{
loadText
(
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[-3,3] }\n"
+
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n"
+
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
(
foo
.
invoke
(
null
).
equals
(
"57"
));
}
public
void
testCollectionGetMultiIndex
()
throws
Exception
{
loadText
(
"import java.util.ArrayList\n"
+
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n"
+
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n"
+
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
(
foo
.
invoke
(
null
).
equals
(
"5"
));
}
public
void
testArrayGetMultiIndex
()
throws
Exception
{
loadText
(
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; return s[-2, 2] }\n"
+
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n"
+
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
(
foo
.
invoke
(
null
).
equals
(
"5"
));
}
public
void
testMap
()
throws
Exception
{
loadText
(
"fun box() : Int? { val s = java.util.HashMap<String,Int?>(); s[\"239\"] = 239; return s[\"239\"] }\n"
+
"fun java.util.HashMap<String,Int?>.set(index: String, elem: Int?) { this.put(index, elem) }"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
((
Integer
)
foo
.
invoke
(
null
)
==
239
);
}
public
void
testLongDouble
()
throws
Exception
{
loadText
(
"fun box() : Int { var l = IntArray(1); l[0.lng] = 4; l[0.lng] += 6; return l[0.lng];}\n"
+
"fun IntArray.set(index: Long, elem: Int) { this[index.int] = elem }\n"
+
"fun IntArray.get(index: Long) = this[index.int]"
);
System
.
out
.
println
(
generateToText
());
Method
foo
=
generateFunction
(
"box"
);
assertTrue
((
Integer
)
foo
.
invoke
(
null
)
==
10
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录