A cool programming language :)
Go to file
2022-08-25 20:02:23 +02:00
cmake updates to the sapphire.sh script 2022-07-19 15:11:24 +02:00
core Precompiled Header :) 2022-06-16 15:56:10 +02:00
docs updates 2022-07-10 18:53:05 +02:00
editors/vscode/sapphirelang Initial commit (added Sapphire to source control) 2022-03-11 17:00:09 +01:00
examples Update examples 2022-08-25 10:02:45 +02:00
external updates 2022-07-02 12:03:06 +02:00
src Change paren_str to use format_string, removing a warning 2022-08-25 20:02:23 +02:00
tests WE CAN MAKE FUNCTIONS NOW!!!!!!!!!!!!!!!!!!!!!!!!! 2022-08-25 18:49:43 +02:00
tools Shebangs!! 2022-08-03 14:55:04 +00:00
.clang-format used clang-format :) 2022-06-14 16:29:51 +02:00
.gitignore Update .gitignore 2022-08-24 13:45:33 +02:00
.gitmodules updates 2022-07-02 12:02:58 +02:00
CMakeLists.txt You can now forward declare functions! 2022-08-25 19:15:43 +02:00
Doxyfile changes :) 2022-07-02 11:49:51 +02:00
README.md Update README.md 2022-07-19 15:33:22 +02:00
sapphire.cpp disclaimer :) 2022-06-08 20:16:14 +02:00
sapphire.sh Shebangs!! 2022-08-03 14:55:04 +00:00
test.py WE CAN MAKE FUNCTIONS NOW!!!!!!!!!!!!!!!!!!!!!!!!! 2022-08-25 18:49:43 +02:00

Sapphire

A modern, fast and reliable programming language. (WIP)

WARNING: Most features in this README (especially the About section) are planned for the future and not yet implemented.

About

Sapphire is a relatively high-level programming language, yet low-level when it needs to be. The language supports low-level memory manipulation using pointers, but pointer arithmetic is only allowed in unsafe contexts, for greater memory safety. Dynamic memory allocation is also a thing, though it is recommended not to use it directly, but instead make great use of smart pointers.

Sapphire is a compiled programming language, with static typing, although type inference is also supported. It also has a high-level standard library, which supports console/file I/O, operating system functions, advanced math operations, string manipulation, and many more.

Basic usage

"Hello world" in Sapphire:

const io from @'core/io';

let @main in {
	io.outln('Hello, World!');
}

or alternatively:

const { outln } from @'core/io';

let @main in {
	outln('Hello, World!');
}

Examples

FizzBuzz:

const io from @'core/io';
const { toString } from @'core/type_utils';

let @fizzBuzz(i32 i) in {
	String result = '';
	if(i % 3 == 0)
	{
		if(i % 5 == 0)
		{
			result = 'FizzBuzz';
		} else {
			result = 'Fizz';
		}
	} else {
		if(i % 5 == 0)
		{
			result = 'Buzz';
		} else {
			result = toString(i);
		}
	}
	io.outln(result);
}

let @main in {
	for(i32 i = 1; i <= 100; i++)
	{
		fizzBuzz(i);
	}
}

Quine:

const io from @'core/io';
String fmt = 'const io from @%ccore/io%c;%cString fmt = %c%s%c;%clet @main in {%c%cio.outf(fmt,39,39,10,39,fmt,39,10,10,9,10,10);%c}%c';
let @main in {
	io.outf(fmt,39,39,10,39,fmt,39,10,10,9,10,10);
}

Documentation

More documentation is available at Documentation.

Building

First, install the required packages. (ninja is optional, you can use any build system you want)

Debian/Ubuntu: # apt install zlib1g-dev build-essential cmake ninja-build llvm-dev

CentOS/Fedora/RHEL: # dnf install gcc gcc-c++ zlib-devel libffi-devel cmake ninja-build llvm-devel

Arch: # pacman -S gcc cmake ninja llvm-libs llvm

For Ninja users: On platforms that install ninja to /usr/bin/ninja instead of /usr/bin/ninja-build, CMake may fail. In that case, symlink ninja-build to ninja (ln -s /usr/bin/ninja /usr/bin/ninja-build).

First-time setup:

./sapphire.sh generate <build system, such as Ninja or Unix Makefiles> <build type: Debug or Release>

To change build type/build system, just run ./sapphire.sh clean followed by the generate command above.

Building:

./sapphire.sh build

Installing (probably will have to be run as administrator/root):

./sapphire.sh install <destination, default depends on platform, on linux it's often /usr/local>

This will install the compiler at <destination>/bin/sapphirec.

Running

The compiler is built at build/sapphirec.

A few example commands:

$ build/sapphirec --version # prints the compiler version
$ build/sapphirec --help # shows usage
$ build/sapphirec main.sp # compiles a file
$ build/sapphirec main.sp -o main # compiles a file with output filename
$ build/sapphirec main.sp -o main --msystem darwin # compiles a file for macOS