Update documentation
This commit is contained in:
parent
20ff72fa72
commit
1182e3688f
@ -7,7 +7,12 @@ motivation to write.
|
|||||||
Documentation is presented in a formal grammar and an example,
|
Documentation is presented in a formal grammar and an example,
|
||||||
syntax-highlighted with Rust, because it's close enough.
|
syntax-highlighted with Rust, because it's close enough.
|
||||||
|
|
||||||
## Syntax
|
## Standard Library
|
||||||
|
|
||||||
|
Reid has a standard library that is referred to as `std` in code. Documentation
|
||||||
|
about importable types and functions can be found [here](./standard_library.md).
|
||||||
|
|
||||||
|
## Syntax and general information
|
||||||
|
|
||||||
Syntax for Reid is very much inspired by rust, and examples of the language can
|
Syntax for Reid is very much inspired by rust, and examples of the language can
|
||||||
be found in the [examples](../examples/)-folder.
|
be found in the [examples](../examples/)-folder.
|
||||||
@ -76,7 +81,7 @@ grammar the syntax for imports is
|
|||||||
<import> :: "import" <ident> "::" <ident> ";"
|
<import> :: "import" <ident> "::" <ident> ";"
|
||||||
```
|
```
|
||||||
|
|
||||||
An example importing the `print`-function from `std` would be
|
An example importing the `print`-function from [`std`](./standard_library.md) would be
|
||||||
``` rust
|
``` rust
|
||||||
import std::print;
|
import std::print;
|
||||||
```
|
```
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# Standard Library
|
# Standard Library
|
||||||
|
|
||||||
### `pub struct String`
|
## Strings
|
||||||
|
|
||||||
|
#### `pub struct String`
|
||||||
|
|
||||||
Editable string value that can be printed and extended
|
Editable string value that can be printed and extended
|
||||||
|
|
||||||
@ -8,38 +10,42 @@ Has the following binops defined:
|
|||||||
- `String` + `*char` = `String`
|
- `String` + `*char` = `String`
|
||||||
- `String` + `u64` = `String`
|
- `String` + `u64` = `String`
|
||||||
|
|
||||||
### `pub fn print(message: String)`
|
#### `pub fn print(message: String)`
|
||||||
|
|
||||||
Prints given `message` to the standard output
|
Prints given `message` to the standard output
|
||||||
|
|
||||||
### `pub fn allocate(size: u64) -> *u8`
|
#### `pub fn new_string() -> String`
|
||||||
|
|
||||||
Unsafely allocates `size` bytes of memory from the stack, and returns a pointer to it, which must be manually freed.
|
|
||||||
|
|
||||||
### `pub fn new_string() -> String`
|
|
||||||
|
|
||||||
Returns a new empty `String`-object, which must later be manually freed.
|
Returns a new empty `String`-object, which must later be manually freed.
|
||||||
|
|
||||||
### `pub fn from_str(string: *char) -> String`
|
#### `pub fn from_str(string: *char) -> String`
|
||||||
|
|
||||||
Creates a new `String`-object containing initially data from the given string-literal which must be later freed.
|
Creates a new `String`-object containing initially data from the given string-literal which must be later freed.
|
||||||
|
|
||||||
### `pub fn set_char(string: &mut String, c: char, position: u64)`
|
#### `pub fn set_char(string: &mut String, c: char, position: u64)`
|
||||||
|
|
||||||
Edits given `string` by setting the character at index `position` to be `c`.
|
Edits given `string` by setting the character at index `position` to be `c`.
|
||||||
|
|
||||||
### `pub fn add_num_to_string(string: &mut String, num: u64)`
|
#### `pub fn add_num_to_string(string: &mut String, num: u64)`
|
||||||
|
|
||||||
Formats the given number into the end of the string.
|
Formats the given number into the end of the string.
|
||||||
|
|
||||||
### `pub fn concat_strings(destination: &mut String, source: String)`
|
#### `pub fn concat_strings(destination: &mut String, source: String)`
|
||||||
|
|
||||||
Concatenates `source` to the end of `destination`.
|
Concatenates `source` to the end of `destination`.
|
||||||
|
|
||||||
### `pub fn clamp(min: f32, max: f32, value: f32) -> f32`
|
## General
|
||||||
|
|
||||||
|
#### `pub fn allocate(size: u64) -> *u8`
|
||||||
|
|
||||||
|
Unsafely allocates `size` bytes of memory from the stack, and returns a pointer to it, which must be manually freed.
|
||||||
|
|
||||||
|
## Maths
|
||||||
|
|
||||||
|
#### `pub fn clamp(min: f32, max: f32, value: f32) -> f32`
|
||||||
|
|
||||||
Returns `value` as clamped between `min` and `max`. Equivalent to `max(min(value, max), min)`
|
Returns `value` as clamped between `min` and `max`. Equivalent to `max(min(value, max), min)`
|
||||||
|
|
||||||
### `pub fn abs(value: f32) -> f32`
|
#### `pub fn abs(value: f32) -> f32`
|
||||||
|
|
||||||
Returns the absolute value of `value`.
|
Returns the absolute value of `value`.
|
Loading…
Reference in New Issue
Block a user