• Stars
    star
    170
  • Rank 223,357 (Top 5 %)
  • Language
    C++
  • License
    Other
  • Created over 12 years ago
  • Updated over 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A functional programming language

Hue

A functional programming language.

I'm just having some fun. This is by no means the futurez of programming, brogramming or anything like that (except it will be renamed to skynet in 2018 and take over the world, but more on that later).

  • Everything is an expression
  • Values are immutable (can't be modified)
  • Fully Unicode (Text type is UTF-32, source files are interpreted as UTF-8 and language symbols can be almost any Unicode character).
  • Fast JIT compiler
  • Close to the metal β€” built on top of LLVM and thus compiles down to highly optimized machine code that's so fast it makes your mama faint
  • Neat codebase with clearly separated components
    • Tokenizer: Reads UTF-8 encoded text and streams Hue language tokens.
    • Parser: Reads Hue language tokens and streams Hue language structures.
    • Transformer: Reads Reads Hue language structures (AST) and transforms the code (i.e. finalizes incomplete function types and infers expression result values).
    • Compiler ("codegen"): Reads Hue language structures (AST) and streams LLVM structures.
    • Runtime library: Provides a few select features like stdio access
  • Features an immutable persistent vector implementation inspired by Clojure that's pretty darn fast (almost constant time complexity.)

Examples

A classic example of a recursive procedure is the function used to calculate the factorial of a natural number. When compiled with optimizations in Hue, this becomes a true tail recursive function.

factorial = func (n Int) if n == 0 1 else n * factorial n - 1
factorial 10  # -> 3628800

The well known mathematical recursive function that computes the Nth Fibonacci number:

fib = func (n Int)
  if n < 2
    n
  else
    (fib n-1) + fib n-2

fib 32  # -> 2178309

Have a look at the tests in the test directory for more examples.

Building

First, you need to grab and build llvm. See deps/llvm/README for details.

Then, it's all just regular make:

$ make

Should give you some stuff in the build subdirectory.

bin/hue

The hue program is a all-in-one tool which is essentially a REPL-able, JIT dynamic compiler.

$ make hue
$ build/bin/hue --help
...
$ build/bin/hue
β†’ 42
42
β†’ 42 * 8
336
β†’ ^C
$ build/bin/hue test/test_lang_data_literals.hue
Hello World
Hello World
$ build/bin/hue -output-ir=- -compile-only test/test_lang_data_literals.hue
# IR code here...
$ build/bin/hue -parse-only test/test_lang_data_literals.hue
# AST repr here...

You can chain hue with llvm tools in order to produce a machine-native program:

$ build/bin/hue -output-ir=- -compile-only test/test_lang_data_literals.hue \
  | llvm-as -o=- | llvm-ld -native -Lbuild/lib -lhuert -o=program -
$ ./program
Hello World
Hello World

If you don't have a local llvm installation, you might need to add the llvm bin directory from deps to your PATH environment variable before running the above.

PATH=$PATH:$(pwd)/deps/llvm/bin/bin

Objectives and plans

  1. Have fun
  2. Take is slowly and go bottom-up, analyzing machine code and drinking coffee
  3. Functions that can capture its environment
  4. Complex types (records/structs/et al) with automatic reference counting
  5. Listen to Black Sabbath and take over the worlds

Seriously, this is just for fun. Don't expect anything from this project.

Language

This section documents the Hue language.

Comments

Comments are not really part of the language (yet), but rather part of the source file format.

Comment = '#' <anything except a line break>* <LF>

A Comment starts with a '#' character and ends with a line break.

Chunk

A unit of execution is called a chunk. Syntactically, a chunk is simply a Block.

Hue handles a chunk as the body of an anonymous function. As such, chunks can define local symbols. Chunks can also be (pre)compiled.

Block

A Block is a list of expressions, which are executed sequentially, where the last expression in the block denotes the result value of the block itself.

Block = Expression+

Expressions can be separated either by their natural boundaries or by line feeds (new-lines), in which case the indentation level is significant. Example:

A
B
  C
  D
E

Here, A, B and E are part of the same block while C and D are part of a different sub-block. The indentation level of a block is defined by the start column of the first expression in the block.

Expression

An Expression is the abstract basic language unit of Hue:

Expression = BinaryOperation
           | '(' Expression ')'
           | Literal
           | Identifier
           | Function
           | Conditional
           | Structure

BinaryOperation

An expression that takes two Expressions and one infix operator:

BinaryOperation = Expression InfixOperator Expression

InfixOperator

Denotes the operation of a BinaryOperation:

InfixOperator = AssignmentOperator | ArithmeticOperator | ComparisonOperator
AssignmentOperator = '='
ArithmeticOperator = '*' | '/' | '+' | '-'
ComparisonOperator = '<' | '>' | '<=' | '>=' | '!=' | '=='

Literal

Literals are embedded data -- an essential part of Hue:

Literal = NumberLiteral
        | BooleanLiteral
        | SequenceLiteral

SequenceLiteral = DataLiteral | TextLiteral

NumberLiteral

A number:

NumberLiteral = IntegerLiteral ['.' IntegerLiteral]? NumberExponent?
IntegerLiteral = DecIntegerLiteral | HexDecimalInteger
NumberExponent = ['E' | 'e'] ['-' | '+']? DecIntegerLiteral
DecIntegerLiteral = 0..9 [0..9 | _]*
HexDecimalInteger = '0x' [0..9 | A..F | a..f | _]+

Internally Hue uses two different kinds of storage types for numbers:

  • Integer numbers are stored as 64 bits where the first bit denotes if the number is negative or positive. The smallest possible value that can be stored is -9_223_372_036_854_775_808 (0x8000000000000000) and the largest possible value is 9_223_372_036_854_775_807 (0x7fffffffffffffff).

  • Fractional numbers are stored as IEEE 754 double-precision floating-point values. There are 18_437_736_874_454_810_624 finite values. Half of them are negative and the other half positive. Beyond these values, precision decreases (exponent >1).

When an operation occurs between an integer and floating point number, the interger number is first promoted to a floating point equivalent. The operation then occurs with floating point operands. If the conversion is destructive (i.e. causing loss of precision), Hue will emit a warning when the encapsulating chunk is compiled.

BooleanLiteral

BooleanLiteral = 'true' | 'false'

Internally represented as a single-bit value. This is the result type of any comparison operation.

SequenceLiteral

A literal sequence of items:

SequenceLiteral = TextLiteral | DataLiteral

TextLiteral

Unicode text:

TextLiteral = '"' [RawCharacterLiteral | EncodedCharacterLiteral]* '"'
RawCharacterLiteral = <Any Unicode character except '"' and '\'>
EncodedCharacterLiteral = '\' ['"' | 't' | 'n' | 'r' | '\' | 'u' CharacterCode]
CharacterCode = [0..9 | A..F | a..f | _]{1,8}

Text is stored as a sequence of 32-bit integers and treated according to the Unicode standard (UTF-32).

Examples:

"Hello World"
""
"ネ \u2192"

DataLiteral

Raw string of bytes:

DataLiteral = "'" [RawByteLiteral | EncodedByteLiteral]* "'"
RawByteLiteral = <any octet except "'" and '\'>
EncodedByteLiteral = '\' ["'" | 't' | 'n' | 'r' | '\' | 'x' ByteCode]
ByteCode = [0..9 | A..F | a..f | _]{1,2}

Examples:

'Hello World'
''
'foo\n\x0bar'

Identifier

A symbolic name that identifies a value:

Identifier = IdentifierCharacter [0..9 | IdentifierCharacter]*
IdentifierCharacter = '_' | A..Z | a..z | <U+80..U+FFFFFFFF>

Examples:

foo
_
bΓΌz

Function

A reusable executable unit:

Function = 'func' FunctionParameters Block
FunctionParameters = '(' Identifier* ')'

Example:

func (a, b) a * b

Conditional

Enables the program to flow into one of two different branches depending on a boolean condition:

Conditional = 'if' Test BranchA 'else' BranchB
Test = Expression
BranchA = Block
BranchB = Block

Example:

if n > 5 100 else 200

Structure

Packages several values together into a unit that can be passed around and referenced.

Structure = 'struct' Block

Only assignment expressions are allowed to exist on the root level of the block. An assignment on the root level defines the symbol in the struct (rather than locally in the current scope).

Example:

user = struct
  uid = 1
  about = struct
    name = "Rasmus Andersson"
    age = 29

user:uid        # -> 1
user:about:age  # -> 29

License

See LICENSE for the standard MIT license.

More Repositories

1

inter

The Inter font family
Python
16,727
star
2

peertalk

iOS and Mac Cocoa library for communicating over USB
Objective-C
3,424
star
3

fb-mac-messenger

⚑️ Mac app wrapping Facebook's Messenger for desktop
Objective-C
2,856
star
4

kod

Programmers' editor for OS X [DEAD PROJECT]
Objective-C
2,296
star
5

node-imagemagick

Imagemagick module for NodeJS β€” NEW MAINTAINER: @yourdeveloper
JavaScript
1,807
star
6

markdown-wasm

Very fast Markdown parser and HTML generator implemented in WebAssembly, based on md4c
C
1,446
star
7

gotalk

Async peer communication protocol & library
Go
1,193
star
8

estrella

Lightweight and versatile build tool based on the esbuild compiler
TypeScript
1,098
star
9

raster

Raster β€” simple CSS grid system
CSS
806
star
10

js-lru

A fast, simple & universal Least Recently Used (LRU) map for JavaScript
JavaScript
774
star
11

sol

A sunny little virtual machine
C
516
star
12

scrup

Take a screenshot (in OS X) β€” paste the URL somewhere a second later
Objective-C
405
star
13

chromium-tabs

[historical] Chromium tabs for cocoa applications (project no longer maintained)
Objective-C
388
star
14

wasm-util

WebAssembly utilities
TypeScript
353
star
15

figplug

Figma plugin builder
TypeScript
336
star
16

cocui

Cocoa meets WebKit for more rapid UI development
Objective-C
329
star
17

ec2-webapp

A template I use to quickly set up Node.js-backed web apps on Amazon EC2
324
star
18

llvmbox

Self contained, fully static llvm tools & libs
C
317
star
19

move

A simple, functional-biased, prototypal and powerful programming language that runs on any ES3 (or better) JavaScript platform, aimed toward people new to programming
JavaScript
302
star
20

immutable-cpp

Persistent immutable data structures for C++
C++
281
star
21

rsm

Virtual computer
C
267
star
22

compis

Contemporary systems programming language in the spirit of C
C
196
star
23

uilayer

CALayer-style API for building rich, high-performance UI graphics in WebKit
JavaScript
192
star
24

sublime-theme

My Sublime Text theme
Python
187
star
25

scripter

The Scripter Figma plugin
JavaScript
178
star
26

gitblog

Git-based blog/cms for PHP, meant as a replacement for Wordpress
PHP
164
star
27

co

A programming language in early development
TypeScript
147
star
28

graphviz

Graphviz web app
JavaScript
118
star
29

LazyDispatch

Thin API and concept on top of libdispatch (aka Grand Central Dispatch) for Cocoa Objective-C code.
Objective-C
102
star
30

afcgi

Asynchronous/multiplexing FastCGI for nginx (incl. ref server implementation)
C
101
star
31

rsms-utils

Collection of CLI programs to help with everyday computer life
Shell
99
star
32

colang

Programming language and compiler β€”WORK IN PROGRESSβ€”
C
71
star
33

xsys

A well-defined system API for abstracting the OS platform
C
68
star
34

figma-plugins

Collection of Figma plugins
TypeScript
67
star
35

mkweb

simple static website generator
JavaScript
63
star
36

fontkit

JS & WASM library for working with fonts
C
62
star
37

js-object-merge

3-way JavaScript Object merging -- Object.merge(v1, v1a, v1b) -> v2
JavaScript
54
star
38

tc

Tokyo Cabinet Python bindings β€” In need of a new maintainer
C
54
star
39

smolmsg

Simple messages
Go
54
star
40

js-wasmc

Simplifies building of WebAssembly modules in C/C++ and JS
JavaScript
53
star
41

sigi-pixel-font

Sigi pixel fonts [archived]
52
star
42

WebView-OSX-Screensaver

WebKit web view as a screensaver on OS X
Objective-C
52
star
43

Go.tmbundle

TextMate bundle for the Go programming language
51
star
44

oui

Web-app client-server framework developed as part of dropular.net
JavaScript
49
star
45

wlang

Programming language in development
C
47
star
46

smisk

High performance web service framework, written in C but controlled by Python. Used by Spotify infra 2009–2015.
Python
45
star
47

memex

Software for archiving my digital stuff like tweets
Go
45
star
48

workenv

My personal work environment
Emacs Lisp
44
star
49

ckit

The little C kit
C
44
star
50

dropub

DroPub β€” drop and publish. Simple OS X MenuItem managing secure transfer of files in the background
Objective-C
42
star
51

serve-http

Simple, safe single-file local web server
JavaScript
42
star
52

go-uuid

Binary sortable universally unique identifier
Go
38
star
53

ghp

Go Hypertext Preprocessor
Go
38
star
54

TypoFig

Mac app for assisting type design in Figma
Objective-C
38
star
55

opencv-face-track-basics

Basic code for tracking faces and eyes using OpenCV
C++
37
star
56

qemu-macos-x86-arm64

Run arm64 Linux Alpine virtualized on macOS x86_64 with QEMU
Shell
35
star
57

tspkg

Create small, fast and easily-distributable packages from TypeScript projects
JavaScript
34
star
58

go-immutable

Immutable data structures for Go
Go
34
star
59

webkit-editor

Experimental text editor which runs in the browser
JavaScript
32
star
60

html5-video

Video player in HTML5
JavaScript
30
star
61

hovden-stitch

A typeface weekend project from 2002 with a classic "stitching"/"embroidery" look
30
star
62

jo

Go-style JavaScript ES6 compiler and packager, based on Babel
JavaScript
30
star
63

libcss-osx

Building libcss as Mac OS X universal binary. Developed as part of Kod (rsms/kod)
Objective-C
29
star
64

tumblr-theme-hunch

The theme used on my blog
28
star
65

dawn-lib

Builds Dawn on Linux and macOS as one single easier-to-use library
Shell
28
star
66

browser-require

CommonJS module require() for web browsers
JavaScript
25
star
67

jsont

A minimal and portable JSON tokenizer for building highly effective and strict parsers (in C and C++)
C
25
star
68

prog-lang-tutorial

JavaScript
25
star
69

node-fsdocs

Simple, ACID and versioned file-system based document database
JavaScript
25
star
70

js-fragment

Client-side templating for modern thinkers
JavaScript
24
star
71

node-couchdb-min

Simplistic CouchDB client with a minimal level of abstraction and connection pooling.
JavaScript
24
star
72

fontctrl

Font manager, keeping font files up to date with a distributed repository model
Go
23
star
73

web-clipboard-promise

Demonstrates lazily-evaluated clipboard data on the Web platform
JavaScript
22
star
74

bezier-tangent

BΓ©zier curve toy
JavaScript
22
star
75

twitter-icon

Alternative icon for Twitter.app
21
star
76

dropular-2010

Redacted snapshot of dropular.net, May 2010
JavaScript
21
star
77

dawn-wire-example

[WIP] Demo of a minimal but functional Dawn-based WebGPU client and server
C++
21
star
78

phpab

Abstract Base – universal PHP runtime library
PHP
18
star
79

NodeCocoa

Embed node.js in Cocoa or write whole Cocoa apps in node.js
Objective-C
17
star
80

ortho-remote

Some code for playing with the Teenage Engineering Ortho Remote
Objective-C
16
star
81

ml-kern

Kerning done by machines (a project to learn more about ML)
JavaScript
16
star
82

asl-logging

Convenience functions and example code for using ASL (Apple System Log facility)
C
14
star
83

js-miniglob

Minimal glob JavaScript implementation ported from Go's path/filepath
JavaScript
13
star
84

hunch-cocoa

An assortment of Cocoa β€” mixed extensions and additions to Cocoa
Objective-C
13
star
85

wasm-loader

WebAssembly module loader with import resolution
TypeScript
12
star
86

cgui

super duper simple gui for C, wrapping imgui and stb
C
12
star
87

cmdr

Helps writing command-line programs with subcommands in Go
Go
12
star
88

spotifycocoa

Cocoa framework of libspotify
Objective-C
12
star
89

macfusion

Fork of http://svn.macfusionapp.org/macfusion2/trunk/ β€” With mainly UI changes like menu item icon and OS-standard volume icons) β€” Download latest release build: http://cloud.github.com/downloads/rsms/Macfusion/Macfusion.zip
Objective-C
12
star
90

hunch-upload

Multiple concurrent files uploads with progress in pure HTML
JavaScript
11
star
91

functional.js

Work in a functional style with JavaScript and TypeScript
JavaScript
11
star
92

coxlang

Programming language w/ subproject that implements the Go scheduler in C++
C++
11
star
93

lolcatos

The lolcat operating system
Assembly
11
star
94

cometps

Simple comet pub/sub
C
9
star
95

node-imgdb

Image fingerprinting
C++
8
star
96

ssl-client-auth-demo

Demonstrates "client-authenticated TLS handshake"
Shell
8
star
97

connect_facebook

Facebook session support for Connect
8
star
98

mode

Node module manager and repository
JavaScript
8
star
99

flup

Drag-and-drop to quickly put images on Flickr
Objective-C
8
star
100

ipvec

Educational persistent vector implementation in C
C
8
star