diff --git a/source/md.c b/source/md.c index 36342d1..a502a77 100644 --- a/source/md.c +++ b/source/md.c @@ -510,7 +510,6 @@ static MD_Node _md_nil_node = 0, // flags MD_ZERO_STRUCT, // string MD_ZERO_STRUCT, // raw_string - 0xdeadffffffffffull, // string_hash 0, // at &_md_nil_node, // ref_target MD_ZERO_STRUCT, // prev_comment @@ -803,6 +802,7 @@ MD_S8FmtV(MD_Arena *arena, char *fmt, va_list args) MD_u64 needed_bytes = md_stbsp_vsnprintf(0, 0, fmt, args)+1; result.str = MD_PushArray(arena, MD_u8, needed_bytes); result.size = needed_bytes - 1; + result.str[needed_bytes-1] = 0; md_stbsp_vsnprintf((char*)result.str, needed_bytes, fmt, args2); return result; } @@ -820,7 +820,7 @@ MD_S8Fmt(MD_Arena *arena, char *fmt, ...) MD_FUNCTION void MD_S8ListPush(MD_Arena *arena, MD_String8List *list, MD_String8 string) { - MD_String8Node *node = MD_PushArray(arena, MD_String8Node, 1); + MD_String8Node *node = MD_PushArrayZero(arena, MD_String8Node, 1); node->string = string; MD_QueuePush(list->first, list->last, node); @@ -922,7 +922,7 @@ MD_S8ListJoin(MD_Arena *arena, MD_String8List list, MD_StringJoin *join_ptr) MD_String8 result = MD_ZERO_STRUCT; result.size = (list.total_size + join.pre.size + sep_count*join.mid.size + join.post.size); - result.str = MD_PushArray(arena, MD_u8, result.size); + result.str = MD_PushArrayZero(arena, MD_u8, result.size); // fill MD_u8 *ptr = result.str; @@ -1005,7 +1005,7 @@ MD_S8Stylize(MD_Arena *arena, MD_String8 string, MD_IdentifierStyle word_style, { result.size += separator.size*(words.node_count-1); } - result.str = MD_PushArray(arena, MD_u8, result.size); + result.str = MD_PushArrayZero(arena, MD_u8, result.size); { MD_u64 write_pos = 0; @@ -1234,7 +1234,7 @@ MD_FUNCTION MD_String8 MD_S8FromS16(MD_Arena *arena, MD_String16 in) { MD_u64 cap = in.size*3; - MD_u8 *str = MD_PushArray(arena, MD_u8, cap + 1); + MD_u8 *str = MD_PushArrayZero(arena, MD_u8, cap + 1); MD_u16 *ptr = in.str; MD_u16 *opl = ptr + in.size; MD_u64 size = 0; @@ -1254,7 +1254,7 @@ MD_FUNCTION MD_String16 MD_S16FromS8(MD_Arena *arena, MD_String8 in) { MD_u64 cap = in.size*2; - MD_u16 *str = MD_PushArray(arena, MD_u16, cap + 1); + MD_u16 *str = MD_PushArrayZero(arena, MD_u16, cap + 1); MD_u8 *ptr = in.str; MD_u8 *opl = ptr + in.size; MD_u64 size = 0; @@ -1275,7 +1275,7 @@ MD_FUNCTION MD_String8 MD_S8FromS32(MD_Arena *arena, MD_String32 in) { MD_u64 cap = in.size*4; - MD_u8 *str = MD_PushArray(arena, MD_u8, cap + 1); + MD_u8 *str = MD_PushArrayZero(arena, MD_u8, cap + 1); MD_u32 *ptr = in.str; MD_u32 *opl = ptr + in.size; MD_u64 size = 0; @@ -1293,7 +1293,7 @@ MD_FUNCTION MD_String32 MD_S32FromS8(MD_Arena *arena, MD_String8 in) { MD_u64 cap = in.size; - MD_u32 *str = MD_PushArray(arena, MD_u32, cap + 1); + MD_u32 *str = MD_PushArrayZero(arena, MD_u32, cap + 1); MD_u8 *ptr = in.str; MD_u8 *opl = ptr + in.size; MD_u64 size = 0; @@ -1507,7 +1507,7 @@ MD_CStyleHexStringFromU64(MD_Arena *arena, MD_u64 x, MD_b32 caps) MD_String8 result = MD_ZERO_STRUCT; result.size = (MD_u64)(ptr - buffer); - result.str = MD_PushArray(arena, MD_u8, result.size); + result.str = MD_PushArrayZero(arena, MD_u8, result.size); MD_MemoryCopy(result.str, buffer, result.size); return(result); } @@ -1594,9 +1594,8 @@ MD_FUNCTION MD_u64 MD_HashPtr(void *p) { MD_u64 h = (MD_u64)p; - // TODO(rjf): Do we want our own equivalent of UINT64_C? - h = (h ^ (h >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); - h = (h ^ (h >> 27)) * UINT64_C(0x94d049bb133111eb); + h = (h ^ (h >> 30)) * 0xbf58476d1ce4e5b9; + h = (h ^ (h >> 27)) * 0x94d049bb133111eb; h = h ^ (h >> 31); return h; } @@ -1683,7 +1682,7 @@ MD_MapInsert(MD_Arena *arena, MD_Map *map, MD_MapKey key, void *val){ MD_MapSlot *result = 0; if (map->bucket_count > 0){ MD_u64 index = key.hash%map->bucket_count; - MD_MapSlot *slot = MD_PushArray(arena, MD_MapSlot, 1); + MD_MapSlot *slot = MD_PushArrayZero(arena, MD_MapSlot, 1); MD_MapBucket *bucket = &map->buckets[index]; MD_QueuePush(bucket->first, bucket->last, slot); slot->key = key; @@ -2165,10 +2164,10 @@ MD_ParseNodeSet(MD_Arena *arena, MD_String8 string, MD_u64 offset, MD_Node *pare if(potential_closer.kind == MD_TokenKind_Reserved) { MD_u8 c = potential_closer.raw_string.str[0]; - if (c == ',' || c == ';') + if(c == ',' || c == ';') { - closer_check_off += potential_closer.raw_string.size; off = closer_check_off; + closer_check_off += potential_closer.raw_string.size; break; } else if(c == '}' || c == ']'|| c == ')') @@ -2970,7 +2969,7 @@ MD_ExprOperatorPush(MD_Arena *arena, MD_ExprOperatorList *list, MD_u32 op_id, MD_ExprOperatorKind kind, MD_u64 precedence, MD_Node *md_node) { - MD_ExprOperatorNode *node = MD_PushArray(arena, MD_ExprOperatorNode, 1); + MD_ExprOperatorNode *node = MD_PushArrayZero(arena, MD_ExprOperatorNode, 1); MD_QueuePush(list->first, list->last, node); list->count += 1; node->op.op_id = op_id; @@ -3050,7 +3049,7 @@ MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOperatorList *list) if(error_str.size == 0) { MD_ExprOperatorList *list = result.table+op.kind; - MD_ExprOperatorNode *op_node_copy = MD_PushArray(arena, MD_ExprOperatorNode, 1); + MD_ExprOperatorNode *op_node_copy = MD_PushArrayZero(arena, MD_ExprOperatorNode, 1); MD_QueuePush(list->first, list->last, op_node_copy); list->count += 1; op_node_copy->op = op; @@ -3401,13 +3400,7 @@ MD_S8ListPush(arena, out, indent_string);\ MD_ReleaseScratch(scratch); } - //- rjf: node string hash - if(flags & MD_GenerateFlag_StringHash) - { - MD_PrintIndent(indent); - MD_S8ListPush(arena, out, MD_S8Fmt(arena, "// string hash: 0x%llx\n", node->string_hash)); - } - + //- rjf: location if(flags & MD_GenerateFlag_Location) { MD_PrintIndent(indent); @@ -3725,10 +3718,8 @@ MD_StringListFromArgCV(MD_Arena *arena, int argument_count, char **arguments) MD_FUNCTION MD_CmdLine MD_MakeCmdLineFromOptions(MD_Arena *arena, MD_String8List options) { - // TODO(rjf): consider everything as plain unstructured inputs after - // a `--` (without a name). - MD_CmdLine cmdln = MD_ZERO_STRUCT; + MD_b32 parsing_only_inputs = 0; for(MD_String8Node *n = options.first, *next = 0; n; n = next) @@ -3738,7 +3729,11 @@ MD_MakeCmdLineFromOptions(MD_Arena *arena, MD_String8List options) //- rjf: figure out whether or not this is an option by checking for `-` or `--` // from the beginning of the string MD_String8 option_name = MD_ZERO_STRUCT; - if(MD_S8Match(MD_S8Prefix(n->string, 2), MD_S8Lit("--"), 0)) + if(MD_S8Match(n->string, MD_S8Lit("--"), 0)) + { + parsing_only_inputs = 1; + } + else if(MD_S8Match(MD_S8Prefix(n->string, 2), MD_S8Lit("--"), 0)) { option_name = MD_S8Skip(n->string, 2); } @@ -3746,6 +3741,7 @@ MD_MakeCmdLineFromOptions(MD_Arena *arena, MD_String8List options) { option_name = MD_S8Skip(n->string, 1); } + //- rjf: trim off anything after a `:` or `=`, use that as the first value string MD_String8 first_value = MD_ZERO_STRUCT; MD_b32 has_many_values = 0; @@ -3766,7 +3762,7 @@ MD_MakeCmdLineFromOptions(MD_Arena *arena, MD_String8List options) } //- rjf: gather arguments - if(option_name.size != 0) + if(option_name.size != 0 && !parsing_only_inputs) { MD_String8List option_values = MD_ZERO_STRUCT; diff --git a/source/md.h b/source/md.h index 1305835..cc8d84e 100644 --- a/source/md.h +++ b/source/md.h @@ -7,9 +7,6 @@ #ifndef MD_H #define MD_H -// TODO(rjf): implicitly-delimited sets are not having their separator flags -// appropriately set - /* NOTE(allen): Notes on overrides/macro options: ** ** Overridable : @@ -77,8 +74,8 @@ # define MD_DEFAULT_SCRATCH 1 #endif -#if !defined(MD_DISABLE_PRINT_HELPERS) -# define MD_DISABLE_PRINT_HELPERS 0 +#if !defined(MD_ENABLE_PRINT_HELPERS) +# define MD_ENABLE_PRINT_HELPERS 0 #endif @@ -316,8 +313,9 @@ //~ Linkage Wrappers #if !defined(MD_FUNCTION) -# define MD_FUNCTION static +# define MD_FUNCTION #endif +#define MD_FUNCTION_IMPL MD_FUNCTION #if !defined(MD_GLOBAL) # define MD_GLOBAL static @@ -605,7 +603,6 @@ struct MD_Node MD_NodeFlags flags; MD_String8 string; MD_String8 raw_string; - MD_u64 string_hash; // Source code location information. MD_u64 offset; @@ -613,7 +610,6 @@ struct MD_Node // Reference. MD_Node *ref_target; - // Comments. // @usage prev_comment/next_comment should be considered "hidden". Rely on // the functions MD_PrevCommentFromNode/MD_NextCommentFromNode to access @@ -829,8 +825,7 @@ enum MD_GenerateFlag_Comments = (1<<3), MD_GenerateFlag_NodeKind = (1<<4), MD_GenerateFlag_NodeFlags = (1<<5), - MD_GenerateFlag_StringHash = (1<<6), - MD_GenerateFlag_Location = (1<<7), + MD_GenerateFlag_Location = (1<<6), MD_GenerateFlags_Tree = (MD_GenerateFlag_Tags | MD_GenerateFlag_TagArguments | @@ -1047,7 +1042,7 @@ MD_FUNCTION MD_ParseResult MD_ParseResultZero(void); MD_FUNCTION MD_ParseResult MD_ParseNodeSet(MD_Arena *arena, MD_String8 string, MD_u64 offset, MD_Node *parent, MD_ParseSetRule rule); MD_FUNCTION MD_ParseResult MD_ParseOneNode(MD_Arena *arena, MD_String8 string, MD_u64 offset); -MD_FUNCTION MD_ParseResult MD_ParseWholeString(MD_Arena *arena, MD_String8 name, MD_String8 contents); +MD_FUNCTION MD_ParseResult MD_ParseWholeString(MD_Arena *arena, MD_String8 filename, MD_String8 contents); MD_FUNCTION MD_ParseResult MD_ParseWholeFile(MD_Arena *arena, MD_String8 filename); @@ -1105,7 +1100,7 @@ MD_FUNCTION MD_String8 MD_StringFromMessageKind(MD_MessageKind kind); MD_FUNCTION MD_String8 MD_FormatMessage(MD_Arena *arena, MD_CodeLoc loc, MD_MessageKind kind, MD_String8 string); -#if !MD_DISABLE_PRINT_HELPERS +#if MD_ENABLE_PRINT_HELPERS #include MD_FUNCTION void MD_PrintMessage(FILE *file, MD_CodeLoc loc, MD_MessageKind kind, MD_String8 string); @@ -1139,10 +1134,6 @@ MD_FUNCTION void MD_ReconstructionFromNode(MD_Arena *arena, MD_String8List *out, int indent, MD_String8 indent_string, MD_GenerateFlags flags); -#if !MD_DISABLE_PRINT_HELPERS -MD_FUNCTION void MD_PrintDebugDumpFromNode(FILE *file, MD_Node *node, MD_GenerateFlags flags); -#endif - //~ Command Line Argument Helper MD_FUNCTION MD_String8List MD_StringListFromArgCV(MD_Arena *arena, int argument_count, diff --git a/source/md_c_helpers.c b/source/md_c_helpers.c index 5a781df..c431cce 100644 --- a/source/md_c_helpers.c +++ b/source/md_c_helpers.c @@ -174,7 +174,7 @@ MD_FUNCTION_IMPL MD_C_Expr * MD_C_MakeExpr(MD_Arena *arena, MD_Node *node, MD_C_ExprKind kind, MD_C_Expr *left, MD_C_Expr *right) { - MD_C_Expr *expr = MD_PushArray(arena, MD_C_Expr, 1); + MD_C_Expr *expr = MD_PushArrayZero(arena, MD_C_Expr, 1); if(left == 0) left = MD_C_NilExpr(); if(right == 0) right = MD_C_NilExpr(); expr->node = node;