mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Add blank lines around lists
See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md032
This commit is contained in:
parent
e3071a22b0
commit
26a1abfea8
11 changed files with 20 additions and 1 deletions
|
@ -21,6 +21,7 @@ Towards the bottom of `symbol.rs` there is a `define_builtins!` macro being used
|
|||
Some of these have `#` inside their name (`first#list`, `#lt` ..). This is a trick we are doing to hide implementation details from Roc programmers. To a Roc programmer, a name with `#` in it is invalid, because `#` means everything after it is parsed to a comment. We are constructing these functions manually, so we are circumventing the parsing step and dont have such restrictions. We get to make functions and values with `#` which as a consequence are not accessible to Roc programmers. Roc programmers simply cannot reference them.
|
||||
|
||||
But we can use these values and some of these are necessary for implementing builtins. For example, `List.get` returns tags, and it is not easy for us to create tags when composing LLVM. What is easier however, is:
|
||||
|
||||
- ..writing `List.#getUnsafe` that has the dangerous signature of `List elem, Nat -> elem` in LLVM
|
||||
- ..writing `List elem, Nat -> Result elem [OutOfBounds]*` in a type safe way that uses `getUnsafe` internally, only after it checks if the `elem` at `Nat` index exists.
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
## Adding a bitcode builtin
|
||||
|
||||
To add a builtin:
|
||||
|
||||
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 argument is the function, the second is the name of it in LLVM.
|
||||
|
|
|
@ -234,12 +234,14 @@ We implement a few linking operations in the Wasm backend. The most important ar
|
|||
In the host .wasm file, `roc__mainForHost_1_exposed` is defined as a Wasm Import, as if it were an external JavaScript function. But when we link the host and app, we need to make it an internal function instead.
|
||||
|
||||
There are a few important facts to note about the Wasm binary format:
|
||||
|
||||
- Function calls refer to the callee by its function index in the file.
|
||||
- If we move a function from one index to another, all of its call sites need to be updated. So we want to minimise this to make linking fast.
|
||||
- If we _remove_ a function, then all functions above it will implicitly have their indices shifted down by 1! This is not good for speed. We should try to _swap_ rather than remove.
|
||||
- JavaScript imports always get the lower indices.
|
||||
|
||||
With that background, here are the linking steps for a single app function that gets called by the host:
|
||||
|
||||
- Remove `roc__mainForHost_1_exposed` from the imports, updating all call sites to the new index, which is somewhere in the app.
|
||||
- Swap the _last_ JavaScript import into the slot where `roc__mainForHost_1_exposed` was, updating all of its call sites in the host.
|
||||
- Insert an internally-defined dummy function at the index where the last JavaScript import used to be.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue