Merge branch 'major/dotting_partials' into feature/enums

feature/enums
Tristan B. V. Kildaire 10 months ago
commit 1dd48215e0

@ -585,21 +585,6 @@ public final class DCodeEmitter : CodeEmitter
emit ~= transform(rhsAssExprInstr)~";";
emmmmit = emit;
}
/**
* Discard instruction (DiscardInstruction)
*/
else if(cast(DiscardInstruction)instruction)
{
DiscardInstruction discardInstruction = cast(DiscardInstruction)instruction;
Value valueInstruction = discardInstruction.getExpressionInstruction();
string emit;
/* Transform the expression */
emit ~= transform(valueInstruction)~";";
emmmmit = emit;
}
/**

@ -789,26 +789,6 @@ public final class PointerDereferenceAssignmentInstruction : Instruction, IRende
}
}
public final class DiscardInstruction : Instruction, IRenderable
{
private Value exprInstr;
this(Value exprInstr)
{
this.exprInstr = exprInstr;
}
public Value getExpressionInstruction()
{
return exprInstr;
}
public string render()
{
return format("discard %s", tryRender(exprInstr));
}
}
public final class CastedValueInstruction : Value, IRenderable
{
/* The uncasted original instruction that must be executed-then-trimmed (casted) */

@ -1077,34 +1077,6 @@ public final class Parser
return true;
}
/**
* Only a subset of expressions are parsed without coming after
* an assignment, functioncall parameters etc
*
* Therefore instead of mirroring a lot fo what is in expression, for now atleast
* I will support everything using discard
*
* TODO: Remove discard and implement the needed mirrors
*/
private DiscardStatement parseDiscard()
{
/* Consume the `discard` */
nextToken();
/* Parse the following expression */
Expression expression = parseExpression();
/* Expect a semi-colon */
expect(SymbolType.SEMICOLON, getCurrentToken());
nextToken();
/* Create a `discard` statement */
DiscardStatement discardStatement = new DiscardStatement(expression);
return discardStatement;
}
private CastedExpression parseCast()
{
CastedExpression castedExpression;
@ -2462,17 +2434,6 @@ public final class Parser
parentToContainer(container, [retStmt.getReturnExpression()]);
}
}
/**
* If we have a `DiscardStatement`
* then we must process its
* contained expression
*/
else if(cast(DiscardStatement)statement)
{
DiscardStatement dcrdStmt = cast(DiscardStatement)statement;
parentToContainer(container, [dcrdStmt.getExpression()]);
}
/**
* If we have an `IfStatement`
* then extract its `Branch`
@ -2872,12 +2833,6 @@ public final class Parser
/* Parse the return statement */
statement = parseReturn();
}
/* If it is a `discard` statement */
else if(symbol == SymbolType.DISCARD)
{
/* Parse the discard statement */
statement = parseDiscard();
}
/* If it is a dereference assigment (a `*`) */
else if(symbol == SymbolType.STAR)
{
@ -3616,71 +3571,6 @@ class myClass2
}
}
/**
* Discard statement test case
*/
unittest
{
string sourceCode = `
module parser_discard;
void function()
{
discard function();
}
`;
File dummyFile;
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
try
{
compiler.doLex();
assert(true);
}
catch(LexerException e)
{
assert(false);
}
try
{
compiler.doParse();
Program program = compiler.getProgram();
// There is only a single module in this program
Module modulle = program.getModules()[0];
/* Module name must be parser_discard */
assert(cmp(modulle.getName(), "parser_discard")==0);
TypeChecker tc = new TypeChecker(compiler);
/* Find the function named `function` */
Entity func = tc.getResolver().resolveBest(modulle, "function");
assert(func);
assert(cast(Function)func); // Ensure it is a Funciton
/* Get the function's body */
Container funcContainer = cast(Container)func;
assert(funcContainer);
Statement[] functionStatements = funcContainer.getStatements();
assert(functionStatements.length == 1);
/* First statement should be a discard */
DiscardStatement discard = cast(DiscardStatement)functionStatements[0];
assert(discard);
/* The statement being discarded should be a function call */
FunctionCall functionCall = cast(FunctionCall)discard.getExpression();
assert(functionCall);
}
catch(TError e)
{
assert(false);
}
}
/**
* Function definition test case
*/

@ -1755,77 +1755,6 @@ public final class Branch : Entity, Container
}
}
public final class DiscardStatement : Statement, MStatementSearchable, MStatementReplaceable
{
private Expression expression;
this(Expression expression)
{
this.expression = expression;
/* Weighted as 2 */
weight = 2;
}
public Expression getExpression()
{
return expression;
}
public override string toString()
{
return "[DiscardStatement: (Exp: "~expression.toString()~")]";
}
public override Statement[] search(TypeInfo_Class clazzType)
{
/* List of returned matches */
Statement[] matches;
/* Are we (ourselves) of this type? */
if(clazzType.isBaseOf(this.classinfo))
{
matches ~= [this];
}
/* Recurse on our `Expression` (if possible) */
MStatementSearchable innerStmt = cast(MStatementSearchable)expression;
if(innerStmt)
{
matches ~= innerStmt.search(clazzType);
}
return matches;
}
public override bool replace(Statement thiz, Statement that)
{
import std.stdio;
writeln("Replace() enter discard");
/* Check if our `Expression` matches, then replace */
if(expression == thiz)
{
// NOTE: This legit makes no sense and won't do anything, we could remove this
// and honestly should probably make this return false
// FIXME: Make this return `false` (see above)
expression = cast(Expression)that;
return true;
}
/* If not direct match, then recurse and replace (if possible) */
else if(cast(MStatementReplaceable)expression)
{
MStatementReplaceable replStmt = cast(MStatementReplaceable)expression;
return replStmt.replace(thiz, that);
}
/* If not direct match and not replaceable */
else
{
return false;
}
}
}
public final class ExternStmt : Statement
{
// Pseudo entity created

@ -3736,32 +3736,6 @@ public final class TypeChecker
pointerDereferenceAssignmentInstruction.setContext(ptrDerefAss.context);
addInstrB(pointerDereferenceAssignmentInstruction);
}
/**
* Discard statement (DiscardStatement)
*/
else if(cast(DiscardStatement)statement)
{
DiscardStatement discardStatement = cast(DiscardStatement)statement;
/* Pop off a Value instruction */
Value exprInstr = cast(Value)popInstr();
assert(exprInstr);
/**
* Code gen
*
* 1. Create the DiscardInstruction containing the Value instruction
* `exprInstr`
* 2. Set the context
* 3. Add the instruction
*/
DiscardInstruction discardInstruction = new DiscardInstruction(exprInstr);
discardInstruction.setContext(discardStatement.context);
addInstrB(discardInstruction);
}
/**
* Standalone expression statements
*/
else if(cast(ExpressionStatement)statement)
{
ExpressionStatement exprStmt = cast(ExpressionStatement)statement;

@ -1145,25 +1145,6 @@ public class DNodeGenerator
return ptrAssDerefDNode;
}
/**
* Discard statement (DiscardStatement)
*/
else if(cast(DiscardStatement)entity)
{
DiscardStatement discardStatement = cast(DiscardStatement)entity;
discardStatement.setContext(context);
DNode discardStatementDNode = pool(discardStatement);
ERROR("Implement discard statement!");
/* Pass the expression */
Expression discardExpression = discardStatement.getExpression();
DNode discardExpresionDNode = expressionPass(discardExpression, context);
discardStatementDNode.needs(discardExpresionDNode);
return discardStatementDNode;
}
/**
* Extern statement (ExternStmt)
*/
else if(cast(ExternStmt)entity)

@ -15,7 +15,7 @@ int function()
stackArr[0] = &val1;
stackArr[1] = &val2;
discard coerce(stackArr);
coerce(stackArr);
return val1+val2;
}
}

@ -14,10 +14,10 @@ int function()
stackArr[0] = &val1;
stackArr[1] = &val2;
discard coerce_good1(stackArr);
discard coerce_good2(stackArr);
discard coerce_good3(stackArr);
discard coerce_good4(stackArr);
coerce_good1(stackArr);
coerce_good2(stackArr);
coerce_good3(stackArr);
coerce_good4(stackArr);
return val1+val2;
}
}

@ -9,7 +9,7 @@ void coerce(int* in)
int function()
{
int[2] stackArr;
discard coerce(stackArr);
coerce(stackArr);
return stackArr[0]+stackArr[1];
}
}

@ -9,7 +9,7 @@ void coerce(int* in)
int function()
{
int[2] stackArr;
discard coerce(stackArr);
coerce(stackArr);
return stackArr[0]+stackArr[1];
}
}

Loading…
Cancel
Save