Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
alinalihassan committed Jan 2, 2019
2 parents 4ce766a + e7f0198 commit 6b358ed
Showing 45 changed files with 473 additions and 202 deletions.
8 changes: 5 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ version: 2
jobs:
build:
docker:
- image: circleci/python:3.7.1
- image: circleci/python:3.7.2
steps:
- checkout
- run: |
pip install --user -r requirements.txt
sudo pip install nose
sudo pip install pytest
sudo pip install pycodestyle
- run: |
nosetests
pytest -vv -p no:cacheprovider
pycodestyle src/* --ignore=E501
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ __pycache__/
out/

\.vscode/
\.pytest_cache/

site/
build/
29 changes: 29 additions & 0 deletions .hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# Pytest
echo "Running pre-commit hooks"
pytest -vv -p no:cacheprovider

if [ $? -ne 0 ]; then
echo "Tests must pass before committing"
exit 1
fi
####

# Pycodestyle
pycodestyle src/* --ignore=E501

if [ $? -ne 0 ]; then
echo "Tests must pass before committing"
exit 1
fi
####

# Prevent master commit
branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "master" ]; then
echo "You can't commit directly to master branch"
exit 1
fi
####
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

___
[![License: GPL v3](https://img.shields.io/badge/license-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Version](https://img.shields.io/badge/version-0.2.0-brightgreen.svg)](https://github.com/hassanalinali/Lesma/blob/master/LICENSE.md)
[![Version](https://img.shields.io/badge/version-0.2.1-brightgreen.svg)](https://github.com/hassanalinali/Lesma/blob/master/LICENSE.md)
[![CircleCI](https://circleci.com/gh/hassanalinali/Lesma/tree/master.svg?style=shield)](https://circleci.com/gh/hassanalinali/Lesma/tree/master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/90fcc06be70d4dd98f54f1bb2713d70c)](https://www.codacy.com/app/hassanalinali/Lesma?utm_source=github.com&utm_medium=referral&utm_content=hassanalinali/Lesma&utm_campaign=Badge_Grade)

@@ -15,7 +15,7 @@ Currently an early Work in Progress, and **many thanks** to [Ayehavgunne](https:
## Features
- **it's fast**, because it should be so, but it won't ever oblige you to make an extra effort for the sake of performance
- **it's compiled**, so you can finally distribute your projects without dependencies, and because binary size also matters, a Hello World example would be around 8kb
- **it's statically typed** so you don't need to guess the type of the variable if your coworker didn't spend the time to use meaningful names
- **it's statically typed** so you don't need to guess the type of the variable if your coworker didn't spend the time to use meaningful names and you can make use of compile-time checks, autocomplete and more
- **it's simple and expressive** because the code should be easily readable and it shouldn't make you guess what it does

## Influences
@@ -54,9 +54,9 @@ python les.py run test.les
python les.py compile test.les
```

Or run the unit tests using nosetests
Or install pytest and run the unit tests yourself
```bash
nosetests
pytest
```

For advanced usage or help, consult the CLI help menu
21 changes: 7 additions & 14 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
# TODO

## Fixes
- [x] Fix **break** and **continue** not branching if the parent block is not the loop
- [x] Fix constant declaration not allowing types
- [ ] Fix Type declaration not expecting square brackets (for lists)
- [ ] Fix input function
- [x] Should not allow declaring the type to an existing variable
- [ ] Fix not being able to return user-defined structs and classes
- [ ] Fix not being able to overload operators on user-defined structs and classes
- [x] Fix Python error on empty input
- [ ] Unicode doesn't work on Windows platforms
- [ ] Fix string and list type declaration not working
- [ ] Fix base unary operators being applied before user defined ones

## Improvements
- [ ] Allow any type for lists/tuples (currently only int)
- [ ] Allow any type for range (currently only int)
- [x] Allow any type for casting
- [x] Change casting syntax
- [ ] Allow more operators on different types such as strings
- [ ] Improve warning messages
- [ ] Add indentation related errors
- [ ] Add docs for as and is
- [x] Add docs for as and is
- [ ] Remove clang as a dependency
- [x] Change from anonymous structs to identified (to allow proper struct types)
- [ ] Move error messages from source files to typechecker
- [ ] Fix array types not working and empty lists
- [ ] Catch struct/class used parameters that are not initialized
- [ ] Add support for functions with same name but different parameters

## Features
- [ ] Implement Null (maybe)
- [ ] Implement Null (maybe someday)
- [ ] Implement Tuples
- [ ] Implement Dictionary
- [ ] Implement Empty lists
- [ ] Implement 'in' as a boolean result
- [ ] Implement anonymous functions
- [x] Implement alias
- [ ] Implement Closure
- [ ] Implement string interpolation
- [ ] Implement Enums
- [x] Implement unsigned numbers
- [x] Implement operator overloading
- [ ] Implement defer keyword
14 changes: 8 additions & 6 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ print(start_at_5(4))
print(start_at_27(15))

# User input
Int age = input('How old are you?')
age: int = input('How old are you?')

# String Interpolation
print('Wow! You are {age} years old?!')
@@ -157,17 +157,19 @@ def operator - (x: int) -> int # One parameters overloads binary operations
return 0 - x + 1

# Extern functions (FFI)
def extern abs(x: int32) -> int32 # from C's stdlib
def extern abs(x: int) -> int # from C's stdlib

print(abs(-5 as int32)) # ints are int64 by default in Lesma, they're int32 in C
print(abs(-5.0 as int)) # ints are int64 by default in Lesma, they're int32 in C

# or you can just let Lesma convert between "compatible" types such as numbers
print(abs(-5))
print(abs(-5.0))

# Named parameters and defaults
def optional_params(x: int, y: int32 = 5, z: double = 9) -> int
# Lesma takes care of casting the return type between "compatible" types
return x + z
return x + z

optional_params(5, z=11)

# Enums
enum Colors
@@ -182,7 +184,7 @@ struct Circle
x: int
y: int

cir: Circle = {radius=5, x=2, y=4}
cir: Circle = Circle(radius=5, x=2, y=4)

print(cir.radius)

2 changes: 1 addition & 1 deletion docs/features/keywords.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ For reference, here are all the keywords categorized by type.
| if | else | for | while |
| switch | case | default | def |
| const | break | continue | pass
| void | alias |
| void | alias | extern | operator |

## Operator keywords

4 changes: 2 additions & 2 deletions docs/features/operators.md
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ Lesma offers the standard mathematical and boolean operators
|And| `and`| And|
|Or| `or`| Or|
|Xor| `xor`| Exclusive Or|
|Is| `is` | Is type operator|
|Is| `is` | Type checking operator|
|As| `as` | Casting operator|
|Not| `not` | Not bool operator|
|Not| `not` | Not boolean operator|
|Equals| `==` | Value equality|
|Not Equals| `!=` | Value inequality|
|Less Than| `<` | Less than value|
4 changes: 2 additions & 2 deletions docs/features/syntax.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- Whitespace is signifiant, indentation uses either Tabs or exactly 4 spaces
- Flow control statements, structs, classes and functions require an indentation
- Whitespace is signifiant, indentation uses either tabs or exactly 4 spaces
- Flow control statements, structs, classes and functions require indentation
- Lesma's Checker will report any invalid syntax or unrecommended behaviour, such incompatible types for operations, or unused variables.
- `_` variable name is used as an ignored result, and is treated differently by the compiler (similar to golang)

58 changes: 35 additions & 23 deletions docs/features/types.md
Original file line number Diff line number Diff line change
@@ -2,24 +2,16 @@ Types are optional in Lesma, you can choose whether you specify them or not. Uns

Operations between different types will either be casted to the larger type if the two types are compatible, or give an error otherwise. Two types are compatible if they are different sizes of the same group type (such as ints or floating points).

The type must be either a user-defined alias, a struct or class, or a built-in type.

!!! warning
Types that are not specified are inferred, this is fundamentally different to dynamic types!

The type must be either a user-defined alias, struct or class, or a built-in type such as:

- `Any`
- `Int`
- `Double`
- `Float`
- `Str`
- `Bool`
- `List`
- `Tuple`
- `Dict`
- `Range`
---

## Built-in Types

## Any
### Any

Any types can receive any kind of value, so it can receive any kind of value at any moment.

@@ -31,7 +23,7 @@ x = "Hey there"
!!! warning
Any not implemented yet!

## Int
### Int
There are multiple types of ints available based on width and signed/unsigned. They can get a minimum of 8 bits width and a maximum of 128. If the width is not specified, it's by default 64.
- Signed: `int`, `int8`, `int16`, `int32`, `int64`, `int128`
- Unsigned: `uint`, `uint8`, `uint16`, `uint32`, `uint64`, `uint128`
@@ -45,21 +37,21 @@ large_num: int128 = 5
!!! info
In Lesma, int and uint are by default 64 bits wide, and they will enlarge by themselves to 128 bits wide if needed. This is not the default behaviour if you specify the size yourself!

## Float
### Float
Float is floating-point real number.

```py
x: float = 0.5
```

## Double
### Double
Double is double-precision floating-point real number.

```py
x: double = 172312.41923
```

## Str
### Str
Str is Lesma's implementation of strings/char lists. All Lesma strings support UTF-8.

```py
@@ -68,13 +60,13 @@ x = '🍌'
x = '夜のコンサートは最高でした。'
```

## Bool
### Bool
Bools occupy only 1 bit, and can be either `true` or `false`.
```py
x: bool = true
```

## List
### List
Lists are mutable by default, are declared using square paranthesis, have dynamic size, start from 0, and the members are accessed using the their index around square paranthesis.

```py
@@ -85,7 +77,7 @@ print(x[2])
!!! warning
Lists currently only support integers, no other types!

## Tuple
### Tuple
Tuples are like lists, but immutable, and declared using round paranthesis.

```py
@@ -96,7 +88,7 @@ print(x[0])
!!! warning
Tuples are not yet implemented!

## Dict
### Dict
Dictionaries are lists of key-value pairs (similar to hashmaps), and they're mutable

```py
@@ -108,7 +100,7 @@ print(x['first_name'])
!!! warning
Dicts are not yet implemented!

## Range
### Range
Ranges are similar to Python's ranges, defined using `start..end` kind of syntax, and they're especially used for loops

```py
@@ -117,4 +109,24 @@ for x in 0..100
```

!!! warning
Ranges can not currently be assigned to variables
Ranges can not currently be assigned to variables

----

## Type Operations

### Is
`Is` binary operator checks if the left operand's type matches the right operand and returns a bool as a result

```py
x: int = 5
print(x is int)
```

### As
`As` binary operator casts the left operand to the right operand type and returns the casted value

```py
x: float = 5.5
print(x as int) # Should print 5
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ Currently an early Work in Progress, and many thanks to [Ayehavgunne](https://gi
## Features
- **it's fast**, because it should be so, but it won't ever oblige you to make an extra effort for the sake of performance
- **it's compiled**, so you can finally distribute your projects without dependencies, and because binary size also matters, a Hello World example would be around 8kb
- **it's statically typed** so you don't need to guess the type of the variable if your coworker didn't spend the time to use meaningful names
- **it's statically typed** so you don't need to guess the type of the variable if your coworker didn't spend the time to use meaningful names and you can make use of compile-time checks, autocomplete and more
- **it's simple and expressive** because the code should be easily readable and it shouldn't make you guess what it does

## Influences
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
halo==0.0.22
llvmlite==0.26.0
llvmlite==0.27.0
docopt==0.6.2
5 changes: 5 additions & 0 deletions setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# Setup Git Hooks
cd .git/hooks/
ln -s -f ../../.hooks/pre-commit.sh ./pre-commit
6 changes: 3 additions & 3 deletions src/les.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ def _run(arg_list):
error(les_file + " is not a valid file")
return

code = open(les_file).read()
code = open(les_file, encoding="utf8").read()
lexer = Lexer(code, les_file)
parser = Parser(lexer)
t = parser.parse()
@@ -55,7 +55,7 @@ def _compile(arg_list):
return

les_file = os.path.abspath(les_file)
code = open(les_file).read()
code = open(les_file, encoding="utf8").read()
lexer = Lexer(code, les_file)
parser = Parser(lexer)
t = parser.parse()
@@ -68,7 +68,7 @@ def _compile(arg_list):


if __name__ == "__main__":
args = docopt(__doc__, version='0.2.0')
args = docopt(__doc__, version='0.2.1')

if args['compile']:
_compile(args)
Loading

0 comments on commit 6b358ed

Please sign in to comment.