smolbasic55 is at least a ECMA-55 Minimal BASIC compiler.
- Assembles to RISC-V or AMD64.
- Full ECMA-55 Minimal BASIC.
- Non-standard features are available.
smolbasic55 [FEATURES] FILE.BAS OUTPUT.S
The generated assembly may need to be linked against the C files data.c, array.c, input.c, print.c, control.c, string.c, math.c, depending
on your code.
FEATURES are enabled with +FEATURE and disabled
with -FEATURE. If FEATURE does not start with NO, NOFEATURE inverts the feature.
NOENDallow missingEND.FULLDEFmakeDEFmore powerful (see below).EXTERNevery function call that is neither user-defined nor builtin is treated as an external call (see below).TYPEadd type suffixes (see below).PTRadd untyped pointer casts (see below).INLINEany line that does not start with a (line) number is pasted verbatim into the assembly output.
Feature flags can also be set in a file with 10 OPTION FLAGS ... (should be the first line number).
If FULLDEF is set, user-defined functions can:
- Have multiple arguments.
- Have string arguments.
- Return strings (e.g.
DEF FNA$(X$)=X$).
If EXTERN is set:
SOMEFUN(...)in an expression translates to an external call that returns a floating-point number.SOMEFUN$(...)in an expression translates to an external call that returns a string.CALL NAME(...)translates to an external call.
If TYPE is set:
- Variables, numbers and functions (if
FULLDEForEXTERNis set) can include the following suffixes:~to indicate a Cchar.%to indicate a Cshort.|to indicate a Cint.&to indicate a Clong.@to indicate a Cvoid*(i.e. an unsigned integer type with the same width as a pointer).!to indicate a Cfloat(or the smallest floating-point type natively supported).
- The
CASTfunction casts its argument to the function type (e.g.CAST~(123&)casts alongto achar).
Many functions promote their arguments to the greatest type, rendering certain casts as no-ops.
For example, PRINT CAST~(500), 500~ will print 500 twice, even though 500 would not fit in a byte.
If PTR is set:
PTR(Var)returns a pointer to a variable.DEREF(Pointer)dereferences a pointer. The type of the function determines the type of the cast.
External functions have the following naming scheme in the generated assembly code:
- The name of the function (without type suffixes).
- If type is string,
$. - If type is enabled by
TYPE, add a type character after$.
If arguments are provided:
- Two underscores (
__). - For every argument:
- If argument is (double) floating-point,
d. - If argument is string,
S. - If
TYPEis set:- If argument is (single) floating-point,
f. - If argument is byte,
c. - If argument is short,
s. - If argument is integer,
i. - If argument is long,
l. - If argument is a pointer,
p.
- If argument is (single) floating-point,
- If argument is (double) floating-point,
Test files were mostly taken from bas55.
This work is licenced under the EUPL-1.2.