Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Illicium: Compiling Pharo to C

Talk from IWST at ESUG19, Cologne, Germany

Livres associés

Gratuit avec un essai de 30 jours de Scribd

Tout voir
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Illicium: Compiling Pharo to C

  1. 1. Illicium Compiling Pharo to C 1Pierre Misse-Chanabier Vincent Aranega Guillermo Polito Stéphane Ducasse
  2. 2. Pharo development 2
  3. 3. Code compilation 3
  4. 4. Slang 4
  5. 5. Slang: Basis 5 anOperator ^ 1 + 2 int anOperator(void) { return 1 + 2; }
  6. 6. Slang: Control flow 6 int anIf(void) { if(true){ 1 + 2; } return 0; } anIf true ifTrue:[ 1 + 2 ]
  7. 7. Slang: a Macro 7 aMacro ^ 1 between: 2 and: 3 int aMacro(void) { return ((1>=2) && (1<=3)); }
  8. 8. Slang: an Unknown Message 8 anUnknownMessage ^ 1 even int anUnknowMessage(void) { return even(1); }
  9. 9. Slang: an Unknown Message 9 anUnknownMessage ^ 1 class int anUnknowMessage(void) { return class(1); }
  10. 10. Slang: a Weird Message 10 aWeirdMessage ^ self between: 1 and: false int aWeirdMessage(void) { return ((self>=1) && (self<=0)); }
  11. 11. Slang: assign a value to a class variable 11 assignToClassVariable aClassVariable := 5 #define aClassVariable null void assignToClassVariable(void) { aClassVariable = 5; }
  12. 12. Slang: Code generation 12 generateModulo: msgNode on: aStream indent: level "Generate the C code for this message onto the given stream." self emitCExpression: msgNode receiver on: aStream. aStream nextPutAll: ' % '. self emitCExpression: msgNode args first on: aStream
  13. 13. 1. No intermediary representation 2. Modularity 3. Blurry language boundaries Problems 13
  14. 14. 14
  15. 15. My solution: Illicium 15
  16. 16. What’s an AST? A Visitor? 5 modulo: 3 16
  17. 17. ● Described by a meta model ● Code generation ○ Class, attributes, accessors [...] ○ Visitors ○ Consistency Intermediary representation: AST C 17
  18. 18. Modularity: Node Translators 18
  19. 19. Modularity: Method Translator, a composition 19
  20. 20. Modularity: Method Translator visit 20 MethodTranslator >> visitLiteralValueNode: aLiteralValueNode ^ (translators at: #literalValueNodeTranslator) translateNode: aLiteralValueNode withMethodTranslator: self
  21. 21. Modularity: LiteralNodeTranslator 21 LiteralNodeTranslator >> TranslateNode: aLiteralNode withMethodTranslator: aTranslator ^ ASTCLiteral new value: aLiteralNode value
  22. 22. Modularity: OverflowSafeLiteralNodeTranslator OverflowSafeLiteralNodeTranslator >> TranslateNode: aLiteralNode aLiteralNode value > 255 ifTrue:[ self error: ‘not going to fit in a byte’ ]. ^ ASTCLiteral new value: aLiteralNode value 22
  23. 23. Modularity: IntegerOnlyLiteralNodeTranslator IntegerOnlyLiteralNodeTranslator >> TranslateNode: aLiteralNode withMethodTranslator: aTranslator aLiteralNode isInteger ifFalse:[ self error: ‘Integers are the only real literals!’ ]. ^ ASTCLiteral new value: aLiteralNode value 23
  24. 24. Modularity: Configurable Method Translator 24
  25. 25. Boundaries: Translation of a MessageNode 25
  26. 26. Boundaries: Translation Classes 26
  27. 27. Boundaries: MessageNodeTranslator 27 MessageNodeTranslator >> translateNode: aMessageNode withMethodTranslator: aTranslator | newReceiver | newReceiver := TranslationSmallInteger new value: aMessageNode receiver; methodTranslator: aTranslator. ˆ newReceiver perform: aMessageNode selector withArguments: aMessageNode arguments
  28. 28. Boundaries: Regular vs Translation classes 28 modulo: aNumber ^ self - (self // aNumber * aNumber) modulo: aNumber ^ ASTCModuloOperator new leftOperand: (self value acceptVisitor: visitor); rightOperand: (aNumber acceptVisitor: visitor); yourself.
  29. 29. Boundaries: Translation process 29
  30. 30. Solution 30 ● Better language delimitation ○ Type dependent ○ Browsable ○ Extensible ● Two modularity point ○ Node specialized translator ○ Translation classes
  31. 31. Conclusion ● Slang ● (IR) Metamodel approach ● (Modularity) Small, replaceable translators ● (Boundaries) Message translation based on type ● (Modularity + Boundaries) Translation classes 31 Pierre Misse-Chanabier pierre.misse-chanabier@inria.fr Hogoww on discord/Github
  32. 32. 32
  33. 33. 33
  34. 34. 34
  35. 35. 35

    Soyez le premier à commenter

    Identifiez-vous pour voir les commentaires

Talk from IWST at ESUG19, Cologne, Germany

Vues

Nombre de vues

406

Sur Slideshare

0

À partir des intégrations

0

Nombre d'intégrations

14

Actions

Téléchargements

2

Partages

0

Commentaires

0

Mentions J'aime

0

×