Skip to content

Commit

Permalink
CodeEmitter
Browse files Browse the repository at this point in the history
- Selecting a queue now requires an owner `Module` and it will also, when the `QueueType` is set to `FUNCTION_DEF_QUEUE`, copy over the correct `Instruction[][string]` and then, furthermore, select the correct `Instruction[]` out of it and set that as the current code queue
- Updated `getFunctionDefinitionsCount(Module owner)` and `getFunctionDefinitionNames(Module owner)` to select the correct `Instruction[][string]` when called
  • Loading branch information
deavmi committed Feb 29, 2024
1 parent 5e57d5c commit d491839
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions source/tlang/compiler/codegen/emit/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,28 @@ public abstract class CodeEmitter

private ulong queueCursor = 0;

public final void selectQueue(QueueType queueType, string funcDefName = "")
public final void selectQueue(Module owner, QueueType queueType, string funcDefName = "")
{
// Move the cursor back to the starting position
resetCursor();

if(queueType == QueueType.ALLOC_QUEUE)
{
selectedQueue = initQueue;
selectedQueue = this.typeChecker.getInitQueue(owner);
}
else if(queueType == QueueType.GLOBALS_QUEUE)
{
selectedQueue = globalCodeQueue;
selectedQueue = this.typeChecker.getGlobalCodeQueue(owner);
}
else
{
//TODO: Ensure valid name by lookup via tc

// Get the function definitions of the current module
functionBodyInstrs = this.typeChecker.getFunctionBodyCodeQueues(owner);

// Select the function definition by name from it
// and make that the current code queue
selectedQueue = functionBodyInstrs[funcDefName];
}
}
Expand Down Expand Up @@ -108,42 +113,32 @@ public abstract class CodeEmitter
return selectedQueue.length;
}

/**
* Required queues
*/
private Instruction[] initQueue;
private Instruction[] globalCodeQueue;

/**
* Required queues (maps to them)
*/
private Instruction[][string] functionBodyInstrs;

public final ulong getFunctionDefinitionsCount()
public final ulong getFunctionDefinitionsCount(Module owner)
{
// Get the function definitions of the current module
functionBodyInstrs = this.typeChecker.getFunctionBodyCodeQueues(owner);

return functionBodyInstrs.keys().length;
}

public final string[] getFunctionDefinitionNames()
public final string[] getFunctionDefinitionNames(Module owner)
{
// Get the function definitions of the current module
functionBodyInstrs = this.typeChecker.getFunctionBodyCodeQueues(owner);

return functionBodyInstrs.keys();
}

this(TypeChecker typeChecker, File file, CompilerConfiguration config, SymbolMapper mapper)
{
this.typeChecker = typeChecker;

/* Extract the allocation queue, the code queue */
initQueue = typeChecker.getInitQueue();
globalCodeQueue = typeChecker.getGlobalCodeQueue();

/* Extract the function definitions string-queue mapping */
functionBodyInstrs = typeChecker.getFunctionBodyCodeQueues();
gprintln("CodeEmitter: Got number of function defs: "~to!(string)(functionBodyInstrs));

this.file = file;
this.config = config;

this.mapper = mapper;
}

Expand Down

0 comments on commit d491839

Please sign in to comment.