• Stars
    star
    242
  • Rank 161,345 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

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

Repository Details

a python-like language with hindley-milner-like type system, which is compiled to c

airtight

an experimental frankenstein

what if guido was a type theory fan? what if we went to an alternate dimension, where python starts like a typed functional language, instead of a class-based oop one?

a python-like language with hindley-milner-like type system, which is compiled to c.

With the help of

code by Robert Smallshire (see below)

Language

We use the new syntax for annotations in Python3

You can add optional annotations to args and returns:

@template(y, z)
def f_map(f: y >> z, s: [y]) -> [z]:
    out = []
    for i in s:
        out = append(out, f(i))
    return out

def nope(a: Integer) -> Integer:
    return a + 4

print(f_map(nope, [2, 4]))
def sum(n: Integer) -> Integer:
    '''sum of the numbers from 0 to n inclusively'''
    result = 0
    for i in range(0, n + 1):
        result += i
    return result

print(sum(2000))

owever we just reuse Python3's syntax. We try to preserve the spirit and semantics in many cases, but look at it like a different language.

you can install it and use it like that

git clone https://github.com/alehander42/airtight.git
cd airtight
bin/airtight # and

Implementation

  • airtight code -> python3 ast (using python3 ast module)
  • python3 ast -> hindley milner ast (easier for type inference, taken from Robert Smallshire, with some more Airtight-specific stuff
  • hindley milner ast -> hindley milner typed ast (running type inference and annotating the tree with types)
  • hindley milner typed ast -> lower level python-like typed ast (converting back to python/c like multiarg functions and assignment nodes)
  • lower level python-like typed ast -> c code (generate c code recursively for each node and based on the core library)

The core library contains some predefined functions, accessible from airtight and some template files which implement generic airtight functions in c (for example core/list.c has placeholders like %{list_type} and %{elem_type} and different copies of the functions are generated for each %{elem_type} in a program})

options for the compiler:

bin/airtight filename.py # compiles it to filename.py.c
bin/airtight filename.py --to-binary # compiles it to filename.py.c and then invokes
                                     # c99 and generates a binary filename
bin/airtight filename.py --hm-ast    # show the hindley milner ast
bin/airtight filename.py --typed-hm-ast # show the typed hindley milner ast
bin/airtight filename.py --typed-c-ast # show the lower level typed ast

the resulting c code is quite amusing:

a_print_AList_AString_AString(
  a_f_map_intREFAString_AList_int_AList_AString(
    &a_wtf_int_AString,
    AList_intOf(2, 2, 4)));

yeah, you need a shower now, doncha

syntactic sugar : [Integer] for list types, y >> z for function types, Integer | Float for union types. we have some extensions to the hindley milner inference algorithm, so the current type system is probably unsound and weird, but you have haskell/idris for that

airtight is just a little kid now and its quite buggy and a proof of concept however if you're interested, you have some ideas/questions, or you just wanna hack on it, feel free to use the issues tab here

Alexander Ivanov

More Repositories

1

hivemind

a multi-syntax language
Ruby
134
star
2

gara

Nim
100
star
3

matchete

A DSL for method overloading in Ruby based on pattern matching
Ruby
55
star
4

breeze

a macro dsl for nim
Nim
47
star
5

hatlog

custom type systems for python in prolog: http://alehander42.me/prolog_type_systems
Python
24
star
6

nim-quicktest

A quickcheck library for Nim
Nim
19
star
7

comprehension

Nim
18
star
8

wire

encode and decode bittorrent peer wire protocol messages with elixir
Elixir
17
star
9

sith

a macro preprocessor for ruby with ruby-like template notation
Ruby
16
star
10

tracker_request

an elixir library for dealing with bittorrent tracker requests and responses
Elixir
14
star
11

poly

Nim
10
star
12

yolandi

A simple torrent client in elixir
Elixir
5
star
13

roswell

a compiler from a python-like language to x86_64 assembly / C
Nim
5
star
14

bencoder

a library to handle bencode in elixir
Elixir
4
star
15

muu

a decorator providing multiline lambdas for Python3
Python
4
star
16

nim-linter

Nim
3
star
17

py-matchete

Python
2
star
18

melt

A language that compiles to Go with more expressive error handling, sum types and generics [ABANDONED]
Go
2
star
19

bach

a lisp dialect that compiles to cpython bytecode
Python
2
star
20

helpful_parser

Nim
2
star
21

learn-compiler

Nim
2
star
22

lodka

Nim
2
star
23

http

Nim
2
star
24

dynamo

Translate mypy annotated python files to python2-compatible
Python
2
star
25

logvm

a concatenative language implemented as a prolog dsl
Prolog
2
star
26

q

proof of a disgusting concept, functions which return results that can adapt to the call site context
Python
2
star
27

ast_diff

a tool for visualizing javascript syntax diffs
JavaScript
1
star
28

dotfiles

Shell
1
star
29

hemingway

dry wine
Python
1
star
30

lang

a hobby language: memory
Nim
1
star
31

lang-sheep

Rust
1
star
32

gagrakacka

a tiny smalltalk
Python
1
star
33

woosh-python

an experimental shell
Python
1
star
34

experiment

a playground for experiments with genetic algorithms, neural networks, pattern recognition, heuristic algorithms etc
1
star
35

delirium

JavaScript
1
star
36

placebo

placebo, a toy web rendering engine in ruby
Ruby
1
star
37

reading

1
star