Skip to content

Lisprez/Hazel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Hazel Language

Hazel | Documentation | Contributing | Compiler design

Twitter

Key Features of Hazel

  • Simplicity: the language can be learned in less than an hour
  • Fast compilation: ≈80k loc/s with a Clang backend, ≈1 million loc/s with x64 and tcc backends (Intel i5-7500, SSD, no optimization)
  • Easy to develop: Hazel compiles itself in less than a second
  • Performance: as fast as C (Hazel's main backend compiles to human-readable C)
  • Safety: no null, no globals, no undefined behavior, immutability by default
  • C to Hazel translation
  • Hot code reloading
  • Innovative memory management
  • Built-in Vision library
  • Easy cross compilation
  • REPL
  • Built-in ORM
  • C backend

Interactive Shell

$ hazel
    Hazel Language 0.0.1 (Apr 8 2021 02:39:23)
    GCC version: 9.3.0 on linux
    All engines are a go!

hazel> print("Hello World")
Hello World
hazel> exit
    Goodbye! Set the world on fire!

Using a script hello.hzl:

print("Hello World")

Running on the terminal is as easy as:

$ hazel hello.hzl
Hello World

Compiler

$ hazel compile hello.hzl -o hello
Starting the compiler engine...
Compiling Hazel code into build/hello.c
Compiling the C code into machine code...
Cleaning up the temporary files...

Finished compiling.

Binary is ready here: build/hello
$ build/hello
hello world

Run hazel --help to see more options.

Uninstall Hazel

You can uninstall the hazel binary and its C headers with:

make uninstall

Stability guarantee and future changes

Despite being at an early development stage, the Hazel language is relatively stable and has backwards compatibility guarantee, meaning that the code you write today is guaranteed to work a month, a year, or five years from now.

There still may be minor syntax changes before the 1.0 release, but they will be handled automatically.

The Hazel core APIs (the standard modules) will still have minor changes until they are stabilized in end-2021. Of course the APIs will grow after that, but without breaking existing code.

Our guarantee: Hazel is always going to be lightweight, portable and extremely fast.

Installing Hazel from source

Linux, macOS, Windows, *BSD, Solaris, WSL, Android, Raspbian

git clone https://github.com/hazel-lang/Hazel
cd Hazel
make

That's it! Now you have a Hazel executable at [path to Hazel repo]/Hazel. [path to Hazel repo] can be anywhere.

(On Windows make means running make.bat, so make sure you use cmd.exe)

Now you can try ./hazel run examples/hello_world.hzl (hazel.exe on Windows).

Hazel is constantly being updated. To update Hazel, simply run:

hazel up

C compiler

It's recommended to use Clang, GCC, or Visual Studio. If you are in development, you most likely already have one of those installed.

However, if none is found when running make on Linux or Windows, TCC is downloaded as the default C backend. It's very lightweight (several MB) so this shouldn't take too long.

Symlinking

NB: it is highly recommended, that you put Hazel on your PATH. That saves you the effort to type in the full path to your Hazel executable every time. Hazel provides a convenience hazel symlink command to do that more easily.

On Unix systems, it creates a /usr/local/bin/Hazel symlink to your executable. To do that, run:

sudo ./hazel symlink

On Windows, start a new shell with administrative privileges, for example by Windows Key, then type cmd.exe, right click on its menu entry, and choose Run as administrator. In the new administrative shell, cd to the path, where you have compiled hazel.exe, then type:

.\hazel.exe symlink

That will make Hazel available everywhere, by adding it to your PATH. You might need to restart your shell/editor after that, so that it can pick the new PATH variable.

NB: there is no need to run hazel symlink more than once - Hazel will continue to be available, even after hazel up, restarts and so on.

You only need to run it again, if you decide to move the Hazel repo folder somewhere else.

Testing and running the examples

Make sure Hazel can compile itself:

hazel self
$ hazel
    Hazel Language 0.0.1 (Apr 8 2021 02:39:23)
    GCC version: 9.3.0 on linux
    All engines are a go!

hazel> print('Hello world')
Hello world
cd examples
hazel hello_world.hzl && ./hello_world    # or simply
hazel  hello_world.hzl                 # this builds the program and runs it right away

Hazel sync

Hazel's sync module and channel implementation uses libatomic.

It is most likely already installed on your system, but if not, you can install it, by doing the following:

MacOS: already installed

Debian/Ubuntu:
sudo apt install libatomic1

Fedora/CentOS/RH:
sudo dnf install libatomic-static

Troubleshooting

Please see the Troubleshooting section on our wiki page

About

Fast, Expressive and High-Performance Language of the Future.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 88.3%
  • C++ 6.2%
  • Python 3.6%
  • Makefile 1.9%