spec.md (2227B)
1 Fela 0.1 spec 2 ============= 3 4 The fela language is a statically typed compiled language, akin to C 5 6 It's name is derived from the 7 [alef](https://doc.cat-v.org/plan_9/2nd_edition/papers/alef/ref), 8 but backwards 9 10 Spec 11 ---- 12 13 Types 14 ----- 15 16 The language should define the following types: 17 18 - `long` as 64 bits 19 - `int` as 32 bits 20 - `short` as 16 bits 21 - `byte` as 8 bits 22 23 The language should also support composite types, via structs 24 like so: 25 26 ``` 27 struct { int a, long b }; 28 ``` 29 30 The language should allow for user defined types via a `type` 31 keyword, it should work similar to `typedef` in c. An example 32 of this would be: 33 34 ``` 35 type pos = struct { 36 int x; 37 int y; 38 }; 39 ``` 40 41 Now the word pos can be used instead of the struct definition. 42 43 Functions should be treated as values, meaning they should have a type. 44 Their type definition should look like this: 45 46 `func(int, int) -> long` 47 48 So a variable which has this type would look like so: 49 50 `func(int, int) -> long foo` 51 52 This has defined the stub of function foo, that takes 53 in 2 int's and returns a long. 54 55 To give the function a body, use curly brackets like so: 56 57 ``` 58 func(int, int) -> int foo = (int a, int b) -> int { 59 return a * b; 60 }; 61 ``` 62 63 This is obviously quite long, to help this, a short hand 64 operator should be implemented like so: 65 66 ``` 67 foo := (int a, int b) -> int { 68 return a * b; 69 }; 70 ``` 71 72 This code is functionally equal to the previous, the type is 73 automatically decided at compile time. 74 75 This technique can also be used for regular variables: 76 77 `bar := 20` 78 79 This will automatically use a long in this case to store the 80 value. 81 82 The default types are as follows: 83 84 - string literals -> `unsigned byte *` 85 - integer literals -> `long` 86 - ... 87 88 Structure 89 --------- 90 91 The language expects programs to have functions defined in the 92 global scope like so: 93 94 ``` 95 foo := (int a) -> int { 96 return a + 1; 97 }; 98 99 bar := (int a) -> int { 100 return a - 4; 101 }; 102 103 main := () -> int { 104 int a = 20; 105 int b = 30; 106 107 return foo(a) + bar(b); 108 }; 109 ``` 110 111 Functions should be defined before use, the program should contain a 112 main function if it is to be executed. If a function intends to 113 define its own variables, it must be done before any expressions 114 are encountered, much like C89. 115 116