diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-04 17:06:09 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-04 17:06:09 -0400 |
| commit | 0b8074154e2671691050bdb3bcb33245625a056c (patch) | |
| tree | 1410e0c4e05c6372e876cd08f16d117e12868f41 /examples/tomodeps | |
| parent | fadcb45baf1274e06cfe37b87655b9146aa52874 (diff) | |
First working compile of refactor to add explicit typing to declarations
and support untyped empty collections and `none`s
Diffstat (limited to 'examples/tomodeps')
| -rw-r--r-- | examples/tomodeps/tomodeps.tm | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm index 96838a66..8da64eb2 100644 --- a/examples/tomodeps/tomodeps.tm +++ b/examples/tomodeps/tomodeps.tm @@ -14,9 +14,9 @@ enum Dependency(File(path:Path), Module(name:Text)) func _get_file_dependencies(file:Path -> {Dependency}): if not file:is_file(): !! Could not read file: $file - return {:Dependency} + return {} - deps := @{:Dependency} + deps : @{Dependency} = @{} if lines := file:by_line(): for line in lines: if line:matches_pattern($Pat/use {..}.tm/): @@ -30,14 +30,14 @@ func _get_file_dependencies(file:Path -> {Dependency}): func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependency}}): return if dependencies:has(dep) - dependencies[dep] = {:Dependency} # Placeholder + dependencies[dep] = {} # Placeholder dep_deps := when dep is File(path): _get_file_dependencies(path) is Module(module): dir := (~/.local/share/tomo/installed/$module) - module_deps := @{:Dependency} - visited := @{:Path} + module_deps : @{Dependency} = @{} + visited : @{Path} = @{} unvisited := @{f:resolved() for f in dir:files() if f:extension() == ".tm"} while unvisited.length > 0: file := unvisited.items[-1] @@ -58,7 +58,7 @@ func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependen _build_dependency_graph(dep2, dependencies) func get_dependency_graph(dep:Dependency -> {Dependency,{Dependency}}): - graph := @{:Dependency,{Dependency}} + graph : @{Dependency={Dependency}} = @{} _build_dependency_graph(dep, graph) return graph @@ -82,16 +82,16 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_ child_prefix := prefix ++ (if is_last: " " else: "│ ") - children := dependencies[dep] or {:Dependency} + children := dependencies[dep] or {} for i,child in children.items: is_child_last := (i == children.length) _draw_tree(child, dependencies, already_printed, child_prefix, is_child_last) func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}): - printed := @{:Dependency} + printed : @{Dependency} = @{} say(_printable_name(dep)) printed:add(dep) - deps := dependencies[dep] or {:Dependency} + deps := dependencies[dep] or {} for i,child in deps.items: is_child_last := (i == deps.length) _draw_tree(child, dependencies, already_printed=printed, is_last=is_child_last) |
