Command-line
- All compilation stages now make use of the `Compiler` object Compiler - Added new exception type `CompilerException` complete with a sub-type enum, `CompilerError` - `getConfig()` will now throw a `CompilerException` when a key is not found, rather than return false (which didn't work under different template types anyways) - Implemented `hasConfig()` to check for the existence of a key in the configuration sub-system's key-value store - The `Compiler` object now stores the `Token[] tokens` generated from the call to `doLex()` - The `Compiler` object now stores the resulting container (`Module`) generated from the call to `doParse()` - Set default symbol mapping technique to the hashmapper technique - Implemented `dolex()` for performing tokenization, it will create and store a `Lexer` instance and the produced `Token[] tokens` into the `Compiler` object - Added `getTokens()` to fetch the tokens generated by `doLex()` - Implemented `doParse()`, `doTypeCheck()` and `doEmit()` in a similiar fashion to `doLex()` - Implemented `getMdoule()` to get the container (`Module`) generated by `doParse()` - Implemented `compile()` which calls `doLex()`, then `doParse()`, then `doTypeCheck()` and finally `doEmit()` CodeEmitter - The `CodeEmitter` constructor now takes in an instance of the chosen `SymbolMapper` DGen - Switched to the instance of the `mapper` inheited from the `CodeMapper` parent class for any `symbolMap` calls required - Use the inherited `TypeChecker` instance and not an instance of it provided by `Context` SymbolMapper - Reworked this class into an abstract class which must have its children implement a `symbolMap(Entity)` interface, this provides us pluggable mapping techniques HashMapper - Moved hashing symbol-mapping technique into `HashMapper` Lebanese - Created a kind-of `SymbolMapper` which, unlike `HashMapper`, produces human-redable-yet-valid C symbols (by replacing the `.`'s with `_`'s) TypeChecker - Removed code for setting now-nonexistent `SymbolMapper.tc` - Removed code for setting now-nonexistent `Context.tc` Context - Removed `static TypeChecker tc` fieldremove_typequeue
parent
a8a88c86e1
commit
d30ffb7684
@ -0,0 +1,25 @@
|
||||
module compiler.codegen.mapper.core;
|
||||
|
||||
import compiler.typecheck.core;
|
||||
import compiler.symbols.data;
|
||||
import std.conv : to;
|
||||
import gogga;
|
||||
|
||||
/**
|
||||
* SymbolMapper
|
||||
*
|
||||
* Maps Entity's to consistent but unique symbol
|
||||
* names (strings)
|
||||
*/
|
||||
public class SymbolMapper
|
||||
{
|
||||
// Used to map names to entities
|
||||
protected TypeChecker tc;
|
||||
|
||||
this(TypeChecker tc)
|
||||
{
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
public abstract string symbolLookup(Entity entityIn);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
module compiler.codegen.mapper.lebanese;
|
||||
|
||||
import compiler.codegen.mapper.core : SymbolMapper;
|
||||
import compiler.typecheck.core;
|
||||
import compiler.symbols.data;
|
||||
import std.string : replace;
|
||||
|
||||
public final class LebaneseMapper : SymbolMapper
|
||||
{
|
||||
this(TypeChecker tc)
|
||||
{
|
||||
super(tc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps given Entity's name to a version whereby all the
|
||||
* `.`'s are placed by underscores preceded by a `t_`
|
||||
*
|
||||
* Params:
|
||||
* entityIn = the Entity to map
|
||||
* Returns: A string of the mapped symbol
|
||||
*/
|
||||
public override string symbolLookup(Entity entityIn)
|
||||
{
|
||||
// Generate the absolute full path of the Entity
|
||||
string absoluteFullPath = tc.getResolver().generateNameBest(entityIn);
|
||||
|
||||
// Generate the name as `_<underscored>`
|
||||
string symbolName = replace(absoluteFullPath, ".", "_");
|
||||
symbolName="t_"~symbolName;
|
||||
|
||||
return symbolName;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue