Compare commits
2 Commits
ed60314841
...
3b02b934d8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b02b934d8 | ||
|
|
d338fabddc |
@@ -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)
|
||||
@@ -47,10 +47,9 @@ typedef double f64;
|
||||
#define CELL_WIDTH (WIDTH / (f64)CELL_ROW_SIZE)
|
||||
#define CELL_HEIGHT (HEIGHT / (f64)CELL_ROW_SIZE)
|
||||
|
||||
#define MUTATION_CHANCE 5000
|
||||
#define MUTATION_OFFSET 1
|
||||
#define MUTATION_CHANCE (SIMULATION_SIZE)
|
||||
|
||||
#define DRAW_PROGRAM_OUTLINE 1
|
||||
#define DRAW_PROGRAM_OUTLINE 0
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
8
src/bf.c
8
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user