How not to Design a Scripting Language Paul Biggar Department of - - PowerPoint PPT Presentation

how not to design a scripting language
SMART_READER_LITE
LIVE PREVIEW

How not to Design a Scripting Language Paul Biggar Department of - - PowerPoint PPT Presentation

Introduction How not to design a scripting language How not to Design a Scripting Language Paul Biggar Department of Computer Science and Statistics Trinity College Dublin StackOverflow London, 28th October, 2009 How not to Design a Scripting


slide-1
SLIDE 1

Introduction How not to design a scripting language

How not to Design a Scripting Language

Paul Biggar

Department of Computer Science and Statistics Trinity College Dublin

StackOverflow London, 28th October, 2009

How not to Design a Scripting Language Paul Biggar

slide-2
SLIDE 2

Introduction How not to design a scripting language

About me

  • PhD candidate, Trinity College Dublin
  • Topic: Compilers, optimizations, scripting languages.

How not to Design a Scripting Language Paul Biggar

slide-3
SLIDE 3

Introduction How not to design a scripting language

About me

  • PhD candidate, Trinity College Dublin
  • Topic: Compilers, optimizations, scripting languages.

PhD Dissertation

Design and Implementation of an Ahead-of-time PHP Compiler phc (http://phpcompiler.org)

How not to Design a Scripting Language Paul Biggar

slide-4
SLIDE 4

Introduction How not to design a scripting language

How not to design a scripting language

  • Compilers
  • Scripting Languages

How not to Design a Scripting Language Paul Biggar

slide-5
SLIDE 5

Introduction How not to design a scripting language

How not to design a scripting language

  • Compilers
  • Scripting Languages
  • Speed

How not to Design a Scripting Language Paul Biggar

slide-6
SLIDE 6

Introduction How not to design a scripting language

What is a scripting language?

  • Javascript
  • Lua
  • Perl
  • PHP
  • Python
  • Ruby

How not to Design a Scripting Language Paul Biggar

slide-7
SLIDE 7

Introduction How not to design a scripting language

What is a scripting language?

  • Javascript
  • Lua
  • Perl
  • PHP
  • Python
  • Ruby

Common Features:

  • Dynamic typing
  • Duck typing
  • Interpreted by default
  • FFI via C API

How not to Design a Scripting Language Paul Biggar

slide-8
SLIDE 8

Introduction How not to design a scripting language

Language implementation

  • Interpreters: Easy, portable

How not to Design a Scripting Language Paul Biggar

slide-9
SLIDE 9

Introduction How not to design a scripting language

Language implementation

  • Interpreters: Easy, portable
  • Compilers: Not too hard, sometimes portable,
  • ptimizations

How not to Design a Scripting Language Paul Biggar

slide-10
SLIDE 10

Introduction How not to design a scripting language

Language implementation

  • Interpreters: Easy, portable
  • Compilers: Not too hard, sometimes portable,
  • ptimizations

NOT THE DRAGON BOOK

Engineering a Compiler by Cooper/Torczon Modern Compiler Implementation in X by Appel

How not to Design a Scripting Language Paul Biggar

slide-11
SLIDE 11

Introduction How not to design a scripting language

Language implementation

  • Interpreters: Easy, portable
  • Compilers: Not too hard, sometimes portable,
  • ptimizations
  • Just-in-time compilers: Very difficult, unportable, fast

interpreter.

How not to Design a Scripting Language Paul Biggar

slide-12
SLIDE 12

Introduction How not to design a scripting language

What’s right with scripting languages?

How not to Design a Scripting Language Paul Biggar

slide-13
SLIDE 13

Introduction How not to design a scripting language

What’s right with scripting languages?

1 Elegant and well designed,

How not to Design a Scripting Language Paul Biggar

slide-14
SLIDE 14

Introduction How not to design a scripting language

What’s right with scripting languages?

1 Elegant and well designed, 2 High level of abstraction,

How not to Design a Scripting Language Paul Biggar

slide-15
SLIDE 15

Introduction How not to design a scripting language

What’s right with scripting languages?

1 Elegant and well designed, 2 High level of abstraction, 3 Dynamic typing (and duck typing).

How not to Design a Scripting Language Paul Biggar

slide-16
SLIDE 16

Introduction How not to design a scripting language

What’s wrong with scripting languages?

Symptoms: Speed, Portability

How not to Design a Scripting Language Paul Biggar

slide-17
SLIDE 17

Introduction How not to design a scripting language

What’s wrong with scripting languages?

Symptoms: Speed, Portability Problem: Language designed for interpreters

  • Run-time source code execution

How not to Design a Scripting Language Paul Biggar

slide-18
SLIDE 18

Introduction How not to design a scripting language

What’s wrong with scripting languages?

Symptoms: Speed, Portability Problem: Language designed for one specific interpreter

  • Run-time source code execution
  • Foreign Function Interface

How not to Design a Scripting Language Paul Biggar

slide-19
SLIDE 19

Introduction How not to design a scripting language FFI

FFI

Foreign Function Interface based on CPython interpreter

  • Access to C libraries
  • Script C applications using Python scripts
  • Rewrite hot code in C

How not to Design a Scripting Language Paul Biggar

slide-20
SLIDE 20

Introduction How not to design a scripting language FFI

FFI (good) implications

  • Libraries not that slow
  • Can break out of Python for slow code.

How not to Design a Scripting Language Paul Biggar

slide-21
SLIDE 21

Introduction How not to design a scripting language FFI

FFI (bad) implications

  • Language is allowed to be slow
  • Must break out of Python for speed.

How not to Design a Scripting Language Paul Biggar

slide-22
SLIDE 22

Introduction How not to design a scripting language FFI

FFI (worse) implications

  • Legacy issues

How not to Design a Scripting Language Paul Biggar

slide-23
SLIDE 23

Introduction How not to design a scripting language FFI

FFI (worse) implications

  • Legacy issues
  • Reimplementations

How not to Design a Scripting Language Paul Biggar

slide-24
SLIDE 24

Introduction How not to design a scripting language FFI

FFI solution

Don’t expose yourself!

  • Importing functions into Python with a Domain Specific

Language is good

How not to Design a Scripting Language Paul Biggar

slide-25
SLIDE 25

Introduction How not to design a scripting language FFI

FFI solution

Don’t expose yourself!

  • Importing functions into Python with a Domain Specific

Language is good

  • Only one way of FFI is better

How not to Design a Scripting Language Paul Biggar

slide-26
SLIDE 26

Introduction How not to design a scripting language FFI

FFI solution

Don’t expose yourself!

  • Importing functions into Python with a Domain Specific

Language is good

  • Only one way of FFI is better
  • Declarative is best

How not to Design a Scripting Language Paul Biggar

slide-27
SLIDE 27

Introduction How not to design a scripting language FFI

FFI solution

Don’t expose yourself!

  • Importing functions into Python with a Domain Specific

Language is good

  • Only one way of FFI is better
  • Declarative is best
  • Any reimplementation can reuse the same libraries without

any modifications

  • CPython itself can change without hassle

How not to Design a Scripting Language Paul Biggar

slide-28
SLIDE 28

Introduction How not to design a scripting language Compiled and interpreted models

Dynamic source code generation

  • eval and dynamic include/import

How not to Design a Scripting Language Paul Biggar

slide-29
SLIDE 29

Introduction How not to design a scripting language Compiled and interpreted models

Dynamic source code generation

  • eval and dynamic include/import
  • meta-programming

eval (mysql_read (...)[0]);

How not to Design a Scripting Language Paul Biggar

slide-30
SLIDE 30

Introduction How not to design a scripting language Compiled and interpreted models

Dynamic source code generation

  • eval and dynamic include/import
  • meta-programming
  • .rc files

username = "myname" password = "mypass" server = "srv.domain.com"

How not to Design a Scripting Language Paul Biggar

slide-31
SLIDE 31

Introduction How not to design a scripting language Compiled and interpreted models

Dynamic source code generation

  • eval and dynamic include/import
  • meta-programming
  • .rc files
  • localization

$lang = ....; include ("localisation/locale.$lang.php");

How not to Design a Scripting Language Paul Biggar

slide-32
SLIDE 32

Introduction How not to design a scripting language Compiled and interpreted models

Dynamic source code generation

We don’t even know the full program source!!

How not to Design a Scripting Language Paul Biggar

slide-33
SLIDE 33

Introduction How not to design a scripting language Compiled and interpreted models

So they can’t be compiled (ahead-of-time)

Downsides:

  • Must use FFI for speed
  • Static analysis
  • Cool optimizations can’t happen

How not to Design a Scripting Language Paul Biggar

slide-34
SLIDE 34

Introduction How not to design a scripting language Compiled and interpreted models

So they can’t be compiled (ahead-of-time)

Downsides:

  • Must use FFI for speed
  • Static analysis
  • Cool optimizations can’t happen

t = ...; for (i = 0; i < strlen(t); i++) { s[i] = t[i]; }

How not to Design a Scripting Language Paul Biggar

slide-35
SLIDE 35

Introduction How not to design a scripting language Compiled and interpreted models

So they can’t be compiled (ahead-of-time)

Downsides:

  • Must use FFI for speed
  • Static analysis
  • Cool optimizations can’t happen

t = ...; _temp = strlen(t); for (i = 0; i < _temp; i++) { s[i] = t[i]; }

How not to Design a Scripting Language Paul Biggar

slide-36
SLIDE 36

Introduction How not to design a scripting language Compiled and interpreted models

So they can’t be compiled (ahead-of-time)

Downsides:

  • Must use FFI for speed
  • Static analysis
  • Cool optimizations can’t happen

alert ($(’li’).get(0).nodeName);

How not to Design a Scripting Language Paul Biggar

slide-37
SLIDE 37

Introduction How not to design a scripting language Compiled and interpreted models

So they can’t be compiled (ahead-of-time)

Downsides:

  • Must use FFI for speed
  • Static analysis
  • Cool optimizations can’t happen

alert ($(’li’)[0].nodeName);

How not to Design a Scripting Language Paul Biggar

slide-38
SLIDE 38

Introduction How not to design a scripting language Compiled and interpreted models

JIT compiled

Tracemonkey

http://hacks.mozilla.org/2009/07/tracemonkey-overview/

How not to Design a Scripting Language Paul Biggar

slide-39
SLIDE 39

Introduction How not to design a scripting language Compiled and interpreted models

JIT compiled

Tracemonkey

http://hacks.mozilla.org/2009/07/tracemonkey-overview/

Type Analysis for Javascript

Simon Holm Jensen, Anders Møller and Peter Thiemann SAS ’09 http://www.brics.dk/TAJS/

How not to Design a Scripting Language Paul Biggar

slide-40
SLIDE 40

Introduction How not to design a scripting language Compiled and interpreted models

Fix at language design time

  • No dynamic include; no eval.
  • Compile-time meta-programming

How not to Design a Scripting Language Paul Biggar

slide-41
SLIDE 41

Introduction How not to design a scripting language Compiled and interpreted models

Fix at language design time

  • No dynamic include; no eval.
  • Compile-time meta-programming
  • .rc files

How not to Design a Scripting Language Paul Biggar

slide-42
SLIDE 42

Introduction How not to design a scripting language Compiled and interpreted models

Fix at language design time

  • No dynamic include; no eval.
  • Compile-time meta-programming
  • .rc files
  • localization

How not to Design a Scripting Language Paul Biggar

slide-43
SLIDE 43

Introduction How not to design a scripting language Compiled and interpreted models

Doing it right

  • Factor
  • compiled model
  • compile-time meta-programming
  • declarative FFI

How not to Design a Scripting Language Paul Biggar

slide-44
SLIDE 44

Introduction How not to design a scripting language Compiled and interpreted models

Open research problems

  • Optimizing boxing
  • High-level optimizations
  • Combining ahead-of-time and JIT compilation

How not to Design a Scripting Language Paul Biggar

slide-45
SLIDE 45

Introduction How not to design a scripting language Compiled and interpreted models

Conclusion

Design the next scripting language right

How not to Design a Scripting Language Paul Biggar