Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Documentation for the work done in GSoC 2022 #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 114 additions & 14 deletions docs/language-reference/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* `~`,`&`,`|`,`<<`,`>>` - Bitwise operators: not, and, or and bitshifts
* `not`,`and`,`or` - Logical operators: not, and, or
* `:=` - Assignment operator
* `+=`,`-=`,`&=`,`|=`,`*=`,`/=`,`>>=`,`<<=` - More assignment operators
* `++`,`--`- Unary Operators
* `?`- Conditional Operators

* Result of Arithmetic and Bitwise operators is Integer constant.
* Result of Comparison and Logical operators is Boolean constant.
Expand Down Expand Up @@ -81,6 +84,59 @@ test_var := true;
* Integer and Character variable can be assigned only Integer expression/Integer constant/Character constant.
* Boolean variable can be assigned only Boolean expression/constant.

### Other Assignment Operators

```cpp
int var;
int var1;
var := 45;
var1 += var;
var1 /= var;
var1 *= 3;
var1 &= 10;
var1 <<= 5;
var1 |= 4;
```

* We can use these different assignment operators according to the user requirements.
* These assignment operators can be used for easier calculations.
* These assignment operators include bitwise,arithmetic assignment operators.

### Unary Operators

```cpp
int a:=10;
int b:=5;
int c:= ++a + 2 ;
int d:= --b;
println(c);
print(d);
```

```cpp
int[10] arr;
for: i in 0:10 {
arr[i] := 0;
i++;
}
```

* The unary increment and decrement operators are introduced for easier and faster calculations.
* These can be used independently in compound statements and arithmetic expressions.

### Conditional Operators

```cpp
int a:=10;
int b;
bool c;
b :=(a>5)? a+5 : a-5 ;
println(b);
c:=(a>5)?true:false;
print(c);
```
* The conditional operators can be used where there is only one condition and results in either of true or false case.

## Arrays

* Arrays are static - their size has to be known at compile time and this size cannot be changed later.
Expand Down Expand Up @@ -413,22 +469,12 @@ def <function_name> : <data_type> : <data_type> <param_name>, <data_type> <param

!!! Note
If return data type is void, then return statement is not needed, and if still it is added, it must be return nothing, i.e., something like this `return ;`

!!! Warning
`return` can only be present in the body of the function only once, that too at the end of the function, not inside any compound statements.

!!! fail "Wrong"
* `return` inside a compound statement, this syntax is not allowed.
```python
def test : int : int a {
if : a < 4 {
return a;
}
}
```
!!! Note
Every non-void function should have a return type

!!! done "Correct"
* `return` is not inside compound statments, It should be placed only at the end of function definition
* `return`statement can be placed at the end of function definition or anywhere in the function block inside compound statements.

```python
def test : int : int a {
int gf := 8;
Expand All @@ -439,6 +485,22 @@ def <function_name> : <data_type> : <data_type> <param_name>, <data_type> <param
return gf;
}
```
!!! Multiple return statements,It can be called anywhere inside the function scope
```
def testing: int: int a, int b, bool control {
int c;
if: control {
c := a + b;
return c;
}
else {
c := a * b;
return c;
}
}
int result := testing(3, 4, true);
print(result);
```


#### Examples
Expand Down Expand Up @@ -496,6 +558,38 @@ Examples according to return types
return;
}
```
Examples of multiple return types

=== "Integer"
```python
def test_func : int : int a, int b {
int aa := a + 5;

if : aa < 3 {
aa : = 0;
return aa + b;
}
else {
aa : = 10;
return aa + b;
}
}
```
=== "Boolean"
```python
def compare : bool : int val {
bool ret := false;

if : val < 0 {
ret := true;
return ret;
}
else {
ret := true;
return ret;
}
}
```

### Function call

Expand Down Expand Up @@ -559,3 +653,9 @@ println("");
#### Stub functions

PRU specific functions will be replaced by stub functions which print "function_name called with arguments arg_name" when called.

#### Error Handling

Currently for error detection there are linenumber and columnnumber specified for precise error/bug location.
This depicts how the current error detection works!
![](/images/column.png)
Binary file added docs/usage/images/column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/usage/images/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion docs/usage/usage-simppru-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ The large box in the screen shows data received from the PRU, It runs using a fo

Using the radio box in the upper right corner, one can change the PRU id, i.e. if one wants to use the features for PRU0 or PRU1

![](images/select_pru_id_screen.png)
![](images/select_pru_id_screen.png)

### Quit Button Feature

Using this quit button you can exit the console.Initially it was done by (Control+C), this is a good alternative to it.
![](/images/quit.png)
7 changes: 7 additions & 0 deletions docs/usage/usage-simppru.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ simppru [OPTION...] FILE
(pocketbeagle, bbb, bbbwireless, bbai)
--load Load generated firmware to /lib/firmware/
-o, --output=<file> Place the output into <file>
-O, --compiler_flags=<flags> Select the compiler flag (-O1,-O2,-O3)
-p, --pru=<pru_id> Select which pru id (0/1) for which program is to
be compiled
--verbose Enable verbose mode (dump symbol table and ast
Expand All @@ -31,6 +32,12 @@ Say we have to compile a example file called `test.sim`, command will be as foll
simppru test.sim --load
```

Trying it with compiler flags which are available(-O1,-O2,-O3)

```bash
simppru -O1 test.sim -o test_firmware -p 0
```

If we only want to generate binary for pru0

```bash
Expand Down