mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 15:48:47 +00:00
adding arena (p6)
This commit is contained in:
@@ -1125,12 +1125,14 @@ main:
|
|||||||
|
|
||||||
@send(Map)
|
@send(Map)
|
||||||
MD_MapMakeBucketCount: {
|
MD_MapMakeBucketCount: {
|
||||||
|
arena: *MD_Arena,
|
||||||
bucket_count: MD_u64,
|
bucket_count: MD_u64,
|
||||||
return: MD_Map,
|
return: MD_Map,
|
||||||
};
|
};
|
||||||
|
|
||||||
@send(Map)
|
@send(Map)
|
||||||
MD_MapMake: {
|
MD_MapMake: {
|
||||||
|
arena: *MD_Arena,
|
||||||
return: MD_Map,
|
return: MD_Map,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1162,6 +1164,7 @@ MD_MapScan: {
|
|||||||
|
|
||||||
@send(Map)
|
@send(Map)
|
||||||
MD_MapInsert: {
|
MD_MapInsert: {
|
||||||
|
arena: *MD_Arena,
|
||||||
map: *MD_Map,
|
map: *MD_Map,
|
||||||
key: MD_MapKey,
|
key: MD_MapKey,
|
||||||
val: *void,
|
val: *void,
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ int main(int argument_count, char **arguments)
|
|||||||
{
|
{
|
||||||
for(MD_EachNode(index_string, node->first_child))
|
for(MD_EachNode(index_string, node->first_child))
|
||||||
{
|
{
|
||||||
MD_MapInsert(&index_table, MD_MapKeyStr(index_string->string), root);
|
MD_MapInsert(arena, &index_table, MD_MapKeyStr(index_string->string), root);
|
||||||
}
|
}
|
||||||
goto end_index_build;
|
goto end_index_build;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ struct Value
|
|||||||
MD_Node *node;
|
MD_Node *node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static MD_Arena *arena = 0;
|
||||||
|
|
||||||
static Value
|
static Value
|
||||||
MakeValue_Number(MD_f64 v)
|
MakeValue_Number(MD_f64 v)
|
||||||
{
|
{
|
||||||
@@ -49,7 +51,7 @@ InsertValueToNamespace(NamespaceNode *ns, MD_String8 string, Value v)
|
|||||||
{
|
{
|
||||||
Value *v_store = malloc(sizeof(*v_store));
|
Value *v_store = malloc(sizeof(*v_store));
|
||||||
*v_store = v;
|
*v_store = v;
|
||||||
MD_MapInsert(&ns->symbol_map, MD_MapKeyStr(string), v_store);
|
MD_MapInsert(arena, &ns->symbol_map, MD_MapKeyStr(string), v_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Value
|
static Value
|
||||||
@@ -180,7 +182,7 @@ EvaluateScope(NamespaceNode *ns, MD_Node *code)
|
|||||||
|
|
||||||
int main(int argument_count, char **arguments)
|
int main(int argument_count, char **arguments)
|
||||||
{
|
{
|
||||||
MD_Arena *arena = MD_ArenaNew(1ull << 40);
|
arena = MD_ArenaNew(1ull << 40);
|
||||||
|
|
||||||
//- rjf: parse command line
|
//- rjf: parse command line
|
||||||
MD_String8List arg_list = MD_StringListFromArgCV(arena, argument_count, arguments);
|
MD_String8List arg_list = MD_StringListFromArgCV(arena, argument_count, arguments);
|
||||||
|
|||||||
+12
-15
@@ -1296,7 +1296,7 @@ MD_F64FromString(MD_String8 string)
|
|||||||
|
|
||||||
|
|
||||||
MD_FUNCTION_IMPL MD_String8
|
MD_FUNCTION_IMPL MD_String8
|
||||||
MD_CStyleHexStringFromU64(MD_u64 x, MD_b32 caps)
|
MD_CStyleHexStringFromU64(MD_Arena *arena, MD_u64 x, MD_b32 caps)
|
||||||
{
|
{
|
||||||
static char md_int_value_to_char[] = "0123456789abcdef";
|
static char md_int_value_to_char[] = "0123456789abcdef";
|
||||||
MD_u8 buffer[10];
|
MD_u8 buffer[10];
|
||||||
@@ -1328,7 +1328,7 @@ MD_CStyleHexStringFromU64(MD_u64 x, MD_b32 caps)
|
|||||||
|
|
||||||
MD_String8 result = MD_ZERO_STRUCT;
|
MD_String8 result = MD_ZERO_STRUCT;
|
||||||
result.size = (MD_u64)(ptr - buffer);
|
result.size = (MD_u64)(ptr - buffer);
|
||||||
result.str = MD_PushArray(MD_u8, result.size);
|
result.str = MD_PushArrayAr(arena, MD_u8, result.size);
|
||||||
MD_MemoryCopy(result.str, buffer, result.size);
|
MD_MemoryCopy(result.str, buffer, result.size);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
@@ -1423,18 +1423,17 @@ MD_HashPtr(void *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION_IMPL MD_Map
|
MD_FUNCTION_IMPL MD_Map
|
||||||
MD_MapMakeBucketCount(MD_u64 bucket_count){
|
MD_MapMakeBucketCount(MD_Arena *arena, MD_u64 bucket_count){
|
||||||
// TODO(allen): permanent arena? scratch arena? -- would really
|
// TODO(allen): super arena?
|
||||||
// make most sense with a parameter
|
|
||||||
MD_Map result = {0};
|
MD_Map result = {0};
|
||||||
result.bucket_count = bucket_count;
|
result.bucket_count = bucket_count;
|
||||||
result.buckets = MD_PushArray(MD_MapBucket, bucket_count); //zero
|
result.buckets = MD_PushArrayZeroAr(arena, MD_MapBucket, bucket_count);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION_IMPL MD_Map
|
MD_FUNCTION_IMPL MD_Map
|
||||||
MD_MapMake(void){
|
MD_MapMake(MD_Arena *arena){
|
||||||
MD_Map result = MD_MapMakeBucketCount(4093);
|
MD_Map result = MD_MapMakeBucketCount(arena, 4093);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1502,13 +1501,11 @@ MD_MapScan(MD_MapSlot *first_slot, MD_MapKey key){
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION_IMPL MD_MapSlot*
|
MD_FUNCTION_IMPL MD_MapSlot*
|
||||||
MD_MapInsert(MD_Map *map, MD_MapKey key, void *val){
|
MD_MapInsert(MD_Arena *arena, MD_Map *map, MD_MapKey key, void *val){
|
||||||
MD_MapSlot *result = 0;
|
MD_MapSlot *result = 0;
|
||||||
if (map->bucket_count > 0){
|
if (map->bucket_count > 0){
|
||||||
MD_u64 index = key.hash%map->bucket_count;
|
MD_u64 index = key.hash%map->bucket_count;
|
||||||
// TODO(allen): again, memory? permanent arena? scratch arena?
|
MD_MapSlot *slot = MD_PushArrayAr(arena, MD_MapSlot, 1);
|
||||||
// should definitely match the table's memory "object"
|
|
||||||
MD_MapSlot *slot = MD_PushArray(MD_MapSlot, 1);
|
|
||||||
MD_MapBucket *bucket = &map->buckets[index];
|
MD_MapBucket *bucket = &map->buckets[index];
|
||||||
MD_QueuePush(bucket->first, bucket->last, slot);
|
MD_QueuePush(bucket->first, bucket->last, slot);
|
||||||
slot->key = key;
|
slot->key = key;
|
||||||
@@ -1519,13 +1516,13 @@ MD_MapInsert(MD_Map *map, MD_MapKey key, void *val){
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION_IMPL MD_MapSlot*
|
MD_FUNCTION_IMPL MD_MapSlot*
|
||||||
MD_MapOverwrite(MD_Map *map, MD_MapKey key, void *val){
|
MD_MapOverwrite(MD_Arena *arena, MD_Map *map, MD_MapKey key, void *val){
|
||||||
MD_MapSlot *result = MD_MapLookup(map, key);
|
MD_MapSlot *result = MD_MapLookup(map, key);
|
||||||
if (result != 0){
|
if (result != 0){
|
||||||
result->val = val;
|
result->val = val;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
result = MD_MapInsert(map, key, val);
|
result = MD_MapInsert(arena, map, key, val);
|
||||||
}
|
}
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
@@ -2308,7 +2305,7 @@ MD_ParseOneNode(MD_Arena *arena, MD_String8 string, MD_u64 offset)
|
|||||||
for(int i_byte = 0; i_byte < bad_token.raw_string.size; ++i_byte)
|
for(int i_byte = 0; i_byte < bad_token.raw_string.size; ++i_byte)
|
||||||
{
|
{
|
||||||
MD_u8 b = bad_token.raw_string.str[i_byte];
|
MD_u8 b = bad_token.raw_string.str[i_byte];
|
||||||
MD_S8ListPush(arena, &bytes, MD_CStyleHexStringFromU64(b, 1));
|
MD_S8ListPush(arena, &bytes, MD_CStyleHexStringFromU64(arena, b, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_StringJoin join = MD_ZERO_STRUCT;
|
MD_StringJoin join = MD_ZERO_STRUCT;
|
||||||
|
|||||||
+6
-5
@@ -803,7 +803,7 @@ MD_FUNCTION MD_u64 MD_U64FromString(MD_String8 string, MD_u32 radix);
|
|||||||
MD_FUNCTION MD_i64 MD_CStyleIntFromString(MD_String8 string);
|
MD_FUNCTION MD_i64 MD_CStyleIntFromString(MD_String8 string);
|
||||||
MD_FUNCTION MD_f64 MD_F64FromString(MD_String8 string);
|
MD_FUNCTION MD_f64 MD_F64FromString(MD_String8 string);
|
||||||
|
|
||||||
MD_FUNCTION MD_String8 MD_CStyleHexStringFromU64(MD_u64 x, MD_b32 caps);
|
MD_FUNCTION MD_String8 MD_CStyleHexStringFromU64(MD_Arena *arena, MD_u64 x, MD_b32 caps);
|
||||||
|
|
||||||
//~ Enum/Flag Strings
|
//~ Enum/Flag Strings
|
||||||
|
|
||||||
@@ -815,14 +815,15 @@ MD_FUNCTION MD_String8List MD_StringListFromNodeFlags(MD_Arena *arena, MD_NodeFl
|
|||||||
MD_FUNCTION MD_u64 MD_HashStr(MD_String8 string);
|
MD_FUNCTION MD_u64 MD_HashStr(MD_String8 string);
|
||||||
MD_FUNCTION MD_u64 MD_HashPtr(void *p);
|
MD_FUNCTION MD_u64 MD_HashPtr(void *p);
|
||||||
|
|
||||||
MD_FUNCTION MD_Map MD_MapMakeBucketCount(MD_u64 bucket_count);
|
MD_FUNCTION MD_Map MD_MapMakeBucketCount(MD_Arena *arena, MD_u64 bucket_count);
|
||||||
MD_FUNCTION MD_Map MD_MapMake(void);
|
MD_FUNCTION MD_Map MD_MapMake(MD_Arena *arena);
|
||||||
MD_FUNCTION MD_MapKey MD_MapKeyStr(MD_String8 string);
|
MD_FUNCTION MD_MapKey MD_MapKeyStr(MD_String8 string);
|
||||||
MD_FUNCTION MD_MapKey MD_MapKeyPtr(void *ptr);
|
MD_FUNCTION MD_MapKey MD_MapKeyPtr(void *ptr);
|
||||||
MD_FUNCTION MD_MapSlot* MD_MapLookup(MD_Map *map, MD_MapKey key);
|
MD_FUNCTION MD_MapSlot* MD_MapLookup(MD_Map *map, MD_MapKey key);
|
||||||
MD_FUNCTION MD_MapSlot* MD_MapScan(MD_MapSlot *first_slot, MD_MapKey key);
|
MD_FUNCTION MD_MapSlot* MD_MapScan(MD_MapSlot *first_slot, MD_MapKey key);
|
||||||
MD_FUNCTION MD_MapSlot* MD_MapInsert(MD_Map *map, MD_MapKey key, void *val);
|
MD_FUNCTION MD_MapSlot* MD_MapInsert(MD_Arena *arena, MD_Map *map, MD_MapKey key, void *val);
|
||||||
MD_FUNCTION MD_MapSlot* MD_MapOverwrite(MD_Map *map, MD_MapKey key, void *val);
|
MD_FUNCTION MD_MapSlot* MD_MapOverwrite(MD_Arena *arena, MD_Map *map, MD_MapKey key,
|
||||||
|
void *val);
|
||||||
|
|
||||||
//~ Parsing
|
//~ Parsing
|
||||||
|
|
||||||
|
|||||||
@@ -571,16 +571,16 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
MD_Map map = MD_MapMake();
|
MD_Map map = MD_MapMake(arena);
|
||||||
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
||||||
MD_MapInsert(&map, keys[i], (void *)i);
|
MD_MapInsert(arena, &map, keys[i], (void *)i);
|
||||||
}
|
}
|
||||||
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
||||||
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
|
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
|
||||||
TestResult(slot && slot->val == (void *)i);
|
TestResult(slot && slot->val == (void *)i);
|
||||||
}
|
}
|
||||||
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
||||||
MD_MapOverwrite(&map, keys[i], (void *)(i + 10));
|
MD_MapOverwrite(arena, &map, keys[i], (void *)(i + 10));
|
||||||
}
|
}
|
||||||
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1){
|
||||||
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
|
MD_MapSlot *slot = MD_MapLookup(&map, keys[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user