Skip to content

Commit

Permalink
SymbolMapper
Browse files Browse the repository at this point in the history
- Moved from `api.d` to `core.d`
  • Loading branch information
deavmi committed Apr 7, 2024
1 parent 42ec17e commit df02598
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 56 deletions.
2 changes: 1 addition & 1 deletion source/tlang/compiler/codegen/emit/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import std.range : walkLength;
import gogga;
import std.conv : to;
import tlang.compiler.configuration : CompilerConfiguration;
import tlang.compiler.codegen.mapper.api : SymbolMapper;
import tlang.compiler.codegen.mapper.core : SymbolMapper;

/**
* TODO: Perhaps have an interface that can emit(Context/Parent, Statement)
Expand Down
2 changes: 1 addition & 1 deletion source/tlang/compiler/codegen/emit/dgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import std.range : walkLength;
import std.string : wrap;
import std.process : spawnProcess, Pid, ProcessException, wait;
import tlang.compiler.typecheck.dependency.core : Context, FunctionData, DNode;
import tlang.compiler.codegen.mapper.api;
import tlang.compiler.codegen.mapper.core;
import tlang.compiler.symbols.data : SymbolType, Variable, Function, VariableParameter;
import tlang.compiler.symbols.check : getCharacter;
import misc.utils : Stack;
Expand Down
49 changes: 0 additions & 49 deletions source/tlang/compiler/codegen/mapper/api.d

This file was deleted.

49 changes: 46 additions & 3 deletions source/tlang/compiler/codegen/mapper/core.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
module tlang.compiler.codegen.mapper.core;

import tlang.compiler.typecheck.core;
import tlang.compiler.symbols.data;
import std.conv : to;
import gogga;
import tlang.compiler.symbols.data : Entity;

/**
* The symbol mapping interface
* that any symbol mapper must
* implement in order to be used
* in the `DGen` code emitter
*/
public interface SymbolMapper
{
/**
* Maps the given `Entity` to a symbol
* name with the provided scope type
*
* Params:
* item = the entity to generate a
* symbol name for
* type = the `ScopeType` to map
* using
* Returns: the symbol name
*/
public string map(Entity item, ScopeType type);
}

/**
* Specifies the kind-of mapping
* that should be done regarding
* the scope/visibility of the
* generated symbol name during
* link time
*/
public enum ScopeType
{
/**
* The mapped symbol name
* should be globally accessible
*/
GLOBAL,

/**
* The mapped symbol name
* should only be valid
* within the current scope
* it was requested from
*/
LOCAL
}

/**
* Describes the mapping technique to use
Expand Down
2 changes: 1 addition & 1 deletion source/tlang/compiler/codegen/mapper/impls.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tlang.compiler.codegen.mapper.impls;

import tlang.compiler.codegen.mapper.api;
import tlang.compiler.codegen.mapper.core;
import tlang.compiler.typecheck.core : TypeChecker;
import tlang.compiler.symbols.data : Entity;
import tlang.compiler.symbols.containers : Module;
Expand Down
2 changes: 1 addition & 1 deletion source/tlang/compiler/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import core.stdc.stdlib;
import tlang.compiler.codegen.emit.core;
import tlang.compiler.codegen.emit.dgen;
import misc.exceptions;
import tlang.compiler.codegen.mapper.api : SymbolMapper;
import tlang.compiler.codegen.mapper.core : SymbolMapper;
import tlang.compiler.codegen.mapper.impls : HashMapper, LebanonMapper;
import std.string : cmp;
import tlang.compiler.configuration : CompilerConfiguration, ConfigEntry;
Expand Down

0 comments on commit df02598

Please sign in to comment.