From: Brendan Hansen Date: Thu, 10 Feb 2022 16:09:47 +0000 (-0600) Subject: cleanup; added random.string X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4bdfbba244e3e1381fd2d52e1a06f66e3e36d622;p=onyx.git cleanup; added random.string --- diff --git a/core/random.onyx b/core/random.onyx index bc633bd5..527fb16f 100644 --- a/core/random.onyx +++ b/core/random.onyx @@ -24,4 +24,19 @@ float :: (lo := 0.0f, hi := 1.0f) -> f32 { choice :: (a: [] $T) -> T { return a[between(0, a.count - 1)]; -} \ No newline at end of file +} + +string :: (bytes_long: u32, alpha_numeric := false, allocator := context.allocator) -> str { + memory :: package core.memory + + s := memory.make_slice(u8, bytes_long, allocator=allocator); + for^ s { + if alpha_numeric { + #persist alpha_numeral := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + *it = choice(alpha_numeral); + } else { + *it = ~~between(32, 127); + } + } + return s; +} diff --git a/misc/onyx-mode.el b/misc/onyx-mode.el index 8dfea243..73edbfd3 100644 --- a/misc/onyx-mode.el +++ b/misc/onyx-mode.el @@ -214,6 +214,7 @@ ;; add indent functionality to some characters (onyx--add-self-insert-hooks) + (display-line-numbers-mode nil) (font-lock-fontify-buffer)) ;;;###autoload diff --git a/src/checker.c b/src/checker.c index 3e1f70e4..876576a7 100644 --- a/src/checker.c +++ b/src/checker.c @@ -466,7 +466,7 @@ CheckStatus check_switch(AstSwitch* switchnode) { if (ctb->original_value == *value) { CHECK(expression, (AstTyped **) &ctb->comparison); found = 1; - break; + break; } } if (found) break; @@ -997,7 +997,7 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop) { if (binop->operation == Binary_Op_Assign && binop->left->kind == Ast_Kind_Subscript && bh_arr_length(operator_overloads[Binary_Op_Subscript_Equals]) > 0) { AstSubscript* sub = (AstSubscript *) binop->left; - + if (binop->potential_substitute == NULL) { u32 current_checking_level_store = current_checking_level; CHECK(expression, &sub->addr); @@ -1042,7 +1042,7 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop) { } } } - + if ((binop->left->flags & Ast_Flag_Comptime) && (binop->right->flags & Ast_Flag_Comptime)) { binop->flags |= Ast_Flag_Comptime; } @@ -1074,7 +1074,7 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop) { if (binop_is_assignment(binop->operation)) return check_binaryop_assignment(pbinop); // NOTE: Comparision operators and boolean operators are handled separately. - if (binop_is_compare(binop->operation)) + if (binop_is_compare(binop->operation)) return check_binaryop_compare(pbinop); if (binop->operation == Binary_Op_Bool_And || binop->operation == Binary_Op_Bool_Or) return check_binaryop_bool(pbinop); @@ -1614,7 +1614,7 @@ CheckStatus check_field_access(AstFieldAccess** pfield) { return Check_Success; } } - + AstNode* n = try_symbol_raw_resolve_from_type(field->expr->type, field->field); AstType* type_node = field->expr->type->ast_type; @@ -2442,7 +2442,7 @@ CheckStatus check_type(AstType** ptype) { bh_arr_each(AstType *, type, ctype->types) CHECK(type, type); break; } - + case Ast_Kind_Array_Type: { AstArrayType* atype = (AstArrayType *) type; if (atype->count_expr) { @@ -2777,7 +2777,7 @@ CheckStatus check_constraint_context(ConstraintContext *cc, Scope *scope, OnyxFi return Check_Error; } else { - // If no error are suppose to be produced, we still need to signal that + // If no error are suppose to be produced, we still need to signal that // the node reached a completed state. return Check_Failed; } @@ -2817,7 +2817,7 @@ CheckStatus check_polyquery(AstPolyQuery *query) { if (header_check == Check_Return_To_Symres) return Check_Return_To_Symres; b32 solved_something = 0; - i32 solved_count = 0; + i32 solved_count = 0; char *err_msg = NULL; bh_arr_each(AstPolyParam, param, query->proc->poly_params) { AstPolySolution sln; @@ -2910,7 +2910,7 @@ void check_entity(Entity* ent) { cs = check_type(&ent->type_alias); break; - case Entity_Type_File_Contents: + case Entity_Type_File_Contents: if (context.options->no_file_contents) { onyx_report_error(ent->expr->token->pos, Error_Critical, "#file_contents is disabled for this compilation."); }