A very trivial scripting language implemented in C11. Only for educational purposes.
- Requires CMake 4.2 (Actually, 3.16+ is fine!)
- Make, Ninja, or another build tool
- Clang is preferred
- Usage:
./project.sh help- Statically-linked binary:
./project.sh br - Dynamically-linked demo binary (uses shared lib):
./project.sh sr
- Statically-linked binary:
- Run
./build/tbasic -ifor the debuggable binary. - Run
./tbasic -ifor the release binary. This is to keep a working release binary separate from the debug build.
- BASIC inspired but:
- No line numbers or GOTO.
- And even more QoL extras!
- Add logical operator (&&, ||) support. OK
- Add assignment operator.
- Add variable assignment. OK
- Add loops support. OK
- Add object base. OK
- Add object heap. OK
- Add simple, fixed size list objects. OK
- Add mark & sweep GC. OK
- Add native function library for: OK
- I/O: print(...args)
- Math: powf(), sqrtf(), clamp(), floorf(), and ceilf()
- Add for-loop variation with
BREAK;andCONTINUE;OK - Add negative number literals. OK
- Add object display methods. OK
- Add immutable strings as separate, interned values. OK
- Create string type. OK
- Add more library functions:
stoi,stofOK
- Add "dict objects": OK
- Add
foo["bar"]syntax for accessing any keys of objects vs.::. OK - Add compiler support for not duplicating string constants. OK
- Add compiler support for dict literals. OK
- Add
make_dict_dudopcode to VM & generation. OK
- Make unified API to register native functions & manipulate VM state. OK
- Support shared object library builds, exposing a header API to the shared lib. OK
- Fix IF-ELSE syntax to allow ELSE IF or premature END. OK
- Add null handling operators: OK
- Prefix
?for compact null checks. - Binary Infix
??for null coalescing.
- Prefix
- Fix var hoisting. OK
- Add
RESERVEopcode. - Change variable generations to set a local offset in the RESERVE-d stack slots upon assignment or initialization.
- Implement
RESERVEopcode.
- Add
- Add try-catch & exceptions. OK
- Add bytecode optimization pass with super-instructions. OK
- Refactor compiler to use cleaner tracking of flag changes, passing bitflags per callee. OK
- Refactor VM to trampoline into native calls vs. doing a branch each time. OK
- Fix exceptions to not naively unwind out of the nearest
RET. What if aRETis in aTRYand makes that exception falsely uncaught? OK
- Add
ASSERT <expr>, <simple-expr, call or literal>;OK - Add lambdas: OK
LET foo : FUN (a, b):
RET a + b;
END;
- Add destructuring of lists into a finite set of names. OK
BIND nums : [a, b, c];
- Fix the atrocious compiler errors to be more specific with column numbers per line. OK
- Add debug info per bytecode chunk e.g line & col per statement. OK
- Add closures. OK
FUN makeCounter(x, y):
RET FUN() USES x, y:
x := x + y;
RET x;
END
END
- Add bitwise NOT, AND, OR, XOR, SHL, SHR... Remove RESERVE opcode in favor of a chunk's non-parameter local count. OK
- Add binary / hexadecimal literals. OK
- Add ASCII escapes in strings.
- Expand builtin library:
- Add
typeoffunction:typeof(val)
- Add list functions:
lsrev(list)lscat(dest, src)using native__lscat(dest, src).lsclr(list)using native__lsclr(list).lsmap(list, fn)lsflt(list, fn)lscut(list, begin, len)apply(fn, argv)using native__apply(fn, argv).
- Add dict functions:
dckeys(dict)using native__iterof(dict).
- Add file stream functions:
fopen(path, bitflags)fclose(fd)fpeek(fd)fread(fd, buf, n)fwrite(fd, buf, n)
- Add
- Add the ability to generate standalone C files which bundle TBasic bytecode & the interpreter as an executable.