mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
fixed typos, added typos checking to CI
This commit is contained in:
parent
960a4fddc5
commit
314503cf7f
43 changed files with 114 additions and 101 deletions
|
@ -42,7 +42,7 @@ fn list_repeat(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
)
|
||||
}
|
||||
```
|
||||
In these builtin definitions you will need to allocate for and list the arguments. For `List.repeat`, the arguments are the `elem_var` and the `len_var`. So in both the `body` and `defn` we list these arguments in a vector, with the `Symobl::ARG_1` adn` Symvol::ARG_2` designating which argument is which.
|
||||
In these builtin definitions you will need to allocate for and list the arguments. For `List.repeat`, the arguments are the `elem_var` and the `len_var`. So in both the `body` and `defn` we list these arguments in a vector, with the `Symobl::ARG_1` and` Symvol::ARG_2` designating which argument is which.
|
||||
|
||||
Since `List.repeat` is implemented entirely as low level functions, its `body` is a `RunLowLevel`, and the `op` is `LowLevel::ListRepeat`. Lets talk about `LowLevel` in the next section.
|
||||
|
||||
|
@ -60,7 +60,7 @@ Its one thing to actually write these functions, its _another_ thing to let the
|
|||
|
||||
## Specifying how we pass args to the function
|
||||
### builtins/mono/src/borrow.rs
|
||||
After we have all of this, we need to specify if the arguements we're passing are owned, borrowed or irrelvant. Towards the bottom of this file, add a new case for you builtin and specify each arg. Be sure to read the comment, as it explains this in more detail.
|
||||
After we have all of this, we need to specify if the arguments we're passing are owned, borrowed or irrelvant. Towards the bottom of this file, add a new case for you builtin and specify each arg. Be sure to read the comment, as it explains this in more detail.
|
||||
|
||||
## Specifying the uniqueness of a function
|
||||
### builtins/src/unique.rs
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
## Adding a bitcode builtin
|
||||
|
||||
To add a builtin:
|
||||
1. Add the function to the relevent module. For `Num` builtin use it in `src/num.zig`, for `Str` builtins use `src/str.zig`, and so on. **For anything you add, you must add tests for it!** Not only does to make the builtins more maintainable, it's the the easiest way to test these functions on Zig. To run the test, run: `zig build test`
|
||||
1. Add the function to the relevant module. For `Num` builtin use it in `src/num.zig`, for `Str` builtins use `src/str.zig`, and so on. **For anything you add, you must add tests for it!** Not only does to make the builtins more maintainable, it's the the easiest way to test these functions on Zig. To run the test, run: `zig build test`
|
||||
2. Make sure the function is public with the `pub` keyword and uses the C calling convention. This is really easy, just add `pub` and `callconv(.C)` to the function declaration like so: `pub fn atan(num: f64) callconv(.C) f64 { ... }`
|
||||
3. In `src/main.zig`, export the function. This is also organized by module. For example, for a `Num` function find the `Num` section and add: `comptime { exportNumFn(num.atan, "atan"); }`. The first arguement is the function, the second is the name of it in LLVM.
|
||||
4. In `compiler/builtins/src/bitcode.rs`, add a constant for the new function. This is how we use it in Rust. Once again, this is organized by module, so just find the relevent area and add your new function.
|
||||
3. In `src/main.zig`, export the function. This is also organized by module. For example, for a `Num` function find the `Num` section and add: `comptime { exportNumFn(num.atan, "atan"); }`. The first argument is the function, the second is the name of it in LLVM.
|
||||
4. In `compiler/builtins/src/bitcode.rs`, add a constant for the new function. This is how we use it in Rust. Once again, this is organized by module, so just find the relevant area and add your new function.
|
||||
5. You can now your function in Rust using `call_bitcode_fn` in `llvm/src/build.rs`!
|
||||
|
||||
## How it works
|
||||
|
@ -32,4 +32,4 @@ There will be two directories like `roc_builtins-[some random characters]`, look
|
|||
|
||||
## Calling bitcode functions
|
||||
|
||||
use the `call_bitcode_fn` function defined in `llvm/src/build.rs` to call bitcode funcitons.
|
||||
use the `call_bitcode_fn` function defined in `llvm/src/build.rs` to call bitcode functions.
|
||||
|
|
|
@ -176,7 +176,7 @@ fn mul_and_decimalize(a: u128, b: u128) i128 {
|
|||
// floor(2^315/10^18) is 66749594872528440074844428317798503581334516323645399060845050244444366430645
|
||||
|
||||
// Add 1.
|
||||
// This can't overflow because the intial numbers are only 127bit due to removing the sign bit.
|
||||
// This can't overflow because the initial numbers are only 127bit due to removing the sign bit.
|
||||
var overflowed = @addWithOverflow(u128, lhs_lo, 1, &lhs_lo);
|
||||
lhs_hi = blk: {
|
||||
if (overflowed) {
|
||||
|
|
|
@ -180,7 +180,7 @@ interface List2
|
|||
## we can free it immediately because there are no other refcounts. However,
|
||||
## in the case of `lists`, we have to iterate through the list and decrement
|
||||
## the refcounts of each of its contained lists - because they, too, have
|
||||
## refcounts! Importantly, beacuse the first element had its refcount incremented
|
||||
## refcounts! Importantly, because the first element had its refcount incremented
|
||||
## because the function returned `first`, that element will actually end up
|
||||
## *not* getting freed at the end - but all the others will be.
|
||||
##
|
||||
|
|
|
@ -318,7 +318,7 @@ Int size : Num [ @Int size ]
|
|||
## >>> coordinates.x + 1
|
||||
##
|
||||
## On the last line, the compiler infers that the `1` in `+ 1` is an #F32
|
||||
## beacuse it's being added to `coordinates.x`, which was defined to be an #F32
|
||||
## because it's being added to `coordinates.x`, which was defined to be an #F32
|
||||
## on the first line.
|
||||
##
|
||||
## Sometimes the compiler has no information about which specific type to pick.
|
||||
|
@ -621,7 +621,7 @@ trunc : Float * -> Int *
|
|||
## Since #Nat has a different maximum number depending on the system you're building
|
||||
## for, this may give a different answer on different systems.
|
||||
##
|
||||
## For example, on a 32-bit sytem, #Num.maxNat will return the same answer as
|
||||
## For example, on a 32-bit system, #Num.maxNat will return the same answer as
|
||||
## #Num.maxU32. This means that calling `Num.toNat 9_000_000_000` on a 32-bit
|
||||
## system will return #Num.maxU32 instead of 9 billion, because 9 billion is
|
||||
## higher than #Num.maxU32 and will not fit in a #Nat on a 32-bit system.
|
||||
|
|
|
@ -194,7 +194,7 @@ startsWith : Str, Str -> Bool
|
|||
## if you want to check whether a string begins with something that's representable
|
||||
## in a single code point, you can use (for example) `Str.startsWithCodePoint '鹏'`
|
||||
## instead of `Str.startsWithCodePoint "鹏"`. ('鹏' evaluates to the [U32]
|
||||
## value `40527`.) This will not work for graphemes which take up mulitple code
|
||||
## value `40527`.) This will not work for graphemes which take up multiple code
|
||||
## points, however; `Str.startsWithCodePoint '👩👩👦👦'` would be a compiler error
|
||||
## because 👩👩👦👦 takes up multiple code points and cannot be represented as a
|
||||
## single [U32]. You'd need to use `Str.startsWithCodePoint "🕊"` instead.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue