benanders / Hydrogen

A toy tracing JIT compiled programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Hydrogen Programming Language

Hydrogen is a toy programming language I'm writing mostly for my own edification. It's an interpreted, dynamically typed language written in C. It's intended to be used as a standalone language, and not embedded within other programs.

The core is written in C with no dependencies beyond the C standard library. Most tests are written in C++ using the Google Test framework. The runtime tests are written using a custom Python script.

Example

Here's some Hydrogen code:

import "io"

struct Node {
	name, child
}

fn (Node) new(name, child) {
	self.name = name
	self.child = nil
}

fn (Node) print() {
	io.print("[" .. self.name)
	if self.child {
		io.print(", ")
		self.child.print()
	}
	io.print("]")
}

let root = new Node("1", new Node("2", new Node("3", nil)))
root.print() // Prints [1, [2, [3]]]

Building

Here's a guide on how to build Hydrogen from its source. This guide uses CMake and Unix Makefiles.

Clone the repository, create a build folder, generate the Makefile, and build the source:

$ git clone https://github.com/benanders/Hydrogen
$ cd Hydrogen
$ mkdir build
$ cd build
$ cmake ..
$ make

You can then use the Hydrogen command line interface by:

$ ./hydrogen

You can run the tests by:

$ make test

License

Hydrogen is licensed under the MIT license. This means you can do basically whatever you want with the code. See the LICENSE file for more details.

About

A toy tracing JIT compiled programming language

License:MIT License


Languages

Language:C 77.6%Language:C++ 21.3%Language:CMake 1.1%