2012-06-27 2 views
2

스칼라 컴파일러의 도움말 메뉴 (2.9.2)스칼라 컴파일러가 "-print"옵션을 사용하여 스칼라 관련 기능을 표시하는 이유는 무엇입니까?

-print Print program with Scala-specific features removed. 

을 말한다 그러나 -print 옵션을 사용하여 다음과 같은 호출은 스칼라 고유의 기능을 보여줍니다

C:\Users\John\Test Scala Project\src\main\scala>type test.scala 
trait A 

C:\Users\John\Test Scala Project\src\main\scala>scalac -print test.scala 
[[syntax trees at end of cleanup]]// Scala source: test.scala 
package <empty> { 
    abstract trait A extends java.lang.Object 
} 

가 왜 특성이 여전히 표시됩니다? 나는 순수한 자바 코드를 기대했을 것이다.

+0

소리는 버그와 유사합니다. 형질은 자명 한 스칼라 특유의 것입니다! –

+0

필자도 항상 저를 괴롭 혔지만, 컴파일러 개발자 관점에서 볼 때 스칼라의 대부분의 매개 변수가 처음부터 시작되었습니다. –

답변

9

설명은 실제로 속이는 것이지만 Java 코드를 인쇄하는 것은 결코 아닙니다. 어쨌든 그렇게 할 수는 없습니다. 스칼라는 유효한 바이트 코드를 생성하지만 Java로 직접 변환 할 수있는 바이트 코드는 생성하지 않습니다.

cleanup 단계 이후에 코드를 생성합니다. cleanupicode 전에 마지막 단계는

phase name id description 
    ---------- -- ----------- 
     parser 1 parse source into ASTs, perform simple desugaring 
     namer 2 resolve names, attach symbols to named trees 
packageobjects 3 load package objects 
     typer 4 the meat and potatoes: type the trees 
superaccessors 5 add super accessors in traits and nested classes 
     pickler 6 serialize symbol tables 
    refchecks 7 reference/override checking, translate nested objects 
    selectiveanf 8 
     liftcode 9 reify trees 
    selectivecps 10 
     uncurry 11 uncurry, translate function values to anonymous classes 
    tailcalls 12 replace tail calls by jumps 
    specialize 13 @specialized-driven class and method specialization 
explicitouter 14 this refs to outer pointers, translate patterns 
     erasure 15 erase types, add interfaces for traits 
     lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs 
    lambdalift 17 move nested functions to top level 
    constructors 18 move field definitions into constructors 
     flatten 19 eliminate inner classes 
     mixin 20 mixin composition 
     cleanup 21 platform-specific cleanups, generate reflective calls 
     icode 22 generate portable intermediate code 
     inliner 23 optimization: do inlining 
     closelim 24 optimization: eliminate uncalled closures 
      dce 25 optimization: eliminate dead code 
      jvm 26 generate JVM bytecode 
     terminal 27 The last phase in the compiler chain 

하는 것으로, 그것은 정말 요점 : 당신이 스칼라 2.9.2에 -Xshow-phases을하려고하면 지금, 당신은이를 볼 수 있습니다. 매개 변수 -print은 추상 구문 트리를 변경 한 모든 것이 완료된 후에 내용을 인쇄합니다. 대서양 표준시가 코드를 생성 할 준비가되었을 때.

+0

자세한 설명을 해주셔서 감사합니다. –