aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-10-30 14:12:57 +0000
committergingerBill <bill@gingerbill.org>2024-10-30 14:12:57 +0000
commit8a00d85cea02f38164b18d9a7e3e7d710c7a6c40 (patch)
tree67c7f058ddf65e64189d4a76add9d6ad685b366d /src
parent2392300ffbc86b09fde2a4d170b8c38f8ad0d382 (diff)
parentf469bbb0049f618d09dd1dd962389c8306db6bbc (diff)
Merge branch 'master' of https://github.com/odin-lang/Odin
Diffstat (limited to 'src')
-rw-r--r--src/big_int.cpp17
-rw-r--r--src/check_builtin.cpp4
-rw-r--r--src/exact_value.cpp1
-rw-r--r--src/gb/gb.h6
-rw-r--r--src/llvm_backend_expr.cpp2
-rw-r--r--src/llvm_backend_stmt.cpp19
-rw-r--r--src/parser.cpp2
-rw-r--r--src/string.cpp1
-rw-r--r--src/unicode.cpp13
9 files changed, 46 insertions, 19 deletions
diff --git a/src/big_int.cpp b/src/big_int.cpp
index 83235483c..8e476f090 100644
--- a/src/big_int.cpp
+++ b/src/big_int.cpp
@@ -62,6 +62,7 @@ gb_internal void big_int_shl (BigInt *dst, BigInt const *x, BigInt const *y);
gb_internal void big_int_shr (BigInt *dst, BigInt const *x, BigInt const *y);
gb_internal void big_int_mul (BigInt *dst, BigInt const *x, BigInt const *y);
gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y);
+gb_internal void big_int_exp_u64(BigInt *dst, BigInt const *x, u64 y, bool *success);
gb_internal void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q, BigInt *r);
gb_internal void big_int_quo (BigInt *z, BigInt const *x, BigInt const *y);
@@ -250,9 +251,7 @@ gb_internal void big_int_from_string(BigInt *dst, String const &s, bool *success
exp *= 10;
exp += v;
}
- for (u64 x = 0; x < exp; x++) {
- big_int_mul_eq(dst, &b);
- }
+ big_int_exp_u64(dst, &b, exp, success);
}
if (is_negative) {
@@ -328,6 +327,18 @@ gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) {
big_int_dealloc(&d);
}
+gb_internal void big_int_exp_u64(BigInt *dst, BigInt const *x, u64 y, bool *success) {
+ if (y > INT_MAX) {
+ *success = false;
+ return;
+ }
+
+ // Note: The cutoff for square-multiply being faster than the naive
+ // for loop is when exp > 4, but it probably isn't worth adding
+ // a fast path.
+ mp_err err = mp_expt_n(x, int(y), dst);
+ *success = err == MP_OKAY;
+}
gb_internal void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) {
mp_mul(x, y, dst);
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 09e558500..42b9e2180 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -1533,6 +1533,10 @@ gb_internal LoadDirectiveResult check_load_directory_directive(CheckerContext *c
for (FileInfo fi : list) {
LoadFileCache *cache = nullptr;
+ if (fi.is_dir) {
+ continue;
+ }
+
if (cache_load_file_directive(c, call, fi.fullpath, err_on_not_found, &cache, LoadFileTier_Contents, /*use_mutex*/false)) {
array_add(&file_caches, cache);
} else {
diff --git a/src/exact_value.cpp b/src/exact_value.cpp
index 1a42a82a9..5d6016ecc 100644
--- a/src/exact_value.cpp
+++ b/src/exact_value.cpp
@@ -687,6 +687,7 @@ gb_internal void match_exact_values(ExactValue *x, ExactValue *y) {
case ExactValue_String:
case ExactValue_Quaternion:
case ExactValue_Pointer:
+ case ExactValue_Compound:
case ExactValue_Procedure:
case ExactValue_Typeid:
return;
diff --git a/src/gb/gb.h b/src/gb/gb.h
index 1fef4b4f5..f74026c7d 100644
--- a/src/gb/gb.h
+++ b/src/gb/gb.h
@@ -2541,7 +2541,11 @@ gb_inline void const *gb_pointer_add_const(void const *ptr, isize bytes) {
gb_inline void const *gb_pointer_sub_const(void const *ptr, isize bytes) { return cast(void const *)(cast(u8 const *)ptr - bytes); }
gb_inline isize gb_pointer_diff (void const *begin, void const *end) { return cast(isize)(cast(u8 const *)end - cast(u8 const *)begin); }
-gb_inline void gb_zero_size(void *ptr, isize size) { memset(ptr, 0, size); }
+gb_inline void gb_zero_size(void *ptr, isize size) {
+ if (size != 0) {
+ memset(ptr, 0, size);
+ }
+}
#if defined(_MSC_VER) && !defined(__clang__)
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index de7cadaf3..b5f6437a4 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -1647,7 +1647,7 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
lb_emit_store(p, a1, id);
return lb_addr_load(p, res);
} else if (dst->kind == Type_Basic) {
- if (src->Basic.kind == Basic_string && dst->Basic.kind == Basic_cstring) {
+ if (src->kind == Type_Basic && src->Basic.kind == Basic_string && dst->Basic.kind == Basic_cstring) {
String str = lb_get_const_string(m, value);
lbValue res = {};
res.type = t;
diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp
index 288e7206a..06d66ac80 100644
--- a/src/llvm_backend_stmt.cpp
+++ b/src/llvm_backend_stmt.cpp
@@ -2018,14 +2018,7 @@ gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) {
gb_internal void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results) {
lb_ensure_abi_function_type(p->module, p);
- lbValue res = {};
-
- TypeTuple *tuple = &p->type->Proc.results->Tuple;
isize return_count = p->type->Proc.result_count;
- isize res_count = return_results.count;
-
- lbFunctionType *ft = lb_get_function_type(p->module, p->type);
- bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
if (return_count == 0) {
// No return values
@@ -2038,7 +2031,17 @@ gb_internal void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return
LLVMBuildRetVoid(p->builder);
}
return;
- } else if (return_count == 1) {
+ }
+
+ lbValue res = {};
+
+ TypeTuple *tuple = &p->type->Proc.results->Tuple;
+ isize res_count = return_results.count;
+
+ lbFunctionType *ft = lb_get_function_type(p->module, p->type);
+ bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
+
+ if (return_count == 1) {
Entity *e = tuple->variables[0];
if (res_count == 0) {
rw_mutex_shared_lock(&p->module->values_mutex);
diff --git a/src/parser.cpp b/src/parser.cpp
index 4029d49de..9d8b0d231 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4262,8 +4262,6 @@ gb_internal bool allow_field_separator(AstFile *f) {
gb_internal Ast *parse_struct_field_list(AstFile *f, isize *name_count_) {
Token start_token = f->curr_token;
- auto decls = array_make<Ast *>(ast_allocator(f));
-
isize total_name_count = 0;
Ast *params = parse_field_list(f, &total_name_count, FieldFlag_Struct, Token_CloseBrace, false, false);
diff --git a/src/string.cpp b/src/string.cpp
index 3c7d96934..190b69041 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -156,6 +156,7 @@ gb_internal isize string_index_byte(String const &s, u8 x) {
gb_internal gb_inline bool str_eq(String const &a, String const &b) {
if (a.len != b.len) return false;
+ if (a.len == 0) return true;
return memcmp(a.text, b.text, a.len) == 0;
}
gb_internal gb_inline bool str_ne(String const &a, String const &b) { return !str_eq(a, b); }
diff --git a/src/unicode.cpp b/src/unicode.cpp
index 665d5b182..cb9fb12ab 100644
--- a/src/unicode.cpp
+++ b/src/unicode.cpp
@@ -1,10 +1,15 @@
-#pragma warning(push)
-#pragma warning(disable: 4245)
+#if defined(GB_SYSTEM_WINDOWS)
+ #pragma warning(push)
+ #pragma warning(disable: 4245)
+#endif
extern "C" {
#include "utf8proc/utf8proc.c"
}
-#pragma warning(pop)
+
+#if defined(GB_SYSTEM_WINDOWS)
+ #pragma warning(pop)
+#endif
gb_internal bool rune_is_letter(Rune r) {
@@ -109,7 +114,7 @@ gb_internal isize utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out)
u8 b1, b2, b3;
Utf8AcceptRange accept;
if (x >= 0xf0) {
- Rune mask = (cast(Rune)x << 31) >> 31;
+ Rune mask = -cast(Rune)(x & 1);
codepoint = (cast(Rune)s0 & (~mask)) | (GB_RUNE_INVALID & mask);
width = 1;
goto end;