Skip to content

Commit

Permalink
docs: new readme and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdelahunt committed Dec 10, 2023
1 parent 31072ac commit bc2b3f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
71 changes: 57 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,74 @@


# The Liam Programming Language
Liam is a strongly typed compiled language intended for performance comparable to C++ but less pain along the way. Liam generates and outputs `c++` which is then compiled to a final binary.
Liam is a strongly typed compiled language intended for performance comparable to C++ but less pain along the way. Liam generates and outputs `c++` which is then compiled to a final binary.

Stack allocated linked list example:

```rust
import "stdlib/basic.liam";
struct NodeAllocator {
buffer: [100]Node,
used: i64
}

fn make_node(allocator: ^NodeAllocator, value: i64) ^Node {
let node : ^Node = &allocator.buffer[allocator.used];
allocator.used = allocator.used + 1;

*node = new Node{
value: value,
next: null
};

struct Person<T> {
name: str,
data: T
return node;
}

fn main() void {
let p: Person<i64> = new Person<i64>{
name: "liam",
data: 12
struct Node {
value: i64,
next: ^Node
}

struct LinkedList {
head: ^Node,
size: i64
}

fn make_linked_list() LinkedList {
return new LinkedList {
head: null,
size: 0
};
}

fn push(list: ^LinkedList, allocator: ^NodeAllocator, value: i64) void {
let new_node := make_node(allocator, value);
if list.head == null {
list.head = new_node;
return;
}

let current_node := list.head;

// there are no while loops yet so having a dummy
// varaible here is needed
for let dummy := 0; current_node.next != null; current_node = current_node.next; {}

current_node.next = new_node;
}

fn main() void {
let allocator : NodeAllocator = zero;
let list := make_linked_list();
push(&list, &allocator, 10);
push(&list, &allocator, 20);
push(&list, &allocator, 30);

print::<str>(p.name);
print::<str>("\n");
for let node := list.head; node != null; node = node.next; {

for let i := 0; i < p.data; i = i + 1; {
print::<i64>(i);
}
}
```

## Documentation
#### [Learning the basics](docs/Learning-the-basics.md)
Some helpful documentation for getting started learning Liam.
Some helpful documentation for getting started learning Liam.
34 changes: 0 additions & 34 deletions docs/Learning-the-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@ fn func_name(param: type) return_type {
}
```

### Generic Functions
```rust
fn func_name<T>(param: T) ^T {
...
}
```

### Generic Function Call
```rust
func_name::<type, type, type>(argument, argument);
```

### Function expression
```rust
let func: fn (i64) void = fn (n: i64) void {
...
}
```

### For Loops
```rust
for let i := 0; i < 10; i = i + 1; {
Expand All @@ -54,14 +35,6 @@ struct struct_name {
}
```

### Generic Structs
```rust
struct struct_name<T> {
member1: T,
member2: type
}
```

### Conditionals
```rust
if condition or another_condition {
Expand All @@ -74,10 +47,3 @@ if condition or another_condition {
let x_ptr: ^type = &x;
let y: type = *x_ptr;
```

### Pointer slice
```rust
let str_array : ^..str = alloc::<str>(100); // equivelent to malloc
str_array[0] = "The first string in a array of 100";
let my_message : str = str_array[0];
```

0 comments on commit bc2b3f8

Please sign in to comment.