package core
-#private
-seed := 8675309
+#private_file seed := 8675309
+
+#private_file RANDOM_MULTIPLIER :: 1664525
+#private_file RANDOM_INCREMENT :: 1013904223
+// #private_file RANDOM_MODULUS :: 1 << 32
random_seed :: proc (s: u32) do seed = s;
random :: proc (s := ^seed) -> u32 {
- *s = *s * 5831 + 102847;
+ *s = *s * RANDOM_MULTIPLIER + RANDOM_INCREMENT;
return *s;
}
node->type = type_build_from_ast(semstate.allocator, node->type_node);
}
+/*
+// NOTE: Returns 1 if the conversion was successful.
+static b32 convert_numlit_to_type(AstNumLit* num, Type* type) {
+ fill_in_type((AstTyped *) num);
+ assert(num->type);
+
+ if (types_are_compatible(num->type, type)) return 1;
+
+ if (!type_is_numeric(type)) return 0;
+
+ if (num->type->Basic.flags & Basic_Flag_Integer) {
+
+ //
+ // Integer literal auto cast rules:
+ // - Up in size always works
+ // - Down in size only works if value is in range of smaller type.
+ // - Cast to float only works if value is less than the maximum precise value for float size.
+ //
+
+ if (type->Basic.flags & Basic_Flag_Integer) {
+ if (num->type->Basic.size < type->Basic.size) {
+ num->value.l = (i64) num->value.i;
+ num->type = type;
+ return 1;
+ }
+ }
+
+ if (type->Basic.flags & Basic_Flag_Float) {
+
+ }
+
+ }
+ else if (num->type->Basic.flags & Basic_Flag_Float) {
+ // NOTE: Floats don't cast to integers implicitly.
+ if ((type->Basic.flags & Basic_Flag_Float) == 0) return 0;
+
+ if (num->type->Basic.kind == Basic_Kind_F32 && type->Basic.kind == Basic_Kind_F64) num->value.d = (f64) num->value.f;
+ else return 0;
+
+ num->type = type;
+
+ return 1;
+ }
+
+ return 0;
+} */
+
// NOTE: Returns 0 if it was not possible to make the types compatible.
static b32 type_check_or_auto_cast(AstTyped* node, Type* type) {
assert(type != NULL);
assert(node != NULL);
if (types_are_compatible(node->type, type)) return 1;
- if (!node_is_auto_cast((AstNode *) node)) return 0;
-
- // If the node is an auto cast, we convert it to a cast node which will reports errors if
- // the cast is illegal in the code generation.
- ((AstUnaryOp *) node)->type = type;
- ((AstUnaryOp *) node)->operation = Unary_Op_Cast;
+ if (node_is_auto_cast((AstNode *) node)) {
+ // If the node is an auto cast, we convert it to a cast node which will reports errors if
+ // the cast is illegal in the code generation.
+ ((AstUnaryOp *) node)->type = type;
+ ((AstUnaryOp *) node)->operation = Unary_Op_Cast;
+ return 1;
+ }
+ else if (node->kind == Ast_Kind_NumLit) {
+ // if (convert_numlit_to_type((AstNumLit *) node, type)) return 1;
+ }
- return 1;
+ return 0;
}
b32 check_return(AstReturn* retnode) {
static void emit_raw_data(OnyxWasmModule* mod, ptr data, AstTyped* node) {
switch (node->kind) {
+ case Ast_Kind_StrLit: {
+ AstStrLit* sl = (AstStrLit *) node;
+
+ // NOTE: This assumes the address and the length fields have been filled out
+ // by emit_string_literal.
+ u32* sdata = (u32 *) data;
+ sdata[0] = sl->addr;
+ sdata[1] = sl->length;
+ break;
+ }
case Ast_Kind_NumLit: {
switch (node->type->Basic.kind) {
case Basic_Kind_Bool: