updated tlibc

This commit is contained in:
Timerix
2025-11-26 20:56:58 +05:00
parent 5397965319
commit cf724a8d13
19 changed files with 289 additions and 242 deletions

View File

@@ -2,5 +2,6 @@
/// NOP
i32 NOP_impl(VM* vm){
(void)vm;
return 0;
}

View File

@@ -30,6 +30,7 @@ i32 JMP_impl(VM* vm);
i32 JNZ_impl(VM* vm);
i32 JZ_impl(VM* vm);
Array_declare(Instruction);
static const Array(Instruction) instructions_array = ARRAY(Instruction, {
Instruction_construct(NOP),
@@ -63,7 +64,7 @@ static const Array(Instruction) instructions_array = ARRAY(Instruction, {
});
const Instruction* Instruction_getByOpcode(Opcode opcode){
if(opcode >= Array_len(&instructions_array, Instruction))
if((u32)opcode >= instructions_array.len)
return NULL;
return (Instruction*)instructions_array.data + opcode;
@@ -75,7 +76,7 @@ static HashMap(Opcode)* opcode_map = NULL;
static void _opcode_map_construct(){
opcode_map = malloc(sizeof(*opcode_map));
HashMap_construct(opcode_map, Opcode, NULL);
for(u32 i = 0; i < Array_len(&instructions_array, Instruction); i++){
for(u32 i = 0; i < instructions_array.len; i++){
Instruction* instr_ptr = (Instruction*)instructions_array.data + i;
HashMap_tryPush(opcode_map, instr_ptr->name, &instr_ptr->opcode);
}
@@ -87,7 +88,7 @@ const Instruction* Instruction_getByName(str name){
str name_upper = str_toUpper(name);
Opcode* op_ptr = HashMap_tryGetPtr(opcode_map, name_upper);
free(name_upper.data);
str_destroy(name_upper);
if(op_ptr == NULL)
return NULL;
return Instruction_getByOpcode(*op_ptr);

View File

@@ -30,7 +30,7 @@ RegisterCode RegisterCode_parse(str r){
else check_code(dl)
else check_code(dh)
free(lower.data);
str_destroy(lower);
return code;
}
@@ -60,15 +60,15 @@ str RegisterCode_toString(RegisterCode code){
break;
case 4:
buf_str.data += 1;
buf_str.size -= 1;
buf_str.len -= 1;
break;
case 7:
buf_str.data[0] = 'l';
buf_str.size -= 1;
buf_str.len -= 1;
break;
case 8:
buf_str.data[0] = 'h';
buf_str.size -= 1;
buf_str.len -= 1;
break;
}