Skip to content

Commit b39b741

Browse files
committed
Add completion-tree-viz highlight ability
1 parent 3a52294 commit b39b741

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

libinterpret/bc_interpreter_backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# define DEBUG(...)
3232
#endif
3333

34-
static int16_t BCGen_isShortJump(const int32_t offset)
34+
static inline int16_t BCGen_isShortJump(const int32_t offset)
3535
{
3636
assert(offset != 0);//, "A Jump to the Jump itself is invalid");
3737

repl/completion_trie.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
#define MAXIMUM(a,b) (((a)>(b)) ? (a) : (b))
1818

19+
typedef struct completion_trie_viz_params_t
20+
{
21+
uint16_t FrameNumber;
22+
uint32_t HighlightedNodeIdx;
23+
} completion_trie_viz_params_t;
24+
1925
static inline void InitializeCIdentifierCharacters(completion_trie_root_t* root) {
2026
static const char cIdentifierChars[] =
2127
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
@@ -388,7 +394,12 @@ LinsertNode: {}
388394
* @param rootPrefix The prefix of the root node.
389395
* @param f The file to which the DOT code will be written.
390396
*/
391-
void CompletionTrie_Print(completion_trie_root_t* root, uint32_t nodeIdx, const char* rootPrefix, FILE* f) {
397+
void CompletionTrie_Print(completion_trie_root_t* root,
398+
uint32_t nodeIdx,
399+
const char* rootPrefix,
400+
FILE* f,
401+
const completion_trie_viz_params_t * params
402+
) {
392403
// Retrieve a pointer to the nodes array for easier access
393404
completion_trie_node_t const * nodes = root->Nodes;
394405
uint32_t childIdx;
@@ -406,6 +417,12 @@ void CompletionTrie_Print(completion_trie_root_t* root, uint32_t nodeIdx, const
406417
childIdx, nodes[childIdx].Prefix4);
407418
}
408419

420+
// Output highlight if we have params
421+
if (params && params->HighlightedNodeIdx == nodeIdx)
422+
{
423+
fprintf(f, "{ %d: %.4s [color=red style=filled fillcolor=lightpink] }\n",
424+
nodeIdx, rootPrefix);
425+
}
409426
// Output DOT code to ensure that child nodes appear in the same rank
410427
fprintf(f, "{ rank = same; ");
411428
for(childIdx = childIdxBegin; childIdx < childIdxEnd; childIdx++)
@@ -421,21 +438,34 @@ void CompletionTrie_Print(completion_trie_root_t* root, uint32_t nodeIdx, const
421438
if (nodes[childIdx].ChildCount)
422439
{
423440
// Recursively traverse child nodes with ChildCount
424-
CompletionTrie_Print(root, childIdx, nodes[childIdx].Prefix4, f);
441+
CompletionTrie_Print(root, childIdx, nodes[childIdx].Prefix4, f, params);
425442
}
426443
}
427444
}
428445

446+
completion_trie_node_t* CompletionTrie_SplitNode(completion_trie_root_t* root,
447+
completion_trie_node_t* nodeToSplit,
448+
int splitAt)
449+
{
450+
return 0;
451+
}
452+
429453
void CompletionTrie_Add(completion_trie_root_t* root, const char* word, uint32_t length)
430454
{
431455
uint32_t remaining_length = length;
432456
completion_trie_node_t* parentNode =
433457
CompletionTrie_FindLongestMatchingPrefix(root, word, &remaining_length);
434458

459+
435460
if (remaining_length)
436461
{
437462
int posWord = length - remaining_length;
438463
parentNode = CompletionTrie_AddChild(root, parentNode, word + posWord, remaining_length);
464+
if (parentNode->ChildCount != 0)
465+
{
466+
// here we potentially need a split to determine if we need a split
467+
// if we do need it we need to compute where to split the parentNode
468+
}
439469
}
440470
// insert terminal node
441471
CompletionTrie_AddChild(root, parentNode, "", 0);
@@ -526,9 +556,10 @@ void CompletionTrie_PrintRanges(completion_trie_root_t* self)
526556
}
527557
#endif
528558

529-
void CompletionTrie_PrintTrie(completion_trie_root_t* self, uint32_t n)
559+
void CompletionTrie_PrintTrie(completion_trie_root_t* self, const completion_trie_viz_params_t params)
530560
{
531561
char fname[32] = "g.dot";
562+
int n = params.FrameNumber;
532563
if (n != 0)
533564
{
534565
snprintf(fname, sizeof(fname), "g%u.dot", n);
@@ -538,17 +569,18 @@ void CompletionTrie_PrintTrie(completion_trie_root_t* self, uint32_t n)
538569
fprintf(f, "digraph G {\n");
539570
fprintf(f, " node [shape=record headport=n]\n");
540571

541-
CompletionTrie_Print(self, 0, "", f);
572+
CompletionTrie_Print(self, 0, "", f, &params);
542573

543574
fprintf(f, "}\n");
544575
fclose(f);
545576
RESTORE_STACK();
546577
}
547578

548-
void CompletionTrie_PrintStats(completion_trie_root_t* self, uint32_t n)
579+
void CompletionTrie_PrintStats(completion_trie_root_t* self, uint16_t n)
549580
{
550581

551-
CompletionTrie_PrintTrie(self, n);
582+
completion_trie_viz_params_t params = {.FrameNumber = n};
583+
CompletionTrie_PrintTrie(self, params);
552584

553585
printf("UsedNodes: %u\n", self->TotalNodes);
554586
printf("AllocatedNodes: %u\n", self->NodesCount);

repl/completion_trie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ void AddIdentifierToCompletionSet (const char* idStr, uint32_t idKey, void* ctx)
4949

5050
void CompletionTrie_PrintRanges(completion_trie_root_t* self);
5151

52-
void CompletionTrie_PrintStats (completion_trie_root_t* root, uint32_t n);
52+
void CompletionTrie_PrintStats (completion_trie_root_t* root, uint16_t n);
5353

5454
#endif

repl/repl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ void AddIdentifierToCompletion(repl_state_t* self, const char* idString)
269269

270270
void Presemantic_(repl_state_t* self)
271271
{
272+
#if 0
272273
metac_type_aggregate_t* compilerStruct = 0;
273274

274275
metac_alloc_t PresemanticAlloc;
@@ -417,6 +418,7 @@ void Presemantic_(repl_state_t* self)
417418
}
418419
// Allocator_Remove
419420
Debug_RemoveAllocator(g_DebugServer, &PresemanticAlloc);
421+
#endif
420422
}
421423

422424

@@ -748,7 +750,7 @@ bool Repl_Loop(repl_state_t* repl, repl_ui_context_t* context)
748750
goto LswitchMode;
749751
}
750752
case 'D' :
751-
CompletionTrie_Print(&repl->CompletionTrie, 0, "", stderr);
753+
CompletionTrie_Print(&repl->CompletionTrie, 0, "", stderr, 0);
752754
goto LswitchMode;
753755
case 'g' :
754756
if (0 == strcmp("lobals", repl->Line + 2))

semantic/metac_semantic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ sema_decl_function_t* MetaCSemantic_doFunctionSemantic(metac_sema_state_t* self,
10061006

10071007
MetaCSemantic_RegisterInScope(self, f->Identifier, METAC_NODE(f));
10081008

1009+
printf("returnTypeIndex %x\n", returnType.v);
1010+
10091011
return f;
10101012
}
10111013

0 commit comments

Comments
 (0)