Lightweight extension language
Sparkling is a little C-style scripting language I've started as a pet project back in late 2012. It has evolved into an active enough project since then, so I'm open-sourcing it in the hopes that
On the one hand, the name "Sparkling" comes from my intent to make the language nice, fast and lightweight, properties I associate with sparks in my mind. On the other hand, my nickname (H2CO3) has a lot to do with carbonated water and bubbles.
Sparkling is influenced by other programming languages, namely:
To learn Sparkling, look at the tutorial/reference manual in doc/
,
then have a look at the examples in the examples/
directory. Don't worry,
there will be more and more documentation over time, but for now that's all
I've got.
Using the Sparkling engine is fairly easy. As in the case of practically any modern scripting language, running a program involves three simple steps:
The Sparkling C API provides functions for these tasks. For usage information,
have a look at implementation of the stand-alone interpreter in spn.c
.
To obtain a debug build (runs slowly, easy to debug):
make
sudo make install
To make a release build (runs fast, hard to debug):
make BUILD=release
sudo make install
To build the JavaScript language bindings:
make -f Makefile.emscripten
To run the unit tests:
make test
To run the unit tests and examine the interpreter using Valgrind:
make test-valgrind
If you have fixed a bug, improved an algorithm or otherwise contributed to the library and you feel like sharing your work with the community, please send me a pull request on GitHub with a concise description of the changes. I only ask you to please respect and follow my coding style (placement of brackets and asterisks, indentation and alignment, whitespace, comments, etc.)
The Sparkling API also has some very basic debugging facilities: namely, it is possible to dump the abstract syntax tree of a parsed program (in order to examine the behavior of the parser) and one can disassemble compiled bytecode as well (so as to debug the compiler and the virtual machine).
If you have any questions or suggestions, you have used Sparkling in your
project or you want to share anything else with me, feel free to drop me an
e-mail or a tweet (I run by the name @H2CO3_iOS
on Twitter). You may also find me on irc.freenode.net
by the same nick, on the channel #sparkling
. I appreciate any feedback,
including constructive (and polite) criticism, improvement suggestions,
questions about usage (if the documentation is unclear), and even donations :P
I've created an entry/wiki page for Sparkling on Rosetta Code, feel free to browse, edit and/or suggest modifications to it. Also check out the list of not implemented tasks and implement some of them at your will (please let me know if/when you implement one, so that I can check it).
The official Sparkling website is h2co3.github.io.
This is an alpha release, so don't expect the engine to be perfect (actually, not even feature-complete). Although I always try to do my best and test my code as much as possible, there may still be bugs - let me know if you find one and I'll fix it as soon as possible. The syntax and semantics of the language are subject to change, too (at least until it leaves alpha), so in the early days, code that ran yesterday can break today. But this is done only in order to let the community decide what kind of features, syntactic and semantic rules would be the best, and when I will have gathered enough suggestions, I'll freeze the language specification. (This is also good for me since now I can procrastinate writing the full specs until the beta release...)
In the meantime, please experiment with the library, write extensions, try
to break the code (I appreciate bug reports), play around with the engine in
various situations, on different platforms. The more people use Sparkling,
the better it will become. Check out the Makefile (with special regards to the
BUILD
variable) as well and tailor it to your needs.
If you are using Emacs, then you will for sure appreciate the Sparkling
major mode (tools/sparkling-mode.el
) and the Flycheck syntax checking plug-in
(tools/sparkling-flycheck.el
).
To use the major mode, put sparkling-mode.el
. into your load-path
, then add
the following line to your Emacs init file (init.el
or .emacs
):
(require 'sparkling-mode)
(You might want to adjust the default tab width in
the major mode file if the default - 8 spaces - does not suit you.)
Similarly, for using the Flycheck plug-in, place sparkling-flycheck.el
inside
your load-path
, copy the tools/spnlint
script in $PATH
, then add
(require 'sparkling-flycheck)
to the init file after the line that says
(require 'flycheck)
.
If you are using Gedit for coding, install the tools/sparkling.lang
file in
the appropriate location to have Gedit recognize the syntax of Sparkling and
apply syntax highlighting on your code.
Notepad++ users can import tools/sparkling-npp.xml
via
Language->Define your language...->[ Import... ]*
Atom users can run the script tools/sparkling-atom-install.sh
.
The code is portable and cross-platform (at least that is my aim), but the
Makefile
isn't. I can only test this on Linux, OS X and iOS. There are a
couple of variables you can change in the Makefile if it doesn't work out of
the box on your platform. A non-exhaustive list of common problems and their
possible solution, respectively:
-isysroot
flag.make LIBEDIT=0
). This does not affect the behavior
of the library (since the library itself doesn't depend on any 3rd-party
libraries), only the usage of the REPL will be less convenient.-fpic
compiler flag by default, which
usually generates faster and/or smaller code, but it doesn't always work.
If it doesn't (the linker will tell you that), try -fPIC
instead.-lm
)src/
folder into your project
should still work.)Happy programming!
-- H2CO3