mirror of https://github.com/tbklang/tlang.git
- Corrected import path for `compiler.lexer` -> `compiler.lexer.core` Parser - Corrected import path for `compiler.lexer` -> `compiler.lexer.core` TypeChecker - Corrected import path for `compiler.lexer` -> `compiler.lexer.core` Compiler - Moved configuration code outside of it - Renamed to `compiler.core` DGen - Check for any object files to link in, if so append them to the `cc` call Lexer - Moved from `compiler.lexer` to `compiler.lexer.core` Configuration - Overhauled configuration system Mapper - Added definition to `SymbolMappingTechnique` Command-line - Migrated to new configuration system - Migrated `SymbolMappingTechnique` to Mapper module - Added support for specifying object fils to link in using the `-ll` flag` Tests - Added `file_io.c` for testing `simple_extern.t` with `extern_test.sh` - Added `extern_test.sh` for testing `simple_extern.t`remove_typequeue v0.5.3
parent
a5d1617d15
commit
d548a066a6
@ -0,0 +1,13 @@
|
||||
#1/bin/sh
|
||||
|
||||
# Compile C to object file as library to link in
|
||||
gcc source/tlang/testing/file_io.c -c -o file_io.o
|
||||
|
||||
# Compile T to C, then compile C and link with other object file into a final object file
|
||||
./tlang compile source/tlang/testing/simple_extern.t -sm HASHMAPPER -et true -pg true -ll file_io.o
|
||||
|
||||
# Run the tlang file
|
||||
./tlang.out
|
||||
|
||||
# Run (with strace) to see it
|
||||
strace -e trace=write ./tlang.out
|
@ -0,0 +1,202 @@
|
||||
module compiler.configuration;
|
||||
|
||||
import compiler.core : CompilerException, CompilerError;
|
||||
import std.string : cmp;
|
||||
|
||||
private union ConfigValue
|
||||
{
|
||||
ulong number;
|
||||
bool boolean;
|
||||
string text;
|
||||
string[] textArray;
|
||||
}
|
||||
|
||||
public enum ConfigType
|
||||
{
|
||||
NUMBER,
|
||||
BOOLEAN,
|
||||
TEXT,
|
||||
TEXT_ARRAY
|
||||
}
|
||||
|
||||
public struct ConfigEntry
|
||||
{
|
||||
private string name;
|
||||
private ConfigValue value;
|
||||
private ConfigType type;
|
||||
|
||||
private this(string entryName, ConfigType entryType)
|
||||
{
|
||||
this.name = entryName;
|
||||
this.type = entryType;
|
||||
}
|
||||
|
||||
this(VType)(string entryName, VType valType)
|
||||
{
|
||||
this(entryName, ConfigType.TEXT);
|
||||
value.text = to!(string)(valType);
|
||||
}
|
||||
|
||||
this(string entryName, ulong entryValue)
|
||||
{
|
||||
this(entryName, ConfigType.NUMBER);
|
||||
value.number = entryValue;
|
||||
}
|
||||
|
||||
this(string entryName, bool entryValue)
|
||||
{
|
||||
this(entryName, ConfigType.BOOLEAN);
|
||||
value.boolean = entryValue;
|
||||
}
|
||||
|
||||
this(string entryName, string entryValue)
|
||||
{
|
||||
this(entryName, ConfigType.TEXT);
|
||||
value.text = entryValue;
|
||||
}
|
||||
|
||||
this(string entryName, string[] entryValue)
|
||||
{
|
||||
this(entryName, ConfigType.TEXT_ARRAY);
|
||||
value.textArray = entryValue;
|
||||
}
|
||||
|
||||
public ulong getNumber()
|
||||
{
|
||||
if(type == ConfigType.NUMBER)
|
||||
{
|
||||
return value.number;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_TYPE_ERROR, "Type mismatch for key '"~name~"'");
|
||||
}
|
||||
}
|
||||
|
||||
public bool getBoolean()
|
||||
{
|
||||
if(type == ConfigType.BOOLEAN)
|
||||
{
|
||||
return value.boolean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_TYPE_ERROR, "Type mismatch for key '"~name~"'");
|
||||
}
|
||||
}
|
||||
|
||||
public string getText()
|
||||
{
|
||||
if(type == ConfigType.TEXT)
|
||||
{
|
||||
return value.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_TYPE_ERROR, "Type mismatch for key '"~name~"'");
|
||||
}
|
||||
}
|
||||
|
||||
public string[] getArray()
|
||||
{
|
||||
if(type == ConfigType.TEXT_ARRAY)
|
||||
{
|
||||
return value.textArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_TYPE_ERROR, "Type mismatch for key '"~name~"'");
|
||||
}
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public ConfigType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Add a union and then also a get funciton that
|
||||
* interprets per each for us (using templatescan be automated
|
||||
* maybe)
|
||||
* Implement this!
|
||||
*/
|
||||
/**
|
||||
* TODO: Implement a union below as the value
|
||||
* of tye key-value pair
|
||||
*/
|
||||
public class CompilerConfiguration
|
||||
{
|
||||
private ConfigEntry[] entries;
|
||||
|
||||
public void addConfig(ConfigEntry entry)
|
||||
{
|
||||
// If duplicate then update entry
|
||||
if(hasConfig(entry.getName()))
|
||||
{
|
||||
updateConfig(entry);
|
||||
}
|
||||
// Else, add a new entry
|
||||
else
|
||||
{
|
||||
entries ~= entry;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfig(ConfigEntry newEntry)
|
||||
{
|
||||
for(ulong i = 0; i < entries.length; i++)
|
||||
{
|
||||
if(cmp(entries[i].getName(), newEntry.getName()) == 0)
|
||||
{
|
||||
if(entries[i].getType() == newEntry.getType())
|
||||
{
|
||||
entries[i] = newEntry;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_TYPE_ERROR, "Tried updating an entry to a different type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigEntry getConfig(string key)
|
||||
{
|
||||
ConfigEntry foundEntry;
|
||||
if(hasConfig_internal(key, foundEntry))
|
||||
{
|
||||
return foundEntry;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CompilerException(CompilerError.CONFIG_KEY_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
private bool hasConfig_internal(string key, ref ConfigEntry foundEntry)
|
||||
{
|
||||
foreach(ConfigEntry curEntry; entries)
|
||||
{
|
||||
if(cmp(curEntry.getName(), key) == 0)
|
||||
{
|
||||
foundEntry = curEntry;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool hasConfig(string key)
|
||||
{
|
||||
ConfigEntry _discard;
|
||||
return hasConfig_internal(key, _discard);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
module compiler.lexer;
|
||||
module compiler.lexer.core;
|
||||
|
||||
import std.container.slist;
|
||||
import gogga;
|
@ -0,0 +1,8 @@
|
||||
#include<unistd.h>
|
||||
|
||||
int ctr = 2;
|
||||
|
||||
unsigned int doWrite(unsigned int fd, unsigned char* buffer, unsigned int count)
|
||||
{
|
||||
write(fd, buffer, count+ctr);
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
module simple_extern;
|
||||
|
||||
extern efunc uint write(uint fd, ubyte* buffer, uint count);
|
||||
extern evar int kak;
|
||||
extern efunc uint doWrite(uint fd, ubyte* buffer, uint count);
|
||||
extern evar int ctr;
|
||||
|
||||
void test()
|
||||
{
|
||||
ubyte* buff;
|
||||
discard write(cast(uint)0, buff, cast(uint)1001);
|
||||
ctr = ctr + 1;
|
||||
|
||||
kak = kak + 1;
|
||||
ubyte* buff;
|
||||
discard doWrite(cast(uint)0, buff, cast(uint)1001);
|
||||
}
|
Loading…
Reference in new issue