From 3b02b934d8c0e5334c858381c586046faee9e230 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 20 Mar 2026 03:14:02 +0000 Subject: [PATCH] some cleanup and changes --- src/base.h | 4 ++-- src/bf.c | 8 -------- src/simulation.c | 5 +++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/base.h b/src/base.h index 3cc23c4..dff24a5 100644 --- a/src/base.h +++ b/src/base.h @@ -36,7 +36,7 @@ typedef double f64; // Simulation constants #define SIZEOF_PROGRAM_POW_2 6 #define SIZEOF_PROGRAM (1 << SIZEOF_PROGRAM_POW_2) -#define NUM_PROGRAMS_POW_2 10 +#define NUM_PROGRAMS_POW_2 12 #define NUM_PROGRAMS (1 << NUM_PROGRAMS_POW_2) #define SIMULATION_SIZE (NUM_PROGRAMS * SIZEOF_PROGRAM) @@ -49,7 +49,7 @@ typedef double f64; #define MUTATION_CHANCE (SIMULATION_SIZE) -#define DRAW_PROGRAM_OUTLINE 1 +#define DRAW_PROGRAM_OUTLINE 0 #endif diff --git a/src/bf.c b/src/bf.c index a7d521a..ce86878 100644 --- a/src/bf.c +++ b/src/bf.c @@ -105,10 +105,6 @@ void program_execute(struct ProgramConcat *prg) switch (opcode) { case '<': - // NOTE: We're doing a safe subtraction here, but maybe we should - // terminate execution if subtraction will overflow? - // ctx.head0 = SAFE_SUB(ctx.head0, 1); - ctx.head0 -= 1; ctx.head0 %= sizeof(prg->tape); ++ctx.ip; @@ -118,10 +114,6 @@ void program_execute(struct ProgramConcat *prg) ++ctx.ip; break; case '{': - // NOTE: We're doing a safe subtraction here, but maybe we should - // terminate execution if subtraction will overflow? - // ctx.head1 = SAFE_SUB(ctx.head1, 1); - ctx.head1 -= 1; ctx.head1 %= sizeof(prg->tape); ++ctx.ip; diff --git a/src/simulation.c b/src/simulation.c index 2761fce..a404d72 100644 --- a/src/simulation.c +++ b/src/simulation.c @@ -45,6 +45,7 @@ void simulation_iterate(simulation_t *sim) { a_b_concat = calloc(1, sizeof(*a_b_concat)); } + // Ensure a_b_concat is completely zeroed memset(a_b_concat, 0, sizeof(*a_b_concat)); // Reaction: Concat, execute, split. @@ -155,7 +156,7 @@ void simulation_pick_rng_neighbour(u64 *a, u64 *b) *b = neighbours[rand() % size]; } -static char *VALID_OPS = "<>{}-+.,[]"; +static const char *VALID_OPS = "<>{}-+.,[]"; static const Color possible_colors[] = { ['<'] = {230, 25, 75, 255}, ['>'] = {60, 180, 75, 255}, ['{'] = {255, 225, 25, 255}, ['}'] = {0, 130, 200, 255}, @@ -167,7 +168,7 @@ static const Color possible_colors[] = { Color simulation_cell_color(const bf_token cell) { - return possible_colors[strchr(VALID_OPS, cell) ? cell : '\0']; + return possible_colors[(!!strchr(VALID_OPS, (u8)cell)) * cell]; } /* Copyright (C) 2026 Aryadev Chavali