Skip to content

Commit

Permalink
test visitor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jtenner committed Sep 5, 2024
1 parent f502d59 commit 76bf5bf
Show file tree
Hide file tree
Showing 6 changed files with 1,153 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/builder/types/block_type.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import internal/structure/types.{
type BlockType, type TypeIDX, type ValType, FuncTypeBlockType,
ValTypeBlockType, VoidBlockType,
}

pub const void = VoidBlockType

pub fn val_type(vt: ValType) {
ValTypeBlockType(vt)
}

pub fn func_type(idx: TypeIDX) {
FuncTypeBlockType(idx)
}
10 changes: 9 additions & 1 deletion src/builder/types/rec_type.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import internal/finger_tree
import internal/structure/types.{
type FieldType, type StructType, type SubType, type ValType,
type FieldType, type FuncType, type StructType, type SubType, type ValType,
ArrayCompositeType, ArrayType, FuncCompositeType, FuncType, RecType,
StructCompositeType, StructType, SubType,
}
Expand All @@ -9,6 +9,14 @@ pub fn from_sub_types(sub_types: List(SubType)) {
RecType(sub_types |> finger_tree.from_list)
}

pub fn from_func_type(func_type: FuncType) {
RecType(
finger_tree.from_list([
SubType(True, finger_tree.new(), FuncCompositeType(func_type)),
]),
)
}

pub fn func_type(parameters: List(ValType), results: List(ValType)) {
RecType(
finger_tree.from_list([
Expand Down
328 changes: 328 additions & 0 deletions src/internal/visitor.gleam
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gleam/io
import gleam/list
import gleam/option.{type Option, None, Some}
import gleam/result.{map, try}
Expand Down Expand Up @@ -46,6 +47,333 @@ import internal/structure/types.{
pub type VisitorCallback(ctx, element) =
fn(ctx, element) -> Result(#(ctx, element), String)

pub const empty_visitor = BinaryModuleVisitor(
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
)

pub type BinaryModuleVisitor(ctx) {
BinaryModuleVisitor(
on_enter_module: Option(VisitorCallback(ctx, BinaryModule)),
Expand Down
Loading

0 comments on commit 76bf5bf

Please sign in to comment.