diff --git a/src/cmp.rs b/src/cmp.rs index f997ee5e..f9575f06 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -26,7 +26,7 @@ pub fn compile_book(trg: Target, book: &hvm::Book) -> String { for (fid, def) in book.defs.iter().enumerate() { code.push_str(&format!(" case {}: return interact_call_{}(net, tm, a, b);\n", fid, &def.name.replace("/","_").replace(".","_").replace("-","_"))); } - code.push_str(&format!(" default: return FALSE;\n")); + code.push_str(&format!(" default: return false;\n")); code.push_str(&format!(" }}\n")); code.push_str(&format!("}}")); @@ -70,7 +70,7 @@ pub fn compile_def(trg: Target, code: &mut String, book: &hvm::Book, tab: usize, code.push_str(&format!(" || !n{:x}", i)); } code.push_str(&format!(") {{\n")); - code.push_str(&format!("{}return FALSE;\n", indent(tab+2))); + code.push_str(&format!("{}return false;\n", indent(tab+2))); code.push_str(&format!("{}}}\n", indent(tab+1))); for i in 0 .. def.vars { code.push_str(&format!("{}vars_create(net, v{:x}, NONE);\n", indent(tab+1), i)); @@ -79,7 +79,7 @@ pub fn compile_def(trg: Target, code: &mut String, book: &hvm::Book, tab: usize, // Allocs resources (using slow allocator) //code.push_str(&format!("{}// Allocates needed resources.\n", indent(tab+1))); //code.push_str(&format!("{}if (!get_resources(net, tm, {}, {}, {})) {{\n", indent(tab+1), def.rbag.len()+1, def.node.len(), def.vars)); - //code.push_str(&format!("{}return FALSE;\n", indent(tab+2))); + //code.push_str(&format!("{}return false;\n", indent(tab+2))); //code.push_str(&format!("{}}}\n", indent(tab+1))); //for i in 0 .. def.node.len() { //code.push_str(&format!("{}Val n{:x} = tm->nloc[0x{:x}];\n", indent(tab+1), i, i)); @@ -102,7 +102,7 @@ pub fn compile_def(trg: Target, code: &mut String, book: &hvm::Book, tab: usize, } // Return - code.push_str(&format!("{}return TRUE;\n", indent(tab+1))); + code.push_str(&format!("{}return true;\n", indent(tab+1))); code.push_str(&format!("{}}}\n", indent(tab))); } diff --git a/src/hvm.c b/src/hvm.c index 80cee930..8ef9f407 100644 --- a/src/hvm.c +++ b/src/hvm.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -16,15 +17,9 @@ #define INTERPRETED #define WITHOUT_MAIN -// Booleans -#define TRUE 1 -#define FALSE 0 - // Types // -------- -typedef uint8_t bool; - typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -251,7 +246,7 @@ bool get_par_flag(Pair pair) { if (get_tag(p1) == REF) { return (get_val(p1) >> 28) == 1; } else { - return FALSE; + return false; } } @@ -716,7 +711,7 @@ static inline Net* net_new() { // --------- u32 node_alloc_1(Net* net, TM* tm, u32* lps) { - while (TRUE) { + while (true) { u32 lc = tm->tid*(G_NODE_LEN/TPC) + (tm->nput%(G_NODE_LEN/TPC)); Pair elem = net->node_buf[lc]; tm->nput += 1; @@ -729,7 +724,7 @@ u32 node_alloc_1(Net* net, TM* tm, u32* lps) { } u32 vars_alloc_1(Net* net, TM* tm, u32* lps) { - while (TRUE) { + while (true) { u32 lc = tm->tid*(G_NODE_LEN/TPC) + (tm->vput%(G_NODE_LEN/TPC)); Port elem = net->vars_buf[lc]; tm->vput += 1; @@ -816,7 +811,7 @@ static inline Port enter(Net* net, Port var) { // Atomically Links `A ~ B`. static inline void link(Net* net, TM* tm, Port A, Port B) { // Attempts to directionally point `A ~> B` - while (TRUE) { + while (true) { // If `A` is NODE: swap `A` and `B`, and continue if (get_tag(A) != VAR && get_tag(B) == VAR) { Port X = A; A = B; B = X; @@ -858,13 +853,13 @@ static inline bool interact_link(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 1, 0, 0)) { debug("interact_link: get_resources failed\n"); - return FALSE; + return false; } // Links. link_pair(net, tm, new_pair(a, b)); - return TRUE; + return true; } // Declared here for use in call interactions. @@ -887,7 +882,7 @@ static inline bool interact_call(Net* net, TM* tm, Port a, Port b, Book* book) { // Allocates needed nodes and vars. if (!get_resources(net, tm, def->rbag_len + 1, def->node_len, def->vars_len)) { debug("interact_call: get_resources failed\n"); - return FALSE; + return false; } // Stores new vars. @@ -906,13 +901,13 @@ static inline bool interact_call(Net* net, TM* tm, Port a, Port b, Book* book) { } link_pair(net, tm, new_pair(adjust_port(net, tm, def->root), b)); - return TRUE; + return true; } #endif // The Void Interaction. static inline bool interact_void(Net* net, TM* tm, Port a, Port b) { - return TRUE; + return true; } // The Eras Interaction. @@ -920,12 +915,12 @@ static inline bool interact_eras(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 2, 0, 0)) { debug("interact_eras: get_resources failed\n"); - return FALSE; + return false; } // Checks availability if (node_load(net, get_val(b)) == 0) { - return FALSE; + return false; } // Loads ports. @@ -937,7 +932,7 @@ static inline bool interact_eras(Net* net, TM* tm, Port a, Port b) { link_pair(net, tm, new_pair(a, B1)); link_pair(net, tm, new_pair(a, B2)); - return TRUE; + return true; } // The Anni Interaction. @@ -945,12 +940,12 @@ static inline bool interact_anni(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 2, 0, 0)) { debug("interact_anni: get_resources failed\n"); - return FALSE; + return false; } // Checks availability if (node_load(net, get_val(a)) == 0 || node_load(net, get_val(b)) == 0) { - return FALSE; + return false; } // Loads ports. @@ -965,7 +960,7 @@ static inline bool interact_anni(Net* net, TM* tm, Port a, Port b) { link_pair(net, tm, new_pair(A1, B1)); link_pair(net, tm, new_pair(A2, B2)); - return TRUE; + return true; } // The Comm Interaction. @@ -973,12 +968,12 @@ static inline bool interact_comm(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 4, 4, 4)) { debug("interact_comm: get_resources failed\n"); - return FALSE; + return false; } // Checks availability if (node_load(net, get_val(a)) == 0 || node_load(net, get_val(b)) == 0) { - return FALSE; + return false; } // Loads ports. @@ -1007,7 +1002,7 @@ static inline bool interact_comm(Net* net, TM* tm, Port a, Port b) { link_pair(net, tm, new_pair(new_port(get_tag(a), tm->nloc[2]), B1)); link_pair(net, tm, new_pair(new_port(get_tag(a), tm->nloc[3]), B2)); - return TRUE; + return true; } // The Oper Interaction. @@ -1015,12 +1010,12 @@ static inline bool interact_oper(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 1, 1, 0)) { debug("interact_oper: get_resources failed\n"); - return FALSE; + return false; } // Checks availability if (node_load(net, get_val(b)) == 0) { - return FALSE; + return false; } // Loads ports. @@ -1039,7 +1034,7 @@ static inline bool interact_oper(Net* net, TM* tm, Port a, Port b) { link_pair(net, tm, new_pair(B1, new_port(OPR, tm->nloc[0]))); } - return TRUE; + return true; } // The Swit Interaction. @@ -1047,12 +1042,12 @@ static inline bool interact_swit(Net* net, TM* tm, Port a, Port b) { // Allocates needed nodes and vars. if (!get_resources(net, tm, 1, 2, 0)) { debug("interact_swit: get_resources failed\n"); - return FALSE; + return false; } // Checks availability if (node_load(net, get_val(b)) == 0) { - return FALSE; + return false; } // Loads ports. @@ -1071,7 +1066,7 @@ static inline bool interact_swit(Net* net, TM* tm, Port a, Port b) { link_pair(net, tm, new_pair(new_port(CON, tm->nloc[0]), B1)); } - return TRUE; + return true; } // Pops a local redex and performs a single interaction. @@ -1116,14 +1111,14 @@ static inline bool interact(Net* net, TM* tm, Book* book) { // If error, pushes redex back. if (!success) { push_redex(net, tm, redex); - return FALSE; + return false; // Else, increments the interaction count. } else if (rule != LINK) { tm->itrs += 1; } } - return TRUE; + return true; } // Evaluator @@ -1137,14 +1132,14 @@ void evaluator(Net* net, TM* tm, Book* book) { // Performs some interactions u32 tick = 0; bool busy = tm->tid == 0; - while (TRUE) { + while (true) { tick += 1; // If we have redexes... if (rbag_len(net, tm) > 0) { // Update global idle counter if (!busy) atomic_fetch_sub_explicit(&net->idle, 1, memory_order_relaxed); - busy = TRUE; + busy = true; // Perform an interaction #ifdef DEBUG @@ -1156,7 +1151,7 @@ void evaluator(Net* net, TM* tm, Book* book) { } else { // Update global idle counter if (busy) atomic_fetch_add_explicit(&net->idle, 1, memory_order_relaxed); - busy = FALSE; + busy = false; //// Peeks a redex from target u32 sid = (tm->tid - 1) % TPC; @@ -1436,12 +1431,12 @@ bool book_load(Book* book, u32* buf) { if (def->rbag_len > DEF_RBAG_LEN) { fprintf(stderr, "def '%s' has too many redexes: %u\n", def->name, def->rbag_len); - return FALSE; + return false; } if (def->node_len > DEF_NODE_LEN) { fprintf(stderr, "def '%s' has too many nodes: %u\n", def->name, def->node_len); - return FALSE; + return false; } // Reads root @@ -1456,7 +1451,7 @@ bool book_load(Book* book, u32* buf) { buf += def->node_len * 2; } - return TRUE; + return true; } // Debug Printing diff --git a/src/hvm.cu b/src/hvm.cu index 854a36e6..051ede99 100644 --- a/src/hvm.cu +++ b/src/hvm.cu @@ -22,9 +22,6 @@ typedef float f32; typedef double f64; typedef unsigned long long int u64; -#define FALSE false -#define TRUE true - // Configuration // ------------- @@ -1917,12 +1914,12 @@ bool book_load(Book* book, u32* buf) { if (def->rbag_len > L_NODE_LEN/TPB) { fprintf(stderr, "def '%s' has too many redexes: %u\n", def->name, def->rbag_len); - return FALSE; + return false; } if (def->node_len > L_NODE_LEN/TPB) { fprintf(stderr, "def '%s' has too many nodes: %u\n", def->name, def->node_len); - return FALSE; + return false; } // Reads root @@ -1937,7 +1934,7 @@ bool book_load(Book* book, u32* buf) { buf += def->node_len * 2; } - return TRUE; + return true; } // Debug Printing diff --git a/src/hvm.cuh b/src/hvm.cuh index d4c85f70..f4d73ea2 100644 --- a/src/hvm.cuh +++ b/src/hvm.cuh @@ -7,7 +7,6 @@ // Types // ----- -typedef uint8_t bool; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; diff --git a/src/hvm.h b/src/hvm.h index 3aab66b1..b4930e25 100644 --- a/src/hvm.h +++ b/src/hvm.h @@ -3,11 +3,11 @@ #include #include +#include // Types // ----- -typedef uint8_t bool; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; diff --git a/src/run.c b/src/run.c index e5bcd955..b072a1fd 100644 --- a/src/run.c +++ b/src/run.c @@ -65,7 +65,7 @@ Ctr readback_ctr(Net* net, Book* book, Port port) { ctr.tag = get_u24(get_val(arg_port)); // Loads remaining arguments - while (TRUE) { + while (true) { app_port = expand(net, book, get_snd(app_node)); if (get_tag(app_port) != CON) break; app_node = node_load(net, get_val(app_port)); @@ -107,7 +107,7 @@ Bytes readback_bytes(Net* net, Book* book, Port port) { bytes.len = 0; // Readback loop - while (TRUE) { + while (true) { // Normalizes the net normalize(net, book); @@ -590,7 +590,7 @@ void do_run_io(Net* net, Book* book, Port port) { setlinebuf(stderr); // IO loop - while (TRUE) { + while (true) { // Normalizes the net normalize(net, book); diff --git a/src/run.cu b/src/run.cu index 414e0406..3350d9f2 100644 --- a/src/run.cu +++ b/src/run.cu @@ -65,7 +65,7 @@ Ctr gnet_readback_ctr(GNet* gnet, Port port) { ctr.tag = get_u24(get_val(arg_port)); // Loads remaining arguments - while (TRUE) { + while (true) { app_port = gnet_expand(gnet, get_snd(app_node)); if (get_tag(app_port) != CON) break; app_node = gnet_node_load(gnet, get_val(app_port)); @@ -109,7 +109,7 @@ extern "C" Bytes gnet_readback_bytes(GNet* gnet, Port port) { bytes.len = 0; // Readback loop - while (TRUE) { + while (true) { // Normalizes the net gnet_normalize(gnet); @@ -626,7 +626,7 @@ void do_run_io(GNet* gnet, Book* book, Port port) { setlinebuf(stderr); // IO loop - while (TRUE) { + while (true) { // Normalizes the net gnet_normalize(gnet);