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
  • Loading branch information
alinalihassan committed Jan 6, 2019
2 parents 6b358ed + b70082a commit 6a378e3
Show file tree
Hide file tree
Showing 23 changed files with 259 additions and 76 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ out/

site/
build/
dist/
dist/
les\.dist/

les\.build/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1-brightgreen.svg)](https://github.com/hassanalinali/Lesma/blob/master/LICENSE.md)
[![Version](https://img.shields.io/badge/version-0.3.0-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)

Expand All @@ -25,8 +25,8 @@ Currently an early Work in Progress, and **many thanks** to [Ayehavgunne](https:
- Swift

## Installing
Currently if you want to test it, you need to build it on your own. In the future I might consider
publishing the binary to the Release Page.
You can pick up the latest release in the [Release tab](https://github.com/hassanalinali/Lesma/releases) and start using it. Lesma is currently being tested and provides binaries only on Unix. Compatibility between operating systems and architectures is not hard to achieve, but simply not a priority.
In the case that your platform is not oficially supported, you need to build it on your own.

## Documentation

Expand All @@ -35,7 +35,7 @@ publishing the binary to the Release Page.

## Build

In order to build Lesma, you need to have [Python 3.7](https://www.python.org/) installed. Currently it's tested only on Linux. It makes use of clang to compile the resulting object file currently, so you need it installed, but only running a file doesn't require clang.
In order to build Lesma, you need to have [Python 3.7](https://www.python.org/) installed. It's currently tested only on Linux. It makes use of clang to compile the resulting object file currently, so you need it installed, but only running a file doesn't require clang.

Clone the repo:
```bash
Expand Down
1 change: 1 addition & 0 deletions build_dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python -m nuitka src/les.py --include-package=lesma --standalone --nofollow-imports --remove-output --python-flag=no_site --plugin-disable=pylint-warnings
11 changes: 7 additions & 4 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [ ] Fix input function
- [ ] Fix not being able to return user-defined structs and classes
- [ ] Fix not being able to overload operators on user-defined structs and classes
- [ ] Unicode doesn't work on Windows platforms
- [ ] Unicode doesn't print properly on Windows platforms
- [ ] Fix string and list type declaration not working
- [ ] Fix base unary operators being applied before user defined ones

Expand All @@ -20,14 +20,17 @@
- [ ] 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
- [ ] Fix local - global variable behaviour, currently there's an implicit main func
- [ ] Allow strings to be used in equalities

## Features
- [ ] Implement Null (maybe someday)
- [ ] Implement Tuples
- [x] Implement Tuples
- [ ] Implement Dictionary
- [ ] Implement 'in' as a boolean result
- [ ] Implement anonymous functions
- [x] Implement anonymous functions
- [ ] Implement Closure
- [ ] Implement string interpolation
- [ ] Implement Enums
- [ ] Implement defer keyword
- [x] Implement defer keyword
- [x] Implement fallthrough and change switch's behaviour
26 changes: 16 additions & 10 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ if 2 in things
if 2 not in things
print('no')

special_num = 1
odd_even = 1

switch special_num
# No implicit fallthrough (in other words, implicit break)
switch odd_even
case 1
print('Number one')
case 2
print('Number two')
break
default
print("Big number")
print(special_num)
fallthrough # Go to the next case
case 3
print('Number three')
print('Odd number')
default
print("Any number")
print(odd_even)
case 4
print('Even number')

# Function Return notation
def fib(n: int) -> int
Expand Down Expand Up @@ -171,6 +171,12 @@ def optional_params(x: int, y: int32 = 5, z: double = 9) -> int

optional_params(5, z=11)

def defer_demo()
defer print("World!")
print("Hello")

defer_demo() # prints Hello World!

# Enums
enum Colors
GREEN
Expand Down
26 changes: 13 additions & 13 deletions docs/features/flow_control.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## While loops

The expression is required to be of type bool.
The evaluation expression is required to be of type bool.

```py
x = 5
Expand All @@ -23,7 +23,7 @@ for num in my_list

## If else statements

The expression is required to be of type bool.
The evaluation expression is required to be of type bool.

```py
if true
Expand All @@ -36,19 +36,19 @@ else

## Switch statement

**Every case needs a break** if you don't want to continue the flow to the next case, only the last case doesn't need a break, this means that the default would still need one if it's not the last case of the switch statement.
**No implicit fallthrough**, this means that in comparison with languages like C, the equivalent to a break statement is implicit in Lesma, therefore you need to specify the `fallthrough` keyword for the flow to go downstream to the other cases. Break statements are not allowed inside a switch statement.

```py
coins = 5
odd_even = 1

switch coins
switch odd_even
case 1
print('You got only one?')
case 2
print('Now we\'re talking')
break
default
print(coins)
print("You got a lot of coins in there")
fallthrough # Go to the next case
case 3
print('I guess 3 is enough')
print('Odd number')
default
print("Any number")
print(odd_even)
case 4
print('Even number')
```
5 changes: 3 additions & 2 deletions docs/features/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ For reference, here are all the keywords categorized by type.
| struct | class | true | false |
| if | else | for | while |
| switch | case | default | def |
| const | break | continue | pass
| const | break | continue | pass |
| void | alias | extern | operator |
| fallthrough | defer

## Operator keywords

Expand All @@ -21,7 +22,7 @@ For reference, here are all the keywords categorized by type.

| | | | |
|---|---|---|---|
|int | int8 | int16 | int32
| int | int8 | int16 | int32 |
| int64 | int128 | uint | uint8 |
| uint16 | uint32 | uint64 | uint128 |
| double | float | str | bool |
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
site_name: Lesma Documentation
site_description: 'The documentation of Lesma language'
site_description: 'Lesma Documentation'
site_url: 'https://hassanalinali.github.io/Lesma/'
site_author: 'Alin Ali Hassan'

repo_name: 'hassanalinali/Lesma'
repo_url: 'https://github.com/hassanalinali/Lesma'

copyright: 'Copyright © 2018 Alin Ali Hassan'
copyright: 'Copyright © 2019 Alin Ali Hassan'

nav:
- Lesma: index.md
Expand Down
2 changes: 1 addition & 1 deletion src/les.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _compile(arg_list):


if __name__ == "__main__":
args = docopt(__doc__, version='0.2.1')
args = docopt(__doc__, version='v0.3.0')

if args['compile']:
_compile(args)
Expand Down
26 changes: 24 additions & 2 deletions src/lesma/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ def __str__(self):
__repr__ = __str__


class Fallthrough(AST):
def __init__(self, line_num):
self.line_num = line_num

def __str__(self):
return FALLTHROUGH

__repr__ = __str__


class Continue(AST):
def __init__(self, line_num):
self.line_num = line_num
Expand All @@ -234,6 +244,17 @@ def __str__(self):
__repr__ = __str__


class Defer(AST):
def __init__(self, line_num, statement):
self.line_num = line_num
self.statement = statement

def __str__(self):
return DEFER

__repr__ = __str__


class BinOp(AST):
def __init__(self, left, op, right, line_num):
self.left = left
Expand Down Expand Up @@ -272,9 +293,10 @@ def __init__(self, obj, field, line_num):


class Type(AST):
def __init__(self, value, line_num, func_ret_type=None):
def __init__(self, value, line_num, func_params=None, func_ret_type=None):
self.value = value
self.func_ret_type = func_ret_type or []
self.func_params = func_params
self.func_ret_type = func_ret_type
self.line_num = line_num


Expand Down
Loading

0 comments on commit 6a378e3

Please sign in to comment.