mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +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
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue