Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
802f6e1c
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,发现更多精彩内容 >>
提交
802f6e1c
编写于
3月 24, 2011
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
function call generation works in some trivial cases
上级
a203886f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
116 addition
and
4 deletion
+116
-4
.idea/projectCodeStyle.xml
.idea/projectCodeStyle.xml
+11
-0
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+55
-3
idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java
idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java
+3
-0
idea/testData/codegen/currentTime.jet
idea/testData/codegen/currentTime.jet
+3
-0
idea/tests/org/jetbrains/jet/JetLightProjectDescriptor.java
idea/tests/org/jetbrains/jet/JetLightProjectDescriptor.java
+17
-0
idea/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java
idea/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java
+23
-1
idea/tests/org/jetbrains/jet/resolve/JetResolveTest.java
idea/tests/org/jetbrains/jet/resolve/JetResolveTest.java
+4
-0
未找到文件。
.idea/projectCodeStyle.xml
浏览文件 @
802f6e1c
...
...
@@ -127,6 +127,17 @@
<option
name=
"LABEL_INDENT_ABSOLUTE"
value=
"false"
/>
<option
name=
"USE_RELATIVE_INDENTS"
value=
"false"
/>
</ADDITIONAL_INDENT_OPTIONS>
<codeStyleSettings
language=
"JavaScript"
>
<option
name=
"ELSE_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"ALIGN_MULTILINE_BINARY_OPERATION"
value=
"true"
/>
<option
name=
"IF_BRACE_FORCE"
value=
"1"
/>
<option
name=
"PARENT_SETTINGS_INSTALLED"
value=
"true"
/>
</codeStyleSettings>
<codeStyleSettings
language=
"PHP"
>
<option
name=
"ELSE_ON_NEW_LINE"
value=
"true"
/>
<option
name=
"IF_BRACE_FORCE"
value=
"1"
/>
<option
name=
"PARENT_SETTINGS_INSTALLED"
value=
"true"
/>
</codeStyleSettings>
</value>
</option>
<option
name=
"USE_PER_PROJECT_SETTINGS"
value=
"true"
/>
...
...
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
802f6e1c
package
org.jetbrains.jet.codegen
;
import
com.intellij.psi.*
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.types.DeclarationDescriptor
;
import
org.jetbrains.jet.lang.types.FunctionDescriptor
;
import
org.objectweb.asm.Label
;
import
org.objectweb.asm.MethodVisitor
;
import
org.objectweb.asm.Opcodes
;
...
...
@@ -257,7 +259,6 @@ public class ExpressionCodegen extends JetVisitor {
}
}
/*
@Override
public
void
visitCallExpression
(
JetCallExpression
expression
)
{
List
<
JetArgument
>
args
=
expression
.
getValueArguments
();
...
...
@@ -270,6 +271,19 @@ public class ExpressionCodegen extends JetVisitor {
if
(
callee
instanceof
JetSimpleNameExpression
)
{
DeclarationDescriptor
funDescriptor
=
bindingContext
.
resolveReferenceExpression
((
JetSimpleNameExpression
)
callee
);
if
(
funDescriptor
instanceof
FunctionDescriptor
)
{
PsiElement
declarationPsiElement
=
bindingContext
.
getDeclarationPsiElement
(
funDescriptor
);
if
(
declarationPsiElement
instanceof
PsiMethod
)
{
PsiMethod
method
=
(
PsiMethod
)
declarationPsiElement
;
if
(
method
.
hasModifierProperty
(
PsiModifier
.
STATIC
))
{
PsiClass
containingClass
=
method
.
getContainingClass
();
String
owner
=
containingClass
.
getQualifiedName
().
replace
(
"."
,
"/"
);
v
.
visitMethodInsn
(
Opcodes
.
INVOKESTATIC
,
owner
,
method
.
getName
(),
getMethodDescriptor
(
method
));
boxIfNeeded
(
method
.
getReturnType
());
}
else
{
throw
new
UnsupportedOperationException
(
"don't know how to generate instance method calls"
);
}
}
}
else
{
throw
new
CompilationException
();
...
...
@@ -280,10 +294,48 @@ public class ExpressionCodegen extends JetVisitor {
}
}
private
void
boxIfNeeded
(
PsiType
type
)
{
if
(
type
==
PsiType
.
LONG
)
{
v
.
invokestatic
(
"java/lang/Long"
,
"valueOf"
,
"(J)Ljava/lang/Long;"
);
}
else
{
throw
new
UnsupportedOperationException
(
"Don't know how to box type "
+
type
);
}
}
private
String
getMethodDescriptor
(
PsiMethod
method
)
{
Type
returnType
=
psiTypeToAsm
(
method
.
getReturnType
());
PsiParameter
[]
parameters
=
method
.
getParameterList
().
getParameters
();
Type
[]
parameterTypes
=
new
Type
[
parameters
.
length
];
for
(
int
i
=
0
;
i
<
parameters
.
length
;
i
++)
{
parameterTypes
[
i
]
=
psiTypeToAsm
(
parameters
[
i
].
getType
());
}
return
Type
.
getMethodDescriptor
(
returnType
,
parameterTypes
);
}
private
Type
psiTypeToAsm
(
PsiType
type
)
{
if
(
type
instanceof
PsiPrimitiveType
)
{
if
(
type
==
PsiType
.
VOID
)
{
return
Type
.
VOID_TYPE
;
}
if
(
type
==
PsiType
.
LONG
)
{
return
Type
.
LONG_TYPE
;
}
}
throw
new
UnsupportedOperationException
(
"don't know how to map type "
+
type
+
" to ASM"
);
}
@Override
public void visitBinaryExpression(JetBinaryExpression expression) {
public
void
visitDotQualifiedExpression
(
JetDotQualifiedExpression
expression
)
{
// gen(expression.getReceiverExpression());
expression
.
getSelectorExpression
().
accept
(
this
);
}
*/
/*
@Override
public void visitBinaryExpression(JetBinaryExpression expression) {
}
*/
private
Type
getType
(
JetProperty
var
)
{
return
InstructionAdapter
.
OBJECT_TYPE
;
// TODO:
...
...
idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java
浏览文件 @
802f6e1c
...
...
@@ -117,6 +117,9 @@ public class FunctionCodegen {
if
(
"Int"
.
equals
(
name
))
{
return
Type
.
getType
(
Integer
.
class
);
}
if
(
"Long"
.
equals
(
name
))
{
return
Type
.
getType
(
Long
.
class
);
}
throw
new
UnsupportedOperationException
(
"Unknown type "
+
name
);
}
...
...
idea/testData/codegen/currentTime.jet
0 → 100644
浏览文件 @
802f6e1c
import java.lang.*
fun f() : Long { return System.currentTimeMillis(); }
\ No newline at end of file
idea/tests/org/jetbrains/jet/JetLightProjectDescriptor.java
0 → 100644
浏览文件 @
802f6e1c
package
org.jetbrains.jet
;
import
com.intellij.openapi.projectRoots.Sdk
;
import
com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
;
import
org.jetbrains.jet.resolve.JetResolveTest
;
/**
* @author yole
*/
public
class
JetLightProjectDescriptor
extends
DefaultLightProjectDescriptor
{
public
static
JetLightProjectDescriptor
INSTANCE
=
new
JetLightProjectDescriptor
();
@Override
public
Sdk
getSdk
()
{
return
JetResolveTest
.
jdkFromIdeaHome
();
}
}
idea/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java
浏览文件 @
802f6e1c
package
org.jetbrains.jet.codegen
;
import
com.intellij.testFramework.LightProjectDescriptor
;
import
com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.JetLightProjectDescriptor
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetNamespace
;
import
org.jetbrains.jet.parsing.JetParsingTest
;
...
...
@@ -24,7 +27,7 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
}
public
void
testPSVM
()
throws
Exception
{
myFixture
.
configureByFile
(
JetParsingTest
.
getTestDataDir
()
+
"/codegen/
PSVM.jet"
);
loadFile
(
"
PSVM.jet"
);
final
String
text
=
generateToText
();
System
.
out
.
println
(
text
);
...
...
@@ -67,6 +70,19 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
assertEquals
(
new
Integer
(
50
),
returnValue
);
}
public
void
testCurrentTime
()
throws
Exception
{
loadFile
(
"currentTime.jet"
);
final
Class
aClass
=
generateToClass
();
final
Method
main
=
firstMethod
(
aClass
);
final
long
returnValue
=
(
Long
)
main
.
invoke
(
null
);
long
currentTime
=
System
.
currentTimeMillis
();
assertTrue
(
Math
.
abs
(
returnValue
-
currentTime
)
<=
1L
);
}
private
void
loadFile
(
final
String
name
)
{
myFixture
.
configureByFile
(
JetParsingTest
.
getTestDataDir
()
+
"/codegen/"
+
name
);
}
private
String
generateToText
()
{
StringWriter
writer
=
new
StringWriter
();
JetFile
jetFile
=
(
JetFile
)
myFixture
.
getFile
();
...
...
@@ -104,4 +120,10 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
return
super
.
loadClass
(
name
);
}
}
@NotNull
@Override
protected
LightProjectDescriptor
getProjectDescriptor
()
{
return
JetLightProjectDescriptor
.
INSTANCE
;
}
}
idea/tests/org/jetbrains/jet/resolve/JetResolveTest.java
浏览文件 @
802f6e1c
...
...
@@ -114,6 +114,10 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
@Override
protected
Sdk
getProjectJDK
()
{
return
jdkFromIdeaHome
();
}
public
static
Sdk
jdkFromIdeaHome
()
{
Properties
properties
=
new
Properties
();
try
{
FileReader
reader
=
new
FileReader
(
getHomeDirectory
()
+
"/idea/idea.properties"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录