Towards a flexible Pharo Compiler Clement Bera and Marcus Denker - - PowerPoint PPT Presentation

towards a flexible pharo compiler
SMART_READER_LITE
LIVE PREVIEW

Towards a flexible Pharo Compiler Clement Bera and Marcus Denker - - PowerPoint PPT Presentation

Towards a flexible Pharo Compiler Clement Bera and Marcus Denker Three Problems Architecture is not reusable Compiler can not be parametrized The mapping between source code and bytecode is overly complex. Reusability AST is


slide-1
SLIDE 1

Towards a flexible Pharo Compiler

Clement Bera and Marcus Denker

slide-2
SLIDE 2

Three Problems

  • Architecture is not reusable
  • Compiler can not be parametrized
  • The mapping between source code and

bytecode is overly complex.

slide-3
SLIDE 3

Reusability

  • AST is special for the Compiler
  • Tools use own AST (RB)
  • AST is destroyed when compiling
  • No reusable backend/parser...
slide-4
SLIDE 4

No Parametrization

  • No pluggable archicture
  • Parser, code generator fixed
  • No infrastructure for compiler options
slide-5
SLIDE 5

Mapping bc2source

  • For the Debugger, we need to map

bytecode to source offsets

  • With closures, we need to map temp
  • ffsets to real temps.

Old Compiler: Encoder builds complex table structure

slide-6
SLIDE 6

Solution: OPAL

  • New compiler framework for Pharo
  • Default compiler in Pharo3
  • Old Compiler will be a loadable package
slide-7
SLIDE 7

Design

  • RB AST
  • Visitors
  • Bytecode

level IR

Smalltalk source code Refactoring browser abstract syntax tree Intermediate representation Bytecode RBParser ASTTranslator + IRBuilder IRByteCodeGenerator OCSemanticAnnotator

slide-8
SLIDE 8

Reusability

  • AST is unchanged
  • Backend independent

AST Interpreter Oz/Hazelnut Reflectivity Metalinks Class Builder Smart suggestions Node navigation

slide-9
SLIDE 9

Parametrization

  • Explicit

compiler context

  • All visitors

are pluggable

Smalltalk source code Refactoring browser abstract syntax tree Intermediate representation Bytecode Compilation context

slide-10
SLIDE 10

Compiler Options

  • Turn off inlining of ifTrue: and friends

MyClass>>foo <compilerOptions: - optionInlineIf> ^ #myNonBooleanObject ifTrue: [ 1 ] ifFalse: [ 0 ]

slide-11
SLIDE 11

Mapping

  • Mapping

uses AST directly

source code Bytecode foo ^ 1 + 2 + 3 76 77 B0 20 B0 7C IRMethod RBMethodNode RBSequenceNode RBReturnNode RBMessageNode 1 RBLiteral ValueNode 1 IRPushLiteral IRSequence RBLiteral ValueNode 1 IRPushLiteral RBLiteral ValueNode 2 IRReturn RBReturnNode IRSend RBMessageNode 1 IRPushLiteral RBLiteral ValueNode 3 RBMessageNode 2 RBLiteral ValueNode 3 IRSend RBMessageNode 2 B0 + 2 1 2 3 + 2 + 3 ^ 1 + 2 + 3 ^ 1 + 2 + 3 foo ^ 1 + 2 + 3 RBLiteral ValueNode 2

slide-12
SLIDE 12

Performance

  • Visitors and IR do cost a bit of speed
  • But not much
slide-13
SLIDE 13

Conclusion

  • Opal solves the problems of the old

compiler

  • Important basis for many features you will

see in Pharo3 and Pharo4

slide-14
SLIDE 14

Conclusion

  • Opal solves the problems of the old

compiler

  • Important basis for many features you will

see in Pharo3 and Pharo4

Questions?