Skip to content

Commit

Permalink
Remove module implementation. (#17)
Browse files Browse the repository at this point in the history
* Delete modules.
* Remove unused module references.
* Bump to 0.3.0
  • Loading branch information
wmedrano authored Sep 11, 2024
1 parent 0a20002 commit 654cfce
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 698 deletions.
6 changes: 5 additions & 1 deletion site/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ following tradeoffs may happen:

## Releases

### 0.2.1 (Current)
### 0.3.0 (Current)

- Remove modules. Their implementation was too hacky.

### 0.2.1

- Improved performance by interning symbol strings.
- `(define (<name> <arg>...) <expr>...)` syntax available for functions.
Expand Down
13 changes: 1 addition & 12 deletions site/fizz-language-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ nav_order: 2
Values - `(define <name> <value>)`
Functions - `(define (<name> <args...>) <expr>...)`

Define a value within the current module that can be referenced.
Define a value that can be referenced.

```lisp
>> (define x 12)
Expand Down Expand Up @@ -84,17 +84,6 @@ $1 = 10
$2 = 10
```

### \*modules\*

`(*modules*)`

Get all the available modules as a list of strings.

```lisp
>> (modules)
$1 = ("*global*" "my-module.fizz")
```


## Strings

Expand Down
8 changes: 1 addition & 7 deletions site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Zig**.

1. Download Fizz and place it in `build.zig.zon`.
```sh
zig fetch --save https://github.com/wmedrano/fiz/archive/refs/tags/v0.2.1.tar.gz
zig fetch --save https://github.com/wmedrano/fiz/archive/refs/tags/v0.3.0.tar.gz
```
1. Add Fizz as a dependency in `build.zig`.
```zig
Expand Down Expand Up @@ -82,12 +82,6 @@ It should be easy to get started writing Fizz. Fizz supports the following:
> >> (list 1 2 3 4)
> >> (struct 'field "yes" 'the-list (list 1 2 3 4))
> ```
- Module system for code organization.
> ```lisp
> (import "src/my-module.fizz") ;; Import a fizz script as a module.
> (define radius 10)
> (my-module/circle-area radius) ;; Reference values with <filename>/<identifier>.
> ```
### Zig Integration
Expand Down
6 changes: 0 additions & 6 deletions src/Ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ pub const Node = union(enum) {
lambda,
// "define"
define,
// "import"
import,
},
/// A reference to a variable or constant. The name is stored as a string.
identifier: []const u8,
Expand All @@ -132,7 +130,6 @@ pub const Node = union(enum) {
.if_expr => try writer.print("if", .{}),
.lambda => try writer.print("lambda", .{}),
.define => try writer.print("define", .{}),
.import => try writer.print("import", .{}),
},
.identifier => |s| try writer.print("identifier({s})", .{s}),
.string => |s| try writer.print("string({s})", .{s}),
Expand Down Expand Up @@ -160,9 +157,6 @@ pub const Node = union(enum) {
if (std.mem.eql(u8, "define", ident)) {
return .{ .keyword = .define };
}
if (std.mem.eql(u8, "import", ident)) {
return .{ .keyword = .import };
}
if (std.fmt.parseInt(i64, ident, 10)) |i| {
return .{ .int = i };
} else |_| {}
Expand Down
14 changes: 1 addition & 13 deletions src/ByteCode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const Symbol = Val.Symbol;
const Val = @import("val.zig").Val;
const Ir = @import("ir.zig").Ir;
const MemoryManager = @import("MemoryManager.zig");
const Module = @import("Module.zig");

const std = @import("std");
const Allocator = std.mem.Allocator;
Expand All @@ -12,14 +11,11 @@ name: []const u8,
arg_count: usize,
locals_count: usize,
instructions: std.ArrayListUnmanaged(Instruction),
module: *Module,

pub fn deinit(self: *ByteCode, allocator: std.mem.Allocator) void {
allocator.free(self.name);
for (self.instructions.items) |i| {
switch (i) {
.deref_local => |sym| allocator.free(sym.module),
.import_module => |path| allocator.free(path),
else => {},
}
}
Expand Down Expand Up @@ -53,15 +49,13 @@ const ByteCodeValuesIter = struct {
self.instructions.len -= 1;
switch (instruction) {
.push_const => |v| return v,
.deref_local => {},
.deref_global => {},
.get_arg => {},
.define => {},
.move => {},
.eval => {},
.jump => {},
.jump_if => {},
.import_module => {},
.ret => {},
}
}
Expand All @@ -80,9 +74,7 @@ pub fn iterateVals(self: *const ByteCode) ByteCodeValuesIter {
pub const Instruction = union(enum) {
/// Push a constant onto the stack.
push_const: Val,
/// Dereference the symbol from the current module.
deref_local: struct { module: []const u8, sym: Symbol },
/// Dereference the symbol from the global module.
/// Dereference a global symbol.
deref_global: Symbol,
/// Get the nth value (0-based index) from the base of the current function call stack.
get_arg: usize,
Expand All @@ -96,8 +88,6 @@ pub const Instruction = union(enum) {
jump: usize,
/// Jump instructions in the bytecode if the top value of the stack is true.
jump_if: usize,
/// Import a module.
import_module: []const u8,
/// Return the top value of the stack. The following should occur:
/// 1. The top value is the return_value.
/// 2. All items on the current function stack are popped.
Expand All @@ -123,13 +113,11 @@ pub const Instruction = union(enum) {
switch (self.*) {
.push_const => |v| try writer.print("push_const({any})", .{v}),
.deref_global => |sym| try writer.print("deref_global({d})", .{sym.id}),
.deref_local => |sym| try writer.print("deref_local({s}, {d})", .{ sym.module, sym.sym.id }),
.get_arg => |n| try writer.print("get_arg({d})", .{n}),
.move => |n| try writer.print("move({d})", .{n}),
.eval => |n| try writer.print("eval({d})", .{n}),
.jump => |n| try writer.print("jump({d})", .{n}),
.jump_if => |n| try writer.print("jump_if({d})", .{n}),
.import_module => |m| try writer.print("import({s})", .{m}),
.ret => try writer.print("ret()", .{}),
.define => |sym| try writer.print("define({d})", .{sym.id}),
}
Expand Down
Loading

0 comments on commit 654cfce

Please sign in to comment.