Remove implicit this for now
This commit is contained in:
@@ -1,16 +1,6 @@
|
|||||||
extern func puts(fmt: cstring)
|
extern func puts(fmt: cstring)
|
||||||
|
|
||||||
interface Printable
|
struct Human
|
||||||
{
|
|
||||||
func print()
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Stringable
|
|
||||||
{
|
|
||||||
func str(): cstring
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Human : Printable, Stringable
|
|
||||||
{
|
{
|
||||||
name: cstring
|
name: cstring
|
||||||
|
|
||||||
@@ -18,11 +8,6 @@ struct Human : Printable, Stringable
|
|||||||
{
|
{
|
||||||
return this.name
|
return this.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func print()
|
|
||||||
{
|
|
||||||
puts(this.str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(args: []cstring): i64
|
func main(args: []cstring): i64
|
||||||
@@ -32,7 +17,6 @@ func main(args: []cstring): i64
|
|||||||
}
|
}
|
||||||
|
|
||||||
puts(human.str())
|
puts(human.str())
|
||||||
// human.print()
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -413,12 +413,10 @@ public partial class QBEGenerator
|
|||||||
|
|
||||||
private Val EmitStructFuncAccess(StructFuncAccessNode structFuncAccess)
|
private Val EmitStructFuncAccess(StructFuncAccessNode structFuncAccess)
|
||||||
{
|
{
|
||||||
var target = EmitUnwrap(EmitExpression(structFuncAccess.Target));
|
|
||||||
|
|
||||||
var structDef = _definitionTable.LookupStruct(structFuncAccess.StructType.Name);
|
var structDef = _definitionTable.LookupStruct(structFuncAccess.StructType.Name);
|
||||||
var func = StructFuncName(structDef.Name, structFuncAccess.Func);
|
var func = StructFuncName(structDef.Name, structFuncAccess.Func);
|
||||||
|
|
||||||
return new Val(func, structFuncAccess.Type, ValKind.Direct, target);
|
return new Val(func, structFuncAccess.Type, ValKind.Direct);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Val EmitInterfaceFuncAccess(InterfaceFuncAccessNode interfaceFuncAccess)
|
private Val EmitInterfaceFuncAccess(InterfaceFuncAccessNode interfaceFuncAccess)
|
||||||
@@ -438,13 +436,7 @@ public partial class QBEGenerator
|
|||||||
var func = TmpName();
|
var func = TmpName();
|
||||||
_writer.Indented($"{func} =l loadl {funcOffset}");
|
_writer.Indented($"{func} =l loadl {funcOffset}");
|
||||||
|
|
||||||
var dataPointer = TmpName();
|
return new Val(func, interfaceFuncAccess.Type, ValKind.Direct);
|
||||||
_writer.Indented($"{dataPointer} =l add {target}, 8");
|
|
||||||
|
|
||||||
var data = TmpName();
|
|
||||||
_writer.Indented($"{data} =l loadl {dataPointer}");
|
|
||||||
|
|
||||||
return new Val(func, interfaceFuncAccess.Type, ValKind.Direct, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Val EmitInterfaceInitializer(InterfaceInitializerNode interfaceInitializer, string? destination = null)
|
private Val EmitInterfaceInitializer(InterfaceInitializerNode interfaceInitializer, string? destination = null)
|
||||||
@@ -484,10 +476,6 @@ public partial class QBEGenerator
|
|||||||
var expression = EmitExpression(funcCall.Expression);
|
var expression = EmitExpression(funcCall.Expression);
|
||||||
|
|
||||||
var parameterStrings = new List<string>();
|
var parameterStrings = new List<string>();
|
||||||
if (expression.ThisArg != null)
|
|
||||||
{
|
|
||||||
parameterStrings.Add($"l {expression.ThisArg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var parameter in funcCall.Parameters)
|
foreach (var parameter in funcCall.Parameters)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -623,7 +623,7 @@ public class CStringLiteral(string value, string name)
|
|||||||
public string Name { get; } = name;
|
public string Name { get; } = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Val(string Name, TypeNode Type, ValKind Kind, string? ThisArg = null);
|
public record Val(string Name, TypeNode Type, ValKind Kind);
|
||||||
|
|
||||||
public class Scope(Scope? parent = null)
|
public class Scope(Scope? parent = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,16 +66,11 @@ public sealed class Parser
|
|||||||
return new SyntaxTree(GetTokens(_tokenIndex), definitions);
|
return new SyntaxTree(GetTokens(_tokenIndex), definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuncSignatureSyntax ParseFuncSignature(TypeSyntax? thisArg = null)
|
private FuncSignatureSyntax ParseFuncSignature()
|
||||||
{
|
{
|
||||||
var startIndex = _tokenIndex;
|
var startIndex = _tokenIndex;
|
||||||
List<FuncParameterSyntax> parameters = [];
|
List<FuncParameterSyntax> parameters = [];
|
||||||
|
|
||||||
if (thisArg != null)
|
|
||||||
{
|
|
||||||
parameters.Add(new FuncParameterSyntax([], "this", thisArg));
|
|
||||||
}
|
|
||||||
|
|
||||||
ExpectSymbol(Symbol.OpenParen);
|
ExpectSymbol(Symbol.OpenParen);
|
||||||
|
|
||||||
while (!TryExpectSymbol(Symbol.CloseParen))
|
while (!TryExpectSymbol(Symbol.CloseParen))
|
||||||
@@ -175,7 +170,7 @@ public sealed class Parser
|
|||||||
if (TryExpectSymbol(Symbol.Func))
|
if (TryExpectSymbol(Symbol.Func))
|
||||||
{
|
{
|
||||||
var funcName = ExpectIdentifier().Value;
|
var funcName = ExpectIdentifier().Value;
|
||||||
var funcSignature = ParseFuncSignature(new CustomTypeSyntax([], name.Value));
|
var funcSignature = ParseFuncSignature();
|
||||||
var funcBody = ParseBlock();
|
var funcBody = ParseBlock();
|
||||||
|
|
||||||
funcs.Add(new StructFuncSyntax(GetTokens(memberStartIndex), funcName, funcSignature, funcBody));
|
funcs.Add(new StructFuncSyntax(GetTokens(memberStartIndex), funcName, funcSignature, funcBody));
|
||||||
|
|||||||
Reference in New Issue
Block a user