11const std = @import ("std" );
22const parse = @import ("parse.zig" );
3+
34pub const HACKER_DIR_SUFFIX = "/.hackeros/hacker-lang" ;
5+
46pub fn deinitParseResult (res : * parse.ParseResult , allocator : std.mem.Allocator ) void {
57 {
68 var it = res .deps .keyIterator ();
@@ -24,6 +26,14 @@ pub fn deinitParseResult(res: *parse.ParseResult, allocator: std.mem.Allocator)
2426 }
2527 res .vars_dict .deinit ();
2628 }
29+ {
30+ var it = res .local_vars .iterator ();
31+ while (it .next ()) | entry | {
32+ allocator .free (entry .key_ptr .* );
33+ allocator .free (entry .value_ptr .* );
34+ }
35+ res .local_vars .deinit ();
36+ }
2737 {
2838 for (res .cmds .items ) | item | {
2939 allocator .free (item );
@@ -43,11 +53,22 @@ pub fn deinitParseResult(res: *parse.ParseResult, allocator: std.mem.Allocator)
4353 res .binaries .deinit ();
4454 }
4555 {
46- for (res .plugins .items ) | item | {
47- allocator .free (item );
56+ for (res .plugins .items ) | p | {
57+ allocator .free (p . path );
4858 }
4959 res .plugins .deinit ();
5060 }
61+ {
62+ var it = res .functions .iterator ();
63+ while (it .next ()) | entry | {
64+ for (entry .value_ptr .items ) | item | {
65+ allocator .free (item );
66+ }
67+ entry .value_ptr .deinit ();
68+ allocator .free (entry .key_ptr .* );
69+ }
70+ res .functions .deinit ();
71+ }
5172 {
5273 for (res .errors .items ) | item | {
5374 allocator .free (item );
@@ -63,15 +84,28 @@ pub fn deinitParseResult(res: *parse.ParseResult, allocator: std.mem.Allocator)
6384 res .config_data .deinit ();
6485 }
6586}
87+
6688pub fn mergeHashMaps (comptime V : type , dest : * std .StringHashMap (V ), src : std .StringHashMap (V ), allocator : std .mem .Allocator ) ! void {
6789 var it = src .iterator ();
6890 while (it .next ()) | entry | {
6991 try dest .put (try allocator .dupe (u8 , entry .key_ptr .* ), entry .value_ptr .* );
7092 }
7193}
94+
7295pub fn mergeStringHashMaps (dest : * std .StringHashMap ([]const u8 ), src : std .StringHashMap ([]const u8 ), allocator : std .mem .Allocator ) ! void {
7396 var it = src .iterator ();
7497 while (it .next ()) | entry | {
7598 try dest .put (try allocator .dupe (u8 , entry .key_ptr .* ), try allocator .dupe (u8 , entry .value_ptr .* ));
7699 }
77100}
101+
102+ pub fn mergeFunctionMaps (dest : * std .StringHashMap (std .ArrayList ([]const u8 )), src : std .StringHashMap (std .ArrayList ([]const u8 )), allocator : std .mem .Allocator ) ! void {
103+ var it = src .iterator ();
104+ while (it .next ()) | entry | {
105+ var new_list = std .ArrayList ([]const u8 ).init (allocator );
106+ for (entry .value_ptr .items ) | item | {
107+ try new_list .append (try allocator .dupe (u8 , item ));
108+ }
109+ try dest .put (try allocator .dupe (u8 , entry .key_ptr .* ), new_list );
110+ }
111+ }
0 commit comments