The BASM programming language, short for "Basic Assembly," is designed to serve as a higher-level intermediate language that acts as a compilation target for various programming languages. BASM is both a compiler (to it's own IL) and a virtual machine (VM).
The BASM programming language is engineered with a distinct philosophy prioritizing ease of implementation and portability across platforms, while still achieving reasonable performance. This approach is guided by the Pareto principle, often referred to as the 80/20 rule, suggesting that with 20% of the effort, it's possible to attain 80% of the maximum achievable performance. This principle underlines BASM's design and operational goals, making it a unique player in the field of programming languages and virtual machines.
BASM's primary objective is not to maximize efficiency at the cost of complexity or portability but to ensure that the language and its corresponding virtual machine can be easily implemented and ported across different platforms. This philosophy acknowledges the trade-offs between the ultimate performance and broader accessibility and usability of the language and its ecosystem.
A core tenet of BASM is to reduce the complexity inherent in implementing both the compiler and the virtual machine. This simplicity facilitates quicker development cycles, easier maintenance, and the ability to extend the language and runtime environment with minimal effort. By focusing on straightforward implementation, BASM lowers the barrier to entry for developers looking to target new platforms or experiment with language design and compilation techniques.
Portability is a cornerstone of BASM's design. The language and VM are crafted to ensure that they can be easily adapted to various operating systems and hardware architectures. This flexibility allows BASM programs to run in diverse environments without necessitating significant alterations to the codebase, making BASM an attractive option for applications requiring cross-platform compatibility.
While BASM emphasizes ease of implementation and portability, it also aims to deliver respectable performance. By achieving 80% of the potential performance with a fraction of the effort required for full optimization, BASM positions itself as sufficiently performant for a wide array of use cases. This level of efficiency is adequate for many applications, striking a balance between the resource-intensive pursuit of peak performance and the practical needs of software development.
BASM distinguishes itself through its pragmatic approach to language design and virtual machine implementation. By prioritizing ease of implementation and portability, and acknowledging the practical trade-offs between optimal performance and broader usability, BASM offers a compelling toolset for developers and educators alike.
Building the BASM project can be accomplished in two primary ways depending on the tools and environment you're working with. Below are detailed instructions for both methods.
The bflat
compiler is a specialized tool designed for compiling C# projects to
native code, resulting in very small executable sizes. Before proceeding, ensure
you have the bflat
compiler installed on your system. You can download and
find installation instructions at flattened.net.
- Open a Terminal Window: Navigate to your project's root directory where
the
build.sh
script is located. - Grant Execution Permissions: If you haven't already, ensure the
build.sh
script is executable by running:
chmod +x build.sh
- Execute the Build Script: Run the following command in the terminal:
./build.sh
This script will automatically clean the previous build, create a new build
directory, and invoke the bflat
compiler with the necessary options to compile
the BASM project.
- Open Command Prompt: Navigate to your project's root directory where the
build.bat
script is located. - Execute the Build Script: Run the following command in the command prompt:
.\build.bat
The build.bat
script performs similar actions as its Linux/Mac counterpart,
tailored for the Windows environment. It cleans up old builds and compiles the
project using bflat
.
You can also utilize the dotnet build command.
- Open a Terminal or Command Prompt: Navigate to your project's root
directory where the
.csproj
or.sln
file is located. Execute the Build Command
: Run the following command:
dotnet build
This command compiles the project, its dependencies, and produces a binary
executable. dotnet build
automatically restores any missing dependencies and
processes the project files.
- Ensure you have the
.NET SDK
installed on your system to usedotnet
commands. If you're unsure, you can check by runningdotnet --version
in your terminal or command prompt. - For more detailed options and configurations for the
dotnet build
command, you can refer to the official .NET documentation or usedotnet build --help
to explore available parameters.
In the examples folder
are several test programs. You can execute them all
with the test.bat
or test.sh
script, depending on your platform.
-
create a basic lexer, parser and tree walking interpreter
-
add different data types
- add int
- add float type
- add bool type
- add string type
-
variable creation and assignment
-
reassignment of variables
-
basic arithmetic expressions
-
if
andelse
control flow -
goto
andgosub
and named labels -
add keywords:
- print,
- if,
- then,
- goto,
- input,
- let,
- set,
- gosub,
- return,
- clear,
- list,
- run,
- end,
-
implement string concatenation via
+
operator -
add some example programs under
examples
folder -
use these for testing. run:
test.bat
ortest.sh
to run the entire examples folder -
improve error reporting, provide line and column where the error occured
-
implement error recovery so the compilation process does not stop at the first error
-
Introduce anonymous label
@@:
- anonymous labels can appear as often as one likes
- one can jump to them by doing:
goto @F
orgoto @B
to go to the next or previous occourence of@@:
respectively - one can optionally specify a number:
@F2
or@B2
to jump that many@@:
labels forward or backward
-
Implement more logical condition, see
evaluateCondition
function in parser -
check the
isPunctuation
function and remove characters that are not needed -
add more datatypes and match mostly c's data types
Type Minimum size (bits) char 8 uchar 8 short 16 ushort 16 int 32 uint 32 long 64 ulong 64 float 32 double 64 -
introduce variable type casting
-
introduce ffi to c to be able to call c functions
- then get rid of intrinsics like
print
andinput
and use c functions instead - start writing a standard library for different kinds of stuff: io, file io, math etc.
- then get rid of intrinsics like
-
get rid of the temporary tree walking interpreter an build a proper VM
- produce an AST instead of directly interpreting the code
- design an instruction set for our VM
- write a code generator that traverses the AST and produces bytecode
- write the actual VM that executes these instructions
-
write a simple vs code extension for syntax highlighting
-
write a language server for linting in vs code