Skip to content

Commit 2dab245

Browse files
committed
Merge branch 'python-antlr'
2 parents dce9a24 + 0756c87 commit 2dab245

File tree

382 files changed

+9270
-10746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+9270
-10746
lines changed

.gitignore

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
dist
2-
cabal-dev
31
pyxell
42
*.exe
53
*.o
6-
*.hi
7-
*.chi
8-
*.chs.h
9-
*.dyn_o
10-
*.dyn_hi
11-
.hpc
12-
.hsenv
13-
.cabal-sandbox/
14-
cabal.sandbox.config
15-
*.prof
16-
*.aux
17-
*.hp
18-
.stack-work/
4+
*.jar
195
.idea/
206
*.iml
21-
*.bak
22-
tmp.*
237
_*
8+
*.tmp
249
*.bc
2510
*.ll

Makefile

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
all: grammar bin libs
1+
all: parser
22

3-
grammar:
4-
+$(MAKE) grammar -C src
5-
bin:
6-
+$(MAKE) bin -C src
7-
libs:
8-
./pyxell -l
3+
parser:
4+
"$(MAKE)" parser -C src
95

106
clean:
11-
+$(MAKE) clean -C src
12-
-rm -f pyxell pyxell.exe
7+
"$(MAKE)" clean -C src

README.md

+50-52
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
Pyxell
22
======
33

4-
### Clear and easy to use multi-paradigm compiled programming language with static typing. ###
4+
### Clear and easy-to-use multi-paradigm compiled programming language with static typing. ###
55

6-
*Note: due to limitations of BNFC and Haskell, the project will be rewritten to ANTLR and Python.*
6+
*Note: Up to version 0.6.0 the project had been developed in Haskell with BNFC. Now it has been rewritten to Python and ANTLR.*
77

88

99
Motivation
1010
----------
1111

12-
Do you like Python for its expressive and intuitive syntax, but miss static type checking and runtime speed of compiled languages?
12+
The project aims to combine the best features of different programming languages,
13+
pack them into a clean syntax with significant indentation,
14+
and provide the execution speed of native machine code.
1315

14-
Do you enjoy functional programming in Haskell, yet find it overly complicated and not exactly suitable for everyday use?
15-
16-
Do you keep looking back at C++ for its speed and power, though can't stand its verbosity and ugliness in comparison to modern languages?
17-
18-
That's why I started creating Pyxell -- to bring together the best features of different programming languages.
16+
It draws mainly from Python, Haskell, C#, and C++,
17+
and tries to avoid common design flaws that have been nicely described
18+
[in this blog post](https://eev.ee/blog/2016/12/01/lets-stop-copying-c/).
1919

2020

2121
Examples
@@ -40,12 +40,12 @@ for x, i in a, 0... do
4040
```
4141

4242
```
43-
func fold<Any T>(T,T->T f, T a, [T] t) T def
44-
for x in t do
45-
a = f(a, x)
46-
return a
43+
func reduce<A,B>([A] a, A->B->B f, B r) B def
44+
for x in a do
45+
r = f(x, r)
46+
return r
4747
48-
print fold(_*_, 1, [2, 3, 4]) -- factorial
48+
print reduce(_*_, 1, [2, 3, 4]) -- 24
4949
```
5050

5151
```
@@ -78,10 +78,13 @@ Features
7878
* First-class functions (+)
7979
* Default and named arguments (+)
8080
* Lambda expressions (+)
81-
* Generic functions (+/-)
81+
* Generic functions (+)
8282
* Module system (+/-)
8383
* Classes with safe references (+)
8484
* Separate nullable types (+)
85+
86+
To do:
87+
8588
* Generic types
8689
* Containers library
8790
* Operator overloading
@@ -97,77 +100,72 @@ Features
97100
Details
98101
-------
99102

100-
* Type checker and LLVM compiler written in Haskell with BNFC.
103+
* LLVM IR generator and type checker written in Python with ANTLR and llvmlite.
101104
* Compilation to machine code (and optimizations) with Clang.
102105

103106

104107
Requirements
105108
------------
106109

107-
These are the software versions that I use. Pyxell may work with others versions, but it is not guaranteed.
110+
* Python 3.8 with packages from `requirements.txt`.
108111

109-
* GHC 8.6.5 with `regex-compat` package
110-
* Clang 6.0.0 with C++ standard library
111-
* BNFC 2.8.2 with `176-source-position` branch (to recompile grammar)
112-
* Python 3.7.4 with packages from `requirements.txt` installed (to run tests)
112+
Sometimes installation of `llvmlite` [fails](https://github.com/numba/llvmlite/issues/527)).
113+
If such a problem occurs, try using `easy_install` instead of `pip install`.
113114

114-
For BNFC to store source code position, install it from source:
115+
* Clang 6 with C++ standard library.
115116

116-
```
117-
git clone https://github.com/BNFC/bnfc.git
118-
cd bnfc/source
119-
git checkout 27079ebf057cce51e33afa619036cbaf6fb78398
120-
git cherry-pick 90e28a4cbecd8cfd4a154f2009d9c5dd4a2dbc78
121-
cabal install
122-
```
123-
124-
To compile and link a Pyxell program correctly, a C++ standard library is required for Clang.
125-
This shouldn't be a problem on Linux, but on Windows this may not work out of the box.
117+
The library shouldn't be a problem on Linux, but on Windows this may not work out of the box.
126118
In some cases Windows SDK installation may be required
127119
or it may be necessary to run `pyxell` with `-target x86_64-pc-windows-gnu`
128120
(run `test.py` with `-t` argument to use this).
129121

122+
* ANTLR 4.7.2 (to build the parser).
123+
124+
Put `antlr-4.7.2-complete.jar` file into `src` folder.
125+
130126

131127
Usage
132128
-----
133129

134130
```
135-
make bin libs
136-
./pyxell code.px
131+
./pyxell.sh program.px
137132
```
138133

139-
If the program is correct, `code.ll` file and an executable should be created in the same folder.
134+
If the program is correct, `program.ll` file and an executable should be created in the same folder.
140135
If not, errors will be displayed, pointing to the erroneous code location.
141136

142-
Run `make grammar` to run BNFC after changing the grammar (`src/Pyxell.cf`).
143-
Run `make libs` to recompile only runtime libraries (`lib/`).
137+
Run `make` after changing the grammar (`src/Pyxell.g4`) to rebuild the parser with ANTLR.
144138

145139

146140
Tests
147141
-----
148142

143+
```
144+
./test.py -v
145+
```
146+
149147
Tests are divided into good (supposed to compile and run properly) and bad (should throw compilation errors).
150148

151-
There is a Python script `test.py`.
152-
You can pass a path pattern to run only selected tests (e.g. `python test.py good`).
149+
The script is multi-threaded.
150+
Total execution time may vary from something like 10 seconds to 2 minutes,
151+
depending on the number of processors in your machine and other factors.
152+
153+
You can pass a path pattern to run only selected tests (e.g. `./test.py good`).
153154
To see all options, run it with `-h`.
154155

155156
Tests serve currently also as a documentation of the language.
156157
You can browse them to learn the syntax and semantics.
157158

158159

159-
Final thoughts
160-
--------------
161-
162-
The goal of this project is to create a language that would be simple, consistent, and powerful enough to be useful
163-
for some basic tasks, where other languages are too verbose, unintuitive, error-prone, or not fast enough.
164-
One example of a use-case could be solving algorithmic problems,
165-
without constantly looking into C++ STL documentation or defining tons of macros.
160+
Alternatives
161+
------------
166162

167-
I do know that there exist many interesting modern programming languages apart from those widely-known,
168-
and most of them provide majority of features from my list. Even though I haven't used them,
169-
I tried my best to learn about their details and discovered that none of them fully meets my expectations.
170-
From what I've found, only Boo has an indentation-based syntax without braces, but is built on top of
171-
C# and .NET platform. Other compiled languages with static typing and type inference are D, Go, Rust, Scala, and Kotlin,
172-
but their syntax is uglier and they are either concentrated on some specific aspect like concurrency (the first 3),
173-
or built on top of Java (the other 2).
163+
There are only a few languages with indentation-based syntax.
164+
The ones that I've found worth mentioning are, in alphabetical order:
165+
* [Boo](https://boo-language.github.io/) (based on .NET),
166+
* [CoffeeScript](https://coffeescript.org/) (transpiled to JS),
167+
* [F#](https://fsharp.org/) (functional, based on .NET),
168+
* [Genie](https://wiki.gnome.org/Projects/Genie) (compiled via C),
169+
* [Haskell](https://www.haskell.org/) (functional, compiled),
170+
* [Nim](https://nim-lang.org/) (compiled via C/C++ or transpiled to JS),
171+
* [Python](https://www.python.org/) (dynamically typed).

lib/random.px

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func randInt(Int r: 2) Int def -- range shouldn't be larger than 2^60
1212
r' >>= 1
1313
x = 0
1414
-- rand() gives only 15 bits of randomness
15-
for i in 1..min(b, 60) step 15 do
15+
for i in 1..(b < 60 ? b : 60) step 15 do
1616
x = (x << 15) + rand()
1717
return x % r
1818

0 commit comments

Comments
 (0)