Designing a Programming Language For Embeddability
CowboyRobot writes "The creators of the Lua language describe the process of designing a new language and the constraints that certain parameters, specifically embeddability, place on the process. 'Many languages (not necessarily scripting languages) support extending through an FFI (foreign function interface). An FFI is not enough to allow a function in the system language to do all that a function in the script can do. Nevertheless, in practice FFI covers most common needs for extending, such as access to external libraries and system calls. Embedding, on the other hand, is harder to support, because it usually demands closer integration between the host program and the script, and an FFI alone does not suffice.'"
<head uuid="0"/>
<body head="0">
'nuff said
</body>
Oh good, another language.
The world's burning. Moped Jesus spotted on I50. Details at 11.
Since it's a given that people are going to be creating new languages, I certainly hope they listen to what Roberto has to say. Lua is a joy to embed into applications compared to python and others.
That reminds me i really should start the OpenQL programming language, that exists not for reasons of grammar but the perfection of maths our true evolutionary route. Anyone interested in assisting the project mail me openql ..a..t gmail. Peace.
Interestingly, Lua does not offer a stable/standardized IR form (i.e. they offer no guarantees that it'll not change from version to version). Expressing a program in IR form is valuable in that you can apply a lot of existing IR optimizations to it to gain performance (IR is a representation somewhere in between abstract syntax trees and low level machine code symbolic representation.), e.g. dead code elimination, constant propagation, copy propagation, strength reduction, common subexpression elimination, loop unrolling, loop fission/fusion, memory layout optimization, structure splitting, array reshaping, etc.
Some of the optimizations I mentioned are key in V8 and WebMonkey's performance gains...however you do get the usual caveat. Such analysis takes time and if you're running a run-once and throw-away code snippet, you have to think if it's worth the trouble.
I think Lua can afford to do this, since most hosts that use Lua runs Lua scripts for a long period of time (e.g. a Game that runs a Lua script for controlling an AI). Applying some of the optimizations mentioned earlier should boost some of these codes' performance by a lot.
Forth http://en.wikipedia.org/wiki/Forth_(programming_language)/ was designed to run on (albeit early) embedded platforms. Extensible, easy to learn, easy to implement. I guess it's just the RPN that scares folks off? ("no you old fool! modern processors are optimized away from stack intensive use!")
All of the people I know who have experienced Lua (5 or so) think it's inferior. One even works at a company that embedded Lua into their product as a scripting language only later to realise that was big mistake.
So what happened to Lua support in GRUB? I saw some pretty nifty things done with that.
thegodmovie.com - watch it
Nowadays you would design special languages for domains using languages to help you built such language like Xtext, Xpand/Xtend. You use templates to generate Java, C or assembler code. This is more a stacking approach than an embedding approach. If I am not mistaken C# has some embedding features. Also tools like MPS support that direction. Even though the embedding method results in less developed DSLs than the top-down approach.
C
Why jump through so many hoops to get an embeddable language, when you could use the same language to write the "host program" as you use to write scripts for it? Lisp is an example of such a concept: compiled Lisp programs still have the ability to interpret Lisp code, and hence the most sensible scripting language for a programming written in Lisp is Lisp itself. Lisp is not the only language with this property, but it is one of the most prominent examples of such a language.
Palm trees and 8
So, if you design your DSL based on the D, it will effect the S of your L?
Who'da thunkit?
After reading the headline, am I the only one that thought embedded in the context of microprocessors instead?
Mathematician, n.:
Someone who believes imaginary things appear right before your i's.
What's the track record for self-morphing languages like Lua and Forth? I just skimmed a Scala book, and it scares me.
I can see niches like producing DSLs, but smells like bad news for general application/system programming.
Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
http://sourceforge.net/projects/tcl/ says: "Tool Command Language (Tcl) is an interpreted language and very portable interpreter for that language. Tcl is embeddable and extensible, and has been widely used since its creation in 1988 by John Ousterhout. See http://www.tcl.tk/ for more info." Another good source of information on Tcl is http://wiki.tcl.tk/
Tcl functions well as glue between applications. Some folks know Tcl but call it "Expect" and may not realize Expect is simply Tcl plus an extension. Another extension, Tk, provides GUI features and is so powerful and popular that it's commonly used from other languages. Bindings exist for several other languages, including Ada (called TASH), Perl, Python (called Tkinter), Ruby, and Common Lisp.
Tcl is used by many people and companies (large and small). Cisco network gear uses embedded Tcl for automating tasks. Oracle uses Tcl for automating testing. The Fortune100 company where I work (but I am not a spokesman, so I won't name them) pays me to write and maintain an application written in Tcl to process payments for many thousands of customers totaling millions of dollars every day for payment through banks and the Federal Reserve.
Tcl is FOSS, but a very popular build is ActiveTcl from ActiveState. http://www.activestate.com/activetcl/
-- Jeff Woods
There are lots of peeps pushing FFI, it's a bunch of crap IMO. They never seem to have any reason except portability, and they always try to hide or deny that it is slow and not very powerful.
There are already so many C libs, actually doing anything with it requires re-inventing all your wheels, and the wheels to make those wheels.
If C is too hard, you're not going to be doing embedded stuff long enough to get good with FFI anyways.
1) It must have an eval function or something like that to turn source into executable code.
2) It must be a library, so the host can load it.
3) Global variables must be accessible, but local variables must not be.
The article gives no argumentation for these.
Without going so far as to judge the claims, I think I can safely say that reading this comment instead of the article will save time.
Really you need to design your application round your embeded scripted language. If added as an afterthought it becomes a "lowest common denominator" interface between your application's type model and the embeded language's.
i know, that will be hard to swallow, and tcl is not one of the , favourite 5 programming languages of mine, but its stable, easy to embed, has clear interfaces, and is leightweight. What else do you need?
Another interpreted, garbage-collected, slow as hell but easy to use than evil C language... When this madness will end?
Religion: The greatest weapon of mass destruction of all time
The should check out Nu: http://programming.nu/index
Full interoperable with Objective-C and thus C/C++.
One word: Culture
To flesh that out. Most cultures prefer infix notation. If you're targeting highly technical people as in Autocad, then embedding Lisp might work. Might. Even if the customers are as technical as Autocad users, they might still resist.
Lua is a good embeddabilibuddy.