Merge branch 'vardec_varass_dependency'

This commit is contained in:
Tristan B. Velloza Kildaire 2023-08-21 15:04:48 +02:00
commit 45579b859f
8 changed files with 100 additions and 60 deletions

View File

@ -63,9 +63,22 @@ jobs:
uses: dlang-community/setup-dlang@v1 uses: dlang-community/setup-dlang@v1
with: with:
compiler: ${{ matrix.dc }} 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 - name: DUB unit tests with coverage
run: dub test --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 - uses: actions/upload-artifact@v3
with: with:

View File

@ -1,7 +1,7 @@
tlang 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 Official Tristan Language project compiler

View File

@ -59,13 +59,17 @@ mixin template EmitBase()
{ {
@ArgGroup("Emit", "Options pertaining to the code emitter") @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) @(ArgConfig.optional)
SymbolMappingTechnique symbolTechnique = SymbolMappingTechnique.HASHMAPPER; SymbolMappingTechnique symbolTechnique = SymbolMappingTechnique.HASHMAPPER;
@ArgNamed("prettygen|pg", "Generate pretty-printed code") @ArgNamed("prettygen|pg", "Generate pretty-printed code")
@(ArgConfig.optional) @(ArgConfig.optional)
bool prettyPrintCodeGen = true; 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") @ArgNamed("output|o", "Filename of generated object file")
@(ArgConfig.optional) @(ArgConfig.optional)
@ -75,6 +79,10 @@ mixin template EmitBase()
@(ArgConfig.optional) @(ArgConfig.optional)
bool entrypointTestEmit = true; // TODO: Change this later to `false` of course 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") @ArgNamed("library-link|ll", "Paths to any object files to ,ink in during the linking phase")
@(ArgConfig.optional) @(ArgConfig.optional)
@(ArgConfig.aggregate) @(ArgConfig.aggregate)
@ -84,7 +92,7 @@ mixin template EmitBase()
void EmitBaseInit(Compiler compiler) void EmitBaseInit(Compiler compiler)
{ {
// Set the symbol mapper technique // 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 // Set whether pretty-printed code should be generated
compiler.getConfig().addConfig(ConfigEntry("dgen:pretty_code", prettyPrintCodeGen)); compiler.getConfig().addConfig(ConfigEntry("dgen:pretty_code", prettyPrintCodeGen));
@ -92,6 +100,12 @@ mixin template EmitBase()
// Set whether or not to enable the entry point testing code // Set whether or not to enable the entry point testing code
compiler.getConfig().addConfig(ConfigEntry("dgen:emit_entrypoint_test", entrypointTestEmit)); 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 // Set the paths to the object files to link in
compiler.getConfig().addConfig(ConfigEntry("linker:link_files", bruh)); compiler.getConfig().addConfig(ConfigEntry("linker:link_files", bruh));
} }

View File

@ -141,6 +141,9 @@ public final class DCodeEmitter : CodeEmitter
gprintln("transform(): "~to!(string)(instruction)); gprintln("transform(): "~to!(string)(instruction));
transformDepth++; transformDepth++;
// The data to emit
string emmmmit;
// At any return decrement the depth // At any return decrement the depth
scope(exit) scope(exit)
{ {
@ -172,12 +175,12 @@ public final class DCodeEmitter : CodeEmitter
{ {
string renamedSymbol = mapper.symbolLookup(typedEntityVariable); string renamedSymbol = mapper.symbolLookup(typedEntityVariable);
return renamedSymbol~" = "~transform(varAs.data)~";"; emmmmit = renamedSymbol~" = "~transform(varAs.data)~";";
} }
/* If it is external */ /* If it is external */
else else
{ {
return typedEntityVariable.getName()~" = "~transform(varAs.data)~";"; emmmmit = typedEntityVariable.getName()~" = "~transform(varAs.data)~";";
} }
} }
/* VariableDeclaration */ /* VariableDeclaration */
@ -218,17 +221,18 @@ public final class DCodeEmitter : CodeEmitter
gprintln("VarDec(with assignment): My assignment type is: "~varAssInstr.getInstrType().getName()); gprintln("VarDec(with assignment): My assignment type is: "~varAssInstr.getInstrType().getName());
// Generate the code to emit // 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 */ /* If the variable is external */
else else
{ {
return "extern "~typeTransform(cast(Type)varDecInstr.varType)~" "~typedEntityVariable.getName()~";"; emmmmit = "extern "~typeTransform(cast(Type)varDecInstr.varType)~" "~typedEntityVariable.getName()~";";
} }
} }
/* LiteralValue */ /* LiteralValue */
else if(cast(LiteralValue)instruction) else if(cast(LiteralValue)instruction)
@ -237,7 +241,7 @@ public final class DCodeEmitter : CodeEmitter
LiteralValue literalValueInstr = cast(LiteralValue)instruction; LiteralValue literalValueInstr = cast(LiteralValue)instruction;
return to!(string)(literalValueInstr.getLiteralValue()); emmmmit = to!(string)(literalValueInstr.getLiteralValue());
} }
/* FetchValueVar */ /* FetchValueVar */
else if(cast(FetchValueVar)instruction) else if(cast(FetchValueVar)instruction)
@ -257,12 +261,12 @@ public final class DCodeEmitter : CodeEmitter
string renamedSymbol = mapper.symbolLookup(typedEntityVariable); string renamedSymbol = mapper.symbolLookup(typedEntityVariable);
return renamedSymbol; emmmmit = renamedSymbol;
} }
/* If it is external */ /* If it is external */
else else
{ {
return typedEntityVariable.getName(); emmmmit = typedEntityVariable.getName();
} }
} }
/* BinOpInstr */ /* BinOpInstr */
@ -320,7 +324,7 @@ public final class DCodeEmitter : CodeEmitter
cvInstr.setRelax(true); 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 */ /* FuncCallInstr */
else if(cast(FuncCallInstr)instruction) else if(cast(FuncCallInstr)instruction)
@ -370,7 +374,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= ";"; emit ~= ";";
} }
return emit; emmmmit = emit;
} }
/* ReturnInstruction */ /* ReturnInstruction */
else if(cast(ReturnInstruction)instruction) else if(cast(ReturnInstruction)instruction)
@ -384,7 +388,7 @@ public final class DCodeEmitter : CodeEmitter
/* Get the return expression instruction */ /* Get the return expression instruction */
Value returnExpressionInstr = returnInstruction.getReturnExpInstr(); Value returnExpressionInstr = returnInstruction.getReturnExpInstr();
return "return "~transform(returnExpressionInstr)~";"; emmmmit = "return "~transform(returnExpressionInstr)~";";
} }
/** /**
* If statements (IfStatementInstruction) * If statements (IfStatementInstruction)
@ -434,7 +438,7 @@ public final class DCodeEmitter : CodeEmitter
} }
} }
return emit; emmmmit = emit;
} }
/** /**
* While loops (WhileLoopInstruction) * While loops (WhileLoopInstruction)
@ -464,7 +468,7 @@ public final class DCodeEmitter : CodeEmitter
/* Closing curly brace */ /* Closing curly brace */
emit~=genTabs(transformDepth)~"}"; emit~=genTabs(transformDepth)~"}";
return emit; emmmmit = emit;
} }
/** /**
* For loops (ForLoopInstruction) * For loops (ForLoopInstruction)
@ -502,7 +506,7 @@ public final class DCodeEmitter : CodeEmitter
// Close curly (body end) // Close curly (body end)
emit~=genTabs(transformDepth)~"}"; emit~=genTabs(transformDepth)~"}";
return emit; emmmmit = emit;
} }
/** /**
* Unary operators (UnaryOpInstr) * Unary operators (UnaryOpInstr)
@ -521,7 +525,7 @@ public final class DCodeEmitter : CodeEmitter
/* Transform the operand */ /* Transform the operand */
emit ~= transform(operandInstruction); emit ~= transform(operandInstruction);
return emit; emmmmit = emit;
} }
/** /**
* Pointer dereference assignment (PointerDereferenceAssignmentInstruction) * Pointer dereference assignment (PointerDereferenceAssignmentInstruction)
@ -551,7 +555,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= transform(rhsAssExprInstr)~";"; emit ~= transform(rhsAssExprInstr)~";";
return emit; emmmmit = emit;
} }
/** /**
* Discard instruction (DiscardInstruction) * Discard instruction (DiscardInstruction)
@ -566,7 +570,7 @@ public final class DCodeEmitter : CodeEmitter
/* Transform the expression */ /* Transform the expression */
emit ~= transform(valueInstruction)~";"; emit ~= transform(valueInstruction)~";";
return emit; emmmmit = emit;
} }
/** /**
* Type casting instruction (CastedValueInstruction) * Type casting instruction (CastedValueInstruction)
@ -593,29 +597,27 @@ public final class DCodeEmitter : CodeEmitter
{ {
/* The original expression */ /* The original expression */
emit ~= transform(uncastedInstruction); 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 else
{ {
// TODO: Implement this /* Handling of primitive types */
gprintln("Non-primitive type casting not yet implemented", DebugType.ERROR); if(cast(Primitive)castingTo)
assert(false); {
/* 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);
}
} }
emmmmit = emit;
return emit;
} }
/** /**
* Array indexing (pointer-based arrays) * Array indexing (pointer-based arrays)
@ -655,7 +657,7 @@ public final class DCodeEmitter : CodeEmitter
// return "*("~transform(indexed)~"+"~transform(index)~")"; // return "*("~transform(indexed)~"+"~transform(index)~")";
return emit; emmmmit = emit;
} }
/** /**
* Array assignments (pointer-based arrays) * Array assignments (pointer-based arrays)
@ -701,7 +703,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= ";"; emit ~= ";";
return emit; emmmmit = emit;
} }
/** /**
* Array indexing (stack-based arrays) * Array indexing (stack-based arrays)
@ -741,7 +743,7 @@ public final class DCodeEmitter : CodeEmitter
// return "(TODO: Stack-array index emit)"; // return "(TODO: Stack-array index emit)";
return emit; emmmmit = emit;
} }
/** /**
* Array assignments (stack-based arrays) * Array assignments (stack-based arrays)
@ -785,12 +787,23 @@ public final class DCodeEmitter : CodeEmitter
// return "(StackArrAssignmentInstr: TODO)"; // return "(StackArrAssignmentInstr: TODO)";
return emit; emmmmit = emit;
} }
// TODO: MAAAAN we don't even have this yet // TODO: MAAAAN we don't even have this yet
// else if(cast(StringExpression)) // 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;
} }
@ -1272,8 +1285,10 @@ int main()
{ {
try try
{ {
//NOTE: Change to system compiler (maybe, we need to choose a good C compiler) string systemCompiler = config.getConfig("dgen:compiler").getText();
string[] compileArgs = ["clang", "-o", "tlang.out", file.name()]; gprintln("Using system C compiler '"~systemCompiler~"' for compilation");
string[] compileArgs = [systemCompiler, "-o", "tlang.out", file.name()];
// Check for object files to be linked in // Check for object files to be linked in
string[] objectFilesLink; string[] objectFilesLink;

View File

@ -200,8 +200,8 @@ public final class CompilerConfiguration
/* Generate a fresh new config */ /* Generate a fresh new config */
CompilerConfiguration config = new CompilerConfiguration(); CompilerConfiguration config = new CompilerConfiguration();
/* Enable Behaviour-C fixes */ /* Enable Behaviour-C fixes (TODO: This should be changed to true before release) */
config.addConfig(ConfigEntry("behavec:preinline_args", true)); config.addConfig(ConfigEntry("dgen:preinline_args", false));
/* Enable pretty code generation for DGen */ /* Enable pretty code generation for DGen */
config.addConfig(ConfigEntry("dgen:pretty_code", true)); config.addConfig(ConfigEntry("dgen:pretty_code", true));
@ -209,8 +209,11 @@ public final class CompilerConfiguration
/* Enable entry point test generation for DGen */ /* Enable entry point test generation for DGen */
config.addConfig(ConfigEntry("dgen:emit_entrypoint_test", true)); config.addConfig(ConfigEntry("dgen:emit_entrypoint_test", true));
/* Set the mapping to hashing of entity names (TODO: This should be changed before release) */ /* Set the mapping to hashing of entity names for DGen (TODO: This should be changed before release) */
config.addConfig(ConfigEntry("emit:mapper", "hashmapper")); 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 * Configure, at compile time, the system type aliases

View File

@ -204,13 +204,13 @@ public class Compiler
throw new CompilerException(CompilerError.TYPECHECK_NOT_YET_PERFORMED); 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"); throw new CompilerException(CompilerError.CONFIG_ERROR, "Missing a symbol mapper");
} }
SymbolMapper mapper; SymbolMapper mapper;
string mapperType = config.getConfig("emit:mapper").getText(); string mapperType = config.getConfig("dgen:mapper").getText();
if(cmp(mapperType, "hashmapper") == 0) if(cmp(mapperType, "hashmapper") == 0)
{ {

View File

@ -718,7 +718,7 @@ public class DNodeGenerator
expect("Only class-type may be used with `new`"); expect("Only class-type may be used with `new`");
assert(false); assert(false);
} }
gprintln("Poe naais"); gprintln("King of the castle");
} }
else else
{ {
@ -981,8 +981,6 @@ public class DNodeGenerator
*/ */
else if(cast(ArrayIndex)exp) else if(cast(ArrayIndex)exp)
{ {
gprintln("Working on expressionPass'ing of ArrayIndex", DebugType.ERROR);
ArrayIndex arrayIndex = cast(ArrayIndex)exp; ArrayIndex arrayIndex = cast(ArrayIndex)exp;
// Set the context as we need to grab it later in the typechecker // Set the context as we need to grab it later in the typechecker
@ -997,9 +995,6 @@ public class DNodeGenerator
Expression indexedExp = arrayIndex.getIndexed(); Expression indexedExp = arrayIndex.getIndexed();
DNode indexedExpDNode = expressionPass(indexedExp, context); DNode indexedExpDNode = expressionPass(indexedExp, context);
dnode.needs(indexedExpDNode); dnode.needs(indexedExpDNode);
// assert(false);
} }
else else
{ {

View File

@ -219,7 +219,7 @@ public final class Resolver
/* Try find the Entity within the current Contaier */ /* Try find the Entity within the current Contaier */
gprintln("resolveUp("~to!(string)(currentContainer)~", "~name~")"); gprintln("resolveUp("~to!(string)(currentContainer)~", "~name~")");
Entity entity = resolveWithin(currentContainer, name); Entity entity = resolveWithin(currentContainer, name);
gprintln("Poes"); gprintln("Certified 2008 financial crisis moment");
gprintln(entity); gprintln(entity);
/* If we found it return it */ /* If we found it return it */