Git Product home page Git Product logo

sparkling's Introduction

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:

  • C, above all. C is a wonderful programming language, it's well-balanced between a high-level and a low-level language. It has enough but not too much abstraction. Its syntax is clear, concise and well-structured. Quite a lot of languages inherit some of C's design decisions, especially its syntax.
  • Lua. Being small, compact, fast and embeddable was a primary goal while I have been designing Sparkling. In addition, having a separate operator for concatenation is just inevitable.
  • Python. Python has dynamic and strict typing. That's good because it's convenient and safe at the same time. Following this pattern, Sparkling has a strict strong type system, but variables don't have types, only values do, so any value can be stored in a variable, and runtime checks enforce the correctness of operations.
  • Design errors of JavaScript. JavaScript is a horrible language in my opinion. (Sorry, but I feel like that, nobody has to agree.) It has some fundamental flaws that I wanted to eliminate in order to create a sane language. Overloading the '+' operator for concatenation, equality operators that don't work the way one would expect, block statements without scope, implicitly global undeclared variables, semi-reserved (unused and unusable) keywords, object and function names hard-coded into the language -- argh. And at the end, people even call JavaScript a "small and lightweight" language, even though when we look at any decent JavaScript engine (just think of V8, Nitro, SquirrelFish, SpiderMonkey, etc.), all of them consist of dozens or even hundreds of megabytes of sophisticated, overly complex code. There isn't any need for that in an embedded scripting language.
  • Other "default" mistakes that almost every scripting language has had so far. For example, the exclusive use of floating-point numbers for arithmetic operations, even for integers. It's a well-known fact that floating-point computations aren't always exact, they behave in a quite counter-intuitive manner and they can even be significantly slower than integer operations. Another thing is garbage collection. It seems to be the silver bullet of automatic memory management when it comes to scripting languages, but it has some definitive, serious downsides. Non-deterministic behavior is one, speed is two, memory overhead is three, the difficulty of a decent implementation is four. Reference counting is a simpler approach that is more lightweight, easier to implement, completely deterministic and it has no memory allocation overhead (a program uses only as much memory as needed). Refcounting has its disadvantages too (e. g. memory leaks caused by cyclic references), but I believe that its good properties outweigh them.

Why Sparkling?

  • Small, embeddable: compiled size around 150 kB; tiny grammar, simple rules
  • Portable: written in pure ANSI C89 - runs on Windows, Linux, OS X, iOS, ... it can also be used from within a C++ program (apart from the requirement that the library itself should be compiled as C and not as C++, the public parts of the API are entirely C++-compatible.)
  • Well-designed (at least it is supposed to be well-designed):
    • strict yet dynamic typing and consistent semantics: less programmer errors
    • uses integers to perform integer operations (faster, exact, allows bit ops)
    • easy-to-grasp, readable C-style syntax
    • no global variables
    • no implicit conversions or type coercion
  • Fast: speed comparable to that of Lua
  • Friendly: automatic memory management
  • Extensible: simple and flexible C API
  • Free: Sparkling is free software, the reference implementation is licensed under the 2-clause BSD License (see LICENSE.txt for details).

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:

  • The compiler and/or the linker may need an explicit (or different) development sysroot to be specified, perhaps using the -isysroot flag.
  • The use of the editline library can be turned off if it isn't installed on your platform (just 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.
  • In order to create a shared library, position-independent code must be generated. This is done using the -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.
  • explicit linkage against some components of the C standard library (maths, time, I/O, etc.) may be necessary using different linker flags (e. g. -lm)
  • You may not be using GCC or clang, in which case I'm sorry but you're on your own. (a properly configured IDE should accept and import the code as-is; most notably, if you are on Windows, then you are probably not using GCC or clang but an IDE and a compiler of which the name I don't even dare to mention; in this case, drag 'n dropping the src/ folder into your project should still work.)

Happy programming!

-- H2CO3

sparkling's People

Contributors

h2co3 avatar idmitrievsky avatar jcubic avatar mattfenwick avatar sfan5 avatar velkyel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkling's Issues

Possible leak in vm

Hello,
I am seeing a leak of 24 bytes with with the context convenience API.

Valgrind output:

==24387== Command: ./leak 123
==24387==
123
==24387==
==24387== HEAP SUMMARY:
==24387==     in use at exit: 8,384 bytes in 126 blocks
==24387==   total heap usage: 24,625 allocs, 24,499 frees, 1,129,725 bytes allocated
==24387==
==24387== 8,384 (24 direct, 8,360 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 8
==24387==    at 0x4028308: malloc (vg_replace_malloc.c:263)
==24387==    by 0x804DA52: spn_malloc (misc.c:30)
==24387==    by 0x8049B8B: spn_object_new (api.c:99)
==24387==    by 0x804CFF2: spn_hashmap_new (hashmap.c:101)
==24387==    by 0x804D09D: spn_makehashmap (hashmap.c:124)
==24387==    by 0x80621AC: dispatch_loop (vm.c:1427)
==24387==    by 0x805F563: spn_vm_callfunc (vm.c:444)
==24387==    by 0x804BD12: spn_ctx_callfunc (ctx.c:270)
==24387==    by 0x804BBF1: spn_ctx_execsrcfile (ctx.c:241)
==24387==    by 0x804C0A7: spn_ctx_load_script_stdlib (ctx.c:380)
==24387==    by 0x804B5FA: spn_ctx_init (ctx.c:40)
==24387==    by 0x80498C5: main (leak.c:19)
==24387==
==24387== LEAK SUMMARY:
==24387==    definitely lost: 24 bytes in 1 blocks
==24387==    indirectly lost: 8,360 bytes in 125 blocks
==24387==      possibly lost: 0 bytes in 0 blocks
==24387==    still reachable: 0 bytes in 0 blocks
==24387==         suppressed: 0 bytes in 0 blocks 

Test case:

#include <stdio.h>
#include "spn.h"

int main(int argc, char *argv[]) {
  SpnContext ctx;
  SpnValue rv;
  char buf[BUFSIZ] = {0};

  if (argc == 1) {
    puts("Must supply a spn exression string argument");
    return 1;
  }
  snprintf(buf,(BUFSIZ - 1),"let x = %s; print(x);",argv[1]);
  spn_ctx_init(&ctx);
  if (spn_ctx_execstring(&ctx,buf,&rv)) {
    printf("failed: %s\n",spn_ctx_geterrmsg(&ctx));
  } else {
    spn_value_release(&rv);
  }
  spn_ctx_free(&ctx);
  return 0;
}

spn_ctx_execsrcfile() does the same, and although I didn't test them, I assume that
spn_ctx_execobjfile(), and spn_ctx_compile_*() will, too, because spn_ctx_init()
calls spn_ctx_load_script_stdlib(), which is the real culprit.

If you do everything that the context convenience API does,
except load the Sparkling libraries, you get no leak, as demonstrated by:
noleak.c

I think that the HashMap allocated at the top of ast_validator.spn is never free'd,

You can't compile with warrings turn on (on Linux)

if you compile (link) you've got warrings from str.c and vm.c:

gcc -c -std=c89 -pedantic -pedantic-errors -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-error=parentheses -Wno-error=pointer-to-int-cast -Wno-unused-parameter -O0 -g -pg -DDEBUG -o bld/str.o src/str.c
src/str.c: In function ‘append_format’:
src/str.c:504:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/str.c:508:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/str.c:572:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/str.c:678:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/str.c:728:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/str.c:732:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
gcc -c -std=c89 -pedantic -pedantic-errors -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-error=parentheses -Wno-error=pointer-to-int-cast -Wno-unused-parameter -O0 -g -pg -DDEBUG -o bld/vm.o src/vm.c
src/vm.c: In function ‘current_bytecode’:
src/vm.c:304:2: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/vm.c: In function ‘nth_call_arg’:
src/vm.c:579:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/vm.c: In function ‘nth_vararg’:
src/vm.c:593:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/vm.c: In function ‘push_and_copy_args’:
src/vm.c:672:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/vm.c:607:13: error: variable ‘entry’ set but not used [-Werror=unused-but-set-variable]
src/vm.c: In function ‘dispatch_loop’:
src/vm.c:961:5: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
cc1: all warnings being treated as errors
make: *** [bld/vm.o] Błąd 1

To compile I needed to turn off all warrings except -Wall

Array Concatenation

For the concat example, it would be trivial to create a loop and just copy the values onto the end of the first array, but there are some opportunities for a concat operator to be built into the language:

  1. ..= The dedicated concat operator for strings could be overloaded to work with arrays, as in:
var array1 = array(1, 2, 3);
array1 ..= array(1, 2, 3,);
  1. A concat() function built into the STL as in:
var array = concat(array1, array2);
  1. += could be overloaded as in:
var array1 = array(1, 2, 3);
array1 += array(1, 2, 3,);

All of which would need to be mirrored in the implementation with some kind of spn_array_concat(..);.

Suggestion: add -export-dynamic (for dynld())

Hello,
I found that adding -export-dynamic to LDFLAGS in the makefile
enables dynamic module loading work, in that modules no longer
need explicit linking to libspn(.a|.so). Instead, they pick up the symbols
by the REPL binary. Similarly, if you statically link libspn.a, but use
-export-dynamic on the final binary, modules again don't need to link
against libspn. Oh, and I am using Linuxl; I don't know if it works on Darwin.

Building for minGW

Hi, thank you for creating Sparkling! ⭐
Have you ever tried building it on Windows machine with MinGW installed?

Consider making a single unified syntax

Several places in the language's grammar have multiple options, e.g. optional parentheses after fn or for. People like me can't make up our minds which one to use, and end up seeing this as a downside rather than a convenience. Might be worthwhile to unify the syntax and make there only be one allowed style.

Extra output from -r option

You've got extra output from running Sparkling with run option.

Sparkling build 87da414, copyright (C) 2013, Árpád Goretity

0
1
2
3
4
5
6
7
8
9

from this script

var i;
for i = 0; i<10; ++i {
    print(i);
}

You've got one extra space before and after the output of the program and copyright notice (which I think should be hidden or option to turn it off) if you write shell script you don't want to have copyright.

Simplifications to how the grammar is presented?

Looking at the grammar, I noticed a few things that I usually do differently -- which, for me, make the grammar shorter, clearer, easier to maintain and extend, and easier to use as a reference for implementing a parser (although that may depend on the choice of parsing technology).

I don't want to tell you how to do your business, but if you're interested, I would be happy to create a fork and whip up a full example.

Here are some of the issues I noticed (which are just my humble, often incorrect opinion):

  • the regex quantifiers rule(?) and rule(*) are easier to read than [ rule ] and { rule }

  • these are hard for me to read:

    argument-declaration-list = IDENT { ',' IDENT }
    const-statement = 'const' IDENT '=' expression { ',' IDENT '=' expression } ';'
    

    these are much easier for me to read, since they get rid of the repetition, clearly show the separator and what's being separated (and how many):

    argument-declaration-list = sepBy1 ',' IDENT
    const-statement = 'const'  sepBy1( ','  init )  ';'
    init =  IDENT '=' expression
    
  • specifying operator precedence is too complicated for me to understand; I find tables of precedence levels and associativities much easier to grasp, for example:

    {'left': {'+': 10, '-': 10, '*': 20, ...}, 
     'prefix': {'++': 100, ...}, ...}
    
  • plus I noticed the tokens don't have grammar-ish definitions

So, in summary: none of these proposals change the language in any way, just how it's specified (with the goal of making the specification clearer).

Feel free to close this issue and ignore me if you think it's a waste of time, or stupid, or whatever.

Design questions about For-Loops

I stumbled upon Sparkling because I was searching for a very simple and elegant scripting language. You have designed a very beautiful language, but why is there a For-Loop at all? You have omitted that ugly Switch-Case-Stuff because the same can be done with a chain of Ifs and Elses. As everything that can be done with a For-Loop can also be done with a While-Loop, have you considered replacing the current For-Loop with a Foreach-Loop like construct completely like in Python?

for let i in range(10) {
}
for let i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] {
}

…would do exactly the same as…

for let i = 0; i < 10; i++ {
}

…and is even shorter. If it iterates over Arrays (not HashMaps), you could do stuff like:

for let element in ["str", 5, "str"] {
}
for let key in hm.keys() {
    print(hm[key]);
}

It would also make people happy who don’t like the semicolons in the For-loop (#24) and you could use the newly introduces in keyword as some Kind of contains operator:

if "needle" in haystackarray {
}

What do you think?

Declaration don't work in interactive mode

$ ./spn -i
Sparkling build 87da414, copyright (C) 2013, Árpád Goretity

> var i = 10;
> print(i);
Sparkling: at address 0x00000005: runtime error: global `i' does not exist or it is nil
Call stack:

    [0   ]  in <main program>

REPL is broken

@jcubic @H2CO3 @mattfenwick @sfan5 @idmitrievsky

1. Variables not saved:

Sparkling build 89061a2, copyright (C) 2013-2017, Árpád Goretity

spn:1> let a = 0;
spn:2> print(a);
global 'a' does not exist or it is nil
Runtime error, call stack:

	[0   ] <main program> in ???: line 1 char 7 near 0x5

2. Only can write in one line:

Sparkling build 89061a2, copyright (C) 2013-2017, Árpád Goretity

spn:1> fn say_hello(name) {
near line 1, char 20: expecting '}' at end of block

spn:2> 

OS: MacOS 10.13.6
CPU: i386
Compiler: Apple LLVM version 7.0.2 (clang-700.1.81)

Weird syntax: assigning to a function?

Hey hey!

I am currently in need of a scripting language that I can take advantage of for a build system, as I need to replace my current one for a big project (the output libary is estimated to become 20MB).

For it, I had this syntax for defining a target, similar goes for rules:

target "libfoo.a" {
    rule "lib";
    input [ files("libfoo/*.src") ];
}

Would a syntax like the following be possible?

target("libfoo") = {
    rule: "lib",
    input: [ files("libfoo/*.c") ]
};

I will be implementing most of the functions via C++.

Kind regards, Ingwie.

Comparison warnings on OpenBSD

On OpenBSD -current running on amd64 I get "comparison between signed and unsigned" warnings (which are treated as errors) in str.c and vm.c since size_t is unsigned on my platform.

`for` does not use parenthesis

I like this project! However, it seems a little odd that the for construct does not use parenthesis around its parameters.

For instance, from the sqrt example:

/* Babylonian method, a. k. a. Newton-Raphson */
function bab_sqrt(x)
{
    /* ... */
}

var test = { 0, 1, 2, 3, 4, 9, 16, 25, 100, 123456789 };
for var i = 0; i < sizeof test; i++ {
    var x = test[i];
    printf("babylonian: %f; C stdlib: %f\n", bab_sqrt(x), sqrt(x));
}

The line function bab_sqrt... is defining a function, and var test = ... is defining a variable, but for var... is executing a loop.

Shouldn't the use of keyword space parameter be used for declarations, while keyword parenthesis parameter be used for actual branching conditionals (for,if,while,foreach, etc?)

Furthermore, since it seems like the intent of Sparkling is to create a scripting language that follows C-style conventions where possible, why deviate in this one area without a particular reasoning? (Perhaps there is purpose for it and I haven't found it?)

Finally, if nothing else, shouldn't foreach match for at least, whether using parenthesis or not?

Thanks for this cool project and I look forward to using it!

getargs don't work

examples that use getargs: cmdargs.spn and fibfact.spn throw (on Linux)

Sparkling: at address 0x00000004: runtime error: global `getargs' does not exist or it is nil
Call stack:

    [0   ]  in <main program>

Wrong error message

If you try to use undefined varaibles you got this error:

global 'Boolean' does not exist or it is nil

but if you define the Boolean and assign the nil value you don't get this error so it's wrong, you never get it when global is nil.

Failed to build on Windows, errors in compile.c

@H2CO3 @jcubic @mattfenwick @sfan5 @idmitrievsky

macOS/Linux/iOS - successfully compiled.

Windows:

sed: -e expression #1, char 1: unknown command: `''
sed: -e expression #1, char 1: unknown command: `''
gcc -c -std=c89 -pedantic -fpic -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-parentheses -Wno-error=pointer-to-int-cast -Wno-error=uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=pedantic -D_XOPEN_SOURCE=700 -DSPARKLING_LIBDIR_RAW="/usr/local/lib/sparkling/" -DUSE_LIBEDIT=1 -DUSE_ANSI_COLORS=1 -DUSE_DYNAMIC_LOADING=1 -O0 -g -pg -DDEBUG -o bld/api.o src/api.c
src/api.c: In function 'spn_object_description':
src/api.c:91:3: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   (unsigned long)(obj)
   ^
src/api.c: In function 'spn_hash_value':
src/api.c:350:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   return (unsigned long)(ptrvalue(key));
          ^
src/api.c:355:33: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   return hashfn ? hashfn(obj) : (unsigned long)(obj);
                                 ^
In file included from src/misc.h:14,
                 from src/api.c:22:
src/api.c: In function 'spn_typetag_name':
src/api.c:508:14: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
  assert(ttag < COUNT(typenames));
              ^
gcc -c -std=c89 -pedantic -fpic -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-parentheses -Wno-error=pointer-to-int-cast -Wno-error=uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=pedantic -D_XOPEN_SOURCE=700 -DSPARKLING_LIBDIR_RAW="/usr/local/lib/sparkling/" -DUSE_LIBEDIT=1 -DUSE_ANSI_COLORS=1 -DUSE_DYNAMIC_LOADING=1 -O0 -g -pg -DDEBUG -o bld/array.o src/array.c
gcc -c -std=c89 -pedantic -fpic -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-parentheses -Wno-error=pointer-to-int-cast -Wno-error=uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=pedantic -D_XOPEN_SOURCE=700 -DSPARKLING_LIBDIR_RAW="/usr/local/lib/sparkling/" -DUSE_LIBEDIT=1 -DUSE_ANSI_COLORS=1 -DUSE_DYNAMIC_LOADING=1 -O0 -g -pg -DDEBUG -o bld/ast.o src/ast.c
gcc -c -std=c89 -pedantic -fpic -fstrict-aliasing -Wall -Wextra -Werror -Wno-error=unused-function -Wno-error=sign-compare -Wno-parentheses -Wno-error=pointer-to-int-cast -Wno-error=uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wno-error=pedantic -D_XOPEN_SOURCE=700 -DSPARKLING_LIBDIR_RAW="/usr/local/lib/sparkling/" -DUSE_LIBEDIT=1 -DUSE_ANSI_COLORS=1 -DUSE_DYNAMIC_LOADING=1 -O0 -g -pg -DDEBUG -o bld/compiler.o src/compiler.c
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/Windows.h:69,
                 from src/misc.h:22,
                 from src/compiler.c:21:
src/compiler.c:407:16: error: expected identifier or '(' before 'int'
 static int max(int x, int y)
                ^~~
src/compiler.c:407:12: error: expected ')' before '>' token
 static int max(int x, int y)
            ^~~
src/compiler.c:407:12: error: expected ')' before '?' token
 static int max(int x, int y)
            ^~~
In file included from src/misc.h:14,
                 from src/compiler.c:21:
src/compiler.c: In function 'search_upvalues':
src/compiler.c:592:47: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   assert(spn_array_count(node->index_to_desc) == upval_idx);
                                               ^~
src/compiler.c:614:46: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
  assert(spn_array_count(node->index_to_desc) == flat_upvalidx);
                                              ^~
At top level:
src/compiler.c:706:13: warning: 'emit_ins_long' defined but not used [-Wunused-function]
 static void emit_ins_long(SpnCompiler *cmp, enum spn_vm_ins opcode,
             ^~~~~~~~~~~~~
make: *** [Makefile:124: bld/compiler.o] Error 1

OS: Windows 10
CPU: x86_64
GCC: 8.0.1

All requirements installed via mingw

Errors:

In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/Windows.h:69,
                 from src/misc.h:22,
                 from src/compiler.c:21:
src/compiler.c:407:16: error: expected identifier or '(' before 'int'
 static int max(int x, int y)
                ^~~
src/compiler.c:407:12: error: expected ')' before '>' token
 static int max(int x, int y)
            ^~~
src/compiler.c:407:12: error: expected ')' before '?' token
 static int max(int x, int y)
            ^~~

Place in code:

static int max(int x, int y)
{
	return x > y ? x : y;
}

I can't understand why this is an error. Maybe @H2CO3 can help me.

There should be tutorial for the language

Reading gramar.txt don't give you all information that you need to write scripts, and there are only few examples that show everything.

in grammar.txt there is sequence-literal = '@[' [ expression { ',' expression } ] ']' but running

@[1,2,3,4,5];

throw:
Sparkling: syntax error near line 1: unexpected character@'`

There should be tutorial that show every aspect of the language. It can be just a script with comments.

Shortcut names are bad

IMO shortcut names like bld instead of build and spn instead of sparkling is a bad think. Binary for every language is full name except the case like awk where name is acronym.

Interactive interpter don't display return values

if you create a function

> function square(x) { return x*x; }

and run

> square(10);

you don't get any result but it should display 100 like

=> 100

the same if you type just a number, you don't get that number in return

> 10;
>

so in fact it's not REPL, but REL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.