How not to Design a Scripting Language
Transcript of How not to Design a Scripting Language
![Page 1: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/1.jpg)
How not to Design a Scripting Language
Paul Biggar
Department of Computer Science and StatisticsTrinity College Dublin
StackOverflow London, 28th October, 2009
How not to Design a Scripting Language Paul Biggar
How not to Design a Scripting Language
Paul Biggar
Department of Computer Science and StatisticsTrinity College Dublin
StackOverflow London, 28th October, 2009
![Page 2: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/2.jpg)
About me
• PhD candidate, Trinity College Dublin• Topic: Compilers, optimizations, scripting languages.
PhD DissertationDesign and Implementation of an Ahead-of-time PHP Compiler
phc (http://phpcompiler.org)
How not to Design a Scripting Language Paul Biggar
1. means I justsubmitted
2. So that’s what thistalk is about
About me
• PhD candidate, Trinity College Dublin• Topic: Compilers, optimizations, scripting languages.
PhD DissertationDesign and Implementation of an Ahead-of-time PHP Compiler
phc (http://phpcompiler.org)
![Page 3: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/3.jpg)
About me
• PhD candidate, Trinity College Dublin• Topic: Compilers, optimizations, scripting languages.
PhD DissertationDesign and Implementation of an Ahead-of-time PHP Compiler
phc (http://phpcompiler.org)
How not to Design a Scripting Language Paul Biggar
1. means I justsubmitted
2. So that’s what thistalk is about
3. Not much PHP
About me
• PhD candidate, Trinity College Dublin• Topic: Compilers, optimizations, scripting languages.
PhD DissertationDesign and Implementation of an Ahead-of-time PHP Compiler
phc (http://phpcompiler.org)
![Page 4: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/4.jpg)
How not to design a scripting language
• Compilers• Scripting Languages
• Speed
How not to Design a Scripting Language Paul Biggar
1. really, this is a talkabout compilersand scriptinglanguages
How not to design a scripting language
• Compilers• Scripting Languages
• Speed
![Page 5: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/5.jpg)
How not to design a scripting language
• Compilers• Scripting Languages
• Speed
How not to Design a Scripting Language Paul Biggar
1. Thats whats in theback of my head allthe time
How not to design a scripting language
• Compilers• Scripting Languages
• Speed
![Page 6: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/6.jpg)
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
1. well, no-oneactually has agood definition ofscripting language!
2. I’m not talkingabout Bash orPowershell or VB,or some littlelanguage youwrote last week
What is a scripting language?• Javascript• Lua• Perl• PHP• Python• Ruby
Common Features:• Dynamic typing• Duck typing• Interpreted by default• FFI via C API
![Page 7: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/7.jpg)
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
1. well, no-oneactually has agood definition ofscripting language!
2. I’m not talkingabout Bash orPowershell or VB,or some littlelanguage youwrote last week
3. exposing theirinternals
What is a scripting language?• Javascript• Lua• Perl• PHP• Python• Ruby
Common Features:• Dynamic typing• Duck typing• Interpreted by default• FFI via C API
![Page 8: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/8.jpg)
Language implementation
• Interpreters: Easy, portable
• Compilers: Not too hard, sometimes portable,optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
How not to Design a Scripting Language Paul Biggar
1. Reads one line ata time (kinda)
2. hence used inmany scriptinglangs
Language implementation
• Interpreters: Easy, portable
• Compilers: Not too hard, sometimes portable,optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
![Page 9: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/9.jpg)
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
How not to Design a Scripting Language Paul Biggar
1. Converts sourcecode into machinecode programs(kinda)
2. Lots of time tooptimize
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
![Page 10: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/10.jpg)
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
How not to Design a Scripting Language Paul Biggar
1. 2 months, Joel,Dragon
2. For intermediateand advanced,there are alsomuch better books
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
![Page 11: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/11.jpg)
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
How not to Design a Scripting Language Paul Biggar
1. Amazingoptimizations;Hotspot; dispatch,exceptions andarithmetic
2. Shockingly difficultto write
Language implementation
• Interpreters: Easy, portable• Compilers: Not too hard, sometimes portable,
optimizations
NOT THE DRAGON BOOKEngineering a Compiler by Cooper/Torczon
Modern Compiler Implementation in X by Appel
• Just-in-time compilers: Very difficult, unportable, fastinterpreter.
![Page 12: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/12.jpg)
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
1. dont dwell here -I’m not here toconvince you
2. the bad things donttouch these
What’s right with scripting languages?
1 Elegant and well designed,2 High level of abstraction,3 Dynamic typing (and duck typing).
![Page 13: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/13.jpg)
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
1. dont dwell here -I’m not here toconvince you
2. the bad things donttouch these
3. Python, Ruby; JStoo in a certain way
What’s right with scripting languages?
1 Elegant and well designed,
2 High level of abstraction,3 Dynamic typing (and duck typing).
![Page 14: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/14.jpg)
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
1. dont dwell here -I’m not here toconvince you
2. the bad things donttouch these
3. get things done, asJoel would say
What’s right with scripting languages?
1 Elegant and well designed,2 High level of abstraction,
3 Dynamic typing (and duck typing).
![Page 15: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/15.jpg)
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
1. dont dwell here -I’m not here toconvince you
2. the bad things donttouch these
3. avoids manyproblems inherentin Java, C# andC++: verbosity,type systems
What’s right with scripting languages?
1 Elegant and well designed,2 High level of abstraction,3 Dynamic typing (and duck typing).
![Page 16: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/16.jpg)
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpretersProblem: Language designed for one specific interpreter
• Run-time source code execution• Foreign Function Interface
How not to Design a Scripting Language Paul Biggar
1. portable to .Net,JVM, etc?
2. not fast means youcant use it as much
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpretersProblem: Language designed for one specific interpreter
• Run-time source code execution• Foreign Function Interface
![Page 17: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/17.jpg)
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpreters
Problem: Language designed for one specific interpreter
• Run-time source code execution
• Foreign Function Interface
How not to Design a Scripting Language Paul Biggar
1. portable to .Net,JVM, etc?
2. not fast means youcant use it as much
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpreters
Problem: Language designed for one specific interpreter
• Run-time source code execution
• Foreign Function Interface
![Page 18: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/18.jpg)
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpreters
Problem: Language designed for one specific interpreter
• Run-time source code execution• Foreign Function Interface
How not to Design a Scripting Language Paul Biggar
1. portable to .Net,JVM, etc?
2. not fast means youcant use it as much
What’s wrong with scripting languages?
Symptoms: Speed, Portability
Problem: Language designed for interpreters
Problem: Language designed for one specific interpreter
• Run-time source code execution• Foreign Function Interface
![Page 19: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/19.jpg)
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
1. define FFI2. glue code in C;
wrap things inpython datastructures; exposeinterpreterinternals
3. Works for allexcept JS - I’musing Python asexample
FFI
Foreign Function Interface based on CPython interpreter
• Access to C libraries• Script C applications using Python scripts• Rewrite hot code in C
![Page 20: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/20.jpg)
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
FFI (good) implications
• Libraries not that slow• Can break out of Python for slow code.
![Page 21: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/21.jpg)
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
1. nice things aboutpython are lost(high level, elegant
FFI (bad) implications
• Language is allowed to be slow• Must break out of Python for speed.
![Page 22: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/22.jpg)
FFI
FFI (worse) implications
• Legacy issues
• Reimplementations
How not to Design a Scripting Language Paul Biggar
1. you cant changethe interpretermuch - it cant getfaster
FFI (worse) implications
• Legacy issues
• Reimplementations
![Page 23: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/23.jpg)
FFI
FFI (worse) implications
• Legacy issues• Reimplementations
How not to Design a Scripting Language Paul Biggar
1. Jython,IronPython, PyPy,cant use the samecode
2. cant evenreimplement ownlanguage
3. by constrast, lookat JS
FFI (worse) implications
• Legacy issues• Reimplementations
![Page 24: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/24.jpg)
FFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
How not to Design a Scripting Language Paul Biggar
1. rule for life, really2. like pyrex, ctypes,
etc3. no implementation
specific code at all4. import functions
directly, andaccess them fromwithin Pythonwithout a line of C
5. Ruby libFFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
![Page 25: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/25.jpg)
FFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better
• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
How not to Design a Scripting Language Paul Biggar
1. rule for life, really2. like pyrex, ctypes,
etc3. for
reimplementation4. no implementation
specific code at all5. import functions
directly, andaccess them fromwithin Pythonwithout a line of C
6. Ruby libFFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better
• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
![Page 26: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/26.jpg)
FFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
How not to Design a Scripting Language Paul Biggar
1. rule for life, really2. like pyrex, ctypes,
etc3. no implementation
specific code at all4. import functions
directly, andaccess them fromwithin Pythonwithout a line of C
5. Ruby libFFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
![Page 27: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/27.jpg)
FFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
How not to Design a Scripting Language Paul Biggar
1. rule for life, really2. like pyrex, ctypes,
etc3. no implementation
specific code at all4. import functions
directly, andaccess them fromwithin Pythonwithout a line of C
5. Ruby libFFI
FFI solution
Don’t expose yourself!
• Importing functions into Python with a Domain SpecificLanguage is good
• Only one way of FFI is better• Declarative is best
• Any reimplementation can reuse the same libraries withoutany modifications
• CPython itself can change without hassle
![Page 28: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/28.jpg)
Compiled and interpreted models
Dynamic source code generation
• eval and dynamic include/import
• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
How not to Design a Scripting Language Paul Biggar
1. Should be used forsource inclusion.But becausethey’re interpreted,they can be usedfor:
Dynamic source code generation
• eval and dynamic include/import
• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
![Page 29: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/29.jpg)
Compiled and interpreted models
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
How not to Design a Scripting Language Paul Biggar
1. Should be used forsource inclusion.But becausethey’re interpreted,they can be usedfor:
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
![Page 30: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/30.jpg)
Compiled and interpreted models
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
How not to Design a Scripting Language Paul Biggar
1. Should be used forsource inclusion.But becausethey’re interpreted,they can be usedfor:
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
![Page 31: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/31.jpg)
Compiled and interpreted models
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
How not to Design a Scripting Language Paul Biggar
1. Should be used forsource inclusion.But becausethey’re interpreted,they can be usedfor:
Dynamic source code generation
• eval and dynamic include/import• meta-programming
eval (mysql_read (...)[0]);
• .rc files
username = "myname"password = "mypass"server = "srv.domain.com"
• localization
$lang = ....;include ("localisation/locale.$lang.php");
![Page 32: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/32.jpg)
Compiled and interpreted models
Dynamic source code generation
We don’t even know the fullprogram source!!
How not to Design a Scripting Language Paul Biggar
1. go to next slidestraight away
Dynamic source code generation
We don’t even know the fullprogram source!!
![Page 33: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/33.jpg)
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];}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){
s[i] = t[i];}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
How not to Design a Scripting Language Paul Biggar
1. self-perpetuatingcycle
2. shame, scriptinglanguages couldreally use staticanalysis
3. high-level meanshigh leveloptimizations? no
4. redundencyelimination - somecant be done byhand
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];
}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){s[i] = t[i];
}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
![Page 34: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/34.jpg)
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];}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){
s[i] = t[i];}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
How not to Design a Scripting Language Paul Biggar
1. self-perpetuatingcycle
2. shame, scriptinglanguages couldreally use staticanalysis
3. high-level meanshigh leveloptimizations? no
4. redundencyelimination - somecant be done byhand
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];
}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){s[i] = t[i];
}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
![Page 35: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/35.jpg)
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];}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){
s[i] = t[i];}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
How not to Design a Scripting Language Paul Biggar
1. self-perpetuatingcycle
2. shame, scriptinglanguages couldreally use staticanalysis
3. high-level meanshigh leveloptimizations? no
4. redundencyelimination - somecant be done byhand
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];
}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){s[i] = t[i];
}
alert ($(’li’).get(0).nodeName);alert ($(’li’)[0].nodeName);
![Page 36: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/36.jpg)
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];}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){
s[i] = t[i];}
alert ($(’li’).get(0).nodeName);
alert ($(’li’)[0].nodeName);
How not to Design a Scripting Language Paul Biggar
1. self-perpetuatingcycle
2. shame, scriptinglanguages couldreally use staticanalysis
3. high-level meanshigh leveloptimizations? no
4. redundencyelimination - somecant be done byhand
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];
}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){s[i] = t[i];
}
alert ($(’li’).get(0).nodeName);
alert ($(’li’)[0].nodeName);
![Page 37: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/37.jpg)
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];}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){
s[i] = t[i];}
alert ($(’li’).get(0).nodeName);
alert ($(’li’)[0].nodeName);
How not to Design a Scripting Language Paul Biggar
1. self-perpetuatingcycle
2. shame, scriptinglanguages couldreally use staticanalysis
3. high-level meanshigh leveloptimizations? no
4. redundencyelimination - somecant be done byhand
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];
}
t = ...;_temp = strlen(t);for (i = 0; i < _temp; i++){s[i] = t[i];
}
alert ($(’li’).get(0).nodeName);
alert ($(’li’)[0].nodeName);
![Page 38: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/38.jpg)
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 ThiemannSAS ’09http://www.brics.dk/TAJS/
How not to Design a Scripting Language Paul Biggar
1. instead, they mustbe JIT compiled.We’ll still never getcool optimizations
2. worse, theresearch just getsus, at run-time,expensively,information wecould get atcompile-time.
JIT compiled
Tracemonkey
http://hacks.mozilla.org/2009/07/tracemonkey-overview/
Type Analysis for Javascript
Simon Holm Jensen, Anders Møller and Peter ThiemannSAS ’09http://www.brics.dk/TAJS/
![Page 39: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/39.jpg)
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 ThiemannSAS ’09http://www.brics.dk/TAJS/
How not to Design a Scripting Language Paul Biggar
1. instead, they mustbe JIT compiled.We’ll still never getcool optimizations
2. worse, theresearch just getsus, at run-time,expensively,information wecould get atcompile-time.
JIT compiled
Tracemonkey
http://hacks.mozilla.org/2009/07/tracemonkey-overview/
Type Analysis for Javascript
Simon Holm Jensen, Anders Møller and Peter ThiemannSAS ’09http://www.brics.dk/TAJS/
![Page 40: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/40.jpg)
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
1. do it like Perl, orC++
Fix at language design time
• No dynamic include; no eval.• Compile-time meta-programming
• .rc files• localization
![Page 41: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/41.jpg)
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
1. sandbox them
Fix at language design time
• No dynamic include; no eval.• Compile-time meta-programming• .rc files
• localization
![Page 42: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/42.jpg)
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
1. With a compiledmodel, we know allthe files
Fix at language design time
• No dynamic include; no eval.• Compile-time meta-programming• .rc files• localization
![Page 43: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/43.jpg)
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
1. unfortunatelychose a paradigmthat nobody knows:stack-based;whoops!
Doing it right
• Factor• compiled model• compile-time meta-programming• declarative FFI
![Page 44: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/44.jpg)
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
1. this is the shit weshould beresearching,instead of findingways aroundintracaibleproblems
2. javascript 10px3. table based4. should be trivial
Open research problems
• Optimizing boxing• High-level optimizations• Combining ahead-of-time and JIT compilation
![Page 45: How not to Design a Scripting Language](https://reader031.fdocuments.in/reader031/viewer/2022013001/61ca892bf3b4fb0a661cdcb8/html5/thumbnails/45.jpg)
Compiled and interpreted models
Conclusion
Design the next scriptinglanguage right
How not to Design a Scripting Language Paul Biggar
Conclusion
Design the next scriptinglanguage right