remove refs
This commit is contained in:
@@ -605,16 +605,6 @@ public class DereferenceNode(List<Token> tokens, NubType type, ExpressionNode ta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RefDereferenceNode(List<Token> tokens, NubType type, ExpressionNode target) : LValueExpressionNode(tokens, type)
|
|
||||||
{
|
|
||||||
public ExpressionNode Target { get; } = target;
|
|
||||||
|
|
||||||
public override IEnumerable<Node> Children()
|
|
||||||
{
|
|
||||||
yield return Target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SizeNode(List<Token> tokens, NubType TargetType) : RValueExpressionNode(tokens, new NubIntType(false, 64))
|
public class SizeNode(List<Token> tokens, NubType TargetType) : RValueExpressionNode(tokens, new NubIntType(false, 64))
|
||||||
{
|
{
|
||||||
public NubType TargetType { get; } = TargetType;
|
public NubType TargetType { get; } = TargetType;
|
||||||
@@ -635,19 +625,6 @@ public class CastNode(List<Token> tokens, NubType type, ExpressionNode value) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RefStructInitializerNode(List<Token> tokens, NubType type, Dictionary<IdentifierToken, ExpressionNode> initializers) : RValueExpressionNode(tokens, type)
|
|
||||||
{
|
|
||||||
public Dictionary<IdentifierToken, ExpressionNode> Initializers { get; } = initializers;
|
|
||||||
|
|
||||||
public override IEnumerable<Node> Children()
|
|
||||||
{
|
|
||||||
foreach (var initializer in Initializers)
|
|
||||||
{
|
|
||||||
yield return initializer.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class EnumReferenceIntermediateNode(List<Token> tokens, IdentifierToken moduleToken, IdentifierToken nameToken) : IntermediateExpression(tokens)
|
public class EnumReferenceIntermediateNode(List<Token> tokens, IdentifierToken moduleToken, IdentifierToken nameToken) : IntermediateExpression(tokens)
|
||||||
{
|
{
|
||||||
public IdentifierToken ModuleToken { get; } = moduleToken;
|
public IdentifierToken ModuleToken { get; } = moduleToken;
|
||||||
|
|||||||
@@ -57,15 +57,6 @@ public sealed class NubPointerType(NubType baseType) : NubType
|
|||||||
public override int GetHashCode() => HashCode.Combine(typeof(NubPointerType), BaseType);
|
public override int GetHashCode() => HashCode.Combine(typeof(NubPointerType), BaseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NubRefType(NubType baseType) : NubType
|
|
||||||
{
|
|
||||||
public NubType BaseType { get; } = baseType;
|
|
||||||
|
|
||||||
public override string ToString() => "&" + BaseType;
|
|
||||||
public override bool Equals(NubType? other) => other is NubRefType;
|
|
||||||
public override int GetHashCode() => HashCode.Combine(typeof(NubRefType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NubFuncType(List<NubType> parameters, NubType returnType) : NubType
|
public class NubFuncType(List<NubType> parameters, NubType returnType) : NubType
|
||||||
{
|
{
|
||||||
public List<NubType> Parameters { get; } = parameters;
|
public List<NubType> Parameters { get; } = parameters;
|
||||||
|
|||||||
@@ -796,16 +796,18 @@ public sealed class TypeChecker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExpressionNode CheckDereference(DereferenceSyntax expression, NubType? _)
|
private DereferenceNode CheckDereference(DereferenceSyntax expression, NubType? _)
|
||||||
{
|
{
|
||||||
var target = CheckExpression(expression.Target);
|
var target = CheckExpression(expression.Target);
|
||||||
|
if (target.Type is not NubPointerType pointerType)
|
||||||
return target.Type switch
|
|
||||||
{
|
{
|
||||||
NubPointerType pointerType => new DereferenceNode(expression.Tokens, pointerType.BaseType, target),
|
throw new CompileException(Diagnostic
|
||||||
NubRefType refType => new RefDereferenceNode(expression.Tokens, refType.BaseType, target),
|
.Error($"Cannot dereference non-pointer type {target.Type}")
|
||||||
_ => throw new CompileException(Diagnostic.Error($"Cannot dereference non-pointer type {target.Type}").At(expression).Build())
|
.At(expression)
|
||||||
};
|
.Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DereferenceNode(expression.Tokens, pointerType.BaseType, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuncCallNode CheckFuncCall(FuncCallSyntax expression, NubType? _)
|
private FuncCallNode CheckFuncCall(FuncCallSyntax expression, NubType? _)
|
||||||
@@ -1090,7 +1092,7 @@ public sealed class TypeChecker
|
|||||||
throw new UnreachableException();
|
throw new UnreachableException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExpressionNode CheckStructInitializer(StructInitializerSyntax expression, NubType? expectedType)
|
private StructInitializerNode CheckStructInitializer(StructInitializerSyntax expression, NubType? expectedType)
|
||||||
{
|
{
|
||||||
NubStructType? structType = null;
|
NubStructType? structType = null;
|
||||||
|
|
||||||
@@ -1104,14 +1106,10 @@ public sealed class TypeChecker
|
|||||||
|
|
||||||
structType = checkedStructType;
|
structType = checkedStructType;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (expectedType is NubStructType expectedStructType)
|
||||||
{
|
{
|
||||||
structType = expectedType switch
|
structType ??= expectedStructType;
|
||||||
{
|
|
||||||
NubStructType expectedStructType => expectedStructType,
|
|
||||||
NubRefType { BaseType: NubStructType expectedStructType } => expectedStructType,
|
|
||||||
_ => structType
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (structType == null)
|
if (structType == null)
|
||||||
@@ -1154,14 +1152,7 @@ public sealed class TypeChecker
|
|||||||
.Build());
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectedType is NubRefType refType && refType.BaseType == structType)
|
return new StructInitializerNode(expression.Tokens, structType, initializers);
|
||||||
{
|
|
||||||
return new RefStructInitializerNode(expression.Tokens, refType, initializers);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new StructInitializerNode(expression.Tokens, structType, initializers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockNode CheckBlock(BlockSyntax node)
|
private BlockNode CheckBlock(BlockSyntax node)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ public class TypeResolver
|
|||||||
SliceTypeSyntax slice => new NubSliceType(ResolveType(slice.BaseType, currentModule)),
|
SliceTypeSyntax slice => new NubSliceType(ResolveType(slice.BaseType, currentModule)),
|
||||||
ConstArrayTypeSyntax arr => new NubConstArrayType(ResolveType(arr.BaseType, currentModule), arr.Size),
|
ConstArrayTypeSyntax arr => new NubConstArrayType(ResolveType(arr.BaseType, currentModule), arr.Size),
|
||||||
PointerTypeSyntax ptr => new NubPointerType(ResolveType(ptr.BaseType, currentModule)),
|
PointerTypeSyntax ptr => new NubPointerType(ResolveType(ptr.BaseType, currentModule)),
|
||||||
RefTypeSyntax r => new NubRefType(ResolveType(r.BaseType, currentModule)),
|
|
||||||
StringTypeSyntax => new NubStringType(),
|
StringTypeSyntax => new NubStringType(),
|
||||||
CustomTypeSyntax c => ResolveCustomType(c, currentModule),
|
CustomTypeSyntax c => ResolveCustomType(c, currentModule),
|
||||||
VoidTypeSyntax => new NubVoidType(),
|
VoidTypeSyntax => new NubVoidType(),
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public static class CType
|
|||||||
NubIntType i => CreateIntType(i, variableName),
|
NubIntType i => CreateIntType(i, variableName),
|
||||||
NubFloatType f => CreateFloatType(f, variableName),
|
NubFloatType f => CreateFloatType(f, variableName),
|
||||||
NubPointerType p => CreatePointerType(p, variableName),
|
NubPointerType p => CreatePointerType(p, variableName),
|
||||||
NubRefType r => CreateRefType(r, variableName),
|
|
||||||
NubSliceType => "nub_slice" + (variableName != null ? $" {variableName}" : ""),
|
NubSliceType => "nub_slice" + (variableName != null ? $" {variableName}" : ""),
|
||||||
NubStringType => "nub_string" + (variableName != null ? $" {variableName}" : ""),
|
NubStringType => "nub_string" + (variableName != null ? $" {variableName}" : ""),
|
||||||
NubConstArrayType a => CreateConstArrayType(a, variableName, constArraysAsPointers),
|
NubConstArrayType a => CreateConstArrayType(a, variableName, constArraysAsPointers),
|
||||||
@@ -49,12 +48,6 @@ public static class CType
|
|||||||
return cType + (varName != null ? $" {varName}" : "");
|
return cType + (varName != null ? $" {varName}" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreateRefType(NubRefType ptr, string? varName)
|
|
||||||
{
|
|
||||||
var baseType = Create(ptr.BaseType);
|
|
||||||
return baseType + "*" + (varName != null ? $" {varName}" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CreatePointerType(NubPointerType ptr, string? varName)
|
private static string CreatePointerType(NubPointerType ptr, string? varName)
|
||||||
{
|
{
|
||||||
var baseType = Create(ptr.BaseType);
|
var baseType = Create(ptr.BaseType);
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ public class Generator
|
|||||||
_writer.WriteLine("""
|
_writer.WriteLine("""
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void *rc_alloc(size_t size, void (*destructor)(void *self));
|
|
||||||
void rc_retain(void *obj);
|
|
||||||
void rc_release(void *obj);
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned long long length;
|
unsigned long long length;
|
||||||
@@ -78,34 +74,6 @@ public class Generator
|
|||||||
{
|
{
|
||||||
var value = EmitExpression(field.Value);
|
var value = EmitExpression(field.Value);
|
||||||
_writer.WriteLine($"self->{field.NameToken.Value} = {value}");
|
_writer.WriteLine($"self->{field.NameToken.Value} = {value}");
|
||||||
EmitConstructor($"self->{field.NameToken.Value}", field.Type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_writer.WriteLine("}");
|
|
||||||
_writer.WriteLine();
|
|
||||||
|
|
||||||
_writer.WriteLine($"void {CType.Create(structType.StructType)}_destroy({CType.Create(structType.StructType)} *self)");
|
|
||||||
_writer.WriteLine("{");
|
|
||||||
using (_writer.Indent())
|
|
||||||
{
|
|
||||||
foreach (var field in structType.Fields)
|
|
||||||
{
|
|
||||||
if (field.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"if (self->{field.NameToken.Value})");
|
|
||||||
_writer.WriteLine("{");
|
|
||||||
using (_writer.Indent())
|
|
||||||
{
|
|
||||||
EmitDestructor($"self->{field.NameToken.Value}", field.Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
_writer.WriteLine("}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EmitDestructor($"self->{field.NameToken.Value}", field.Type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,14 +99,6 @@ public class Generator
|
|||||||
{
|
{
|
||||||
using (BeginScope())
|
using (BeginScope())
|
||||||
{
|
{
|
||||||
foreach (var parameter in funcNode.Prototype.Parameters)
|
|
||||||
{
|
|
||||||
if (parameter.Type is NubRefType)
|
|
||||||
{
|
|
||||||
Scope.Defer(() => _writer.WriteLine($"rc_release({parameter.NameToken.Value});"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EmitBlock(funcNode.Body);
|
EmitBlock(funcNode.Body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,23 +168,16 @@ public class Generator
|
|||||||
|
|
||||||
private void EmitLine(Token? token)
|
private void EmitLine(Token? token)
|
||||||
{
|
{
|
||||||
// if (token == null) return;
|
if (token == null) return;
|
||||||
// var file = token.Span.FilePath;
|
var file = token.Span.FilePath;
|
||||||
// var line = token.Span.Start.Line;
|
var line = token.Span.Start.Line;
|
||||||
// _writer.WriteLine($"#line {line} \"{file}\"");
|
_writer.WriteLine($"#line {line} \"{file}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EmitAssignment(AssignmentNode assignmentNode)
|
private void EmitAssignment(AssignmentNode assignmentNode)
|
||||||
{
|
{
|
||||||
var target = EmitExpression(assignmentNode.Target);
|
var target = EmitExpression(assignmentNode.Target);
|
||||||
var value = EmitExpression(assignmentNode.Value);
|
var value = EmitExpression(assignmentNode.Value);
|
||||||
|
|
||||||
if (assignmentNode.Target.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({value});");
|
|
||||||
_writer.WriteLine($"rc_release({target});");
|
|
||||||
}
|
|
||||||
|
|
||||||
_writer.WriteLine($"{target} = {value};");
|
_writer.WriteLine($"{target} = {value};");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,10 +279,6 @@ public class Generator
|
|||||||
var returnValue = EmitExpression(returnNode.Value);
|
var returnValue = EmitExpression(returnNode.Value);
|
||||||
var tmp = NewTmp();
|
var tmp = NewTmp();
|
||||||
_writer.WriteLine($"{CType.Create(returnNode.Value.Type, tmp)} = {returnValue};");
|
_writer.WriteLine($"{CType.Create(returnNode.Value.Type, tmp)} = {returnValue};");
|
||||||
if (returnNode.Value.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({tmp});");
|
|
||||||
}
|
|
||||||
|
|
||||||
EmitScopeCleanup();
|
EmitScopeCleanup();
|
||||||
EmitLine(returnNode.Tokens.FirstOrDefault());
|
EmitLine(returnNode.Tokens.FirstOrDefault());
|
||||||
@@ -349,13 +298,7 @@ public class Generator
|
|||||||
if (variableDeclarationNode.Assignment != null)
|
if (variableDeclarationNode.Assignment != null)
|
||||||
{
|
{
|
||||||
var value = EmitExpression(variableDeclarationNode.Assignment);
|
var value = EmitExpression(variableDeclarationNode.Assignment);
|
||||||
|
|
||||||
_writer.WriteLine($"{CType.Create(variableDeclarationNode.Type, variableDeclarationNode.NameToken.Value)} = {value};");
|
_writer.WriteLine($"{CType.Create(variableDeclarationNode.Type, variableDeclarationNode.NameToken.Value)} = {value};");
|
||||||
|
|
||||||
if (variableDeclarationNode.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({variableDeclarationNode.NameToken.Value});");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -402,8 +345,6 @@ public class Generator
|
|||||||
FuncCallNode funcCallNode => EmitFuncCall(funcCallNode),
|
FuncCallNode funcCallNode => EmitFuncCall(funcCallNode),
|
||||||
FuncIdentifierNode funcIdentifierNode => FuncName(funcIdentifierNode.ModuleToken.Value, funcIdentifierNode.NameToken.Value, funcIdentifierNode.ExternSymbolToken?.Value),
|
FuncIdentifierNode funcIdentifierNode => FuncName(funcIdentifierNode.ModuleToken.Value, funcIdentifierNode.NameToken.Value, funcIdentifierNode.ExternSymbolToken?.Value),
|
||||||
AddressOfNode addressOfNode => EmitAddressOf(addressOfNode),
|
AddressOfNode addressOfNode => EmitAddressOf(addressOfNode),
|
||||||
RefDereferenceNode refDereferenceNode => EmitRefDereference(refDereferenceNode),
|
|
||||||
RefStructInitializerNode refStructInitializerNode => EmitRefStructInitializer(refStructInitializerNode),
|
|
||||||
SizeNode sizeBuiltinNode => $"sizeof({CType.Create(sizeBuiltinNode.TargetType)})",
|
SizeNode sizeBuiltinNode => $"sizeof({CType.Create(sizeBuiltinNode.TargetType)})",
|
||||||
SliceIndexAccessNode sliceIndexAccessNode => EmitSliceArrayIndexAccess(sliceIndexAccessNode),
|
SliceIndexAccessNode sliceIndexAccessNode => EmitSliceArrayIndexAccess(sliceIndexAccessNode),
|
||||||
StringLiteralNode stringLiteralNode => EmitStringLiteral(stringLiteralNode),
|
StringLiteralNode stringLiteralNode => EmitStringLiteral(stringLiteralNode),
|
||||||
@@ -546,24 +487,13 @@ public class Generator
|
|||||||
var parameterNames = new List<string>();
|
var parameterNames = new List<string>();
|
||||||
foreach (var parameter in funcCallNode.Parameters)
|
foreach (var parameter in funcCallNode.Parameters)
|
||||||
{
|
{
|
||||||
var result = EmitExpression(parameter);
|
parameterNames.Add(EmitExpression(parameter));
|
||||||
if (parameter.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({result});");
|
|
||||||
}
|
|
||||||
|
|
||||||
parameterNames.Add(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmp = NewTmp();
|
var tmp = NewTmp();
|
||||||
|
|
||||||
_writer.WriteLine($"{CType.Create(funcCallNode.Type)} {tmp} = {name}({string.Join(", ", parameterNames)});");
|
_writer.WriteLine($"{CType.Create(funcCallNode.Type)} {tmp} = {name}({string.Join(", ", parameterNames)});");
|
||||||
|
|
||||||
if (funcCallNode.Type is NubRefType)
|
|
||||||
{
|
|
||||||
Scope.Defer(() => _writer.WriteLine($"rc_release({tmp});"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,36 +503,6 @@ public class Generator
|
|||||||
return $"&{value}";
|
return $"&{value}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string EmitRefDereference(RefDereferenceNode refDereferenceNode)
|
|
||||||
{
|
|
||||||
var pointer = EmitExpression(refDereferenceNode.Target);
|
|
||||||
return $"*{pointer}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private string EmitRefStructInitializer(RefStructInitializerNode refStructInitializerNode)
|
|
||||||
{
|
|
||||||
var type = (NubRefType)refStructInitializerNode.Type;
|
|
||||||
var structType = (NubStructType)type.BaseType;
|
|
||||||
|
|
||||||
var tmp = NewTmp();
|
|
||||||
_writer.WriteLine($"{CType.Create(type)} {tmp} = ({CType.Create(type)})rc_alloc(sizeof({CType.Create(structType)}), (void (*)(void *)){CType.Create(structType)}_destroy);");
|
|
||||||
Scope.Defer(() => _writer.WriteLine($"rc_release({tmp});"));
|
|
||||||
|
|
||||||
EmitConstructor(tmp, structType);
|
|
||||||
|
|
||||||
foreach (var initializer in refStructInitializerNode.Initializers)
|
|
||||||
{
|
|
||||||
var value = EmitExpression(initializer.Value);
|
|
||||||
_writer.WriteLine($"{tmp}->{initializer.Key} = {value};");
|
|
||||||
if (initializer.Value.Type is NubRefType)
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({tmp}->{initializer.Key});");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string EmitSliceArrayIndexAccess(SliceIndexAccessNode sliceIndexAccessNode)
|
private string EmitSliceArrayIndexAccess(SliceIndexAccessNode sliceIndexAccessNode)
|
||||||
{
|
{
|
||||||
var targetType = (NubSliceType)sliceIndexAccessNode.Target.Type;
|
var targetType = (NubSliceType)sliceIndexAccessNode.Target.Type;
|
||||||
@@ -630,7 +530,7 @@ public class Generator
|
|||||||
|
|
||||||
var tmp = NewTmp();
|
var tmp = NewTmp();
|
||||||
_writer.WriteLine($"{CType.Create(structType)} {tmp} = ({CType.Create(structType)}){{0}};");
|
_writer.WriteLine($"{CType.Create(structType)} {tmp} = ({CType.Create(structType)}){{0}};");
|
||||||
EmitConstructor($"&{tmp}", structType);
|
_writer.WriteLine($"{CType.Create(structType)}_create(&{tmp});");
|
||||||
|
|
||||||
foreach (var initializer in structInitializerNode.Initializers)
|
foreach (var initializer in structInitializerNode.Initializers)
|
||||||
{
|
{
|
||||||
@@ -721,59 +621,6 @@ public class Generator
|
|||||||
{
|
{
|
||||||
deferred.Invoke();
|
deferred.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
var variables = Scope.GetVariables();
|
|
||||||
while (variables.TryPop(out var variable))
|
|
||||||
{
|
|
||||||
EmitDestructor(variable.Ident, variable.Type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EmitConstructor(string target, NubType type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case NubStructType structType:
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"{CType.Create(structType)}_create({target});");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NubRefType:
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_retain({target});");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EmitDestructor(string target, NubType type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case NubStructType structType:
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"{CType.Create(structType)}_destroy({target});");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NubConstArrayType constArrayType:
|
|
||||||
{
|
|
||||||
var index = NewTmp();
|
|
||||||
_writer.WriteLine($"for (unsigned long long {index} = 0; {index} < {constArrayType.Size}; ++{index})");
|
|
||||||
_writer.WriteLine("{");
|
|
||||||
using (_writer.Indent())
|
|
||||||
{
|
|
||||||
EmitDestructor($"&({target}[{index}])", constArrayType.ElementType);
|
|
||||||
}
|
|
||||||
|
|
||||||
_writer.WriteLine("}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NubRefType:
|
|
||||||
{
|
|
||||||
_writer.WriteLine($"rc_release({target});");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScopeDisposer BeginScope()
|
private ScopeDisposer BeginScope()
|
||||||
@@ -800,7 +647,7 @@ public class Variable(string ident, NubType type)
|
|||||||
|
|
||||||
public class Scope
|
public class Scope
|
||||||
{
|
{
|
||||||
private bool _hasTerminated = false;
|
private bool _hasTerminated;
|
||||||
private readonly List<Action> _deferred = [];
|
private readonly List<Action> _deferred = [];
|
||||||
private readonly List<Variable> _variables = [];
|
private readonly List<Variable> _variables = [];
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public static class HeaderGenerator
|
|||||||
|
|
||||||
writer.WriteLine($"}} {CType.Create(structType)};");
|
writer.WriteLine($"}} {CType.Create(structType)};");
|
||||||
writer.WriteLine($"void {CType.Create(structType)}_create({CType.Create(structType)} *self);");
|
writer.WriteLine($"void {CType.Create(structType)}_create({CType.Create(structType)} *self);");
|
||||||
writer.WriteLine($"void {CType.Create(structType)}_destroy({CType.Create(structType)} *self);");
|
|
||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -716,12 +716,6 @@ public sealed class Parser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TryExpectSymbol(Symbol.Ampersand))
|
|
||||||
{
|
|
||||||
var baseType = ParseType();
|
|
||||||
return new RefTypeSyntax(GetTokens(startIndex), baseType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TryExpectSymbol(Symbol.Caret))
|
if (TryExpectSymbol(Symbol.Caret))
|
||||||
{
|
{
|
||||||
var baseType = ParseType();
|
var baseType = ParseType();
|
||||||
|
|||||||
@@ -150,6 +150,4 @@ public record ConstArrayTypeSyntax(List<Token> Tokens, TypeSyntax BaseType, ulon
|
|||||||
|
|
||||||
public record CustomTypeSyntax(List<Token> Tokens, IdentifierToken? ModuleToken, IdentifierToken NameToken) : TypeSyntax(Tokens);
|
public record CustomTypeSyntax(List<Token> Tokens, IdentifierToken? ModuleToken, IdentifierToken NameToken) : TypeSyntax(Tokens);
|
||||||
|
|
||||||
public record RefTypeSyntax(List<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -11,17 +11,11 @@ struct Name
|
|||||||
struct Human
|
struct Human
|
||||||
{
|
{
|
||||||
age: u64
|
age: u64
|
||||||
name: &Name
|
name: Name
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "main" func main(argc: i64, argv: [?]^i8): i64
|
extern "main" func main(argc: i64, argv: [?]^i8): i64
|
||||||
{
|
{
|
||||||
let x: [2]Human = [{}, {}]
|
let x: [2]Human = [{}, {}]
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func test(x: &Human): &Human
|
|
||||||
{
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user