added some concepts for custom lang
This commit is contained in:
+58
@@ -14,3 +14,61 @@
|
||||
- signed integer types (I8, I16, I32)
|
||||
- boolean type (Bool)
|
||||
- custom struct & dynamic types (Struct)
|
||||
- pointer types (&Type)
|
||||
- result, error and option types (Result, Err, Option)
|
||||
|
||||
## Control Flow
|
||||
|
||||
- we should support the following control flow
|
||||
- if/else-if/else
|
||||
- loop/break/continue
|
||||
- for loops and while loops can be constructed with conditions in these loops
|
||||
|
||||
```dsc
|
||||
if condition {
|
||||
// do something
|
||||
} else if condition {
|
||||
// do something else
|
||||
} else {
|
||||
// do something else
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
- functions will be treated as types, rather than language features
|
||||
|
||||
```dsc
|
||||
add: Func = |x: U32, y: U32| -> U32 {
|
||||
return x + y;
|
||||
}
|
||||
```
|
||||
|
||||
## Struct Definitions
|
||||
|
||||
- we define the struct type as it's constructor.
|
||||
|
||||
```dsc
|
||||
// struct definition
|
||||
Point: Struct = {
|
||||
x: U32,
|
||||
y: U32
|
||||
};
|
||||
|
||||
// constructor
|
||||
Point.new = |x: U32, y: U32| -> Point {
|
||||
return {
|
||||
x: x,
|
||||
y: y
|
||||
};
|
||||
};
|
||||
|
||||
// method
|
||||
Point.add = |p1: Point, p2: Point| -> Point {
|
||||
return {
|
||||
x: p1.x + p2.x,
|
||||
y: p1.y + p2.y
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user