Link Search Menu Expand Document

The Blade Language Documentation

Welcome! This is the official documentation for Blade 0.0.71.

This documentation is a work in progress!

Star Follow @blade-lang


def sum(numbers) {
    var result = 0

    for num in numbers {
        result += num
    }

    echo 'the sum is ${result}'
}

sum([1, 2, 3, 4]) # this prints "the sum is 10"

A simple Blade program to sum a list of numbers by @BenStigsen.



What is Blade?


Blade is a simple, fast, clean and dynamic language that allows you to develop complex applications quickly. Blade emphasises algorithm over syntax and for this reason, it has a very small but powerful syntax set with a very natural feel.

Blade is NOT named after any weapon, but rather after the iconic Marvel Comics vampire slayer — Blade.

Download


Windows   Linux   MacOS  

  • This downloads only support x86-64 plaforms.
  • Apple M1 devices should install Rosetta 2 to run the downloaded application or install from source.
  • For other platforms, you’ll need to install from source (see below for details).

Installing Blade from source


Blade currently supports and have been tested on the Linux, OSX and Windows operating system. To install Blade, you need to have CMake and a C/C++ compiler toolchain/IDE installed on your computer.

For Linux and macOS

If you are on a Unix, OSX or Linux machine, you can use the automated install tool by running the command below in your favorite terminal.

$ bash <(curl -s https://raw.githubusercontent.com/blade-lang/blade/main/scripts/install.sh)

For Windows

Starting from version 0.0.7, Blade’s officially supported compilers for the Windows environment is now the TDM-GCC and WinLibs compiler. The decision to change the official compiler from Visual Studio and MSYS2 to TDM-GCC and WinLibs is to allow a minial configuration effort while installing Blade as well as to allow us to develop Blade faster as trying to be cross-compatible with Visual Studio has proven to slow down the growth of the language and the ecosystem and setting up MSYS2 environment to compile Blade is more work than required for either TDM-GCC or WinLibs.

This also allows us to build valid Blade C extensions on Windows with less hassle. Check out the blade-ext-demo or any of the extension in the ext directory for more info on how to write a valid C extension for Blade.

Important Notice

  1. Only TDM-GCC, WinLibs, MinGW64 and MSVC compiler have been tested and are currently guaranted to build Blade. While other compilers may build it, they are not currently recommended.
  2. For MSVC, a minimum of Windows SDK version 10.0.18362 is recommended. This will be readily available from Visual studio 2017 on Windows 10 and above.

To install Blade with TDM-GCC or WinLibs, install TDM-GCC or WinLibs via the given links. Add TDM-GCC or WinLibs bin directory to your environment path. TDM-GCC also allows you to add to path during its installation. After this, run the following commands from the root of your Blade clone:

git clone https://github.com/blade-lang/blade.git
cd blade
cmake -B . -DCMAKE_MAKE_PROGRAM=mingw32-make -G "Unix Makefiles"
cmake --build .

This will build and install Blade into a new directory called blade within the current directory. You can move this directory to any location on your computer.

To make Blade (blade) available from your terminal, you’ll need to add the generated blade directory to your computer paths.

See this, this or this Stack overflow questions for information on adding Blade installation directory to path.

For all other platforms


For environments without an autoinstall and the adventurous ones, to install Blade, so far as you can successfully setup git, cmake and one of GCC or Clang based compilers, you can use the following commands to install Blade:

$ git clone https://github.com/blade-lang/blade.git
$ cd blade
$ cmake -B .
$ cmake --build .

See BUILDING for more details.

Running the Blade REPL


Blade comes with support for REPL (Read-Evaluate-Print-Loop). The REPL mode is triggered when calling the Blade (blade) executable without any file.

Something like this:

$ blade
Blade 0.0.71 (running on BladeVM 0.0.6), REPL/Interactive mode = ON
Clang 13.0.0, (Build time = Feb  8 2022, 02:47:36)
Type ".exit" to quit or ".credits" for more information
%> echo 'Hello, World'
'Hello, World'
%> 

To exit the loop, simply type .exit and press enter or press the Ctrl+D combination on your keyboard.

We’ll be using this mode a lot in this documentation.

Running a Blade script


The blade command can take a file as parameter and execute the file as simply as follows:

$ blade somefilename.b
...

Did you notice how the filename ends with a .b? Blade program files should make use of the .b extension. This is the recommended convention.

It is important to remember that:

While Blade may not enforce the .b extension for all scripts, it is a requirement for a script that is meant to be imported as a module into another program.

Editor Support


For editor support, we recommend Visual Studio Code along with the blade-vscode Extension. Support for more editors are planned and on the way.

Blade CLI options


Blade CLI comes with lots of options to control how Blade runs and how it runs your scripts.

Type:

$ blade -h

to show the CLI options. It should look something like this.

Usage: blade [-[h | d | j | v | g]] [filename]
   -h    Show this help message.
   -v    Show version string.
   -b    Buffer terminal outputs.
         [This will cause the output to be buffered with 1kb]
   -d    Show generated bytecode.
   -j    Show stack objects during execution.
   -g    Sets the minimum heap size in kilobytes before the GC
         can start. [Default = 1024 (1mb)]

This help message will automatically be triggered when you try to use an unsupported switch.

For example, to get the version of Blade installed:

$ blade -v
Blade 0.0.71 (running on BladeVM 0.0.6)

How to contribute


Along with Blade’s goal to be simplicity, flexibility and expressiveness is a strong desire to make the community around it as friendly and welcoming as possible. Therefore, all forms of contributions from pull requests, suggestions, typo fixes in documentation, feature request, bug reports and any contribution at all is greatly welcomed and appreciated.

WE NEED HELP! From review of this documentation, to suggestions on the core features of Blade, testing of Blade features, writing more comprehensive tests, bug detection, code fixes and more. PLEASE CONTRIBUTE!

Contributing code, fixes and features


The standard. The general workflow is as follows.

  1. Find/file an issue on the Issues tab.
  2. Fork the repo and make your changes.
  3. Push your changes to a branch in your forked repo. For coding guidelines, see the project README file.
  4. Submit a pull request to Blade from your forked repo.

You can also just mail your issues to Ore Richard Muyiwa directly.

Sponsors


  • Jetbrains

Back to top

Copyright © 2021 Ore Richard Muyiwa. Distributed under the MIT license.