diff --git a/CMakeLists.txt b/CMakeLists.txt index c2a1715d2f..aea8901f46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,7 @@ if(MINGW) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args") endif() -set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") +set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") set(EXE_LDFLAGS " ") if(ZIG_TEST_COVERAGE) set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage") @@ -193,6 +193,9 @@ target_link_libraries(zig LINK_PUBLIC ${LLVM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +if(MINGW) + target_link_libraries(zig LINK_PUBLIC version) +endif() install(TARGETS zig DESTINATION bin) install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) diff --git a/src/analyze.cpp b/src/analyze.cpp index 162270ceea..2f586f3a3e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -573,7 +573,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t entry->is_copyable = false; buf_resize(&entry->name, 0); - buf_appendf(&entry->name, "[%" PRIu64 "]%s", array_size, buf_ptr(&child_type->name)); + buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s", array_size, buf_ptr(&child_type->name)); if (!entry->zero_bits) { entry->type_ref = child_type->type_ref ? LLVMArrayType(child_type->type_ref, @@ -2756,7 +2756,7 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari if (param_decl_node && !is_var_args) { param_name = param_decl_node->data.param_decl.name; } else { - param_name = buf_sprintf("arg%zu", i); + param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i); } TypeTableEntry *param_type = param_info->type; @@ -3934,7 +3934,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { { BigNum *bignum = &const_val->data.x_bignum; const char *negative_str = bignum->is_negative ? "-" : ""; - buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint); + buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint); return; } case TypeTableEntryIdMetaType: @@ -3945,7 +3945,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { BigNum *bignum = &const_val->data.x_bignum; assert(bignum->kind == BigNumKindInt); const char *negative_str = bignum->is_negative ? "-" : ""; - buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint); + buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint); } return; case TypeTableEntryIdFloat: @@ -3983,7 +3983,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { return; } case ConstPtrSpecialHardCodedAddr: - buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&type_entry->data.pointer.child_type->name), + buf_appendf(buf, "(&%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->data.pointer.child_type->name), const_val->data.x_ptr.data.hard_coded_addr.addr); return; case ConstPtrSpecialDiscard: @@ -4000,7 +4000,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { case TypeTableEntryIdBlock: { AstNode *node = const_val->data.x_block->source_node; - buf_appendf(buf, "(scope:%zu:%zu)", node->line + 1, node->column + 1); + buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1); return; } case TypeTableEntryIdArray: diff --git a/src/ast_render.cpp b/src/ast_render.cpp index dbf3316353..a1b443986f 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -5,8 +5,9 @@ * See http://opensource.org/licenses/MIT */ -#include "ast_render.hpp" #include "analyze.hpp" +#include "ast_render.hpp" +#include "os.hpp" #include @@ -529,7 +530,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { case BigNumKindInt: { const char *negative_str = node->data.number_literal.bignum->is_negative ? "-" : ""; - fprintf(ar->f, "%s%llu", negative_str, node->data.number_literal.bignum->data.x_uint); + fprintf(ar->f, "%s%" ZIG_PRI_llu, negative_str, node->data.number_literal.bignum->data.x_uint); } break; case BigNumKindFloat: @@ -962,7 +963,7 @@ static void ast_render_tld_fn(AstRender *ar, Buf *name, TldFn *tld_fn) { if (param_info->is_noalias) { fprintf(ar->f, "noalias "); } - Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%zu", i); + Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%" ZIG_PRI_usize "", i); fprintf(ar->f, "%s: %s", buf_ptr(param_name), buf_ptr(¶m_info->type->name)); } if (fn_type_id->return_type->id == TypeTableEntryIdVoid) { diff --git a/src/bignum.cpp b/src/bignum.cpp index bbd1a6c92d..e963b71ba3 100644 --- a/src/bignum.cpp +++ b/src/bignum.cpp @@ -7,6 +7,7 @@ #include "bignum.hpp" #include "buffer.hpp" +#include "os.hpp" #include #include @@ -350,7 +351,7 @@ Buf *bignum_to_buf(BigNum *bn) { return buf_sprintf("%f", bn->data.x_float); } else { const char *neg = bn->is_negative ? "-" : ""; - return buf_sprintf("%s%llu", neg, bn->data.x_uint); + return buf_sprintf("%s%" ZIG_PRI_llu "", neg, bn->data.x_uint); } } diff --git a/src/codegen.cpp b/src/codegen.cpp index aadb6d1a91..eae06df337 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -559,7 +559,7 @@ static LLVMValueRef get_floor_ceil_fn(CodeGen *g, TypeTableEntry *type_entry, Zi } char fn_name[64]; - sprintf(fn_name, "llvm.%s.f%zu", name, type_entry->data.floating.bit_count); + sprintf(fn_name, "llvm.%s.f%" ZIG_PRI_usize "", name, type_entry->data.floating.bit_count); LLVMTypeRef fn_type = LLVMFunctionType(type_entry->type_ref, &type_entry->type_ref, 1, false); LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type); @@ -2166,7 +2166,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru { size_t index = find_asm_index(g, asm_node, asm_token); assert(index < SIZE_MAX); - buf_appendf(&llvm_template, "$%zu", index); + buf_appendf(&llvm_template, "$%" ZIG_PRI_usize "", index); break; } case AsmTokenIdUniqueId: diff --git a/src/errmsg.cpp b/src/errmsg.cpp index 234527d7dc..ef61d09740 100644 --- a/src/errmsg.cpp +++ b/src/errmsg.cpp @@ -30,9 +30,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) { if (err_type == ErrTypeError) { - fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); + fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); } else if (err_type == ErrTypeNote) { - fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); + fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); } else { zig_unreachable(); } @@ -44,9 +44,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) fprintf(stderr, GREEN "^" RESET "\n"); } else { if (err_type == ErrTypeError) { - fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text); + fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": error: %s\n", path, line, col, text); } else if (err_type == ErrTypeNote) { - fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text); + fprintf(stderr, " %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": note: %s\n", path, line, col, text); } else { zig_unreachable(); } diff --git a/src/ir.cpp b/src/ir.cpp index a3d0fc9558..3a22218ee3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3815,7 +3815,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) { add_node_error(irb->codegen, node, - buf_sprintf("expected %zu arguments, found %zu", + buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, builtin_fn->param_count, actual_param_count)); return irb->codegen->invalid_instruction; } @@ -5810,7 +5810,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, render_instance_name_recursive(irb->codegen, name, &fn_entry->fndef_scope->base, irb->exec->begin_scope); buf_appendf(name, ")"); } else { - name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind), + name = buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", container_string(kind), buf_ptr(node->owner->path), node->line + 1, node->column + 1); } } @@ -6681,7 +6681,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru *bbc += 1; if (*bbc > quota) { - ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %zu backwards branches", quota)); + ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", quota)); return false; } return true; @@ -7236,7 +7236,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc uint64_t index = val->data.x_bignum.data.x_uint; if (index == 0 || index >= ira->codegen->error_decls.length) { ir_add_error(ira, source_instr, - buf_sprintf("integer value %" PRIu64 " represents no error", index)); + buf_sprintf("integer value %" ZIG_PRI_u64 " represents no error", index)); return ira->codegen->invalid_instruction; } @@ -8949,7 +8949,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal if (fn_type_id->is_var_args) { if (call_param_count < src_param_count) { ErrorMsg *msg = ir_add_error_node(ira, source_node, - buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count)); + buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count)); if (fn_proto_node) { add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); @@ -8958,7 +8958,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal } } else if (src_param_count != call_param_count) { ErrorMsg *msg = ir_add_error_node(ira, source_node, - buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count)); + buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count)); if (fn_proto_node) { add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); @@ -9784,7 +9784,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc size_t len = end - start; if (index >= len) { ir_add_error(ira, &elem_ptr_instruction->base, - buf_sprintf("index %zu outside argument list of size %zu", index, len)); + buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len)); return ira->codegen->builtin_types.entry_invalid; } size_t abs_index = start + index; @@ -9818,7 +9818,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc uint64_t array_len = array_type->data.array.len; if (index >= array_len) { ir_add_error_node(ira, elem_ptr_instruction->base.source_node, - buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64, + buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, index, array_len)); return ira->codegen->builtin_types.entry_invalid; } @@ -9876,7 +9876,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc } if (new_index >= mem_size) { ir_add_error_node(ira, elem_ptr_instruction->base.source_node, - buf_sprintf("index %" PRIu64 " outside pointer of size %zu", index, old_size)); + buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); return ira->codegen->builtin_types.entry_invalid; } } else if (is_slice(array_type)) { @@ -9885,7 +9885,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc uint64_t slice_len = len_field->data.x_bignum.data.x_uint; if (index >= slice_len) { ir_add_error_node(ira, elem_ptr_instruction->base.source_node, - buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64, + buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, index, slice_len)); return ira->codegen->builtin_types.entry_invalid; } @@ -11986,7 +11986,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; if (ptr_field_index != field->src_index) { ir_add_error(ira, &instruction->base, - buf_sprintf("field '%s' has index %zu but pointer value is index %zu of struct '%s'", + buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", buf_ptr(field->name), field->src_index, ptr_field_index, buf_ptr(&container_type->name))); return ira->codegen->builtin_types.entry_invalid; diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 583e1bcf90..05d8a780cf 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -8,6 +8,7 @@ #include "analyze.hpp" #include "ir.hpp" #include "ir_print.hpp" +#include "os.hpp" struct IrPrint { CodeGen *codegen; @@ -28,7 +29,7 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) { ir_print_indent(irp); const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)"; const char *ref_count = ir_has_side_effects(instruction) ? - "-" : buf_ptr(buf_sprintf("%zu", instruction->ref_count)); + "-" : buf_ptr(buf_sprintf("%" ZIG_PRI_usize "", instruction->ref_count)); fprintf(irp->f, "#%-3zu| %-12s| %-2s| ", instruction->debug_id, type_name, ref_count); } @@ -40,7 +41,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { } static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) { - fprintf(irp->f, "#%zu", instruction->debug_id); + fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id); } static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) { @@ -52,7 +53,7 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) } static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) { - fprintf(irp->f, "$%s_%zu", bb->name_hint, bb->debug_id); + fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id); } static void ir_print_return(IrPrint *irp, IrInstructionReturn *return_instruction) { @@ -245,7 +246,7 @@ static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerIni ir_print_other_instruction(irp, instruction->container_type); fprintf(irp->f, "{"); if (instruction->item_count > 50) { - fprintf(irp->f, "...(%zu items)...", instruction->item_count); + fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count); } else { for (size_t i = 0; i < instruction->item_count; i += 1) { IrInstruction *item = instruction->items[i]; @@ -1194,7 +1195,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) { IrBasicBlock *current_block = executable->basic_block_list.at(bb_i); - fprintf(irp->f, "%s_%zu:\n", current_block->name_hint, current_block->debug_id); + fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id); for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) { IrInstruction *instruction = current_block->instruction_list.at(instr_i); ir_print_instruction(irp, instruction); diff --git a/src/link.cpp b/src/link.cpp index f67b05724a..6d12512a2f 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -184,10 +184,10 @@ static void construct_linker_job_elf(LinkJob *lj) { lj->args.append("-shared"); if (buf_len(&lj->out_file) == 0) { - buf_appendf(&lj->out_file, "lib%s.so.%zu.%zu.%zu", + buf_appendf(&lj->out_file, "lib%s.so.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch); } - soname = buf_sprintf("lib%s.so.%zu", buf_ptr(g->root_out_name), g->version_major); + soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major); } lj->args.append("-o"); diff --git a/src/os.cpp b/src/os.cpp index 8ad4d6639d..ddf01d3393 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -10,7 +10,6 @@ #include "error.hpp" #if defined(_WIN32) -#define ZIG_OS_WINDOWS #if !defined(NOMINMAX) #define NOMINMAX @@ -38,11 +37,18 @@ #endif + #if defined(__MACH__) #include #include #endif +#if defined(ZIG_OS_WINDOWS) +static double win32_time_resolution; +#elif defined(__MACH__) +static clock_serv_t cclock; +#endif + #include #include #include @@ -118,16 +124,24 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) { return os_path_split(full_path, out_dirname, nullptr); } +bool os_is_sep(uint8_t c) { +#if defined(ZIG_OS_WINDOWS) + return c == '\\' || c == '/'; +#else + return c == '/'; +#endif +} + void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) { size_t len = buf_len(full_path); if (len != 0) { size_t last_index = len - 1; - if (buf_ptr(full_path)[last_index] == '/') { + if (os_is_sep(buf_ptr(full_path)[last_index])) { last_index -= 1; } for (size_t i = last_index;;) { uint8_t c = buf_ptr(full_path)[i]; - if (c == '/') { + if (os_is_sep(c)) { if (out_dirname) { buf_init_from_mem(out_dirname, buf_ptr(full_path), i); } @@ -177,7 +191,7 @@ void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname) { void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) { buf_init_from_buf(out_full_path, dirname); uint8_t c = *(buf_ptr(out_full_path) + buf_len(out_full_path) - 1); - if (c != '/') + if (!os_is_sep(c)) buf_append_char(out_full_path, '/'); buf_append_buf(out_full_path, basename); } @@ -214,7 +228,13 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) { bool os_path_is_absolute(Buf *path) { #if defined(ZIG_OS_WINDOWS) -#error "missing os_path_is_absolute implementation" + if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\")) + return true; + + if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':') + return true; + + return false; #elif defined(ZIG_OS_POSIX) return buf_ptr(path)[0] == '/'; #else @@ -258,7 +278,7 @@ int os_file_exists(Buf *full_path, bool *result) { *result = access(buf_ptr(full_path), F_OK) != -1; return 0; #else - zig_panic("TODO implement os_file_exists for non-posix"); + return GetFileAttributes(buf_ptr(full_path)) != INVALID_FILE_ATTRIBUTES; #endif } @@ -465,7 +485,7 @@ static int os_exec_process_windows(const char *exe, ZigList &args, if (!GetExitCodeProcess(piProcInfo.hProcess, &exit_code)) { zig_panic("GetExitCodeProcess failed"); } - term->how == TerminationIdClean; + term->how = TerminationIdClean; term->code = exit_code; CloseHandle(piProcInfo.hProcess); @@ -760,6 +780,18 @@ int os_make_path(Buf *path) { } int os_make_dir(Buf *path) { +#if defined(ZIG_OS_WINDOWS) + if (mkdir(buf_ptr(path)) == -1) { + if (errno == EEXIST) + return ErrorPathAlreadyExists; + if (errno == ENOENT) + return ErrorFileNotFound; + if (errno == EACCES) + return ErrorAccess; + return ErrorUnexpected; + } + return 0; +#else if (mkdir(buf_ptr(path), 0755) == -1) { if (errno == EEXIST) return ErrorPathAlreadyExists; @@ -770,4 +802,19 @@ int os_make_dir(Buf *path) { return ErrorUnexpected; } return 0; +#endif +} + +int zig_os_init(void) { +#if defined(ZIG_OS_WINDOWS) + unsigned __int64 frequency; + if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) { + win32_time_resolution = 1.0 / (double) frequency; + } else { + return ErrorSystemResources; + } +#elif defined(__MACH__) + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); +#endif + return 0; } diff --git a/src/os.hpp b/src/os.hpp index 6e2ed6bf96..f137baebfb 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -61,6 +61,8 @@ int os_file_exists(Buf *full_path, bool *result); int os_rename(Buf *src_path, Buf *dest_path); double os_get_time(void); +bool os_is_sep(uint8_t c); + #if defined(__APPLE__) #define ZIG_OS_DARWIN #elif defined(_WIN32) @@ -77,4 +79,16 @@ double os_get_time(void); #define ZIG_ARCH_UNKNOWN #endif +#if defined(ZIG_OS_WINDOWS) +#define ZIG_PRI_usize "Iu" +#define ZIG_PRI_u64 "I64u" +#define ZIG_PRI_llu "I64u" +#define ZIG_PRI_x64 "I64x" +#else +#define ZIG_PRI_usize "zu" +#define ZIG_PRI_u64 PRIu64 +#define ZIG_PRI_llu "llu" +#define ZIG_PRI_x64 PRIx64 +#endif + #endif diff --git a/src/parseh.cpp b/src/parseh.cpp index f7248a8089..9eb851c01a 100644 --- a/src/parseh.cpp +++ b/src/parseh.cpp @@ -628,7 +628,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) { const ParmVarDecl *param = fn_decl->getParamDecl(i); const char *name = decl_name(param); if (strlen(name) == 0) { - name_buf = buf_sprintf("arg%zu", i); + name_buf = buf_sprintf("arg%" ZIG_PRI_usize "", i); } else { name_buf = buf_create_from_str(name); } diff --git a/src/target.cpp b/src/target.cpp index 3ad232c44d..20508f6b1a 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -529,7 +529,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { } const char *target_o_file_ext(ZigTarget *target) { - if (target->env_type == ZigLLVM_MSVC) { + if (target->env_type == ZigLLVM_MSVC || target->os == ZigLLVM_Win32) { return ".obj"; } else { return ".o"; diff --git a/std/os/path.zig b/std/os/path.zig index fc4ca61ca5..ce767f6bae 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -81,6 +81,9 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { } pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { + if (builtin.os == builtin.Os.windows) { + @compileError("TODO implement os.path.resolve for windows"); + } if (paths.len == 0) return os.getCwd(allocator); @@ -152,6 +155,9 @@ fn testResolve(args: ...) -> []u8 { } pub fn dirname(path: []const u8) -> []const u8 { + if (builtin.os == builtin.Os.windows) { + @compileError("TODO implement os.path.dirname for windows"); + } if (path.len == 0) return path[0..0]; var end_index: usize = path.len - 1; @@ -189,6 +195,9 @@ fn testDirname(input: []const u8, expected_output: []const u8) { } pub fn basename(path: []const u8) -> []const u8 { + if (builtin.os == builtin.Os.windows) { + @compileError("TODO implement os.path.basename for windows"); + } if (path.len == 0) return []u8{}; @@ -231,6 +240,9 @@ fn testBasename(input: []const u8, expected_output: []const u8) { /// resolve to the same path (after calling ::resolve on each), a zero-length /// string is returned. pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { + if (builtin.os == builtin.Os.windows) { + @compileError("TODO implement os.path.relative for windows"); + } const resolved_from = %return resolve(allocator, from); defer allocator.free(resolved_from); @@ -299,6 +311,9 @@ fn testRelative(from: []const u8, to: []const u8, expected_output: []const u8) { /// extra `/` characters in ::pathname. /// Caller must deallocate result. pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { + if (builtin.os == builtin.Os.windows) { + @compileError("TODO implement os.path.real for windows"); + } const fd = %return os.posixOpen(pathname, posix.O_PATH|posix.O_NONBLOCK|posix.O_CLOEXEC, 0, allocator); defer os.posixClose(fd);