cleanup
This commit is contained in:
103
attempt_1/main.c
103
attempt_1/main.c
@@ -84,38 +84,37 @@ global DictEntry dict[256];
|
||||
global U8 dict_count = 0;
|
||||
|
||||
IA_ void scatter(U4 token, const char* anno_str) {
|
||||
if (tape_arena.used + sizeof(U4) <= tape_arena.capacity && anno_arena.used + sizeof(U8) <= anno_arena.capacity) {
|
||||
U4*r ptr = u4_r(tape_arena.start + tape_arena.used);
|
||||
ptr[0] = token;
|
||||
tape_arena.used += sizeof(U4);
|
||||
U8*r aptr = u8_r(anno_arena.start + anno_arena.used);
|
||||
aptr[0] = 0;
|
||||
if (anno_str) {
|
||||
char* dest = (char*)aptr;
|
||||
int i = 0;
|
||||
while(i < 8 && anno_str[i]) {
|
||||
dest[i] = anno_str[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
anno_arena.used += sizeof(U8);
|
||||
if (tape_arena.used + sizeof(U4) <= tape_arena.capacity && anno_arena.used + sizeof(U8) <= anno_arena.capacity) {
|
||||
U4*r ptr = u4_r(tape_arena.start + tape_arena.used);
|
||||
ptr[0] = token;
|
||||
tape_arena.used += sizeof(U4);
|
||||
U8*r aptr = u8_r(anno_arena.start + anno_arena.used);
|
||||
aptr[0] = 0;
|
||||
if (anno_str) {
|
||||
char* dest = (char*)aptr;
|
||||
int i = 0; while(i < 8 && anno_str[i]) {
|
||||
dest[i] = anno_str[i];
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
anno_arena.used += sizeof(U8);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Minimal x86-64 Emitter ---
|
||||
internal void emit8(U1 b) {
|
||||
if (code_arena.used + 1 <= code_arena.capacity) {
|
||||
U1*r ptr = u1_r(code_arena.start + code_arena.used);
|
||||
ptr[0] = b;
|
||||
code_arena.used += 1;
|
||||
}
|
||||
if (code_arena.used + 1 <= code_arena.capacity) {
|
||||
U1*r ptr = u1_r(code_arena.start + code_arena.used);
|
||||
ptr[0] = b;
|
||||
code_arena.used += 1;
|
||||
}
|
||||
}
|
||||
internal void emit32(U4 val) {
|
||||
if (code_arena.used + 4 <= code_arena.capacity) {
|
||||
U4*r ptr = u4_r(code_arena.start + code_arena.used);
|
||||
ptr[0] = val;
|
||||
code_arena.used += 4;
|
||||
}
|
||||
if (code_arena.used + 4 <= code_arena.capacity) {
|
||||
U4*r ptr = u4_r(code_arena.start + code_arena.used);
|
||||
ptr[0] = val;
|
||||
code_arena.used += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal void compile_action(U4 val)
|
||||
@@ -386,7 +385,7 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
|
||||
if (wparam == MS_VK_TAB) {
|
||||
// Cycle Color Tag
|
||||
U4 t = tape_ptr[cursor_idx];
|
||||
U4 t = tape_ptr[cursor_idx];
|
||||
U4 tag = (unpack_tag(t) + 1) % STag_Count;
|
||||
tape_ptr[cursor_idx] = pack_token(tag, unpack_val(t));
|
||||
}
|
||||
@@ -403,7 +402,6 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
if (tape_count > 0) {
|
||||
U8*r anno_ptr = u8_r(anno_arena.start);
|
||||
for (U8 i = delete_idx; i < tape_count - 1; i ++) {
|
||||
@@ -413,30 +411,31 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
tape_arena.used -= sizeof(U4);
|
||||
anno_arena.used -= sizeof(U8);
|
||||
}
|
||||
} else if (wparam == MS_VK_SPACE || wparam == MS_VK_RETURN) {
|
||||
// Insert New Token
|
||||
// Shift: insert AFTER cursor | Regular: insert BEFORE cursor
|
||||
B4 is_shift = (ms_get_async_key_state(MS_VK_SHIFT) & 0x8000) != 0;
|
||||
U8 insert_idx = cursor_idx;
|
||||
if (is_shift) insert_idx ++;
|
||||
}
|
||||
else if (wparam == MS_VK_SPACE || wparam == MS_VK_RETURN) {
|
||||
// Insert New Token
|
||||
// Shift: insert AFTER cursor | Regular: insert BEFORE cursor
|
||||
B4 is_shift = (ms_get_async_key_state(MS_VK_SHIFT) & 0x8000) != 0;
|
||||
U8 insert_idx = cursor_idx;
|
||||
if (is_shift) insert_idx ++;
|
||||
|
||||
if (tape_arena.used + sizeof(U4) <= tape_arena.capacity && anno_arena.used + sizeof(U8) <= anno_arena.capacity) {
|
||||
U8*r anno_ptr = u8_r(anno_arena.start);
|
||||
for (U8 i = tape_count; i > insert_idx; i--) {
|
||||
tape_ptr[i] = tape_ptr[i-1];
|
||||
anno_ptr[i] = anno_ptr[i-1];
|
||||
}
|
||||
if (wparam == MS_VK_RETURN) {
|
||||
tape_ptr[insert_idx] = pack_token(STag_Format, 0xA);
|
||||
anno_ptr[insert_idx] = 0;
|
||||
} else {
|
||||
tape_ptr[insert_idx] = pack_token(STag_Comment, id2(' ',' '));
|
||||
anno_ptr[insert_idx] = 0;
|
||||
}
|
||||
if (is_shift) cursor_idx++;
|
||||
tape_arena.used += sizeof(U4);
|
||||
anno_arena.used += sizeof(U8);
|
||||
if (tape_arena.used + sizeof(U4) <= tape_arena.capacity && anno_arena.used + sizeof(U8) <= anno_arena.capacity) {
|
||||
U8*r anno_ptr = u8_r(anno_arena.start);
|
||||
for (U8 i = tape_count; i > insert_idx; i --) {
|
||||
tape_ptr[i] = tape_ptr[i-1];
|
||||
anno_ptr[i] = anno_ptr[i-1];
|
||||
}
|
||||
if (wparam == MS_VK_RETURN) {
|
||||
tape_ptr[insert_idx] = pack_token(STag_Format, 0xA);
|
||||
anno_ptr[insert_idx] = 0;
|
||||
} else {
|
||||
tape_ptr[insert_idx] = pack_token(STag_Comment, id2(' ',' '));
|
||||
anno_ptr[insert_idx] = 0;
|
||||
}
|
||||
if (is_shift) cursor_idx ++;
|
||||
tape_arena.used += sizeof(U4);
|
||||
anno_arena.used += sizeof(U8);
|
||||
}
|
||||
}
|
||||
|
||||
// Interaction: Reset VM and compile
|
||||
@@ -535,7 +534,7 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
}
|
||||
}
|
||||
else if (unpack_tag(tape_ptr[i]) == STag_Format && unpack_val(tape_ptr[i]) == 0xA) {
|
||||
x = start_x;
|
||||
x = start_x;
|
||||
y += spacing_y;
|
||||
}
|
||||
else {
|
||||
@@ -583,7 +582,7 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
|
||||
ms_set_text_color(hdc, 0x00C8C8C8);
|
||||
ms_text_out_a(hdc, 400, 520, "Global Memory (Contiguous Array):", 33);
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int i=0; i < 4; i ++) {
|
||||
char glob_str[32] = "[0]: 00000000";
|
||||
glob_str[1] = '0' + i;
|
||||
u64_to_hex(vm_globals[i], glob_str + 5, 8);
|
||||
@@ -594,7 +593,7 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam)
|
||||
// Print Log
|
||||
ms_set_text_color(hdc, 0x00C8C8C8);
|
||||
ms_text_out_a(hdc, 750, 520, "Print Log:", 10);
|
||||
for (int i=0; i<log_count && i<4; i++) {
|
||||
for (int i = 0; i<log_count && i < 4; i ++) {
|
||||
char log_str[32] = "00000000";
|
||||
u64_to_hex(log_buffer[i], log_str, 8);
|
||||
ms_set_text_color(hdc, 0x0094BAA1);
|
||||
|
||||
Reference in New Issue
Block a user