Skip to content

Commit

Permalink
Merge pull request #4 from X-R-G-B/enhanceReadme
Browse files Browse the repository at this point in the history
Enhance Readme
  • Loading branch information
Saverio976 authored Dec 20, 2023
2 parents 3139860 + 2e4e3a3 commit a8c2613
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 131 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ jobs:
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
run: mdbook build

- name: Install Haskell
uses: haskell-actions/setup@v2
with:
enable-stack: true
stack-version: 'latest'

- name: Compil
if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main'
run: |
if ! stack build; then
exit 0
fi
- name: Setup Pages
if: github.ref == 'refs/heads/main'
uses: actions/configure-pages@v3
Expand Down
75 changes: 34 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

## Documentation

-- **Comentary**
- **Comentary**

```c
// This is a comment
```

-- **Variables Declaration**
- **Variables Declaration**

```hs
@Int a = 1;
@String b = "hello";
```

-- **Variables Assignment**
- **Variables Assignment**

```hs
a = 1;
Expand All @@ -33,17 +33,11 @@ b = "hello";
@Bool a = True;
@Bool b = False;
@Int c = 1;
@List[Int] d = [1, 2, 3];
@Char e = 'a';
@String f = "hello";
@List[Char] g = ['a', 'b', 'c'];
@StringView f = "hello";
```

- **Built-in Global Variables**

```c
@List[String] ARGS = ["programfilepath", "arg1", "arg2"];
```
There is a `Void` type that can be used to return nothing.

- **Function Declaration**

Expand All @@ -53,6 +47,11 @@ fn add(a: Int, b: Int) -> Int
// the next line is the `return`
<- a + b;
};

export fn sub(a: Int, b: Int) -> Int
{
<- a - b;
};
```

- **Function Call**
Expand Down Expand Up @@ -80,23 +79,6 @@ fn add(a: Int, b: Int, c: Int) -> Int
};
```

- **Built-in Functions**

```c
// print to stdout
print("hello");
// print to stderr
printErr("hello");
// get a line from stdin
getLine();
// transform a type to a string
str(1);
// get the type of a value in string format
type(a);
// call a function with string
call("add", [1, 2]);
```
- **Generic Functions**

```rust
Expand Down Expand Up @@ -141,17 +123,6 @@ while (i < 10)
};
```

```c
@List[Int] lst = [1, 2, 3];
foreach (a in lst)
{
if (a == 2)
{
break;
};
};
```
- **Imports**

```c
Expand Down Expand Up @@ -185,15 +156,37 @@ a != b
```c
struct Point
{
a: Int,
x: Int,
y: Int,
};
```

- **Structs Initialization**
```
@Point p = {1, 2};
```

- **Structs Access**
```
p:x
```

- **Nested Structs**
```
struct Rect
{
Point size;
Point pos;
};
@Rect r = {{1, 2}, {3, 4}};
r:size:x
```

- **Generic Structs**

```c
struct Rect[A]
{
a: A,
attribute: A,
};
```
225 changes: 225 additions & 0 deletions docs/ByteCodeSpec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Spec for ByteCode

:: All value starting with `0x` are hexadecimal

## Header

1. The file starts with:

```
0x00 0x61 0x73 0x6D
0x01 0x00 0x00 0x00
```

## Type Section

```
0x01
```

### Function Type

```
0x60
```

#### Number of Parameters

- for 2 parameters
```
0x02
```
#### Parameters Type
```
0x7F: i32
0x7D: f32
```
#### Return Type
```
0x7F: i32
0x7D: f32
0x00: void
```
## Function Section
```
0x03
```
## Export Section
```
0x07
```
Instructions
------------
## Instructions
### Stack
#### local
##### local.get <index>
```
0x20
```
Get a local variable by its index and add it to the stack.
##### local.set <index>
```
0x21
```
Get the top of the stack and set a local variable by its index.
#### global
##### global.get <index>
```
0x23
```
Get a global variable by its index and add it to the stack.
##### global.set <index>
```
0x24
```
Get the top of the stack and set a global variable by its index.
#### i32
##### i32.const <value>
```
0x41
```
Push an `Int32` to the stack.
### Memory
#### i32
##### i32.store
```
0x36
```
Take the top of the stack. This will be the value stored in memory.
Take the top of the stack. This will be the index in memory.
Store the value in memory at the index.
##### i32.load
```
0x28
```
Take the top of the stack. This will be the index in memory.
Push an `Int32` to the stack with the value at address in memory.
### Condition
#### i32
##### i32.gt_s
```
0x4a
```
Compare the 2 values on the top of the stack.
If the first value is greater than the second value, push `1` to the stack.
else, push `0`
##### i32.eq
```
0x46
```
Compare the 2 values on the top of the stack.
If the first value is equal to the second value, push `1` to the stack.
else, push `0`
#### control
##### if...else...end
- if
```
0x04
```
Enter in the first branch if the top of the stack is 1.
- else
```
0x05
```
Enter in the second branch if the top of the stack is 0.
- end
```
0x0b
```
Exit from the if/else block.
##### loop <label> ... br <label>
- loop <label>
```
0x03
```
Create a label for the loop
Label is a number
- br <label>
```
0x0c
```
Jump to the label
Label is a number
### Operations
#### i32
##### i32.add
```
0x6a
```
Add the 2 values on the top of the stack.
Push the result to the stack.
Loading

0 comments on commit a8c2613

Please sign in to comment.