Remove hook concept
This commit is contained in:
@@ -308,16 +308,6 @@ public class QBEGenerator
|
||||
{
|
||||
var value = EmitExpression(source);
|
||||
_writer.Indented($"blit {value}, {destinationAddress}, {SizeOf(source.Type)}");
|
||||
|
||||
if (source.Type is NubStructType structType)
|
||||
{
|
||||
var copyFunc = structType.Functions.FirstOrDefault(x => x.Hook == "oncopy");
|
||||
if (copyFunc != null)
|
||||
{
|
||||
_writer.Indented($"call {StructFuncName(structType.Module, structType.Name, copyFunc.Name)}(l {destinationAddress})");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -409,13 +399,7 @@ public class QBEGenerator
|
||||
_writer.WriteLine(") {");
|
||||
_writer.WriteLine("@start");
|
||||
|
||||
var scope = new Scope();
|
||||
foreach (var parameter in function.Signature.Parameters)
|
||||
{
|
||||
scope.Variables.Push(new Variable(parameter.Name, parameter.Type));
|
||||
}
|
||||
|
||||
EmitBlock(function.Body, scope);
|
||||
EmitBlock(function.Body);
|
||||
|
||||
// Implicit return for void functions if no explicit return has been set
|
||||
if (function.Signature.ReturnType is NubVoidType && function.Body.Statements.LastOrDefault() is not ReturnNode)
|
||||
@@ -453,13 +437,7 @@ public class QBEGenerator
|
||||
_writer.WriteLine(") {");
|
||||
_writer.WriteLine("@start");
|
||||
|
||||
var scope = new Scope();
|
||||
foreach (var parameter in funcDef.Signature.Parameters)
|
||||
{
|
||||
scope.Variables.Push(new Variable(parameter.Name, parameter.Type));
|
||||
}
|
||||
|
||||
EmitBlock(funcDef.Body, scope);
|
||||
EmitBlock(funcDef.Body);
|
||||
|
||||
_writer.WriteLine("}");
|
||||
_writer.NewLine();
|
||||
@@ -530,18 +508,6 @@ public class QBEGenerator
|
||||
{
|
||||
EmitStatement(defer.Statement);
|
||||
}
|
||||
|
||||
while (Scope.Variables.TryPop(out var variable))
|
||||
{
|
||||
if (variable.Type is NubStructType structType)
|
||||
{
|
||||
var destroyFunc = structType.Functions.FirstOrDefault(x => x.Hook == "ondestroy");
|
||||
if (destroyFunc != null)
|
||||
{
|
||||
_writer.Indented($"call {StructFuncName(structType.Module, structType.Name, destroyFunc.Name)}(l %{variable.Name})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EmitIf(IfNode ifStatement)
|
||||
@@ -588,8 +554,6 @@ public class QBEGenerator
|
||||
{
|
||||
EmitCopyInto(variableDeclaration.Assignment, name);
|
||||
}
|
||||
|
||||
Scope.Variables.Push(new Variable(variableDeclaration.Name, variableDeclaration.Type));
|
||||
}
|
||||
|
||||
private void EmitWhile(WhileNode whileStatement)
|
||||
@@ -956,12 +920,6 @@ public class QBEGenerator
|
||||
{
|
||||
_writer.Indented($"call {StructCtorName(structInitializer.StructType.Module, structInitializer.StructType.Name)}(l {destinationAddress})");
|
||||
|
||||
var createFunc = structInitializer.StructType.Functions.FirstOrDefault(x => x.Hook == "oncreate");
|
||||
if (createFunc != null)
|
||||
{
|
||||
_writer.Indented($"call {StructFuncName(structInitializer.StructType.Module, structInitializer.StructType.Name, createFunc.Name)}(l {destinationAddress})");
|
||||
}
|
||||
|
||||
foreach (var (field, value) in structInitializer.Initializers)
|
||||
{
|
||||
var offset = TmpName();
|
||||
@@ -1028,16 +986,6 @@ public class QBEGenerator
|
||||
foreach (var parameter in structFuncCall.Parameters)
|
||||
{
|
||||
var value = EmitExpression(parameter);
|
||||
|
||||
if (parameter.Type is NubStructType structType)
|
||||
{
|
||||
var copyFunc = structType.Functions.FirstOrDefault(x => x.Hook == "oncopy");
|
||||
if (copyFunc != null)
|
||||
{
|
||||
_writer.Indented($"call {StructFuncName(structType.Module, structType.Name, copyFunc.Name)}(l {value})");
|
||||
}
|
||||
}
|
||||
|
||||
parameterStrings.Add($"{FuncQBETypeName(parameter.Type)} {value}");
|
||||
}
|
||||
|
||||
@@ -1141,16 +1089,6 @@ public class QBEGenerator
|
||||
foreach (var parameter in funcCall.Parameters)
|
||||
{
|
||||
var value = EmitExpression(parameter);
|
||||
|
||||
if (parameter.Type is NubStructType structType)
|
||||
{
|
||||
var copyFunc = structType.Functions.FirstOrDefault(x => x.Hook == "oncopy");
|
||||
if (copyFunc != null)
|
||||
{
|
||||
_writer.Indented($"call {StructFuncName(structType.Module, structType.Name, copyFunc.Name)}(l {value})");
|
||||
}
|
||||
}
|
||||
|
||||
parameterStrings.Add($"{FuncQBETypeName(parameter.Type)} {value}");
|
||||
}
|
||||
|
||||
@@ -1267,7 +1205,7 @@ public class QBEGenerator
|
||||
foreach (var function in definition.Functions)
|
||||
{
|
||||
var parameters = function.Signature.Parameters.Select(x => x.Type).ToList();
|
||||
functionTypes.Add(new NubStructFuncType(function.Name, function.Hook, parameters, function.Signature.ReturnType));
|
||||
functionTypes.Add(new NubStructFuncType(function.Name, parameters, function.Signature.ReturnType));
|
||||
}
|
||||
|
||||
return new NubStructType(definition.Module, definition.Name, fieldTypes, functionTypes);
|
||||
@@ -1316,12 +1254,9 @@ public class QBEGenerator
|
||||
|
||||
public class Scope
|
||||
{
|
||||
public readonly Stack<Variable> Variables = [];
|
||||
public readonly Stack<DeferNode> Defers = [];
|
||||
}
|
||||
|
||||
public record Variable(string Name, NubType Type);
|
||||
|
||||
public class StringLiteral(string value, string name)
|
||||
{
|
||||
public string Value { get; } = value;
|
||||
|
||||
Reference in New Issue
Block a user