Skip to content

Commit

Permalink
Merge branch 'vardec_varass_dependency'
Browse files Browse the repository at this point in the history
  • Loading branch information
deavmi committed Aug 21, 2023
2 parents 2b00276 + 16caf6e commit 45579b8
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 60 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/d.yml
Expand Up @@ -63,9 +63,22 @@ jobs:
uses: dlang-community/setup-dlang@v1
with:
compiler: ${{ matrix.dc }}

- name: Install Doveralls (code coverage tool)
run: |
# wget -O doveralls "https://github.com/ColdenCullen/doveralls/releases/download/v1.1.5/doveralls_linux_travis"
# mv doveralls_linux_travis doveralls
# chmod +x doveralls
dub fetch doveralls
sudo apt install libcurl4-openssl-dev
- name: DUB unit tests with coverage
run: dub test --coverage

- name: Coverage upload
run: |
export CI_BRANCH=$(git branch --show-current)
dub run doveralls -- -t ${{secrets.COVERALLS_REPO_TOKEN}}
- uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
tlang
=====

[![D](https://github.com/tbklang/tlang/actions/workflows/d.yml/badge.svg)](https://github.com/tbklang/tlang/actions/workflows/d.yml)
[![D](https://github.com/tbklang/tlang/actions/workflows/d.yml/badge.svg?branch=vardec_varass_dependency)](https://github.com/tbklang/tlang/actions/workflows/d.yml) [![Coverage Status](https://coveralls.io/repos/github/tbklang/tlang/badge.svg?branch=vardec_varass_dependency)](https://coveralls.io/github/tbklang/tlang?branch=vardec_varass_dependency)

Official Tristan Language project compiler

Expand Down
18 changes: 16 additions & 2 deletions source/tlang/commandline/commands.d
Expand Up @@ -59,13 +59,17 @@ mixin template EmitBase()
{
@ArgGroup("Emit", "Options pertaining to the code emitter")
{
@ArgNamed("symbol-mapper|sm", "The symbol mapping technique to use")
@ArgNamed("symbol-mapper|sm", "The symbol mapping technique to use for DGen (C emitter)")
@(ArgConfig.optional)
SymbolMappingTechnique symbolTechnique = SymbolMappingTechnique.HASHMAPPER;

@ArgNamed("prettygen|pg", "Generate pretty-printed code")
@(ArgConfig.optional)
bool prettyPrintCodeGen = true;

@ArgNamed("ccompiler|cc", "The system C compiler to use for DGne (C emitter)")
@(ArgConfig.optional)
string systemCC = "clang";

@ArgNamed("output|o", "Filename of generated object file")
@(ArgConfig.optional)
Expand All @@ -75,6 +79,10 @@ mixin template EmitBase()
@(ArgConfig.optional)
bool entrypointTestEmit = true; // TODO: Change this later to `false` of course

@ArgNamed("preinlineArguments|pia", "Whether or not to preinline function call arguments in DGen (C emitter)")
@(ArgConfig.optional)
bool preinlineArguments = false; // TODO: Change this later to `true` of course

@ArgNamed("library-link|ll", "Paths to any object files to ,ink in during the linking phase")
@(ArgConfig.optional)
@(ArgConfig.aggregate)
Expand All @@ -84,14 +92,20 @@ mixin template EmitBase()
void EmitBaseInit(Compiler compiler)
{
// Set the symbol mapper technique
compiler.getConfig().addConfig(ConfigEntry("emit:mapper", symbolTechnique));
compiler.getConfig().addConfig(ConfigEntry("dgen:mapper", symbolTechnique));

// Set whether pretty-printed code should be generated
compiler.getConfig().addConfig(ConfigEntry("dgen:pretty_code", prettyPrintCodeGen));

// Set whether or not to enable the entry point testing code
compiler.getConfig().addConfig(ConfigEntry("dgen:emit_entrypoint_test", entrypointTestEmit));

// Set whether or not to enable pre-inlining of function call arguments in DGen
compiler.getConfig().addConfig(ConfigEntry("dgen:preinline_args", preinlineArguments));

// Set the C compiler to use for DGen
compiler.getConfig().addConfig(ConfigEntry("dgen:compiler", systemCC));

// Set the paths to the object files to link in
compiler.getConfig().addConfig(ConfigEntry("linker:link_files", bruh));
}
Expand Down
103 changes: 59 additions & 44 deletions source/tlang/compiler/codegen/emit/dgen.d
Expand Up @@ -141,6 +141,9 @@ public final class DCodeEmitter : CodeEmitter
gprintln("transform(): "~to!(string)(instruction));
transformDepth++;

// The data to emit
string emmmmit;

// At any return decrement the depth
scope(exit)
{
Expand Down Expand Up @@ -172,12 +175,12 @@ public final class DCodeEmitter : CodeEmitter
{
string renamedSymbol = mapper.symbolLookup(typedEntityVariable);

return renamedSymbol~" = "~transform(varAs.data)~";";
emmmmit = renamedSymbol~" = "~transform(varAs.data)~";";
}
/* If it is external */
else
{
return typedEntityVariable.getName()~" = "~transform(varAs.data)~";";
emmmmit = typedEntityVariable.getName()~" = "~transform(varAs.data)~";";
}
}
/* VariableDeclaration */
Expand Down Expand Up @@ -218,17 +221,18 @@ public final class DCodeEmitter : CodeEmitter
gprintln("VarDec(with assignment): My assignment type is: "~varAssInstr.getInstrType().getName());

// Generate the code to emit
return typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~" = "~transform(varAssInstr)~";";
emmmmit = typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~" = "~transform(varAssInstr)~";";
}
else
{
emmmmit = typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~";";
}

return typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~";";
}
/* If the variable is external */
else
{
return "extern "~typeTransform(cast(Type)varDecInstr.varType)~" "~typedEntityVariable.getName()~";";
emmmmit = "extern "~typeTransform(cast(Type)varDecInstr.varType)~" "~typedEntityVariable.getName()~";";
}

}
/* LiteralValue */
else if(cast(LiteralValue)instruction)
Expand All @@ -237,7 +241,7 @@ public final class DCodeEmitter : CodeEmitter

LiteralValue literalValueInstr = cast(LiteralValue)instruction;

return to!(string)(literalValueInstr.getLiteralValue());
emmmmit = to!(string)(literalValueInstr.getLiteralValue());
}
/* FetchValueVar */
else if(cast(FetchValueVar)instruction)
Expand All @@ -257,12 +261,12 @@ public final class DCodeEmitter : CodeEmitter

string renamedSymbol = mapper.symbolLookup(typedEntityVariable);

return renamedSymbol;
emmmmit = renamedSymbol;
}
/* If it is external */
else
{
return typedEntityVariable.getName();
emmmmit = typedEntityVariable.getName();
}
}
/* BinOpInstr */
Expand Down Expand Up @@ -320,7 +324,7 @@ public final class DCodeEmitter : CodeEmitter
cvInstr.setRelax(true);
}

return transform(binOpInstr.lhs)~to!(string)(getCharacter(binOpInstr.operator))~transform(binOpInstr.rhs);
emmmmit = transform(binOpInstr.lhs)~to!(string)(getCharacter(binOpInstr.operator))~transform(binOpInstr.rhs);
}
/* FuncCallInstr */
else if(cast(FuncCallInstr)instruction)
Expand Down Expand Up @@ -370,7 +374,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= ";";
}

return emit;
emmmmit = emit;
}
/* ReturnInstruction */
else if(cast(ReturnInstruction)instruction)
Expand All @@ -384,7 +388,7 @@ public final class DCodeEmitter : CodeEmitter
/* Get the return expression instruction */
Value returnExpressionInstr = returnInstruction.getReturnExpInstr();

return "return "~transform(returnExpressionInstr)~";";
emmmmit = "return "~transform(returnExpressionInstr)~";";
}
/**
* If statements (IfStatementInstruction)
Expand Down Expand Up @@ -434,7 +438,7 @@ public final class DCodeEmitter : CodeEmitter
}
}

return emit;
emmmmit = emit;
}
/**
* While loops (WhileLoopInstruction)
Expand Down Expand Up @@ -464,7 +468,7 @@ public final class DCodeEmitter : CodeEmitter
/* Closing curly brace */
emit~=genTabs(transformDepth)~"}";

return emit;
emmmmit = emit;
}
/**
* For loops (ForLoopInstruction)
Expand Down Expand Up @@ -502,7 +506,7 @@ public final class DCodeEmitter : CodeEmitter
// Close curly (body end)
emit~=genTabs(transformDepth)~"}";

return emit;
emmmmit = emit;
}
/**
* Unary operators (UnaryOpInstr)
Expand All @@ -521,7 +525,7 @@ public final class DCodeEmitter : CodeEmitter
/* Transform the operand */
emit ~= transform(operandInstruction);

return emit;
emmmmit = emit;
}
/**
* Pointer dereference assignment (PointerDereferenceAssignmentInstruction)
Expand Down Expand Up @@ -551,7 +555,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= transform(rhsAssExprInstr)~";";


return emit;
emmmmit = emit;
}
/**
* Discard instruction (DiscardInstruction)
Expand All @@ -566,7 +570,7 @@ public final class DCodeEmitter : CodeEmitter
/* Transform the expression */
emit ~= transform(valueInstruction)~";";

return emit;
emmmmit = emit;
}
/**
* Type casting instruction (CastedValueInstruction)
Expand All @@ -593,29 +597,27 @@ public final class DCodeEmitter : CodeEmitter
{
/* The original expression */
emit ~= transform(uncastedInstruction);
return emit;
}

/* Handling of primitive types */
if(cast(Primitive)castingTo)
{
/* Add the actual cast */
emit ~= "("~typeTransform(castingTo)~")";

/* The expression being casted */
emit ~= transform(uncastedInstruction);
}
else
{
// TODO: Implement this
gprintln("Non-primitive type casting not yet implemented", DebugType.ERROR);
assert(false);
}


/* Handling of primitive types */
if(cast(Primitive)castingTo)
{
/* Add the actual cast */
emit ~= "("~typeTransform(castingTo)~")";

/* The expression being casted */
emit ~= transform(uncastedInstruction);
}
else
{
// TODO: Implement this
gprintln("Non-primitive type casting not yet implemented", DebugType.ERROR);
assert(false);
}
}

return emit;
emmmmit = emit;
}
/**
* Array indexing (pointer-based arrays)
Expand Down Expand Up @@ -655,7 +657,7 @@ public final class DCodeEmitter : CodeEmitter


// return "*("~transform(indexed)~"+"~transform(index)~")";
return emit;
emmmmit = emit;
}
/**
* Array assignments (pointer-based arrays)
Expand Down Expand Up @@ -701,7 +703,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= ";";


return emit;
emmmmit = emit;
}
/**
* Array indexing (stack-based arrays)
Expand Down Expand Up @@ -741,7 +743,7 @@ public final class DCodeEmitter : CodeEmitter


// return "(TODO: Stack-array index emit)";
return emit;
emmmmit = emit;
}
/**
* Array assignments (stack-based arrays)
Expand Down Expand Up @@ -785,12 +787,23 @@ public final class DCodeEmitter : CodeEmitter

// return "(StackArrAssignmentInstr: TODO)";

return emit;
emmmmit = emit;
}
// TODO: MAAAAN we don't even have this yet
// else if(cast(StringExpression))
/**
* Unsupported instruction
*
* If you get here then normally it's because
* you didn't implement a transformation for
* an instruction yet.
*/
else
{
emmmmit = "<TODO: Base emit: "~to!(string)(instruction)~">";
}

return "<TODO: Base emit: "~to!(string)(instruction)~">";
return emmmmit;
}


Expand Down Expand Up @@ -1272,8 +1285,10 @@ int main()
{
try
{
//NOTE: Change to system compiler (maybe, we need to choose a good C compiler)
string[] compileArgs = ["clang", "-o", "tlang.out", file.name()];
string systemCompiler = config.getConfig("dgen:compiler").getText();
gprintln("Using system C compiler '"~systemCompiler~"' for compilation");

string[] compileArgs = [systemCompiler, "-o", "tlang.out", file.name()];

// Check for object files to be linked in
string[] objectFilesLink;
Expand Down
11 changes: 7 additions & 4 deletions source/tlang/compiler/configuration.d
Expand Up @@ -200,17 +200,20 @@ public final class CompilerConfiguration
/* Generate a fresh new config */
CompilerConfiguration config = new CompilerConfiguration();

/* Enable Behaviour-C fixes */
config.addConfig(ConfigEntry("behavec:preinline_args", true));
/* Enable Behaviour-C fixes (TODO: This should be changed to true before release) */
config.addConfig(ConfigEntry("dgen:preinline_args", false));

/* Enable pretty code generation for DGen */
config.addConfig(ConfigEntry("dgen:pretty_code", true));

/* Enable entry point test generation for DGen */
config.addConfig(ConfigEntry("dgen:emit_entrypoint_test", true));

/* Set the mapping to hashing of entity names (TODO: This should be changed before release) */
config.addConfig(ConfigEntry("emit:mapper", "hashmapper"));
/* Set the mapping to hashing of entity names for DGen (TODO: This should be changed before release) */
config.addConfig(ConfigEntry("dgen:mapper", "hashmapper"));

/* Set the system C compiler for DGen to clang */
config.addConfig(ConfigEntry("dgen:compiler", "clang"));

/**
* Configure, at compile time, the system type aliases
Expand Down
4 changes: 2 additions & 2 deletions source/tlang/compiler/core.d
Expand Up @@ -204,13 +204,13 @@ public class Compiler
throw new CompilerException(CompilerError.TYPECHECK_NOT_YET_PERFORMED);
}

if(!config.hasConfig("emit:mapper"))
if(!config.hasConfig("dgen:mapper"))
{
throw new CompilerException(CompilerError.CONFIG_ERROR, "Missing a symbol mapper");
}

SymbolMapper mapper;
string mapperType = config.getConfig("emit:mapper").getText();
string mapperType = config.getConfig("dgen:mapper").getText();

if(cmp(mapperType, "hashmapper") == 0)
{
Expand Down

0 comments on commit 45579b8

Please sign in to comment.