Skip to content

Commit

Permalink
docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemenno committed Jan 15, 2019
1 parent 8a9ccff commit 1fb14ff
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 18 deletions.
10 changes: 10 additions & 0 deletions docs/_data/videos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ demo_20141210:
“Demo: Iteration and arrays, uninitialized values, enums.” _YouTube_, uploaded by Jonathan Blow, Dec 10, 2014
url: https://youtu.be/-UPFH0eWHEI

demo_20141211_qa:
mla: |-
“Q&A for Iteration and arrays, uninitialized values, enums.” _YouTube_, uploaded by Jonathan Blow, Dec 11, 2014
url: https://youtu.be/K45J_9jns7w

demo_20150121:
mla: |-
“Data-Oriented Demo: SOA, composition.” _YouTube_, uploaded by Jonathan Blow, Jan 21, 2015
url: https://youtu.be/ZHqFrNyLlpA

reboot_2017:
mla: |-
“Reboot Develop 2017 - Jonathan Blow, Thekla Inc. / Making Game Programming Less Terrible.” _YouTube_, uploaded by Reboot Develop, May 22, 2017
Expand Down
110 changes: 92 additions & 18 deletions docs/_features/General-Syntax.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
layout: page
title: General Syntax
order: 1

footnotes:
-
label: array-declaration
video: demo_20141210
time: 1600
text: .
-
label: basic-types
video: demo_20141031
Expand All @@ -19,16 +25,43 @@ footnotes:
time: 1968
text: |-
`for`.. `break`, `continue`, `return`.
-
label: for-remove
video: demo_20141210
time: 2106
text: |-
the `remove` primitive removes the current element from the array. is inherent in the loop in the way `break` or `continue` are.
-
label: defer
video: demo_20141031
time: 1365
text: defer is not a macro, it is a core part of the language understood by the compiler and debugger.
-
label: default-values
video: demo_20141211_qa
time: 232
text: default values are always zero. the default value...is the zero value for your type.
-
label: default-value-initialization
video: demo_20141210
time: 1075
text: |-
every single thing in the language always gets initialized to its default value, which is usually zero unless you specify a different default value. but, for performance reasons, you have the ability to say, "well, actually, let's not initialize this thing."
-
label: enum-declaration
video: demo_20141031
time: 1058
text: enums are typed, can be named or anonymous, and can refer to values declared elsewhere.
-
label: enum-introspection
video: demo_20141210
time: 2684
text: an enum is actually syntactic sugar for a struct that has some elements that tells you things about the enum.
-
label: enum-typing
video: demo_20141210
time: 2906
text: enums are strict types, distinct from all other types declared in the program, and can be treated with strict or loose typing behavior on a per-statement basis.
-
label: function-declaration
video: ideas_20140926
Expand All @@ -42,7 +75,15 @@ footnotes:
`new` and `delete` are cleaner than c++.
-
label: prevent-initialization
text: 'FIXME: find this video reference'
video: demo_20141210
time: 1238
text: |-
dash-dash-dash (`---`) means don't initialize this.
-
label: pointer-declaration
video: demo_20141210
time: 769
text: for pointers, use Pascal-style pointy hat (`^`) instead of ampersand (`&`). still use star (`*`) to dereference a pointer.
-
label: scalar-declaration
video: ideas_20140926
Expand Down Expand Up @@ -112,28 +153,35 @@ footnotes:
> Use `:` to declare, `=` to assign <br>
> `name : type = value`
- `f : float;` Declares `f`, explicitly typed to `float`
- `f : float;` Declares `f`, explicitly typed to `float` (default value is `0`)[^default-values]
- `f : float = 1;` Declares and initializes `f`
- `f := 1;` Declares and initializes `f`, implicitly typed
- `f = 1;` Assigns `f`, must already be declared
- `c := 'c` - single quote for characters (`u8` literals) {% comment %} # FIXME: is this still in? see: https://youtu.be/UTqZNujQOlA?t=1936 {% endcomment %}

### Pointers and Addresses

> Use `*` for pointer, `!` for ownership, `&` for address
> Use `^` for pointer, `*` for address[^pointer-declaration], `!` for ownership
```cpp
e : Entity;

pointer : ^Entity;
pointer = *e;

owned : node *! = null;
other : node * = &graph.node;
other : node * = *graph.node;
```

### Arrays
### Arrays [^array-declaration]

> Provide size allocations in square brackets: `[3]` <br>
> Use two periods to create a dynamically sized array: `[..]`
> Provide static size allocations in square brackets: `[3]` <br>
> Use two periods to create a dynamically sized array: `[..]` <br>
> Array indices are zero-based (the first element is at index `0`). <br>
> _see also: [Iteration](#iteration)_.
```cpp
a: [10] int; // An array of 10 integers
a: [10] int; // A static array of 10 integers
b: [..] int; // A dynamic array of integers
print("size of array: %", a.count);
```
Expand All @@ -148,7 +196,9 @@ Vector3 :: struct {
}
```

### Enums [^enum-declaration]
### Enums

Enum elements can be initialized to arbitrary values.[^enum-declaration]

```cpp
My_Enum :: enum u16 {
Expand All @@ -162,6 +212,28 @@ My_Enum :: enum u16 {
MIDDLE_VALUE := 8;
```

Introspection for enums includes count, value range, and names.[^enum-introspection]

```cpp
printf("My_Enum ranges from %d to %d.\n", My_Enum.lowest_value, My_Enum.highest_value);
printf("My_Enum has %d members:\n", My_Enum.count);
for My_Enum.names {
printf(" name: %s: value: %d\n", My_Enum.names[it_index], My_Enum.values[it_index]);
}
```
Enum values can be treated with strict or loose typing.[^enum-typing]
```cpp
x : My_Enum:strict;
x = My_Enum.VALUE_THREE; // valid
x = 10; // compiler error, even though 10 is a valid u16
y : My_Enum:loose;
y = 10; // valid
y = cast(My_Enum.VALUE_THREE, My_Enum.loose);
```

### Functions and lambdas [^function-declaration]

> Function declarations follow a style of progressive enhancement that allows for straight-forward maturation of code. <br>
Expand Down Expand Up @@ -207,15 +279,13 @@ some_function(arg1, arg2, x: float) -> float { return x * x; };
```cpp
answer, error := ???;
```
```

## Initialization

> variable declarations are automatically initialized to type defaults. <br>
> initialization can be implicit (accept default), explicit (provide value), or blocked (`---`). <br>
[^prevent-initialization]: []()
> initialization can be _implicit_ (accept default), _explicit_ (provide value), or _blocked_ (`---`).[^default-value-initialization] [^prevent-initialization] <br>
```cpp
Vector2_implicit :: struct {
Expand All @@ -233,27 +303,31 @@ Vector2_blocked :: struct {

vi: Vector2_implicit; print("% %\n", vi.x, vi.y); // "0 0"
ve: Vector2_explicit; print("% %\n", ve.x, ve.y); // "3 5"
vb: Vector2_blocked; print("% %\n", vb.x, vb.y); // compiler error?
veb: Vector2_explicit = ---; print("% %\n", ve.x, ve.y); // compiler error?
vb: Vector2_blocked; print("% %\n", vb.x, vb.y); // undefined, possibly zeroes
veb: Vector2_explicit = ---; print("% %\n", ve.x, ve.y); // undefined, possibly zeroes
```
## Iteration
### for [^for-iteration] [^for-statements]
`for` - supports named or implicit iterators (`it`) <br>
`for` - supports named or implicit (`it`) iterators over ranges or arrays <br>
`break` - exits current scope <br>
`continue` - skips to next iteration <br>
`return` - exits current function with value <br>
`remove <it>` - deletes iterator from array being visited [^for-remove] <br>
```cpp
for n: 1..count {
for n : 1..count {
printf("n is: %d\n", n);
}
results : int[];
for results printf("Hey: %d\n", it);
for r : results {
if r == 3 then remove r;
}
for results printf("results[%d] == %d\n", it_index, it);
```

```cpp
Expand Down

0 comments on commit 1fb14ff

Please sign in to comment.