mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Basic Linux Build!
This commit is contained in:
@@ -144,7 +144,7 @@ String odin_root_dir(void) {
|
||||
Array(char) path_buf;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
wchar_t *text;
|
||||
u8 *text;
|
||||
|
||||
if (global_module_path_set) {
|
||||
return global_module_path;
|
||||
@@ -212,11 +212,10 @@ String path_to_fullpath(gbAllocator a, String s) {
|
||||
}
|
||||
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
||||
String path_to_fullpath(gbAllocator a, String s) {
|
||||
char* p = realpath(s.text, 0);
|
||||
// GB_ASSERT(p && "file does not exist");
|
||||
if(!p) return make_string_c("");
|
||||
char *p = realpath(cast(char *)s.text, 0);
|
||||
if(p == NULL) return make_string_c("");
|
||||
|
||||
return make_string(p, strlen(p));
|
||||
return make_string_c(p);
|
||||
}
|
||||
#else
|
||||
#error Implement system
|
||||
|
||||
+17
-11
@@ -580,7 +580,7 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
|
||||
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
|
||||
|
||||
MapEntity entity_map = {0};
|
||||
MapEntity entity_map = {0}; // Key: String
|
||||
map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*variant_count);
|
||||
|
||||
Entity *using_index_expr = NULL;
|
||||
@@ -593,6 +593,12 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
|
||||
|
||||
field_count = check_fields(c, NULL, ut->fields, fields, field_count, str_lit("union"));
|
||||
|
||||
for (isize i = 0; i < field_count; i++) {
|
||||
Entity *f = fields[i];
|
||||
String name = f->token.string;
|
||||
map_entity_set(&entity_map, hash_string(name), f);
|
||||
}
|
||||
|
||||
union_type->Record.fields = fields;
|
||||
union_type->Record.field_count = field_count;
|
||||
|
||||
@@ -2324,10 +2330,10 @@ void check_cast(Checker *c, Operand *x, Type *type) {
|
||||
}
|
||||
}
|
||||
} else if (check_is_castable_to(c, x, type)) {
|
||||
can_convert = true;
|
||||
if (x->mode != Addressing_Constant || is_type_any(type)) {
|
||||
if (x->mode != Addressing_Constant) {
|
||||
x->mode = Addressing_Value;
|
||||
}
|
||||
can_convert = true;
|
||||
}
|
||||
|
||||
if (!can_convert) {
|
||||
@@ -2348,9 +2354,7 @@ void check_cast(Checker *c, Operand *x, Type *type) {
|
||||
if (is_const_expr && !is_type_constant_type(type)) {
|
||||
final_type = default_type(x->type);
|
||||
}
|
||||
if (!is_type_any(final_type)) {
|
||||
update_expr_type(c, x->expr, final_type, true);
|
||||
}
|
||||
update_expr_type(c, x->expr, final_type, true);
|
||||
}
|
||||
|
||||
x->type = type;
|
||||
@@ -5166,10 +5170,15 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
}
|
||||
|
||||
for (; index < elem_count; index++) {
|
||||
GB_ASSERT(cl->elems.e != NULL);
|
||||
AstNode *e = cl->elems.e[index];
|
||||
if (e == NULL) {
|
||||
error_node(node, "Invalid literal element");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e->kind == AstNode_FieldValue) {
|
||||
error_node(e,
|
||||
"`field = value` is only allowed in struct literals");
|
||||
error_node(e, "`field = value` is only allowed in struct literals");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -5351,7 +5360,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
switch (ce->token.kind) {
|
||||
case Token_cast:
|
||||
check_cast(c, o, t);
|
||||
o->expr = node;
|
||||
break;
|
||||
case Token_transmute: {
|
||||
if (o->mode == Addressing_Constant) {
|
||||
@@ -5462,8 +5470,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
default:
|
||||
GB_PANIC("Unknown cast expression");
|
||||
}
|
||||
|
||||
o->expr = node;
|
||||
case_end;
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define GB_IMPLEMENTATION
|
||||
#include "gb/gb.h"
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
gbAllocator heap_allocator(void) {
|
||||
|
||||
+33
-6
@@ -278,6 +278,7 @@ extern "C" {
|
||||
// #include <stdarg.h>
|
||||
#if !defined(GB_SYSTEM_WINDOWS)
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -315,6 +316,10 @@ extern "C" {
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(GB_CPU_X86)
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
@@ -3646,15 +3651,15 @@ gb_inline void *gb_memcopy(void *dest, void const *source, isize n) {
|
||||
#if defined(_MSC_VER)
|
||||
// TODO(bill): Is this good enough?
|
||||
__movsb(cast(u8 *)dest, cast(u8 *)source, n);
|
||||
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
||||
// #elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
||||
// NOTE(zangent): I assume there's a reason this isn't being used elsewhere,
|
||||
// but casting pointers as arguments to an __asm__ call is considered an
|
||||
// error on MacOS and (I think) Linux
|
||||
// TODO(zangent): Figure out how to refactor the asm code so it works on MacOS,
|
||||
// since this is probably not the way the author intended this to work.
|
||||
memcpy(dest, source, n);
|
||||
// memcpy(dest, source, n);
|
||||
#elif defined(GB_CPU_X86)
|
||||
__asm__ __volatile__("rep movsb" : "+D"(cast(u8 *)dest), "+S"(cast(u8 *)source), "+c"(n) : : "memory");
|
||||
__asm__ __volatile__("rep movsb" : "+D"(dest), "+S"(source), "+c"(n) : : "memory");
|
||||
#else
|
||||
u8 *d = cast(u8 *)dest;
|
||||
u8 const *s = cast(u8 const *)source;
|
||||
@@ -4849,6 +4854,26 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
|
||||
case gbAllocation_Resize:
|
||||
ptr = _aligned_realloc(old_memory, size, alignment);
|
||||
break;
|
||||
|
||||
#elif defined(GB_SYSTEM_LINUX)
|
||||
// TODO(bill): *nix version that's decent
|
||||
case gbAllocation_Alloc: {
|
||||
// ptr = aligned_alloc(alignment, size);
|
||||
ptr = malloc(size+alignment);
|
||||
|
||||
if (flags & gbAllocatorFlag_ClearToZero) {
|
||||
gb_zero_size(ptr, size);
|
||||
}
|
||||
} break;
|
||||
|
||||
case gbAllocation_Free: {
|
||||
free(old_memory);
|
||||
} break;
|
||||
|
||||
case gbAllocation_Resize: {
|
||||
ptr = realloc(old_memory, size);
|
||||
// ptr = gb_default_resize_align(gb_heap_allocator(), old_memory, old_size, size, alignment);
|
||||
} break;
|
||||
#else
|
||||
// TODO(bill): *nix version that's decent
|
||||
case gbAllocation_Alloc: {
|
||||
@@ -4864,8 +4889,7 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
|
||||
} break;
|
||||
|
||||
case gbAllocation_Resize: {
|
||||
gbAllocator a = gb_heap_allocator();
|
||||
ptr = gb_default_resize_align(a, old_memory, old_size, size, alignment);
|
||||
ptr = gb_default_resize_align(gb_heap_allocator(), old_memory, old_size, size, alignment);
|
||||
} break;
|
||||
#endif
|
||||
|
||||
@@ -7595,7 +7619,10 @@ gbFileError gb_file_close(gbFile *f) {
|
||||
return gbFileError_Invalid;
|
||||
}
|
||||
|
||||
if (f->filename) gb_free(gb_heap_allocator(), cast(char *)f->filename);
|
||||
//
|
||||
// TODO HACK(bill): Memory Leak!!!
|
||||
// if (f->filename) gb_free(gb_heap_allocator(), cast(char *)f->filename);
|
||||
//
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
if (f->fd.p == INVALID_HANDLE_VALUE) {
|
||||
|
||||
@@ -548,6 +548,8 @@ typedef struct irGen {
|
||||
irModule module;
|
||||
gbFile output_file;
|
||||
bool opt_called;
|
||||
String output_base;
|
||||
String output_name;
|
||||
} irGen;
|
||||
|
||||
|
||||
@@ -6650,9 +6652,13 @@ bool ir_gen_init(irGen *s, Checker *c) {
|
||||
ir_init_module(&s->module, c);
|
||||
// s->module.generate_debug_info = false;
|
||||
|
||||
String init_fullpath = c->parser->init_fullpath;
|
||||
// TODO(bill): generate appropriate output name
|
||||
int pos = cast(int)string_extension_position(c->parser->init_fullpath);
|
||||
gbFileError err = gb_file_create(&s->output_file, gb_bprintf("%.*s.ll", pos, c->parser->init_fullpath.text));
|
||||
int pos = cast(int)string_extension_position(init_fullpath);
|
||||
int dir_pos = cast(int)string_extension_position(init_fullpath);
|
||||
s->output_name = filename_from_path(init_fullpath);
|
||||
s->output_base = make_string(init_fullpath.text, pos);
|
||||
gbFileError err = gb_file_create(&s->output_file, gb_bprintf("%.*s.ll", pos, init_fullpath.text));
|
||||
if (err != gbFileError_None) {
|
||||
return false;
|
||||
}
|
||||
@@ -6792,12 +6798,6 @@ void ir_gen_tree(irGen *s) {
|
||||
} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
|
||||
// Handle later
|
||||
} else if (scope->is_init && e->kind == Entity_Procedure && str_eq(name, str_lit("main"))) {
|
||||
#ifdef GB_SYSTEM_OSX
|
||||
} else if (str_eq(name, str_lit("args")) && str_eq(e->token.pos.file, get_fullpath_core(heap_allocator(), str_lit("os_x.odin")))) {
|
||||
#endif
|
||||
#ifdef GB_SYSTEM_LINUX
|
||||
} else if (str_eq(name, str_lit("args")) && str_eq(e->token.pos.file, get_fullpath_core(heap_allocator(), str_lit("os_linux.odin")))) {
|
||||
#endif
|
||||
} else {
|
||||
name = ir_mangle_name(s, e->token.pos.file, e);
|
||||
}
|
||||
@@ -7227,11 +7227,6 @@ void ir_gen_tree(irGen *s) {
|
||||
tag = ir_emit_conv(proc, ti_ptr, t_type_info_tuple_ptr);
|
||||
irValue *record = ir_emit_struct_ep(proc, tag, 2);
|
||||
|
||||
{
|
||||
irValue *align = ir_const_int(a, type_align_of(a, t));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align);
|
||||
}
|
||||
|
||||
irValue *memory_types = ir_type_info_member_types_offset(proc, t->Tuple.variable_count);
|
||||
irValue *memory_names = ir_type_info_member_names_offset(proc, t->Tuple.variable_count);
|
||||
|
||||
@@ -7261,16 +7256,12 @@ void ir_gen_tree(irGen *s) {
|
||||
irValue *record = ir_emit_struct_ep(proc, tag, 2);
|
||||
|
||||
{
|
||||
irValue *size = ir_const_int(a, type_size_of(a, t));
|
||||
irValue *align = ir_const_int(a, type_align_of(a, t));
|
||||
irValue *packed = ir_const_bool(a, t->Record.is_packed);
|
||||
irValue *ordered = ir_const_bool(a, t->Record.is_ordered);
|
||||
irValue *custom_align = ir_const_bool(a, t->Record.custom_align);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), size);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 5), packed);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 6), ordered);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 7), custom_align);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), packed);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), ordered);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 5), custom_align);
|
||||
}
|
||||
|
||||
irValue *memory_types = ir_type_info_member_types_offset(proc, t->Record.field_count);
|
||||
@@ -7375,13 +7366,6 @@ void ir_gen_tree(irGen *s) {
|
||||
tag = ir_emit_conv(proc, ti_ptr, t_type_info_raw_union_ptr);
|
||||
irValue *record = ir_emit_struct_ep(proc, tag, 2);
|
||||
|
||||
{
|
||||
irValue *size = ir_const_int(a, type_size_of(a, t));
|
||||
irValue *align = ir_const_int(a, type_align_of(a, t));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), size);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align);
|
||||
}
|
||||
|
||||
irValue *memory_types = ir_type_info_member_types_offset(proc, t->Record.field_count);
|
||||
irValue *memory_names = ir_type_info_member_names_offset(proc, t->Record.field_count);
|
||||
irValue *memory_offsets = ir_type_info_member_offsets_offset(proc, t->Record.field_count);
|
||||
|
||||
+6
-3
@@ -1386,7 +1386,8 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
|
||||
|
||||
void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
|
||||
|
||||
#ifndef GB_SYSTEM_WINDOWS
|
||||
// #ifndef GB_SYSTEM_WINDOWS
|
||||
#if 0
|
||||
bool is_main_proc = proc->parent == NULL && str_eq(proc->name, str_lit("main"));
|
||||
|
||||
AstFile fake_file;
|
||||
@@ -1541,8 +1542,9 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
|
||||
|
||||
ir_fprintf(f, " ");
|
||||
|
||||
#ifndef GB_SYSTEM_WINDOWS
|
||||
if(uses_args)
|
||||
// #ifndef GB_SYSTEM_WINDOWS
|
||||
#if 0
|
||||
if(uses_args)
|
||||
ir_fprintf(f, "@.nix_argpatch_main");
|
||||
else
|
||||
#endif
|
||||
@@ -1713,6 +1715,7 @@ void print_llvm_ir(irGen *ir) {
|
||||
if (scope != NULL) {
|
||||
// TODO(bill): Fix this rule. What should it be?
|
||||
in_global_scope = scope->is_global || scope->is_init;
|
||||
// in_global_scope = value->Global.name_is_not_mangled;
|
||||
}
|
||||
|
||||
ir_print_encoded_global(f, ir_get_global_name(m, v), in_global_scope);
|
||||
|
||||
+15
-15
@@ -107,7 +107,7 @@ i32 system_exec_command_line_app(char *name, bool is_silent, char *fmt, ...) {
|
||||
// }
|
||||
|
||||
// exit_code = status;
|
||||
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
#endif
|
||||
@@ -249,9 +249,9 @@ int main(int argc, char **argv) {
|
||||
#if 1
|
||||
timings_start_section(&timings, str_lit("llvm-opt"));
|
||||
|
||||
char const *output_name = ir_gen.output_file.filename;
|
||||
isize base_name_len = gb_path_extension(output_name)-1 - output_name;
|
||||
String output = make_string(cast(u8 *)output_name, base_name_len);
|
||||
String output_name = ir_gen.output_name;
|
||||
String output_base = ir_gen.output_base;
|
||||
int base_name_len = output_base.len;
|
||||
|
||||
i32 optimization_level = 0;
|
||||
optimization_level = gb_clamp(optimization_level, 0, 3);
|
||||
@@ -261,7 +261,7 @@ int main(int argc, char **argv) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
// For more passes arguments: http://llvm.org/docs/Passes.html
|
||||
exit_code = system_exec_command_line_app("llvm-opt", false,
|
||||
"\"%.*sbin/opt\" \"%s\" -o \"%.*s\".bc "
|
||||
"\"%.*sbin/opt\" \"%.*s\".ll -o \"%.*s\".bc "
|
||||
"-mem2reg "
|
||||
"-memcpyopt "
|
||||
"-die "
|
||||
@@ -270,7 +270,7 @@ int main(int argc, char **argv) {
|
||||
// "-S "
|
||||
"",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
output_name, LIT(output));
|
||||
LIT(output_base), LIT(output_base));
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ int main(int argc, char **argv) {
|
||||
// NOTE(zangent): This is separate because it seems that LLVM tools are packaged
|
||||
// with the Windows version, while they will be system-provided on MacOS and GNU/Linux
|
||||
exit_code = system_exec_command_line_app("llvm-opt", false,
|
||||
"opt \"%s\" -o \"%.*s\".bc "
|
||||
"opt \"%.*s\".ll -o \"%.*s\".bc "
|
||||
"-mem2reg "
|
||||
"-memcpyopt "
|
||||
"-die "
|
||||
@@ -292,7 +292,7 @@ int main(int argc, char **argv) {
|
||||
// "-dce "
|
||||
// "-S "
|
||||
"",
|
||||
output_name, LIT(output));
|
||||
LIT(output_base), LIT(output_base));
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
}
|
||||
@@ -307,7 +307,7 @@ int main(int argc, char **argv) {
|
||||
// "-debug-pass=Arguments "
|
||||
"",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output),
|
||||
LIT(output_base),
|
||||
optimization_level,
|
||||
LIT(build_context.llc_flags));
|
||||
if (exit_code != 0) {
|
||||
@@ -343,7 +343,7 @@ int main(int argc, char **argv) {
|
||||
" %.*s "
|
||||
" %s "
|
||||
"",
|
||||
LIT(output), LIT(output), output_ext,
|
||||
LIT(output_base), LIT(output_base), output_ext,
|
||||
lib_str, LIT(build_context.link_flags),
|
||||
link_settings
|
||||
);
|
||||
@@ -354,7 +354,7 @@ int main(int argc, char **argv) {
|
||||
// timings_print_all(&timings);
|
||||
|
||||
if (run_output) {
|
||||
system_exec_command_line_app("odin run", false, "%.*s.exe", cast(int)base_name_len, output_name);
|
||||
system_exec_command_line_app("odin run", false, "%.*s.exe", LIT(output_base));
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -369,7 +369,7 @@ int main(int argc, char **argv) {
|
||||
"%.*s "
|
||||
// "-debug-pass=Arguments "
|
||||
"",
|
||||
LIT(output),
|
||||
LIT(output_base),
|
||||
optimization_level,
|
||||
LIT(build_context.llc_flags));
|
||||
if (exit_code != 0) {
|
||||
@@ -430,7 +430,7 @@ int main(int argc, char **argv) {
|
||||
// It probably has to do with including the entire CRT, but
|
||||
// that's quite a complicated issue to solve while remaining distro-agnostic.
|
||||
// Clang can figure out linker flags for us, and that's good enough _for now_.
|
||||
linker = "clang";
|
||||
linker = "clang -Wno-unused-command-line-argument";
|
||||
#endif
|
||||
|
||||
exit_code = system_exec_command_line_app("ld-link", true,
|
||||
@@ -446,7 +446,7 @@ int main(int argc, char **argv) {
|
||||
// This points the linker to where the entry point is
|
||||
" -e _main "
|
||||
#endif
|
||||
, linker, LIT(output), LIT(output), output_ext,
|
||||
, linker, LIT(output_base), LIT(output_base), output_ext,
|
||||
lib_str, LIT(build_context.link_flags),
|
||||
link_settings
|
||||
);
|
||||
@@ -457,7 +457,7 @@ int main(int argc, char **argv) {
|
||||
// timings_print_all(&timings);
|
||||
|
||||
if (run_output) {
|
||||
system_exec_command_line_app("odin run", false, "%.*s", cast(int)base_name_len, output_name);
|
||||
system_exec_command_line_app("odin run", false, "%.*s", LIT(output_base));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1916,9 +1916,9 @@ void ssa_print_exact_value(gbFile *f, ssaValue *v) {
|
||||
break;
|
||||
case ExactValue_Integer:
|
||||
if (is_type_unsigned(t)) {
|
||||
gb_fprintf(f, " [%llu]", ev.value_integer);
|
||||
gb_fprintf(f, " [%llu]", cast(unsigned long long)ev.value_integer);
|
||||
} else {
|
||||
gb_fprintf(f, " [%lld]", ev.value_integer);
|
||||
gb_fprintf(f, " [%lld]", cast(long long)ev.value_integer);
|
||||
}
|
||||
break;
|
||||
case ExactValue_Float:
|
||||
@@ -1929,7 +1929,7 @@ void ssa_print_exact_value(gbFile *f, ssaValue *v) {
|
||||
} else if (is_type_f64(t)) {
|
||||
f64 fp = cast(f64)ev.value_float;
|
||||
u64 x = *cast(u64 *)&fp;
|
||||
gb_fprintf(f, " [0x%llx]", x);
|
||||
gb_fprintf(f, " [0x%llx]", cast(unsigned long long)x);
|
||||
} else {
|
||||
GB_PANIC("unhandled integer");
|
||||
}
|
||||
@@ -1938,7 +1938,7 @@ void ssa_print_exact_value(gbFile *f, ssaValue *v) {
|
||||
gb_fprintf(f, " [%.*s]", LIT(ev.value_string));
|
||||
break;
|
||||
case ExactValue_Pointer:
|
||||
gb_fprintf(f, " [0x%llx]", ev.value_pointer);
|
||||
gb_fprintf(f, " [0x%llx]", cast(unsigned long long)cast(uintptr)ev.value_pointer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -188,6 +188,22 @@ bool string_contains_char(String s, u8 c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String filename_from_path(String s) {
|
||||
isize i = string_extension_position(s);
|
||||
if (i > 0) {
|
||||
isize j = 0;
|
||||
s.len = i;
|
||||
for (j = i-1; j >= 0; j--) {
|
||||
if (s.text[j] == '/' ||
|
||||
s.text[j] == '\\') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
s.text += j+1;
|
||||
s.len = i-j-1;
|
||||
}
|
||||
return make_string(NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -207,7 +223,7 @@ bool string_contains_char(String s, u8 c) {
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
int convert_multibyte_to_widechar(char *multibyte_input, int input_length, wchar_t *output, int output_size) {
|
||||
int convert_multibyte_to_widechar(char *multibyte_input, usize input_length, wchar_t *output, usize output_size) {
|
||||
iconv_t conv = iconv_open("WCHAR_T", "UTF-8");
|
||||
size_t result = iconv(conv, cast(char **)&multibyte_input, &input_length, cast(char **)&output, &output_size);
|
||||
iconv_close(conv);
|
||||
@@ -215,7 +231,7 @@ bool string_contains_char(String s, u8 c) {
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
int convert_widechar_to_multibyte(wchar_t* widechar_input, int input_length, char* output, int output_size) {
|
||||
int convert_widechar_to_multibyte(wchar_t* widechar_input, usize input_length, char* output, usize output_size) {
|
||||
iconv_t conv = iconv_open("UTF-8", "WCHAR_T");
|
||||
size_t result = iconv(conv, (char**) &widechar_input, &input_length, (char**) &output, &output_size);
|
||||
iconv_close(conv);
|
||||
|
||||
+1
-1
@@ -414,7 +414,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) {
|
||||
TokenizerInitError err = TokenizerInit_None;
|
||||
|
||||
char *c_str = gb_alloc_array(heap_allocator(), char, fullpath.len+1);
|
||||
memcpy(c_str, fullpath.text, fullpath.len);
|
||||
gb_memcopy(c_str, fullpath.text, fullpath.len);
|
||||
c_str[fullpath.len] = '\0';
|
||||
|
||||
// TODO(bill): Memory map rather than copy contents
|
||||
|
||||
+3
-3
@@ -2058,12 +2058,12 @@ gbString write_type_to_string(gbString str, Type *type) {
|
||||
break;
|
||||
|
||||
case Type_Array:
|
||||
str = gb_string_appendc(str, gb_bprintf("[%lld]", type->Array.count));
|
||||
str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count));
|
||||
str = write_type_to_string(str, type->Array.elem);
|
||||
break;
|
||||
|
||||
case Type_Vector:
|
||||
str = gb_string_appendc(str, gb_bprintf("[vector %lld]", type->Vector.count));
|
||||
str = gb_string_appendc(str, gb_bprintf("[vector %d]", cast(int)type->Vector.count));
|
||||
str = write_type_to_string(str, type->Vector.elem);
|
||||
break;
|
||||
|
||||
@@ -2177,7 +2177,7 @@ gbString write_type_to_string(gbString str, Type *type) {
|
||||
case Type_Map: {
|
||||
str = gb_string_appendc(str, "map[");
|
||||
if (type->Map.count > 0) {
|
||||
str = gb_string_appendc(str, gb_bprintf("%lld, ", type->Map.count));
|
||||
str = gb_string_appendc(str, gb_bprintf("%d, ", cast(int)type->Map.count));
|
||||
}
|
||||
str = write_type_to_string(str, type->Map.key);
|
||||
str = gb_string_appendc(str, "]");
|
||||
|
||||
Reference in New Issue
Block a user