1
1
Pyxell
2
2
======
3
3
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. ###
5
5
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 .*
7
7
8
8
9
9
Motivation
10
10
----------
11
11
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.
13
15
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/ ) .
19
19
20
20
21
21
Examples
@@ -40,12 +40,12 @@ for x, i in a, 0... do
40
40
```
41
41
42
42
```
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
47
47
48
- print fold (_*_, 1, [2, 3, 4]) -- factorial
48
+ print reduce (_*_, 1, [2, 3, 4]) -- 24
49
49
```
50
50
51
51
```
@@ -78,10 +78,13 @@ Features
78
78
* First-class functions (+)
79
79
* Default and named arguments (+)
80
80
* Lambda expressions (+)
81
- * Generic functions (+/- )
81
+ * Generic functions (+)
82
82
* Module system (+/-)
83
83
* Classes with safe references (+)
84
84
* Separate nullable types (+)
85
+
86
+ To do:
87
+
85
88
* Generic types
86
89
* Containers library
87
90
* Operator overloading
@@ -97,77 +100,72 @@ Features
97
100
Details
98
101
-------
99
102
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 .
101
104
* Compilation to machine code (and optimizations) with Clang.
102
105
103
106
104
107
Requirements
105
108
------------
106
109
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 ` .
108
111
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 ` .
113
114
114
- For BNFC to store source code position, install it from source:
115
+ * Clang 6 with C++ standard library.
115
116
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.
126
118
In some cases Windows SDK installation may be required
127
119
or it may be necessary to run ` pyxell ` with ` -target x86_64-pc-windows-gnu `
128
120
(run ` test.py ` with ` -t ` argument to use this).
129
121
122
+ * ANTLR 4.7.2 (to build the parser).
123
+
124
+ Put ` antlr-4.7.2-complete.jar ` file into ` src ` folder.
125
+
130
126
131
127
Usage
132
128
-----
133
129
134
130
```
135
- make bin libs
136
- ./pyxell code.px
131
+ ./pyxell.sh program.px
137
132
```
138
133
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.
140
135
If not, errors will be displayed, pointing to the erroneous code location.
141
136
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.
144
138
145
139
146
140
Tests
147
141
-----
148
142
143
+ ```
144
+ ./test.py -v
145
+ ```
146
+
149
147
Tests are divided into good (supposed to compile and run properly) and bad (should throw compilation errors).
150
148
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 ` ).
153
154
To see all options, run it with ` -h ` .
154
155
155
156
Tests serve currently also as a documentation of the language.
156
157
You can browse them to learn the syntax and semantics.
157
158
158
159
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
+ ------------
166
162
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).
0 commit comments