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.'"
It's 18 years old. If you don't care to know anything about existing languages, why would having newer ones bother you?
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.
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!")
Bah. Newfangled crap. I'll stick to COBOL, thank you very much.
thegodmovie.com - watch it
So what happened to Lua support in GRUB? I saw some pretty nifty things done with that.
thegodmovie.com - watch it
Inferior to what?
Hamsters are at least as feathery as penguins. HamLix
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.
I think the main reason Lua doesn't have a stable IR form is because in practice there simply isn't a need for the kinds of optimizations it would enable. Lua firmly establishes itself as an embedded scripting language, so in nearly all practical cases whatever Lua code is included in your application represents a negligible amount of resources used (or at the very least isn't one of the big bottlenecks). This is on top of the fact that Lua code already is very fast for a scripting language. If Lua performance is really needed, a JIT compiler exists that'd improve performance to the point of making further optimizations more or less irrelevant.
V8 and WebMonkey, conversely, need such optimizations because the JavaScript code becomes the bottleneck in big web applications. In their case, the interpreter needs to be as fast as possible, which makes every optimization useful.
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
It would be helpful if you included some details.
AccountKiller
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.
World of Warcraft uses LUA for mods, and noone seems to be having any problems with it. If anything, theres too many mods.
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?
Hilscher uses it in some of their communications gateways. From my personal experience in one particular application, the interpreter was too slow to move all the bits and bytes that had to be moved between two systems speaking different protocols, while keeping the communications (machine) cycle at 1ms. YMMV of course, so this is just a specific case, not a generalization.
I think it'd have been much easier for me as a customer if they simply provided an export library exposing relevant APIs in their firmware, provided remote gdb interface, and provided customers with the build of the open source C compiler that they most likely use themselves (their chips use an ARM core). You'd then upload the linked "executable" into the system, it'd get linked there, and executed just like Lua interpeter is being executed.
I don't see any direct benefits from using scripting languages where it's not hard at all to link your own code into the running system. In many embedded applications, you need realtime and deterministic performance. With any garbage-collected language it means that every machine/process cycle when you need to do garbage collection, to keep the overhead distributed across machine cycles. If you do GC too rarely, it may take too long and won't fit into a machine cycle any longer.
Scripting languages kinda lose their appeal if the API exposed to the scripting language has 1:1 mapping to the underlying C API. High-level languages like Python or Lua are supposed to provide benefits because you program at a higher level of abstraction than bare C. Yet if the interface to the system is very low level, you end up writing C-like code in the scripting language. That's especially true if your functionality is fairly simple -- there's no reason to introduce additional layers of abstraction in your own code, after all. Yet the underlying abstractions in the platform you work on may have nice mappings to abstractions of the scripting language (collections, iterators, closures, etc) -- but they are not exposed as such. I'd much prefer straight C to a bastardized Lua.
A successful API design takes a mixture of software design and pedagogy.
We have a prefix-form for math, observe:
add 3, 5, 10
multiply 2, 2, 2, 2, 2
etc.
Math is really the only thing we use infix for and if you discuss it using prefix operation, as above, nobody has a problem understanding, and therefore getting how lisp works. (add-this-list 1 2 3)
LISP's lispisms really only bug other, often narrowly skilled, programers who can't imagine another way to do anything. To someone learning from scratch it's so simple its oddity is of little importance.