Skip to content

Commit

Permalink
Fix import instrutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Aug 25, 2024
1 parent b8ffd50 commit cdb0918
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions site/zig-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ nav_order: 1
```
1. Add Fizz as a dependency in `build.zig`.
```zig
// Create the fizz dependency.
const fizz = b.dependency("fizz", .{
.target = target,
.optimize = optimize,
});
..
// Use it for our executable.
exe.root_module.addImport("fizz", fizz.module("fizz"));
```
1. Create the Fizz virtual machine in your code, for example, `src/main.zig`.
```zig
Expand Down Expand Up @@ -52,29 +58,6 @@ nav_order: 1
try vm.runGc();
```
## Memory Management
Fizz is a garbage collected language. As the program runs, it will allocate
memory as needed. However, when the memory is not needed, it will stick around
until either `Vm.deinit` or `Vm.runGc` has run.
{: .todo}
> Allow Garbage Collector to automatically run when needed.
```zig
const fizz = @import("fizz");
var vm = try fizz.Vm.init(allocator);
// Do stuff
...
// Run GC to free up some memory.
try vm.runGc();
// Run deinit to free all memory.
defer vm.deinit();
```
## Evaluating Expressions
Expressions can be evaluated with `vm.evalStr`. The value of the returned
Expand Down Expand Up @@ -155,6 +138,31 @@ defer allocator.free(result.my_string);
defer allocator.free(result.my_list);
```
## Memory Management
Fizz is a garbage collected language. As the program runs, it will allocate
memory as needed. However, when the memory is not needed, it will stick around
until either `Vm.deinit` or `Vm.runGc` has run.
{: .todo}
> Allow Garbage Collector to automatically run when needed.
> <https://github.com/wmedrano/fizz/issues/4>
```zig
const fizz = @import("fizz");
var vm = try fizz.Vm.init(allocator);
// Do stuff
...
// Run GC to free up some memory.
try vm.runGc();
// Run deinit to free all memory.
defer vm.deinit();
```
## Custom Functions
{: .warning}
Expand Down

0 comments on commit cdb0918

Please sign in to comment.