Skip to content

Commit

Permalink
add --no-run option
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchen committed Feb 7, 2025
1 parent 0388910 commit 90076e8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/std/collections/hashmap.c3
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ fn Key[] HashMap.copy_keys(&map, Allocator allocator = allocator::heap())
{
while (entry)
{
$if COPY_KEYS:
list[index++] = entry.key.copy(allocator);
$else
//$if COPY_KEYS:
// list[index++] = entry.key.copy(allocator);
//$else
list[index++] = entry.key;
$endif
//$endif
entry = entry.next;
}
}
Expand Down Expand Up @@ -419,9 +419,9 @@ fn HashMapKeyIterator HashMap.key_iter(&self)

fn void HashMap.add_entry(&map, uint hash, Key key, Value value, uint bucket_index) @private
{
$if COPY_KEYS:
key = key.copy(map.allocator);
$endif
//$if COPY_KEYS:
//key = key.copy(map.allocator);
//$endif
Entry* entry = allocator::new(map.allocator, Entry, { .hash = hash, .key = key, .value = value, .next = map.table[bucket_index] });
map.table[bucket_index] = entry;
if (map.count++ >= map.threshold)
Expand Down Expand Up @@ -531,19 +531,19 @@ fn bool HashMap.remove_entry_for_key(&map, Key key) @private
fn void HashMap.create_entry(&map, uint hash, Key key, Value value, int bucket_index) @private
{
Entry *e = map.table[bucket_index];
$if COPY_KEYS:
key = key.copy(map.allocator);
$endif
//$if COPY_KEYS:
//key = key.copy(map.allocator);
//$endif
Entry* entry = allocator::new(map.allocator, Entry, { .hash = hash, .key = key, .value = value, .next = map.table[bucket_index] });
map.table[bucket_index] = entry;
map.count++;
}

fn void HashMap.free_entry(&self, Entry *entry) @local
{
$if COPY_KEYS:
allocator::free(self.allocator, entry.key);
$endif
//$if COPY_KEYS:
//allocator::free(self.allocator, entry.key);
//$endif
self.free_internal(entry);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/std/encoding/json.c3
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn Object*! parse_map(JsonContext* context) @local
temp_key.append(string);
parse_expected(context, COLON)!;
Object* element = parse_any(context)!;
map.set(temp_key.str_view(), element);
map.set(temp_key.copy_str(context.allocator), element);
token = advance(context)!;
if (token == JsonTokenType.COMMA)
{
Expand Down
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Improve error message when using ',' in struct declarations. #1920
- Compile time array assign ops, e.g. `$c[1] += 3` #1890.
- Add `inline` to enums #1819.
- Add flag `--no-run`. For commands which may run executable after building, skip the run step. #1931

### Fixes
- Fix issue requiring prefix on a generic interface declaration.
Expand Down
1 change: 1 addition & 0 deletions src/build/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ typedef struct BuildOptions_
bool print_output;
bool print_input;
bool run_once;
bool no_run;
int verbosity_level;
const char *panicfn;
const char *benchfn;
Expand Down
6 changes: 6 additions & 0 deletions src/build/build_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static void usage(bool full)
print_opt("--template <template>", "Select template for 'init': \"exe\", \"static-lib\", \"dynamic-lib\" or a path.");
print_opt("--symtab <value>", "Sets the preferred symtab size.");
print_opt("--run-once", "After running the output file, delete it immediately.");
print_opt("--no-run", "For commands which may run executable after building, skip the run step");
print_opt("--trust=<option>", "Trust level: none (default), include ($include allowed), full ($exec / exec allowed).");
print_opt("--output-dir <dir>", "Override general output directory.");
print_opt("--build-dir <dir>", "Override build output directory.");
Expand Down Expand Up @@ -1229,6 +1230,11 @@ static void parse_option(BuildOptions *options)
options->testing = true;
return;
}
if (match_longopt("no-run"))
{
options->no_run = true;
return;
}
if (match_longopt("help"))
{
usage(true);
Expand Down
5 changes: 5 additions & 0 deletions src/build/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
break;
}

if (options->no_run)
{
target->run_after_compile = false;
}

switch (options->command)
{
case COMMAND_BUILD:
Expand Down
Empty file added testing
Empty file.

0 comments on commit 90076e8

Please sign in to comment.