A Fusion of C and Javascript
This post is a midnight braindump of an idea for a low-level scripting language that marries many of the good parts of C and Javascript (and sprinklings of other languages) together, at least in my opinion. It’s not fully fleshed out and may turn out to be a fever dream of impossibility come the morning, but I think it may very well be implementable in LLVM (hence the LLSL quasi-title) with most of the speed of C and most of the ease of Javascript.
Here’s a list of desired features:
var
keyword for creating any of those data types, but static and must be initialized with a value.1 + 2
is +(1, 2)
. Ternary operators not allowed. Operator syntax is just syntactic sugar.var func = (arg1, arg2, ...) => statementOrFunction, statementOrFunction;
if
is just a function that takes three functions, the conditional function, the true function, and the false function. Implemented with whatever LLVM’s jumpIfZero
and jumpIfNotZero
opcodes are.require
method has to absolutely be present for loading code, and is actually a compiler construct."
and '
are identical, just changing which character needs escaping.&
is used to get the value of pointer of a variable. Useful in the inline-ASM syntax. May be restricted to within it like \
general is with escaping strings.#
is the comment symbol, because fuck the //
/* */
holy wars, and easier to use as a script with the interpreter (if my guess is right, compilation for this thing should be faster than JVM startup times, most of the time)`
, var
, byte
, struct
, =
, =>
, {
, }
, [
, ]
, (
, )
, require
, export
, "
, '
, .
, ,
, ;
, &
, #
. That’s it!Possible example code:
var print = require('print');
var helloWorld = 'Hello, World!';
print(helloWorld);
Simple hello world exercise looks identical to node.js
var print = require('print');
var < = (a byte, b byte) => `LT &a &b`;
print(8 < 3); # Prints 0
Defining a comparison operator with inline LLVM about as easy as the Hello, World.
var print = require('print');
var myStruct = {
foo = 'bar',
baz = [ 123, 456 ]
};
print(myStruct.foo); # Prints bar
Structs look JSON-ish. Debating reuse of equal sign, but would like to keep :
free for custom operators.
var print = require('print');
var HashTable = require('HashTable'); # Functions that create structs should be capitalized
# Not sure if the following will be possible
var myHash = HashTable({
foo = 'bar',
baz = 123
}); # HashTable can be initialized with a struct and auto-boxes the values (somehow)
myHash.set('newValue', 'someValue'); # This will only work with the desired operator overloading
print(myHash.get('newValue')); # Prints someValue
There are some kinks to figure out with actual hash tables so they aren’t totally Java-y, but this seems feasible to my sleep-deprived brain. Perhaps need a typeof
keyword, too.
This past month has not been good for story writing. Lots of extra work, plus hosting a guest for the 4th one week, my son’s birthday another, his birthday party this past weekend… I intend to have the story written by this weekend and be back on track, though.