concepts of programming languages
play

Concepts of Programming Languages Stack based Paradimgs Timo - PowerPoint PPT Presentation

Table of Content Introduction Concepts Fields of Use Implementations Optimization Concepts of Programming Languages Stack based Paradimgs Timo Luerweg Universit at zu L ubeck 30. November 2015 Timo Luerweg (Uni L ubeck) Concepts


  1. Table of Content Introduction Concepts Fields of Use Implementations Optimization Concepts of Programming Languages Stack based Paradimgs Timo Luerweg Universit¨ at zu L¨ ubeck 30. November 2015 Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 1

  2. Table of Content Introduction Concepts Fields of Use Implementations Optimization Outline Introduction 1 Concepts 2 Fields of Use 3 Implementations 4 Optimization 5 Conclusion 6 Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 2

  3. Table of Content Introduction Concepts Fields of Use Implementations Optimization Introduction What are Stack-based Languages? Rely on one (or more) Stacks to execute programs Operations are executed on the top elements of the stack Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 3

  4. Table of Content Introduction Concepts Fields of Use Implementations Optimization Syntax Stack based Languages use Reverse Polish Notation (Postfix) Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 4

  5. Table of Content Introduction Concepts Fields of Use Implementations Optimization Syntax Stack based Languages use Reverse Polish Notation (Postfix) Notation reflects operation Doesn’t need parentheses Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 4

  6. Table of Content Introduction Concepts Fields of Use Implementations Optimization Infix and Postfix Example (Infix to Postfix) 4 + 5 · 8 · (3 + 6) + 2 Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 5

  7. Table of Content Introduction Concepts Fields of Use Implementations Optimization Infix and Postfix Example (Infix to Postfix) 4 + 5 · 8 · (3 + 6) + 2 ([4 ([5 8 · ][3 6 +] · ) + ]2 + ) Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 5

  8. Table of Content Introduction Concepts Fields of Use Implementations Optimization Infix and Postfix Example (Infix to Postfix) 4 + 5 · 8 · (3 + 6) + 2 ([4 ([5 8 · ][3 6 +] · ) + ]2 + ) 4 5 8 · 3 6 + · + 2+ Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 5

  9. Table of Content Introduction Concepts Fields of Use Implementations Optimization Intermediate Languages Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 6

  10. Table of Content Introduction Concepts Fields of Use Implementations Optimization Intermediate Languages Reasons for a frequent use are: Easy to generate code from Compact representation as Byte-Code Reduced set of instructions Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 6

  11. Table of Content Introduction Concepts Fields of Use Implementations Optimization Intermediate Languages Reasons for a frequent use are: Easy to generate code from Compact representation as Byte-Code Reduced set of instructions Conversion with Shunting-yard algorithm Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 6

  12. Table of Content Introduction Concepts Fields of Use Implementations Optimization Intermediate Languages Reasons for a frequent use are: Easy to generate code from Compact representation as Byte-Code Reduced set of instructions Conversion with Shunting-yard algorithm Examples: Java Byte code ( .class) Elisp byte-code PostScript Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 6

  13. Table of Content Introduction Concepts Fields of Use Implementations Optimization Meta Programming Reasons for a possible use in this field are: Conceptually simple Extendible Code generation and modification at runtime possible Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 7

  14. Table of Content Introduction Concepts Fields of Use Implementations Optimization Forth Imperative Language Uses two stacks: Data and Return Stack Popular in Embedded Systems and Micro-controllers Different versions depending on “stack size” Untyped (5 + ”a” is possible) Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 8

  15. Table of Content Introduction Concepts Fields of Use Implementations Optimization Forth Example (Hello World) : HELLO .”Hello World ” ; Example (4 2 · 5 2 ) 4 dup ∗ 5 dup ∗ ∗ . Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 9

  16. Table of Content Introduction Concepts Fields of Use Implementations Optimization Joy Functional language Based on the composition of functions (not lambda calculus) Programs can pass whole structures as parameters Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 10

  17. Table of Content Introduction Concepts Fields of Use Implementations Optimization Joy Example (Hello World) ”Hello world” (or) ”Hello” ” world” concat Example (4 2 · 5 2 ) 4 dup ∗ 5 dup ∗ ∗ (or) [4 5] [ dup ∗ ] map 5 get get ∗ Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 11

  18. Table of Content Introduction Concepts Fields of Use Implementations Optimization Variable Elimination Speed up execution Reduce Load and Store instructions Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 12

  19. Table of Content Introduction Concepts Fields of Use Implementations Optimization Variable Elimination Requirements: Split able in blocks (of same size) Different branches leave same variables on the stack The stack is in the same state as before (Optional) Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 13

  20. Table of Content Introduction Concepts Fields of Use Implementations Optimization Variable Elimination Requirements: Split able in blocks (of same size) Different branches leave same variables on the stack The stack is in the same state as before (Optional) Difference between Local and Global eliminaiton Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 13

  21. Table of Content Introduction Concepts Fields of Use Implementations Optimization Local Variable Elimination Algorithms exist(see example) Is performed on a single block of code only removes redundant variables Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 14

  22. Table of Content Introduction Concepts Fields of Use Implementations Optimization Example a = b * c; b = a / 8; c = a - b; Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 15

  23. Example 1 ( −− ) 76 LOCAL@ \ b @ 2 ( 76 −− ) 77 LOCAL@ \ c @ 3 (76 77 −− ) ∗ 4 ( 75 −− ) 75 LOCAL! \ a ! 5 ( −− ) 75 LOCAL@ \ a @ 6 ( 75 −− ) 8 \ l i t e r a l 8 7 (75 88 −− ) / 8 ( 76 −− ) 76 LOCAL! \ b ! 9 ( −− ) 75 LOCAL@ \ a @ (DEAD) 10 ( 75 −− ) 76 LOCAL@ \ b @ 11 (75 76 −− ) − 12 ( 77 −− ) 77 LOCAL! \ c !

  24. Example 1 ( −− ) 76 LOCAL@ 2 ( 76 −− ) 77 LOCAL@ 3 (76 77 −− ) ∗ 4 ( 75 −− ) DUP \ copy of 75 5 (75 75 −− ) 75 LOCAL! 6 ( 75 −− ) NOP \ 75 LOCAL@ 7 ( 75 −− ) 8 8 (75 88 −− ) / 9 ( 76 −− ) 76 LOCAL! 10 ( −− ) 75 LOCAL@ 11 ( 75 −− ) 76 LOCAL@ 12 (75 76 −− ) − 13 ( 77 −− ) 77 LOCAL!

  25. Example 1 ( −− ) 76 LOCAL@ 2 ( 76 −− ) 77 LOCAL@ 3 ( 76 77 −− ) ∗ 4 ( 75 −− ) DUP 5 ( 75 75 −− ) 75 LOCAL! (DEAD) 6 ( 75 −− ) NOP 7 ( 75 −− ) 8 8 ( 75 88 −− ) UNDER 9 (75 75 88 −− ) / 10 ( 75 76 −− ) 76 LOCAL! 11 ( 75 −− ) NOP \ 75 LOCAL@ 12 ( 75 −− ) 76 LOCAL@ 13 ( 75 76 −− ) − 14 ( 77 −− ) 77 LOCAL!

  26. Example 1 ( −− ) 76 LOCAL@ 2 ( 76 −− ) 77 LOCAL@ 3 ( 76 77 −− ) ∗ 4 ( 75 −− ) DUP 5 ( 75 75 −− ) 75 LOCAL! (DEAD) \ ∗ 6 ( 75 −− ) NOP 7 ( 75 −− ) 8 8 ( 75 88 −− ) UNDER 9 (75 75 88 −− ) / 10 ( 75 76 −− ) TUCK \ copy of 76 11 (76 75 76 −− ) 76 LOCAL! 12 ( 76 75 −− ) NOP 13 ( 76 75 −− ) SWAP \ 76 LOCAL@ 14 ( 75 76 −− ) − 15 ( 77 −− ) 77 LOCAL!

  27. Example 1 ( −− ) 76 LOCAL@ 2 ( 76 −− ) 77 LOCAL@ 3 ( 76 77 −− ) ∗ 4 ( 75 −− ) 8 5 ( 75 88 −− ) UNDER 6 (75 75 88 −− ) / 7 ( 75 76 −− ) DUP 8 (76 75 76 −− ) 76 LOCAL! 9 ( 75 76 −− ) − 10 ( 77 −− ) 77 LOCAL!

  28. Table of Content Introduction Concepts Fields of Use Implementations Optimization Global Variable Elimination No algorithm at this point Can be applied manually Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 21

  29. Table of Content Introduction Concepts Fields of Use Implementations Optimization Results of Variable Elimination Results differ with different Stack depths Some programs are hard to optimize Timo Luerweg (Uni L¨ ubeck) Concepts of Programming Languages 30. November 2015 22

  30. Results of Variable Elimination Figure: 1 Intra-block stack Figure: 2 The number of local scheduling removes most variable instructions in the redundant accesses to local compiled code reduces variables. dramatically with stack scheduling.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend