Skip to content

Commit

Permalink
Merge branch 'cpp-target'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsol committed Mar 3, 2020
2 parents e64a08e + 9ef4434 commit 0f5acc2
Show file tree
Hide file tree
Showing 237 changed files with 4,378 additions and 6,982 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pyxell
*.exe
*.o
*.jar
.idea/
*.iml
_*
*.tmp
*.bc
*.ll
*.cpp
*.gch
*.spec
build/
dist/
38 changes: 17 additions & 21 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
Copyright (c) 2018 Adam Sołtysik. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
The MIT License (MIT)

- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Copyright (c) 2020 Adam Sołtysik

- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

- Neither the name of the copyright holder nor the names of contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ libs:
python pyxell.py --libs

exe:
python -m PyInstaller --add-data "lib/;lib/" pyxell.py --noconfirm
python -m PyInstaller --hidden-import=decorator --add-data "lib/;lib/" pyxell.py --noconfirm

clean:
"$(MAKE)" clean -C src
Expand Down
97 changes: 48 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
Pyxell
======

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

*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.*
### Clean and easy-to-use multi-paradigm programming language with static typing. ###


Motivation
----------

The project aims to combine the best features of different programming languages,
pack them into a clean syntax with significant indentation,
pack them into a clean and consistent syntax,
and provide the execution speed of native machine code.

It draws mainly from Python, Haskell, C#, and C++,
Expand All @@ -27,7 +25,7 @@ func fib(Int n) Int def
return 0
a, b = 0, 1
for i in 2..n do
a, b = b, a + b
a, b = b, a+b
return b
print fib(10)
Expand Down Expand Up @@ -64,44 +62,38 @@ print c.s ?? "---"
Features
--------

* Python-like syntax with semantic indentation (+)
* Strongly static typing with partial type inference (+)
* Full compilation to machine code (+)
* 64-bit integers and double-precision floating-point numbers (+)
* Native tuples (+)
* Immutable strings (+)
* String interpolation (+)
* Mutable arrays (+)
* Extensive for-loops with ranges, steps, and zipping (+)
* Array comprehension (+)
* Slicing (+)
* First-class functions (+)
* Default and named arguments (+)
* Lambda expressions (+)
* Generic functions (+)
* Module system (+/-)
* Classes with safe references (+)
* Separate nullable types (+)
* Python-like syntax with semantic indentation
* Strongly static typing with partial type inference
* 64-bit integers and double-precision floating-point numbers
* Native tuples
* Immutable strings
* String interpolation
* Mutable arrays
* Complex for-loops with ranges, steps, and zipping
* Array comprehension and slicing
* First-class functions
* Default and named arguments
* Lambda expressions
* Generic functions
* Classes with safe references
* Inheritance and virtual methods
* Nullable types
* Full transpilation to C++17 and compilation to machine code
* Automatic memory management (utilizing C++'s smart pointers)

To do:

* Generic types
* Containers library
* Operator overloading
* Arbitrary-precision arithmetic
* Closures
* Coroutines
* Coroutines/generators
* Arbitrary-precision arithmetic
* Exception handling
* Unicode
* Generic classes
* Operator overloading
* Multiple inheritance
* Automatic memory management
* Concurrency


Details
-------

* LLVM IR generator and type checker written in Python with ANTLR and llvmlite.
* Compilation to machine code (and optimizations) with Clang.
* Module system


Requirements
Expand All @@ -113,12 +105,7 @@ Requirements
python -m pip install -r requirements.txt
```

* Clang 6+ with C++ standard library.

The library shouldn't be a problem on Linux, but on Windows this may not work out of the box.
In some cases Windows SDK installation may be required
or it may be necessary to run `pyxell` with `-target x86_64-pc-windows-gnu`
(run `test.py` with `-t` argument to use this).
* C++17 compiler (e.g. GCC 7+ or Clang 5+).


Usage
Expand All @@ -128,17 +115,21 @@ Usage
python pyxell.py [-r] program.px
```

If the program is correct, `program.ll` file and `program.exe` executable should be created in the same folder.
If the program is correct, `program.cpp` file and `program.exe` executable will be created in the same folder.
If not, errors will be displayed, pointing to the erroneous code location.

If `-r` option is given, the compiled program will be run immediately after compilation.

By default, `gcc` command is used to compile the code.
You can pick a different command using `-c` option.
Write `-c=none` to skip the compilation step (only C++ code will be created).

Executable
----------

You can build a standalone application using `pyinstaller`. Install it using `pip`, then run `make exe`.
An executable (not requiring Python to run) will be created in the `dist/pyxell` folder.
PyInstaller
-----------

You can build a standalone application using `PyInstaller`. Install it using `pip`, then run `make exe`.
An executable `pyxell.exe` (not requiring Python to run) will be created in the `dist/pyxell` folder.


Development
Expand All @@ -149,7 +140,7 @@ first [download ANTLR](https://www.antlr.org/download/antlr-4.7.2-complete.jar)
and put the `antlr-4.7.2-complete.jar` file into `src` folder,
then run `make parser`.

After changing the code of Pyxell libraries (`lib/*.px` or `src/library.py` files),
After changing the code of Pyxell libraries (`lib/*.px` files),
run `make libs` to rebuild them.


Expand All @@ -163,8 +154,8 @@ python test.py -v
Tests are divided into good (supposed to compile and run properly) and bad (should throw compilation errors).

The script is multi-threaded.
Total execution time may vary from something like 10 seconds to 2 minutes,
depending on the number of processors in your machine and other factors.
Total execution time may vary from something like 20 seconds to 5 minutes,
depending on the number of available CPU cores and other factors.

You can pass a path pattern to run only selected tests (e.g. `python test.py arrays`).
To see all options, run it with `-h`.
Expand All @@ -185,3 +176,11 @@ Some more or less similar to Pyxell are, in alphabetical order:
* [Haskell](https://www.haskell.org/) (functional, compiled),
* [Nim](https://nim-lang.org/) (compiled via C/C++ or transpiled to JS),
* [Python](https://www.python.org/) (dynamically typed).


History
-------

* The project was originaly written in Haskell, with BNFC as the parser generator, and used LLVM as the target language.
* In version 0.7.0 the code was rewritten to Python, with ANTLR as the parser generator.
* In version 0.9.0 the project was refactored to use C++ as the target language.
Loading

0 comments on commit 0f5acc2

Please sign in to comment.