Home

Awesome

What is Sparkling?

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

  1. it will be useful for the community, and
  2. others seeing the potential in it will help me make it better.

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:

Why Sparkling?

How do I use it?

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:

  1. Parse the source text;
  2. Compile it into bytecode;
  3. Execute the bytecode.

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.

Building the library and the REPL

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

How do I hack on it?

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).

What else?

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.

A word about text editors

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.

Portability note:

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:

Happy programming!

-- H2CO3