summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/ast.h2
-rw-r--r--src/codegen/codegen.c2
-rw-r--r--src/parser/parser_expr.c14
-rw-r--r--std/core.zc2
-rw-r--r--std/map.zc3
-rw-r--r--std/set.zc3
-rw-r--r--std/time.zc9
7 files changed, 21 insertions, 14 deletions
diff --git a/src/ast/ast.h b/src/ast/ast.h
index e22b35c..8c5bff4 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -311,7 +311,7 @@ struct ASTNode
struct
{
int type_kind;
- int int_val;
+ unsigned long long int_val;
double float_val;
char *string_val;
} literal;
diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c
index 17b0816..eef1057 100644
--- a/src/codegen/codegen.c
+++ b/src/codegen/codegen.c
@@ -494,7 +494,7 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out)
else
{
- fprintf(out, "%d", node->literal.int_val);
+ fprintf(out, "%lluULL", (unsigned long long)node->literal.int_val);
}
break;
case NODE_EXPR_CALL:
diff --git a/src/parser/parser_expr.c b/src/parser/parser_expr.c
index 93a50e2..f7af80f 100644
--- a/src/parser/parser_expr.c
+++ b/src/parser/parser_expr.c
@@ -918,22 +918,16 @@ ASTNode *parse_primary(ParserContext *ctx, Lexer *l)
node->literal.type_kind = 0;
node->type_info = type_new(TYPE_INT);
char *s = token_strdup(t);
- long long val;
+ unsigned long long val;
if (t.len > 2 && s[0] == '0' && s[1] == 'b')
{
- val = strtoll(s + 2, NULL, 2);
+ val = strtoull(s + 2, NULL, 2);
}
else
{
- val = strtoll(s, NULL, 0);
+ val = strtoull(s, NULL, 0);
}
-
- if (val > 2147483647LL || val < -2147483648LL)
- {
- warn_integer_overflow(t, "int", val);
- }
-
- node->literal.int_val = (int)val;
+ node->literal.int_val = (unsigned long long)val;
free(s);
}
else if (t.type == TOK_FLOAT)
diff --git a/std/core.zc b/std/core.zc
index daf6a96..bfa82ea 100644
--- a/std/core.zc
+++ b/std/core.zc
@@ -4,3 +4,5 @@ include <string.h>
include <stdio.h>
include <stdbool.h>
include <stdarg.h>
+
+var __zen_hash_seed: usize = 14695981039346656037; \ No newline at end of file
diff --git a/std/map.zc b/std/map.zc
index cd54f3d..a7bae69 100644
--- a/std/map.zc
+++ b/std/map.zc
@@ -3,8 +3,9 @@ import "./core.zc"
import "./option.zc"
raw {
+ extern size_t __zen_hash_seed;
size_t _map_hash_str(const char* str) {
- size_t hash = 14695981039346656037UL;
+ size_t hash = __zen_hash_seed;
while (*str) {
hash ^= (unsigned char)*str++;
hash *= 1099511628211UL;
diff --git a/std/set.zc b/std/set.zc
index b5a2e58..1de43ac 100644
--- a/std/set.zc
+++ b/std/set.zc
@@ -3,8 +3,9 @@ import "./core.zc"
import "./option.zc"
raw {
+ extern size_t __zen_hash_seed;
size_t _set_hash(const void* data, size_t len) {
- size_t hash = 14695981039346656037UL;
+ size_t hash = __zen_hash_seed;
const unsigned char* bytes = (const unsigned char*)data;
for (size_t i = 0; i < len; i++) {
hash ^= bytes[i];
diff --git a/std/time.zc b/std/time.zc
index 72e611a..1191821 100644
--- a/std/time.zc
+++ b/std/time.zc
@@ -29,7 +29,16 @@ impl Duration {
struct Time {}
+extern size_t __zen_hash_seed;
+
impl Time {
+ fn randomize_hash() {
+ raw {
+ srand(time(NULL));
+ __zen_hash_seed ^= (size_t)rand();
+ }
+ }
+
fn now() -> U64 {
return _time_now_impl();
}