Compare commits

...

2 Commits

Author SHA1 Message Date
nub31
3505e2547a ... 2025-10-24 15:33:56 +02:00
nub31
766ca9a6b9 remove cstring 2025-10-24 15:27:14 +02:00
10 changed files with 322 additions and 260 deletions

View File

@@ -24,9 +24,6 @@ def map_type(clang_type: Type):
if not decl.is_definition():
return "^void"
if pointee.kind == TypeKind.CHAR_S or pointee.kind == TypeKind.CHAR_U:
return "cstring"
if pointee.kind == TypeKind.FUNCTIONPROTO:
arg_types = []

View File

@@ -2,8 +2,10 @@ using NubLang.Syntax;
namespace NubLang.Ast;
public abstract record Node(List<Token> Tokens)
public abstract class Node(List<Token> tokens)
{
public List<Token> Tokens { get; } = tokens;
public abstract IEnumerable<Node> Children();
public IEnumerable<Node> Descendants()
@@ -29,26 +31,42 @@ public abstract record Node(List<Token> Tokens)
#region Definitions
public abstract record DefinitionNode(List<Token> Tokens, string Module, string Name) : Node(Tokens);
public record FuncParameterNode(List<Token> Tokens, string Name, NubType Type) : Node(Tokens)
public abstract class DefinitionNode(List<Token> tokens, string module, string name) : Node(tokens)
{
public string Module { get; } = module;
public string Name { get; } = name;
}
public class FuncParameterNode(List<Token> tokens, string name, NubType type) : Node(tokens)
{
public string Name { get; } = name;
public NubType Type { get; } = type;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record FuncPrototypeNode(List<Token> Tokens, string Module, string Name, string? ExternSymbol, List<FuncParameterNode> Parameters, NubType ReturnType) : Node(Tokens)
public class FuncPrototypeNode(List<Token> tokens, string module, string name, string? externSymbol, List<FuncParameterNode> parameters, NubType returnType) : Node(tokens)
{
public string Module { get; } = module;
public string Name { get; } = name;
public string? ExternSymbol { get; } = externSymbol;
public List<FuncParameterNode> Parameters { get; } = parameters;
public NubType ReturnType { get; } = returnType;
public override IEnumerable<Node> Children()
{
return Parameters;
}
}
public record FuncNode(List<Token> Tokens, FuncPrototypeNode Prototype, BlockNode? Body) : DefinitionNode(Tokens, Prototype.Module, Prototype.Name)
public class FuncNode(List<Token> tokens, FuncPrototypeNode prototype, BlockNode? body) : DefinitionNode(tokens, prototype.Module, prototype.Name)
{
public FuncPrototypeNode Prototype { get; } = prototype;
public BlockNode? Body { get; } = body;
public override IEnumerable<Node> Children()
{
yield return Prototype;
@@ -63,36 +81,45 @@ public record FuncNode(List<Token> Tokens, FuncPrototypeNode Prototype, BlockNod
#region Statements
public abstract record StatementNode(List<Token> Tokens) : Node(Tokens);
public abstract class StatementNode(List<Token> tokens) : Node(tokens);
public abstract record TerminalStatementNode(List<Token> Tokens) : StatementNode(Tokens);
public abstract class TerminalStatementNode(List<Token> tokens) : StatementNode(tokens);
public record BlockNode(List<Token> Tokens, List<StatementNode> Statements) : StatementNode(Tokens)
public class BlockNode(List<Token> tokens, List<StatementNode> statements) : StatementNode(tokens)
{
public List<StatementNode> Statements { get; } = statements;
public override IEnumerable<Node> Children()
{
return Statements;
}
}
public record StatementFuncCallNode(List<Token> Tokens, FuncCallNode FuncCall) : StatementNode(Tokens)
public class StatementFuncCallNode(List<Token> tokens, FuncCallNode funcCall) : StatementNode(tokens)
{
public FuncCallNode FuncCall { get; } = funcCall;
public override IEnumerable<Node> Children()
{
yield return FuncCall;
}
}
public record ReturnNode(List<Token> Tokens, ExpressionNode? Value) : TerminalStatementNode(Tokens)
public class ReturnNode(List<Token> tokens, ExpressionNode? value) : TerminalStatementNode(tokens)
{
public ExpressionNode? Value { get; } = value;
public override IEnumerable<Node> Children()
{
if (Value != null) yield return Value;
}
}
public record AssignmentNode(List<Token> Tokens, LValueExpressionNode Target, ExpressionNode Value) : StatementNode(Tokens)
public class AssignmentNode(List<Token> tokens, LValueExpressionNode target, ExpressionNode value) : StatementNode(tokens)
{
public LValueExpressionNode Target { get; } = target;
public ExpressionNode Value { get; } = value;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -100,8 +127,12 @@ public record AssignmentNode(List<Token> Tokens, LValueExpressionNode Target, Ex
}
}
public record IfNode(List<Token> Tokens, ExpressionNode Condition, BlockNode Body, Variant<IfNode, BlockNode>? Else) : StatementNode(Tokens)
public class IfNode(List<Token> tokens, ExpressionNode condition, BlockNode body, Variant<IfNode, BlockNode>? @else) : StatementNode(tokens)
{
public ExpressionNode Condition { get; } = condition;
public BlockNode Body { get; } = body;
public Variant<IfNode, BlockNode>? Else { get; } = @else;
public override IEnumerable<Node> Children()
{
yield return Condition;
@@ -113,15 +144,19 @@ public record IfNode(List<Token> Tokens, ExpressionNode Condition, BlockNode Bod
}
}
public record VariableDeclarationNode(List<Token> Tokens, string Name, ExpressionNode? Assignment, NubType Type) : StatementNode(Tokens)
public class VariableDeclarationNode(List<Token> tokens, string name, ExpressionNode? assignment, NubType type) : StatementNode(tokens)
{
public string Name { get; } = name;
public ExpressionNode? Assignment { get; } = assignment;
public NubType Type { get; } = type;
public override IEnumerable<Node> Children()
{
if (Assignment != null) yield return Assignment;
}
}
public record ContinueNode(List<Token> Tokens) : TerminalStatementNode(Tokens)
public class ContinueNode(List<Token> tokens) : TerminalStatementNode(tokens)
{
public override IEnumerable<Node> Children()
{
@@ -129,7 +164,7 @@ public record ContinueNode(List<Token> Tokens) : TerminalStatementNode(Tokens)
}
}
public record BreakNode(List<Token> Tokens) : TerminalStatementNode(Tokens)
public class BreakNode(List<Token> tokens) : TerminalStatementNode(tokens)
{
public override IEnumerable<Node> Children()
{
@@ -137,8 +172,11 @@ public record BreakNode(List<Token> Tokens) : TerminalStatementNode(Tokens)
}
}
public record WhileNode(List<Token> Tokens, ExpressionNode Condition, BlockNode Body) : StatementNode(Tokens)
public class WhileNode(List<Token> tokens, ExpressionNode condition, BlockNode body) : StatementNode(tokens)
{
public ExpressionNode Condition { get; } = condition;
public BlockNode Body { get; } = body;
public override IEnumerable<Node> Children()
{
yield return Condition;
@@ -146,8 +184,13 @@ public record WhileNode(List<Token> Tokens, ExpressionNode Condition, BlockNode
}
}
public record ForSliceNode(List<Token> Tokens, string ElementName, string? IndexName, ExpressionNode Target, BlockNode Body) : StatementNode(Tokens)
public class ForSliceNode(List<Token> tokens, string elementName, string? indexName, ExpressionNode target, BlockNode body) : StatementNode(tokens)
{
public string ElementName { get; } = elementName;
public string? IndexName { get; } = indexName;
public ExpressionNode Target { get; } = target;
public BlockNode Body { get; } = body;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -155,8 +198,13 @@ public record ForSliceNode(List<Token> Tokens, string ElementName, string? Index
}
}
public record ForConstArrayNode(List<Token> Tokens, string ElementName, string? IndexName, ExpressionNode Target, BlockNode Body) : StatementNode(Tokens)
public class ForConstArrayNode(List<Token> tokens, string elementName, string? indexName, ExpressionNode target, BlockNode body) : StatementNode(tokens)
{
public string ElementName { get; } = elementName;
public string? IndexName { get; } = indexName;
public ExpressionNode Target { get; } = target;
public BlockNode Body { get; } = body;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -164,8 +212,10 @@ public record ForConstArrayNode(List<Token> Tokens, string ElementName, string?
}
}
public record DeferNode(List<Token> Tokens, StatementNode Statement) : StatementNode(Tokens)
public class DeferNode(List<Token> tokens, StatementNode statement) : StatementNode(tokens)
{
public StatementNode Statement { get; } = statement;
public override IEnumerable<Node> Children()
{
yield return Statement;
@@ -204,120 +254,153 @@ public enum BinaryOperator
BitwiseOr
}
public abstract record ExpressionNode(List<Token> Tokens, NubType Type) : Node(Tokens);
public abstract record LValueExpressionNode(List<Token> Tokens, NubType Type) : ExpressionNode(Tokens, Type);
public abstract record RValueExpressionNode(List<Token> Tokens, NubType Type) : ExpressionNode(Tokens, Type);
public abstract record IntermediateExpression(List<Token> Tokens) : ExpressionNode(Tokens, new NubVoidType());
public record StringLiteralNode(List<Token> Tokens, string Value) : RValueExpressionNode(Tokens, new NubStringType())
public abstract class ExpressionNode(List<Token> tokens, NubType type) : Node(tokens)
{
public NubType Type { get; } = type;
}
public abstract class LValueExpressionNode(List<Token> tokens, NubType type) : ExpressionNode(tokens, type);
public abstract class RValueExpressionNode(List<Token> tokens, NubType type) : ExpressionNode(tokens, type);
public abstract class IntermediateExpression(List<Token> tokens) : ExpressionNode(tokens, new NubVoidType());
public class StringLiteralNode(List<Token> tokens, string value) : RValueExpressionNode(tokens, new NubStringType())
{
public string Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record CStringLiteralNode(List<Token> Tokens, string Value) : RValueExpressionNode(Tokens, new NubCStringType())
public class CStringLiteralNode(List<Token> tokens, string value) : RValueExpressionNode(tokens, new NubPointerType(new NubIntType(true, 8)))
{
public string Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record I8LiteralNode(List<Token> Tokens, sbyte Value) : RValueExpressionNode(Tokens, new NubIntType(true, 8))
public class I8LiteralNode(List<Token> tokens, sbyte value) : RValueExpressionNode(tokens, new NubIntType(true, 8))
{
public sbyte Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record I16LiteralNode(List<Token> Tokens, short Value) : RValueExpressionNode(Tokens, new NubIntType(true, 16))
public class I16LiteralNode(List<Token> tokens, short value) : RValueExpressionNode(tokens, new NubIntType(true, 16))
{
public short Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record I32LiteralNode(List<Token> Tokens, int Value) : RValueExpressionNode(Tokens, new NubIntType(true, 32))
public class I32LiteralNode(List<Token> tokens, int value) : RValueExpressionNode(tokens, new NubIntType(true, 32))
{
public int Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record I64LiteralNode(List<Token> Tokens, long Value) : RValueExpressionNode(Tokens, new NubIntType(true, 64))
public class I64LiteralNode(List<Token> tokens, long value) : RValueExpressionNode(tokens, new NubIntType(true, 64))
{
public long Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record U8LiteralNode(List<Token> Tokens, byte Value) : RValueExpressionNode(Tokens, new NubIntType(false, 8))
public class U8LiteralNode(List<Token> tokens, byte value) : RValueExpressionNode(tokens, new NubIntType(false, 8))
{
public byte Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record U16LiteralNode(List<Token> Tokens, ushort Value) : RValueExpressionNode(Tokens, new NubIntType(false, 16))
public class U16LiteralNode(List<Token> tokens, ushort value) : RValueExpressionNode(tokens, new NubIntType(false, 16))
{
public ushort Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record U32LiteralNode(List<Token> Tokens, uint Value) : RValueExpressionNode(Tokens, new NubIntType(false, 32))
public class U32LiteralNode(List<Token> tokens, uint value) : RValueExpressionNode(tokens, new NubIntType(false, 32))
{
public uint Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record U64LiteralNode(List<Token> Tokens, ulong Value) : RValueExpressionNode(Tokens, new NubIntType(false, 64))
public class U64LiteralNode(List<Token> tokens, ulong value) : RValueExpressionNode(tokens, new NubIntType(false, 64))
{
public ulong Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record Float32LiteralNode(List<Token> Tokens, float Value) : RValueExpressionNode(Tokens, new NubFloatType(32))
public class Float32LiteralNode(List<Token> tokens, float value) : RValueExpressionNode(tokens, new NubFloatType(32))
{
public float Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record Float64LiteralNode(List<Token> Tokens, double Value) : RValueExpressionNode(Tokens, new NubFloatType(64))
public class Float64LiteralNode(List<Token> tokens, double value) : RValueExpressionNode(tokens, new NubFloatType(64))
{
public double Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record BoolLiteralNode(List<Token> Tokens, NubType Type, bool Value) : RValueExpressionNode(Tokens, Type)
public class BoolLiteralNode(List<Token> tokens, NubType type, bool value) : RValueExpressionNode(tokens, type)
{
public bool Value { get; } = value;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record BinaryExpressionNode(List<Token> Tokens, NubType Type, ExpressionNode Left, BinaryOperator Operator, ExpressionNode Right) : RValueExpressionNode(Tokens, Type)
public class BinaryExpressionNode(List<Token> tokens, NubType type, ExpressionNode left, BinaryOperator @operator, ExpressionNode right) : RValueExpressionNode(tokens, type)
{
public ExpressionNode Left { get; } = left;
public BinaryOperator Operator { get; } = @operator;
public ExpressionNode Right { get; } = right;
public override IEnumerable<Node> Children()
{
yield return Left;
@@ -325,16 +408,22 @@ public record BinaryExpressionNode(List<Token> Tokens, NubType Type, ExpressionN
}
}
public record UnaryExpressionNode(List<Token> Tokens, NubType Type, UnaryOperator Operator, ExpressionNode Operand) : RValueExpressionNode(Tokens, Type)
public class UnaryExpressionNode(List<Token> tokens, NubType type, UnaryOperator @operator, ExpressionNode operand) : RValueExpressionNode(tokens, type)
{
public UnaryOperator Operator { get; } = @operator;
public ExpressionNode Operand { get; } = operand;
public override IEnumerable<Node> Children()
{
yield return Operand;
}
}
public record FuncCallNode(List<Token> Tokens, NubType Type, ExpressionNode Expression, List<ExpressionNode> Parameters) : RValueExpressionNode(Tokens, Type)
public class FuncCallNode(List<Token> tokens, NubType type, ExpressionNode expression, List<ExpressionNode> parameters) : RValueExpressionNode(tokens, type)
{
public ExpressionNode Expression { get; } = expression;
public List<ExpressionNode> Parameters { get; } = parameters;
public override IEnumerable<Node> Children()
{
yield return Expression;
@@ -345,40 +434,53 @@ public record FuncCallNode(List<Token> Tokens, NubType Type, ExpressionNode Expr
}
}
public record VariableIdentifierNode(List<Token> Tokens, NubType Type, string Name) : LValueExpressionNode(Tokens, Type)
public class VariableIdentifierNode(List<Token> tokens, NubType type, string name) : LValueExpressionNode(tokens, type)
{
public string Name { get; } = name;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record FuncIdentifierNode(List<Token> Tokens, NubType Type, string Module, string Name, string? ExternSymbol) : RValueExpressionNode(Tokens, Type)
public class FuncIdentifierNode(List<Token> tokens, NubType type, string module, string name, string? externSymbol) : RValueExpressionNode(tokens, type)
{
public string Module { get; } = module;
public string Name { get; } = name;
public string? ExternSymbol { get; } = externSymbol;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record ArrayInitializerNode(List<Token> Tokens, NubType Type, List<ExpressionNode> Values) : RValueExpressionNode(Tokens, Type)
public class ArrayInitializerNode(List<Token> tokens, NubType type, List<ExpressionNode> values) : RValueExpressionNode(tokens, type)
{
public List<ExpressionNode> Values { get; } = values;
public override IEnumerable<Node> Children()
{
return Values;
}
}
public record ConstArrayInitializerNode(List<Token> Tokens, NubType Type, List<ExpressionNode> Values) : RValueExpressionNode(Tokens, Type)
public class ConstArrayInitializerNode(List<Token> tokens, NubType type, List<ExpressionNode> values) : RValueExpressionNode(tokens, type)
{
public List<ExpressionNode> Values { get; } = values;
public override IEnumerable<Node> Children()
{
return Values;
}
}
public record ArrayIndexAccessNode(List<Token> Tokens, NubType Type, ExpressionNode Target, ExpressionNode Index) : LValueExpressionNode(Tokens, Type)
public class ArrayIndexAccessNode(List<Token> tokens, NubType type, ExpressionNode target, ExpressionNode index) : LValueExpressionNode(tokens, type)
{
public ExpressionNode Target { get; } = target;
public ExpressionNode Index { get; } = index;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -386,8 +488,11 @@ public record ArrayIndexAccessNode(List<Token> Tokens, NubType Type, ExpressionN
}
}
public record ConstArrayIndexAccessNode(List<Token> Tokens, NubType Type, ExpressionNode Target, ExpressionNode Index) : LValueExpressionNode(Tokens, Type)
public class ConstArrayIndexAccessNode(List<Token> tokens, NubType type, ExpressionNode target, ExpressionNode index) : LValueExpressionNode(tokens, type)
{
public ExpressionNode Target { get; } = target;
public ExpressionNode Index { get; } = index;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -395,8 +500,11 @@ public record ConstArrayIndexAccessNode(List<Token> Tokens, NubType Type, Expres
}
}
public record SliceIndexAccessNode(List<Token> Tokens, NubType Type, ExpressionNode Target, ExpressionNode Index) : LValueExpressionNode(Tokens, Type)
public class SliceIndexAccessNode(List<Token> tokens, NubType type, ExpressionNode target, ExpressionNode index) : LValueExpressionNode(tokens, type)
{
public ExpressionNode Target { get; } = target;
public ExpressionNode Index { get; } = index;
public override IEnumerable<Node> Children()
{
yield return Target;
@@ -404,24 +512,31 @@ public record SliceIndexAccessNode(List<Token> Tokens, NubType Type, ExpressionN
}
}
public record AddressOfNode(List<Token> Tokens, NubType Type, LValueExpressionNode LValue) : RValueExpressionNode(Tokens, Type)
public class AddressOfNode(List<Token> tokens, NubType type, LValueExpressionNode lValue) : RValueExpressionNode(tokens, type)
{
public LValueExpressionNode LValue { get; } = lValue;
public override IEnumerable<Node> Children()
{
yield return LValue;
}
}
public record StructFieldAccessNode(List<Token> Tokens, NubType Type, ExpressionNode Target, string Field) : LValueExpressionNode(Tokens, Type)
public class StructFieldAccessNode(List<Token> tokens, NubType type, ExpressionNode target, string field) : LValueExpressionNode(tokens, type)
{
public ExpressionNode Target { get; } = target;
public string Field { get; } = field;
public override IEnumerable<Node> Children()
{
yield return Target;
}
}
public record StructInitializerNode(List<Token> Tokens, NubType Type, Dictionary<string, ExpressionNode> Initializers) : RValueExpressionNode(Tokens, Type)
public class StructInitializerNode(List<Token> tokens, NubType type, Dictionary<string, ExpressionNode> initializers) : RValueExpressionNode(tokens, type)
{
public Dictionary<string, ExpressionNode> Initializers { get; } = initializers;
public override IEnumerable<Node> Children()
{
foreach (var initializer in Initializers)
@@ -431,32 +546,41 @@ public record StructInitializerNode(List<Token> Tokens, NubType Type, Dictionary
}
}
public record DereferenceNode(List<Token> Tokens, NubType Type, ExpressionNode Target) : LValueExpressionNode(Tokens, Type)
public class DereferenceNode(List<Token> tokens, NubType type, ExpressionNode target) : LValueExpressionNode(tokens, type)
{
public ExpressionNode Target { get; } = target;
public override IEnumerable<Node> Children()
{
yield return Target;
}
}
public record SizeNode(List<Token> Tokens, NubType Type, NubType TargetType) : RValueExpressionNode(Tokens, Type)
public class SizeNode(List<Token> tokens, NubType TargetType) : RValueExpressionNode(tokens, new NubIntType(false, 64))
{
public NubType TargetType { get; } = TargetType;
public override IEnumerable<Node> Children()
{
return [];
}
}
public record CastNode(List<Token> Tokens, NubType Type, ExpressionNode Value) : RValueExpressionNode(Tokens, Type)
public class CastNode(List<Token> tokens, NubType type, ExpressionNode value) : RValueExpressionNode(tokens, type)
{
public ExpressionNode Value { get; } = value;
public override IEnumerable<Node> Children()
{
yield return Value;
}
}
public record EnumReferenceIntermediateNode(List<Token> Tokens, string Module, string Name) : IntermediateExpression(Tokens)
public class EnumReferenceIntermediateNode(List<Token> tokens, string module, string name) : IntermediateExpression(tokens)
{
public string Module { get; } = module;
public string Name { get; } = name;
public override IEnumerable<Node> Children()
{
return [];

View File

@@ -125,13 +125,6 @@ public class NubArrayType(NubType elementType) : NubType
public override int GetHashCode() => HashCode.Combine(typeof(NubArrayType), ElementType);
}
public class NubCStringType : NubType
{
public override string ToString() => "cstring";
public override bool Equals(NubType? other) => other is NubCStringType;
public override int GetHashCode() => HashCode.Combine(typeof(NubCStringType));
}
public class NubStringType : NubType
{
public override string ToString() => "string";
@@ -143,7 +136,7 @@ public static class NameMangler
{
public static string Mangle(params IEnumerable<NubType> types)
{
var readable = string.Join("_", types.Select(EncodeType));
var readable = string.Join(":", types.Select(EncodeType));
return ComputeShortHash(readable);
}
@@ -153,12 +146,13 @@ public static class NameMangler
NubBoolType => "B",
NubIntType i => (i.Signed ? "I" : "U") + i.Width,
NubFloatType f => "F" + f.Width,
NubCStringType => "CS",
NubStringType => "S",
NubPointerType p => "P" + EncodeType(p.BaseType),
NubSliceType a => "A" + EncodeType(a.ElementType),
NubFuncType fn => "FN(" + string.Join(",", fn.Parameters.Select(EncodeType)) + ")" + EncodeType(fn.ReturnType),
NubStructType st => "ST(" + st.Module + "." + st.Name + ")",
NubArrayType a => $"A({EncodeType(a.ElementType)})",
NubConstArrayType ca => $"CA({EncodeType(ca.ElementType)})",
NubSliceType a => $"SL{EncodeType(a.ElementType)}()",
NubPointerType p => $"P({EncodeType(p.BaseType)})",
NubFuncType fn => $"FN({string.Join(":", fn.Parameters.Select(EncodeType))}:{EncodeType(fn.ReturnType)})",
NubStructType st => $"ST({st.Module}:{st.Name})",
_ => throw new NotSupportedException($"Cannot encode type: {node}")
};

View File

@@ -309,8 +309,7 @@ public sealed class TypeChecker
FloatLiteralSyntax expression => CheckFloatLiteral(expression, expectedType),
MemberAccessSyntax expression => CheckMemberAccess(expression, expectedType),
StructInitializerSyntax expression => CheckStructInitializer(expression, expectedType),
InterpretSyntax expression => CheckExpression(expression.Target, expectedType) with { Type = ResolveType(expression.Type) },
SizeSyntax expression => new SizeNode(node.Tokens, new NubIntType(false, 64), ResolveType(expression.Type)),
SizeSyntax expression => new SizeNode(node.Tokens, ResolveType(expression.Type)),
CastSyntax expression => CheckCast(expression, expectedType),
_ => throw new ArgumentOutOfRangeException(nameof(node))
};
@@ -373,7 +372,6 @@ public sealed class TypeChecker
case NubPointerType when to is NubPointerType { BaseType: NubVoidType }:
case NubConstArrayType constArrayType1 when to is NubArrayType arrayType && constArrayType1.ElementType == arrayType.ElementType:
case NubConstArrayType constArrayType3 when to is NubSliceType sliceType2 && constArrayType3.ElementType == sliceType2.ElementType:
case NubCStringType when to is NubStringType:
{
return true;
}
@@ -391,7 +389,6 @@ public sealed class TypeChecker
case NubPointerType when to is NubPointerType:
case NubPointerType when to is NubIntType:
case NubIntType when to is NubPointerType:
case NubCStringType when to is NubPointerType { BaseType: NubIntType { Width: 8 } }:
{
return true;
}
@@ -819,7 +816,7 @@ public sealed class TypeChecker
private ExpressionNode CheckStringLiteral(StringLiteralSyntax expression, NubType? expectedType)
{
if (expectedType is NubCStringType)
if (expectedType is NubPointerType { BaseType: NubIntType { Signed: true, Width: 8 } })
{
return new CStringLiteralNode(expression.Tokens, expression.Value);
}
@@ -1031,35 +1028,12 @@ public sealed class TypeChecker
};
}
private bool AlwaysReturns(StatementNode statement)
{
switch (statement)
{
case ReturnNode:
return true;
case BlockNode block:
return block.Statements.Count != 0 && AlwaysReturns(block.Statements.Last());
case IfNode ifNode:
{
if (!AlwaysReturns(ifNode.Body))
{
return false;
}
return !ifNode.Else.HasValue || ifNode.Else.Value.Match(AlwaysReturns, AlwaysReturns);
}
default:
return false;
}
}
private NubType ResolveType(TypeSyntax type)
{
return type switch
{
ArrayTypeSyntax arr => new NubArrayType(ResolveType(arr.BaseType)),
BoolTypeSyntax => new NubBoolType(),
CStringTypeSyntax => new NubCStringType(),
IntTypeSyntax i => new NubIntType(i.Signed, i.Width),
FloatTypeSyntax f => new NubFloatType(f.Width),
FuncTypeSyntax func => new NubFuncType(func.Parameters.Select(ResolveType).ToList(), ResolveType(func.ReturnType)),

View File

@@ -12,14 +12,13 @@ public static class CType
NubBoolType => "bool" + (variableName != null ? $" {variableName}" : ""),
NubIntType intType => CreateIntType(intType, variableName),
NubFloatType floatType => CreateFloatType(floatType, variableName),
NubCStringType => "char*" + (variableName != null ? $" {variableName}" : ""),
NubPointerType ptr => CreatePointerType(ptr, variableName),
NubSliceType => "slice" + (variableName != null ? $" {variableName}" : ""),
NubStringType => "string" + (variableName != null ? $" {variableName}" : ""),
NubSliceType => "struct nub_slice" + (variableName != null ? $" {variableName}" : ""),
NubStringType => "struct nub_string" + (variableName != null ? $" {variableName}" : ""),
NubConstArrayType arr => CreateConstArrayType(arr, variableName, constArraysAsPointers),
NubArrayType arr => CreateArrayType(arr, variableName),
NubFuncType fn => CreateFuncType(fn, variableName),
NubStructType st => $"{st.Module}_{st.Name}" + (variableName != null ? $" {variableName}" : ""),
NubStructType st => $"struct {st.Module}_{st.Name}_{NameMangler.Mangle(st)}" + (variableName != null ? $" {variableName}" : ""),
_ => throw new NotSupportedException($"C type generation not supported for: {type}")
};
}
@@ -28,10 +27,10 @@ public static class CType
{
var cType = intType.Width switch
{
8 => intType.Signed ? "int8_t" : "uint8_t",
16 => intType.Signed ? "int16_t" : "uint16_t",
32 => intType.Signed ? "int32_t" : "uint32_t",
64 => intType.Signed ? "int64_t" : "uint64_t",
8 => intType.Signed ? "char" : "unsigned char",
16 => intType.Signed ? "short" : "unsigned short",
32 => intType.Signed ? "int" : "unsigned int",
64 => intType.Signed ? "long long" : "unsigned long long",
_ => throw new NotSupportedException($"Unsupported integer width: {intType.Width}")
};
return cType + (varName != null ? $" {varName}" : "");

View File

@@ -29,34 +29,26 @@ public class Generator
return externSymbol ?? $"{module}_{name}";
}
private static string StructName(string module, string name)
{
return $"{module}_{name}";
}
public string Emit()
{
_writer.WriteLine("""
#include <stdint.h>
#include <stddef.h>
typedef struct
struct nub_string
{
size_t length;
unsigned long long length;
char *data;
} string;
};
typedef struct
struct nub_slice
{
size_t length;
unsigned long long length;
void *data;
} slice;
};
""");
foreach (var structType in _compilationUnit.ImportedStructTypes)
{
_writer.WriteLine("typedef struct");
_writer.WriteLine(CType.Create(structType));
_writer.WriteLine("{");
using (_writer.Indent())
{
@@ -66,7 +58,7 @@ public class Generator
}
}
_writer.WriteLine($"}} {StructName(structType.Module, structType.Name)};");
_writer.WriteLine("};");
_writer.WriteLine();
}
@@ -198,7 +190,7 @@ public class Generator
var target = EmitExpression(forSliceNode.Target);
var indexName = forSliceNode.IndexName ?? NewTmp();
_writer.WriteLine($"for (size_t {indexName} = 0; {indexName} < {target}.length; ++{indexName})");
_writer.WriteLine($"for (unsigned long long {indexName} = 0; {indexName} < {target}.length; ++{indexName})");
_writer.WriteLine("{");
using (_writer.Indent())
{
@@ -215,7 +207,7 @@ public class Generator
var target = EmitExpression(forConstArrayNode.Target);
var indexName = forConstArrayNode.IndexName ?? NewTmp();
_writer.WriteLine($"for (size_t {indexName} = 0; {indexName} < {targetType.Size}; ++{indexName})");
_writer.WriteLine($"for (unsigned long long {indexName} = 0; {indexName} < {targetType.Size}; ++{indexName})");
_writer.WriteLine("{");
using (_writer.Indent())
{
@@ -470,15 +462,9 @@ public class Generator
{
var value = EmitExpression(castNode.Value);
if (castNode is { Type: NubSliceType, Value.Type: NubConstArrayType arrayType })
if (castNode is { Type: NubSliceType sliceType, Value.Type: NubConstArrayType arrayType })
{
return $"(slice){{.length = {arrayType.Size}, .data = (void*){value}}}";
}
// todo(nub31): Stop depending on libc
if (castNode is { Type: NubCStringType, Value.Type: NubStringType })
{
return $"(string){{.length = strlen({value}), .data = {value}}}";
return $"({CType.Create(sliceType)}){{.length = {arrayType.Size}, .data = (void*){value}}}";
}
return $"({CType.Create(castNode.Type)}){value}";
@@ -509,7 +495,7 @@ public class Generator
private string EmitStringLiteral(StringLiteralNode stringLiteralNode)
{
var length = Encoding.UTF8.GetByteCount(stringLiteralNode.Value);
return $"(string){{.length = {length}, .data = \"{stringLiteralNode.Value}\"}}";
return $"(nub_string){{.length = {length}, .data = \"{stringLiteralNode.Value}\"}}";
}
private string EmitStructFieldAccess(StructFieldAccessNode structFieldAccessNode)

View File

@@ -510,14 +510,6 @@ public sealed class Parser
ExpectSymbol(Symbol.CloseParen);
return new SizeSyntax(GetTokens(startIndex), type);
}
case "interpret":
{
var type = ParseType();
ExpectSymbol(Symbol.Comma);
var expression = ParseExpression();
ExpectSymbol(Symbol.CloseParen);
return new InterpretSyntax(GetTokens(startIndex), type, expression);
}
case "cast":
{
var expression = ParseExpression();
@@ -736,8 +728,6 @@ public sealed class Parser
return new VoidTypeSyntax(GetTokens(startIndex));
case "string":
return new StringTypeSyntax(GetTokens(startIndex));
case "cstring":
return new CStringTypeSyntax(GetTokens(startIndex));
case "bool":
return new BoolTypeSyntax(GetTokens(startIndex));
default:

View File

@@ -114,8 +114,6 @@ public record DereferenceSyntax(List<Token> Tokens, ExpressionSyntax Target) : E
public record SizeSyntax(List<Token> Tokens, TypeSyntax Type) : ExpressionSyntax(Tokens);
public record InterpretSyntax(List<Token> Tokens, TypeSyntax Type, ExpressionSyntax Target) : ExpressionSyntax(Tokens);
public record CastSyntax(List<Token> Tokens, ExpressionSyntax Value) : ExpressionSyntax(Tokens);
#endregion
@@ -138,8 +136,6 @@ public record BoolTypeSyntax(List<Token> Tokens) : TypeSyntax(Tokens);
public record StringTypeSyntax(List<Token> Tokens) : TypeSyntax(Tokens);
public record CStringTypeSyntax(List<Token> Tokens) : TypeSyntax(Tokens);
public record SliceTypeSyntax(List<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);
public record ArrayTypeSyntax(List<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);

View File

@@ -255,7 +255,7 @@ export struct FilePathList
{
capacity: u32
count: u32
paths: ^cstring
paths: ^^i8
}
export struct AutomationEvent
{
@@ -995,7 +995,7 @@ export enum NPatchLayout : u32
NPATCH_THREE_PATCH_VERTICAL = 1
NPATCH_THREE_PATCH_HORIZONTAL = 2
}
export extern "InitWindow" func InitWindow(width: i32, height: i32, title: cstring): void
export extern "InitWindow" func InitWindow(width: i32, height: i32, title: ^i8): void
export extern "CloseWindow" func CloseWindow(): void
export extern "WindowShouldClose" func WindowShouldClose(): bool
export extern "IsWindowReady" func IsWindowReady(): bool
@@ -1015,7 +1015,7 @@ export extern "MinimizeWindow" func MinimizeWindow(): void
export extern "RestoreWindow" func RestoreWindow(): void
export extern "SetWindowIcon" func SetWindowIcon(image: Image): void
export extern "SetWindowIcons" func SetWindowIcons(images: ^Image, count: i32): void
export extern "SetWindowTitle" func SetWindowTitle(title: cstring): void
export extern "SetWindowTitle" func SetWindowTitle(title: ^i8): void
export extern "SetWindowPosition" func SetWindowPosition(x: i32, y: i32): void
export extern "SetWindowMonitor" func SetWindowMonitor(monitor: i32): void
export extern "SetWindowMinSize" func SetWindowMinSize(width: i32, height: i32): void
@@ -1038,9 +1038,9 @@ export extern "GetMonitorPhysicalHeight" func GetMonitorPhysicalHeight(monitor:
export extern "GetMonitorRefreshRate" func GetMonitorRefreshRate(monitor: i32): i32
export extern "GetWindowPosition" func GetWindowPosition(): Vector2
export extern "GetWindowScaleDPI" func GetWindowScaleDPI(): Vector2
export extern "GetMonitorName" func GetMonitorName(monitor: i32): cstring
export extern "SetClipboardText" func SetClipboardText(text: cstring): void
export extern "GetClipboardText" func GetClipboardText(): cstring
export extern "GetMonitorName" func GetMonitorName(monitor: i32): ^i8
export extern "SetClipboardText" func SetClipboardText(text: ^i8): void
export extern "GetClipboardText" func GetClipboardText(): ^i8
export extern "GetClipboardImage" func GetClipboardImage(): Image
export extern "EnableEventWaiting" func EnableEventWaiting(): void
export extern "DisableEventWaiting" func DisableEventWaiting(): void
@@ -1069,11 +1069,11 @@ export extern "BeginVrStereoMode" func BeginVrStereoMode(config: VrStereoConfig)
export extern "EndVrStereoMode" func EndVrStereoMode(): void
export extern "LoadVrStereoConfig" func LoadVrStereoConfig(device: VrDeviceInfo): VrStereoConfig
export extern "UnloadVrStereoConfig" func UnloadVrStereoConfig(config: VrStereoConfig): void
export extern "LoadShader" func LoadShader(vsFileName: cstring, fsFileName: cstring): Shader
export extern "LoadShaderFromMemory" func LoadShaderFromMemory(vsCode: cstring, fsCode: cstring): Shader
export extern "LoadShader" func LoadShader(vsFileName: ^i8, fsFileName: ^i8): Shader
export extern "LoadShaderFromMemory" func LoadShaderFromMemory(vsCode: ^i8, fsCode: ^i8): Shader
export extern "IsShaderValid" func IsShaderValid(shader: Shader): bool
export extern "GetShaderLocation" func GetShaderLocation(shader: Shader, uniformName: cstring): i32
export extern "GetShaderLocationAttrib" func GetShaderLocationAttrib(shader: Shader, attribName: cstring): i32
export extern "GetShaderLocation" func GetShaderLocation(shader: Shader, uniformName: ^i8): i32
export extern "GetShaderLocationAttrib" func GetShaderLocationAttrib(shader: Shader, attribName: ^i8): i32
export extern "SetShaderValue" func SetShaderValue(shader: Shader, locIndex: i32, value: ^void, uniformType: i32): void
export extern "SetShaderValueV" func SetShaderValueV(shader: Shader, locIndex: i32, value: ^void, uniformType: i32, count: i32): void
export extern "SetShaderValueMatrix" func SetShaderValueMatrix(shader: Shader, locIndex: i32, mat: Matrix): void
@@ -1098,58 +1098,58 @@ export extern "SetRandomSeed" func SetRandomSeed(seed: u32): void
export extern "GetRandomValue" func GetRandomValue(min: i32, max: i32): i32
export extern "LoadRandomSequence" func LoadRandomSequence(count: u32, min: i32, max: i32): ^i32
export extern "UnloadRandomSequence" func UnloadRandomSequence(sequence: ^i32): void
export extern "TakeScreenshot" func TakeScreenshot(fileName: cstring): void
export extern "TakeScreenshot" func TakeScreenshot(fileName: ^i8): void
export extern "SetConfigFlags" func SetConfigFlags(flags: u32): void
export extern "OpenURL" func OpenURL(url: cstring): void
export extern "TraceLog" func TraceLog(logLevel: i32, text: cstring): void
export extern "OpenURL" func OpenURL(url: ^i8): void
export extern "TraceLog" func TraceLog(logLevel: i32, text: ^i8): void
export extern "SetTraceLogLevel" func SetTraceLogLevel(logLevel: i32): void
export extern "MemAlloc" func MemAlloc(size: u32): ^void
export extern "MemRealloc" func MemRealloc(ptr: ^void, size: u32): ^void
export extern "MemFree" func MemFree(ptr: ^void): void
export extern "SetTraceLogCallback" func SetTraceLogCallback(callback: func(i32, cstring, i32): void): void
export extern "SetLoadFileDataCallback" func SetLoadFileDataCallback(callback: func(cstring, ^i32): ^u8): void
export extern "SetSaveFileDataCallback" func SetSaveFileDataCallback(callback: func(cstring, ^void, i32): bool): void
export extern "SetLoadFileTextCallback" func SetLoadFileTextCallback(callback: func(cstring): cstring): void
export extern "SetSaveFileTextCallback" func SetSaveFileTextCallback(callback: func(cstring, cstring): bool): void
export extern "LoadFileData" func LoadFileData(fileName: cstring, dataSize: ^i32): ^u8
export extern "SetTraceLogCallback" func SetTraceLogCallback(callback: func(i32, ^i8, i32): void): void
export extern "SetLoadFileDataCallback" func SetLoadFileDataCallback(callback: func(^i8, ^i32): ^u8): void
export extern "SetSaveFileDataCallback" func SetSaveFileDataCallback(callback: func(^i8, ^void, i32): bool): void
export extern "SetLoadFileTextCallback" func SetLoadFileTextCallback(callback: func(^i8): ^i8): void
export extern "SetSaveFileTextCallback" func SetSaveFileTextCallback(callback: func(^i8, ^i8): bool): void
export extern "LoadFileData" func LoadFileData(fileName: ^i8, dataSize: ^i32): ^u8
export extern "UnloadFileData" func UnloadFileData(data: ^u8): void
export extern "SaveFileData" func SaveFileData(fileName: cstring, data: ^void, dataSize: i32): bool
export extern "ExportDataAsCode" func ExportDataAsCode(data: ^u8, dataSize: i32, fileName: cstring): bool
export extern "LoadFileText" func LoadFileText(fileName: cstring): cstring
export extern "UnloadFileText" func UnloadFileText(text: cstring): void
export extern "SaveFileText" func SaveFileText(fileName: cstring, text: cstring): bool
export extern "FileExists" func FileExists(fileName: cstring): bool
export extern "DirectoryExists" func DirectoryExists(dirPath: cstring): bool
export extern "IsFileExtension" func IsFileExtension(fileName: cstring, ext: cstring): bool
export extern "GetFileLength" func GetFileLength(fileName: cstring): i32
export extern "GetFileExtension" func GetFileExtension(fileName: cstring): cstring
export extern "GetFileName" func GetFileName(filePath: cstring): cstring
export extern "GetFileNameWithoutExt" func GetFileNameWithoutExt(filePath: cstring): cstring
export extern "GetDirectoryPath" func GetDirectoryPath(filePath: cstring): cstring
export extern "GetPrevDirectoryPath" func GetPrevDirectoryPath(dirPath: cstring): cstring
export extern "GetWorkingDirectory" func GetWorkingDirectory(): cstring
export extern "GetApplicationDirectory" func GetApplicationDirectory(): cstring
export extern "MakeDirectory" func MakeDirectory(dirPath: cstring): i32
export extern "ChangeDirectory" func ChangeDirectory(dir: cstring): bool
export extern "IsPathFile" func IsPathFile(path: cstring): bool
export extern "IsFileNameValid" func IsFileNameValid(fileName: cstring): bool
export extern "LoadDirectoryFiles" func LoadDirectoryFiles(dirPath: cstring): FilePathList
export extern "LoadDirectoryFilesEx" func LoadDirectoryFilesEx(basePath: cstring, filter: cstring, scanSubdirs: bool): FilePathList
export extern "SaveFileData" func SaveFileData(fileName: ^i8, data: ^void, dataSize: i32): bool
export extern "ExportDataAsCode" func ExportDataAsCode(data: ^u8, dataSize: i32, fileName: ^i8): bool
export extern "LoadFileText" func LoadFileText(fileName: ^i8): ^i8
export extern "UnloadFileText" func UnloadFileText(text: ^i8): void
export extern "SaveFileText" func SaveFileText(fileName: ^i8, text: ^i8): bool
export extern "FileExists" func FileExists(fileName: ^i8): bool
export extern "DirectoryExists" func DirectoryExists(dirPath: ^i8): bool
export extern "IsFileExtension" func IsFileExtension(fileName: ^i8, ext: ^i8): bool
export extern "GetFileLength" func GetFileLength(fileName: ^i8): i32
export extern "GetFileExtension" func GetFileExtension(fileName: ^i8): ^i8
export extern "GetFileName" func GetFileName(filePath: ^i8): ^i8
export extern "GetFileNameWithoutExt" func GetFileNameWithoutExt(filePath: ^i8): ^i8
export extern "GetDirectoryPath" func GetDirectoryPath(filePath: ^i8): ^i8
export extern "GetPrevDirectoryPath" func GetPrevDirectoryPath(dirPath: ^i8): ^i8
export extern "GetWorkingDirectory" func GetWorkingDirectory(): ^i8
export extern "GetApplicationDirectory" func GetApplicationDirectory(): ^i8
export extern "MakeDirectory" func MakeDirectory(dirPath: ^i8): i32
export extern "ChangeDirectory" func ChangeDirectory(dir: ^i8): bool
export extern "IsPathFile" func IsPathFile(path: ^i8): bool
export extern "IsFileNameValid" func IsFileNameValid(fileName: ^i8): bool
export extern "LoadDirectoryFiles" func LoadDirectoryFiles(dirPath: ^i8): FilePathList
export extern "LoadDirectoryFilesEx" func LoadDirectoryFilesEx(basePath: ^i8, filter: ^i8, scanSubdirs: bool): FilePathList
export extern "UnloadDirectoryFiles" func UnloadDirectoryFiles(files: FilePathList): void
export extern "IsFileDropped" func IsFileDropped(): bool
export extern "LoadDroppedFiles" func LoadDroppedFiles(): FilePathList
export extern "UnloadDroppedFiles" func UnloadDroppedFiles(files: FilePathList): void
export extern "GetFileModTime" func GetFileModTime(fileName: cstring): i64
export extern "GetFileModTime" func GetFileModTime(fileName: ^i8): i64
export extern "CompressData" func CompressData(data: ^u8, dataSize: i32, compDataSize: ^i32): ^u8
export extern "DecompressData" func DecompressData(compData: ^u8, compDataSize: i32, dataSize: ^i32): ^u8
export extern "EncodeDataBase64" func EncodeDataBase64(data: ^u8, dataSize: i32, outputSize: ^i32): cstring
export extern "EncodeDataBase64" func EncodeDataBase64(data: ^u8, dataSize: i32, outputSize: ^i32): ^i8
export extern "DecodeDataBase64" func DecodeDataBase64(data: ^u8, outputSize: ^i32): ^u8
export extern "ComputeCRC32" func ComputeCRC32(data: ^u8, dataSize: i32): u32
export extern "ComputeMD5" func ComputeMD5(data: ^u8, dataSize: i32): ^u32
export extern "ComputeSHA1" func ComputeSHA1(data: ^u8, dataSize: i32): ^u32
export extern "LoadAutomationEventList" func LoadAutomationEventList(fileName: cstring): AutomationEventList
export extern "LoadAutomationEventList" func LoadAutomationEventList(fileName: ^i8): AutomationEventList
export extern "UnloadAutomationEventList" func UnloadAutomationEventList(list: AutomationEventList): void
export extern "ExportAutomationEventList" func ExportAutomationEventList(list: AutomationEventList, fileName: cstring): bool
export extern "ExportAutomationEventList" func ExportAutomationEventList(list: AutomationEventList, fileName: ^i8): bool
export extern "SetAutomationEventList" func SetAutomationEventList(list: ^AutomationEventList): void
export extern "SetAutomationEventBaseFrame" func SetAutomationEventBaseFrame(frame: i32): void
export extern "StartAutomationEventRecording" func StartAutomationEventRecording(): void
@@ -1164,7 +1164,7 @@ export extern "GetKeyPressed" func GetKeyPressed(): i32
export extern "GetCharPressed" func GetCharPressed(): i32
export extern "SetExitKey" func SetExitKey(key: i32): void
export extern "IsGamepadAvailable" func IsGamepadAvailable(gamepad: i32): bool
export extern "GetGamepadName" func GetGamepadName(gamepad: i32): cstring
export extern "GetGamepadName" func GetGamepadName(gamepad: i32): ^i8
export extern "IsGamepadButtonPressed" func IsGamepadButtonPressed(gamepad: i32, button: i32): bool
export extern "IsGamepadButtonDown" func IsGamepadButtonDown(gamepad: i32, button: i32): bool
export extern "IsGamepadButtonReleased" func IsGamepadButtonReleased(gamepad: i32, button: i32): bool
@@ -1172,7 +1172,7 @@ export extern "IsGamepadButtonUp" func IsGamepadButtonUp(gamepad: i32, button: i
export extern "GetGamepadButtonPressed" func GetGamepadButtonPressed(): i32
export extern "GetGamepadAxisCount" func GetGamepadAxisCount(gamepad: i32): i32
export extern "GetGamepadAxisMovement" func GetGamepadAxisMovement(gamepad: i32, axis: i32): f32
export extern "SetGamepadMappings" func SetGamepadMappings(mappings: cstring): i32
export extern "SetGamepadMappings" func SetGamepadMappings(mappings: ^i8): i32
export extern "SetGamepadVibration" func SetGamepadVibration(gamepad: i32, leftMotor: f32, rightMotor: f32, duration: f32): void
export extern "IsMouseButtonPressed" func IsMouseButtonPressed(button: i32): bool
export extern "IsMouseButtonDown" func IsMouseButtonDown(button: i32): bool
@@ -1269,18 +1269,18 @@ export extern "CheckCollisionPointLine" func CheckCollisionPointLine(point: Vect
export extern "CheckCollisionPointPoly" func CheckCollisionPointPoly(point: Vector2, points: ^Vector2, pointCount: i32): bool
export extern "CheckCollisionLines" func CheckCollisionLines(startPos1: Vector2, endPos1: Vector2, startPos2: Vector2, endPos2: Vector2, collisionPoint: ^Vector2): bool
export extern "GetCollisionRec" func GetCollisionRec(rec1: Rectangle, rec2: Rectangle): Rectangle
export extern "LoadImage" func LoadImage(fileName: cstring): Image
export extern "LoadImageRaw" func LoadImageRaw(fileName: cstring, width: i32, height: i32, format: i32, headerSize: i32): Image
export extern "LoadImageAnim" func LoadImageAnim(fileName: cstring, frames: ^i32): Image
export extern "LoadImageAnimFromMemory" func LoadImageAnimFromMemory(fileType: cstring, fileData: ^u8, dataSize: i32, frames: ^i32): Image
export extern "LoadImageFromMemory" func LoadImageFromMemory(fileType: cstring, fileData: ^u8, dataSize: i32): Image
export extern "LoadImage" func LoadImage(fileName: ^i8): Image
export extern "LoadImageRaw" func LoadImageRaw(fileName: ^i8, width: i32, height: i32, format: i32, headerSize: i32): Image
export extern "LoadImageAnim" func LoadImageAnim(fileName: ^i8, frames: ^i32): Image
export extern "LoadImageAnimFromMemory" func LoadImageAnimFromMemory(fileType: ^i8, fileData: ^u8, dataSize: i32, frames: ^i32): Image
export extern "LoadImageFromMemory" func LoadImageFromMemory(fileType: ^i8, fileData: ^u8, dataSize: i32): Image
export extern "LoadImageFromTexture" func LoadImageFromTexture(texture: Texture): Image
export extern "LoadImageFromScreen" func LoadImageFromScreen(): Image
export extern "IsImageValid" func IsImageValid(image: Image): bool
export extern "UnloadImage" func UnloadImage(image: Image): void
export extern "ExportImage" func ExportImage(image: Image, fileName: cstring): bool
export extern "ExportImageToMemory" func ExportImageToMemory(image: Image, fileType: cstring, fileSize: ^i32): ^u8
export extern "ExportImageAsCode" func ExportImageAsCode(image: Image, fileName: cstring): bool
export extern "ExportImage" func ExportImage(image: Image, fileName: ^i8): bool
export extern "ExportImageToMemory" func ExportImageToMemory(image: Image, fileType: ^i8, fileSize: ^i32): ^u8
export extern "ExportImageAsCode" func ExportImageAsCode(image: Image, fileName: ^i8): bool
export extern "GenImageColor" func GenImageColor(width: i32, height: i32, color: Color): Image
export extern "GenImageGradientLinear" func GenImageGradientLinear(width: i32, height: i32, direction: i32, start: Color, end: Color): Image
export extern "GenImageGradientRadial" func GenImageGradientRadial(width: i32, height: i32, density: f32, inner: Color, outer: Color): Image
@@ -1289,12 +1289,12 @@ export extern "GenImageChecked" func GenImageChecked(width: i32, height: i32, ch
export extern "GenImageWhiteNoise" func GenImageWhiteNoise(width: i32, height: i32, factor: f32): Image
export extern "GenImagePerlinNoise" func GenImagePerlinNoise(width: i32, height: i32, offsetX: i32, offsetY: i32, scale: f32): Image
export extern "GenImageCellular" func GenImageCellular(width: i32, height: i32, tileSize: i32): Image
export extern "GenImageText" func GenImageText(width: i32, height: i32, text: cstring): Image
export extern "GenImageText" func GenImageText(width: i32, height: i32, text: ^i8): Image
export extern "ImageCopy" func ImageCopy(image: Image): Image
export extern "ImageFromImage" func ImageFromImage(image: Image, rec: Rectangle): Image
export extern "ImageFromChannel" func ImageFromChannel(image: Image, selectedChannel: i32): Image
export extern "ImageText" func ImageText(text: cstring, fontSize: i32, color: Color): Image
export extern "ImageTextEx" func ImageTextEx(font: Font, text: cstring, fontSize: f32, spacing: f32, tint: Color): Image
export extern "ImageText" func ImageText(text: ^i8, fontSize: i32, color: Color): Image
export extern "ImageTextEx" func ImageTextEx(font: Font, text: ^i8, fontSize: f32, spacing: f32, tint: Color): Image
export extern "ImageFormat" func ImageFormat(image: ^Image, newFormat: i32): void
export extern "ImageToPOT" func ImageToPOT(image: ^Image, fill: Color): void
export extern "ImageCrop" func ImageCrop(image: ^Image, crop: Rectangle): void
@@ -1346,9 +1346,9 @@ export extern "ImageDrawTriangleLines" func ImageDrawTriangleLines(dst: ^Image,
export extern "ImageDrawTriangleFan" func ImageDrawTriangleFan(dst: ^Image, points: ^Vector2, pointCount: i32, color: Color): void
export extern "ImageDrawTriangleStrip" func ImageDrawTriangleStrip(dst: ^Image, points: ^Vector2, pointCount: i32, color: Color): void
export extern "ImageDraw" func ImageDraw(dst: ^Image, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color): void
export extern "ImageDrawText" func ImageDrawText(dst: ^Image, text: cstring, posX: i32, posY: i32, fontSize: i32, color: Color): void
export extern "ImageDrawTextEx" func ImageDrawTextEx(dst: ^Image, font: Font, text: cstring, position: Vector2, fontSize: f32, spacing: f32, tint: Color): void
export extern "LoadTexture" func LoadTexture(fileName: cstring): Texture
export extern "ImageDrawText" func ImageDrawText(dst: ^Image, text: ^i8, posX: i32, posY: i32, fontSize: i32, color: Color): void
export extern "ImageDrawTextEx" func ImageDrawTextEx(dst: ^Image, font: Font, text: ^i8, position: Vector2, fontSize: f32, spacing: f32, tint: Color): void
export extern "LoadTexture" func LoadTexture(fileName: ^i8): Texture
export extern "LoadTextureFromImage" func LoadTextureFromImage(image: Image): Texture
export extern "LoadTextureCubemap" func LoadTextureCubemap(image: Image, layout: i32): Texture
export extern "LoadRenderTexture" func LoadRenderTexture(width: i32, height: i32): RenderTexture
@@ -1385,55 +1385,55 @@ export extern "GetPixelColor" func GetPixelColor(srcPtr: ^void, format: i32): Co
export extern "SetPixelColor" func SetPixelColor(dstPtr: ^void, color: Color, format: i32): void
export extern "GetPixelDataSize" func GetPixelDataSize(width: i32, height: i32, format: i32): i32
export extern "GetFontDefault" func GetFontDefault(): Font
export extern "LoadFont" func LoadFont(fileName: cstring): Font
export extern "LoadFontEx" func LoadFontEx(fileName: cstring, fontSize: i32, codepoints: ^i32, codepointCount: i32): Font
export extern "LoadFont" func LoadFont(fileName: ^i8): Font
export extern "LoadFontEx" func LoadFontEx(fileName: ^i8, fontSize: i32, codepoints: ^i32, codepointCount: i32): Font
export extern "LoadFontFromImage" func LoadFontFromImage(image: Image, key: Color, firstChar: i32): Font
export extern "LoadFontFromMemory" func LoadFontFromMemory(fileType: cstring, fileData: ^u8, dataSize: i32, fontSize: i32, codepoints: ^i32, codepointCount: i32): Font
export extern "LoadFontFromMemory" func LoadFontFromMemory(fileType: ^i8, fileData: ^u8, dataSize: i32, fontSize: i32, codepoints: ^i32, codepointCount: i32): Font
export extern "IsFontValid" func IsFontValid(font: Font): bool
export extern "LoadFontData" func LoadFontData(fileData: ^u8, dataSize: i32, fontSize: i32, codepoints: ^i32, codepointCount: i32, type: i32): ^GlyphInfo
export extern "GenImageFontAtlas" func GenImageFontAtlas(glyphs: ^GlyphInfo, glyphRecs: ^^Rectangle, glyphCount: i32, fontSize: i32, padding: i32, packMethod: i32): Image
export extern "UnloadFontData" func UnloadFontData(glyphs: ^GlyphInfo, glyphCount: i32): void
export extern "UnloadFont" func UnloadFont(font: Font): void
export extern "ExportFontAsCode" func ExportFontAsCode(font: Font, fileName: cstring): bool
export extern "ExportFontAsCode" func ExportFontAsCode(font: Font, fileName: ^i8): bool
export extern "DrawFPS" func DrawFPS(posX: i32, posY: i32): void
export extern "DrawText" func DrawText(text: cstring, posX: i32, posY: i32, fontSize: i32, color: Color): void
export extern "DrawTextEx" func DrawTextEx(font: Font, text: cstring, position: Vector2, fontSize: f32, spacing: f32, tint: Color): void
export extern "DrawTextPro" func DrawTextPro(font: Font, text: cstring, position: Vector2, origin: Vector2, rotation: f32, fontSize: f32, spacing: f32, tint: Color): void
export extern "DrawText" func DrawText(text: ^i8, posX: i32, posY: i32, fontSize: i32, color: Color): void
export extern "DrawTextEx" func DrawTextEx(font: Font, text: ^i8, position: Vector2, fontSize: f32, spacing: f32, tint: Color): void
export extern "DrawTextPro" func DrawTextPro(font: Font, text: ^i8, position: Vector2, origin: Vector2, rotation: f32, fontSize: f32, spacing: f32, tint: Color): void
export extern "DrawTextCodepoint" func DrawTextCodepoint(font: Font, codepoint: i32, position: Vector2, fontSize: f32, tint: Color): void
export extern "DrawTextCodepoints" func DrawTextCodepoints(font: Font, codepoints: ^i32, codepointCount: i32, position: Vector2, fontSize: f32, spacing: f32, tint: Color): void
export extern "SetTextLineSpacing" func SetTextLineSpacing(spacing: i32): void
export extern "MeasureText" func MeasureText(text: cstring, fontSize: i32): i32
export extern "MeasureTextEx" func MeasureTextEx(font: Font, text: cstring, fontSize: f32, spacing: f32): Vector2
export extern "MeasureText" func MeasureText(text: ^i8, fontSize: i32): i32
export extern "MeasureTextEx" func MeasureTextEx(font: Font, text: ^i8, fontSize: f32, spacing: f32): Vector2
export extern "GetGlyphIndex" func GetGlyphIndex(font: Font, codepoint: i32): i32
export extern "GetGlyphInfo" func GetGlyphInfo(font: Font, codepoint: i32): GlyphInfo
export extern "GetGlyphAtlasRec" func GetGlyphAtlasRec(font: Font, codepoint: i32): Rectangle
export extern "LoadUTF8" func LoadUTF8(codepoints: ^i32, length: i32): cstring
export extern "UnloadUTF8" func UnloadUTF8(text: cstring): void
export extern "LoadCodepoints" func LoadCodepoints(text: cstring, count: ^i32): ^i32
export extern "LoadUTF8" func LoadUTF8(codepoints: ^i32, length: i32): ^i8
export extern "UnloadUTF8" func UnloadUTF8(text: ^i8): void
export extern "LoadCodepoints" func LoadCodepoints(text: ^i8, count: ^i32): ^i32
export extern "UnloadCodepoints" func UnloadCodepoints(codepoints: ^i32): void
export extern "GetCodepointCount" func GetCodepointCount(text: cstring): i32
export extern "GetCodepoint" func GetCodepoint(text: cstring, codepointSize: ^i32): i32
export extern "GetCodepointNext" func GetCodepointNext(text: cstring, codepointSize: ^i32): i32
export extern "GetCodepointPrevious" func GetCodepointPrevious(text: cstring, codepointSize: ^i32): i32
export extern "CodepointToUTF8" func CodepointToUTF8(codepoint: i32, utf8Size: ^i32): cstring
export extern "TextCopy" func TextCopy(dst: cstring, src: cstring): i32
export extern "TextIsEqual" func TextIsEqual(text1: cstring, text2: cstring): bool
export extern "TextLength" func TextLength(text: cstring): u32
export extern "TextFormat" func TextFormat(text: cstring): cstring
export extern "TextSubtext" func TextSubtext(text: cstring, position: i32, length: i32): cstring
export extern "TextReplace" func TextReplace(text: cstring, replace: cstring, by: cstring): cstring
export extern "TextInsert" func TextInsert(text: cstring, insert: cstring, position: i32): cstring
export extern "TextJoin" func TextJoin(textList: ^cstring, count: i32, delimiter: cstring): cstring
export extern "TextSplit" func TextSplit(text: cstring, delimiter: i8, count: ^i32): ^cstring
export extern "TextAppend" func TextAppend(text: cstring, append: cstring, position: ^i32): void
export extern "TextFindIndex" func TextFindIndex(text: cstring, find: cstring): i32
export extern "TextToUpper" func TextToUpper(text: cstring): cstring
export extern "TextToLower" func TextToLower(text: cstring): cstring
export extern "TextToPascal" func TextToPascal(text: cstring): cstring
export extern "TextToSnake" func TextToSnake(text: cstring): cstring
export extern "TextToCamel" func TextToCamel(text: cstring): cstring
export extern "TextToInteger" func TextToInteger(text: cstring): i32
export extern "TextToFloat" func TextToFloat(text: cstring): f32
export extern "GetCodepointCount" func GetCodepointCount(text: ^i8): i32
export extern "GetCodepoint" func GetCodepoint(text: ^i8, codepointSize: ^i32): i32
export extern "GetCodepointNext" func GetCodepointNext(text: ^i8, codepointSize: ^i32): i32
export extern "GetCodepointPrevious" func GetCodepointPrevious(text: ^i8, codepointSize: ^i32): i32
export extern "CodepointToUTF8" func CodepointToUTF8(codepoint: i32, utf8Size: ^i32): ^i8
export extern "TextCopy" func TextCopy(dst: ^i8, src: ^i8): i32
export extern "TextIsEqual" func TextIsEqual(text1: ^i8, text2: ^i8): bool
export extern "TextLength" func TextLength(text: ^i8): u32
export extern "TextFormat" func TextFormat(text: ^i8): ^i8
export extern "TextSubtext" func TextSubtext(text: ^i8, position: i32, length: i32): ^i8
export extern "TextReplace" func TextReplace(text: ^i8, replace: ^i8, by: ^i8): ^i8
export extern "TextInsert" func TextInsert(text: ^i8, insert: ^i8, position: i32): ^i8
export extern "TextJoin" func TextJoin(textList: ^^i8, count: i32, delimiter: ^i8): ^i8
export extern "TextSplit" func TextSplit(text: ^i8, delimiter: i8, count: ^i32): ^^i8
export extern "TextAppend" func TextAppend(text: ^i8, append: ^i8, position: ^i32): void
export extern "TextFindIndex" func TextFindIndex(text: ^i8, find: ^i8): i32
export extern "TextToUpper" func TextToUpper(text: ^i8): ^i8
export extern "TextToLower" func TextToLower(text: ^i8): ^i8
export extern "TextToPascal" func TextToPascal(text: ^i8): ^i8
export extern "TextToSnake" func TextToSnake(text: ^i8): ^i8
export extern "TextToCamel" func TextToCamel(text: ^i8): ^i8
export extern "TextToInteger" func TextToInteger(text: ^i8): i32
export extern "TextToFloat" func TextToFloat(text: ^i8): f32
export extern "DrawLine3D" func DrawLine3D(startPos: Vector3, endPos: Vector3, color: Color): void
export extern "DrawPoint3D" func DrawPoint3D(position: Vector3, color: Color): void
export extern "DrawCircle3D" func DrawCircle3D(center: Vector3, radius: f32, rotationAxis: Vector3, rotationAngle: f32, color: Color): void
@@ -1455,7 +1455,7 @@ export extern "DrawCapsuleWires" func DrawCapsuleWires(startPos: Vector3, endPos
export extern "DrawPlane" func DrawPlane(centerPos: Vector3, size: Vector2, color: Color): void
export extern "DrawRay" func DrawRay(ray: Ray, color: Color): void
export extern "DrawGrid" func DrawGrid(slices: i32, spacing: f32): void
export extern "LoadModel" func LoadModel(fileName: cstring): Model
export extern "LoadModel" func LoadModel(fileName: ^i8): Model
export extern "LoadModelFromMesh" func LoadModelFromMesh(mesh: Mesh): Model
export extern "IsModelValid" func IsModelValid(model: Model): bool
export extern "UnloadModel" func UnloadModel(model: Model): void
@@ -1477,8 +1477,8 @@ export extern "DrawMesh" func DrawMesh(mesh: Mesh, material: Material, transform
export extern "DrawMeshInstanced" func DrawMeshInstanced(mesh: Mesh, material: Material, transforms: ^Matrix, instances: i32): void
export extern "GetMeshBoundingBox" func GetMeshBoundingBox(mesh: Mesh): BoundingBox
export extern "GenMeshTangents" func GenMeshTangents(mesh: ^Mesh): void
export extern "ExportMesh" func ExportMesh(mesh: Mesh, fileName: cstring): bool
export extern "ExportMeshAsCode" func ExportMeshAsCode(mesh: Mesh, fileName: cstring): bool
export extern "ExportMesh" func ExportMesh(mesh: Mesh, fileName: ^i8): bool
export extern "ExportMeshAsCode" func ExportMeshAsCode(mesh: Mesh, fileName: ^i8): bool
export extern "GenMeshPoly" func GenMeshPoly(sides: i32, radius: f32): Mesh
export extern "GenMeshPlane" func GenMeshPlane(width: f32, length: f32, resX: i32, resZ: i32): Mesh
export extern "GenMeshCube" func GenMeshCube(width: f32, height: f32, length: f32): Mesh
@@ -1490,13 +1490,13 @@ export extern "GenMeshTorus" func GenMeshTorus(radius: f32, size: f32, radSeg: i
export extern "GenMeshKnot" func GenMeshKnot(radius: f32, size: f32, radSeg: i32, sides: i32): Mesh
export extern "GenMeshHeightmap" func GenMeshHeightmap(heightmap: Image, size: Vector3): Mesh
export extern "GenMeshCubicmap" func GenMeshCubicmap(cubicmap: Image, cubeSize: Vector3): Mesh
export extern "LoadMaterials" func LoadMaterials(fileName: cstring, materialCount: ^i32): ^Material
export extern "LoadMaterials" func LoadMaterials(fileName: ^i8, materialCount: ^i32): ^Material
export extern "LoadMaterialDefault" func LoadMaterialDefault(): Material
export extern "IsMaterialValid" func IsMaterialValid(material: Material): bool
export extern "UnloadMaterial" func UnloadMaterial(material: Material): void
export extern "SetMaterialTexture" func SetMaterialTexture(material: ^Material, mapType: i32, texture: Texture): void
export extern "SetModelMeshMaterial" func SetModelMeshMaterial(model: ^Model, meshId: i32, materialId: i32): void
export extern "LoadModelAnimations" func LoadModelAnimations(fileName: cstring, animCount: ^i32): ^ModelAnimation
export extern "LoadModelAnimations" func LoadModelAnimations(fileName: ^i8, animCount: ^i32): ^ModelAnimation
export extern "UpdateModelAnimation" func UpdateModelAnimation(model: Model, anim: ModelAnimation, frame: i32): void
export extern "UpdateModelAnimationBones" func UpdateModelAnimationBones(model: Model, anim: ModelAnimation, frame: i32): void
export extern "UnloadModelAnimation" func UnloadModelAnimation(anim: ModelAnimation): void
@@ -1515,10 +1515,10 @@ export extern "CloseAudioDevice" func CloseAudioDevice(): void
export extern "IsAudioDeviceReady" func IsAudioDeviceReady(): bool
export extern "SetMasterVolume" func SetMasterVolume(volume: f32): void
export extern "GetMasterVolume" func GetMasterVolume(): f32
export extern "LoadWave" func LoadWave(fileName: cstring): Wave
export extern "LoadWaveFromMemory" func LoadWaveFromMemory(fileType: cstring, fileData: ^u8, dataSize: i32): Wave
export extern "LoadWave" func LoadWave(fileName: ^i8): Wave
export extern "LoadWaveFromMemory" func LoadWaveFromMemory(fileType: ^i8, fileData: ^u8, dataSize: i32): Wave
export extern "IsWaveValid" func IsWaveValid(wave: Wave): bool
export extern "LoadSound" func LoadSound(fileName: cstring): Sound
export extern "LoadSound" func LoadSound(fileName: ^i8): Sound
export extern "LoadSoundFromWave" func LoadSoundFromWave(wave: Wave): Sound
export extern "LoadSoundAlias" func LoadSoundAlias(source: Sound): Sound
export extern "IsSoundValid" func IsSoundValid(sound: Sound): bool
@@ -1526,8 +1526,8 @@ export extern "UpdateSound" func UpdateSound(sound: Sound, data: ^void, sampleCo
export extern "UnloadWave" func UnloadWave(wave: Wave): void
export extern "UnloadSound" func UnloadSound(sound: Sound): void
export extern "UnloadSoundAlias" func UnloadSoundAlias(alias: Sound): void
export extern "ExportWave" func ExportWave(wave: Wave, fileName: cstring): bool
export extern "ExportWaveAsCode" func ExportWaveAsCode(wave: Wave, fileName: cstring): bool
export extern "ExportWave" func ExportWave(wave: Wave, fileName: ^i8): bool
export extern "ExportWaveAsCode" func ExportWaveAsCode(wave: Wave, fileName: ^i8): bool
export extern "PlaySound" func PlaySound(sound: Sound): void
export extern "StopSound" func StopSound(sound: Sound): void
export extern "PauseSound" func PauseSound(sound: Sound): void
@@ -1541,8 +1541,8 @@ export extern "WaveCrop" func WaveCrop(wave: ^Wave, initFrame: i32, finalFrame:
export extern "WaveFormat" func WaveFormat(wave: ^Wave, sampleRate: i32, sampleSize: i32, channels: i32): void
export extern "LoadWaveSamples" func LoadWaveSamples(wave: Wave): ^f32
export extern "UnloadWaveSamples" func UnloadWaveSamples(samples: ^f32): void
export extern "LoadMusicStream" func LoadMusicStream(fileName: cstring): Music
export extern "LoadMusicStreamFromMemory" func LoadMusicStreamFromMemory(fileType: cstring, data: ^u8, dataSize: i32): Music
export extern "LoadMusicStream" func LoadMusicStream(fileName: ^i8): Music
export extern "LoadMusicStreamFromMemory" func LoadMusicStreamFromMemory(fileType: ^i8, data: ^u8, dataSize: i32): Music
export extern "IsMusicValid" func IsMusicValid(music: Music): bool
export extern "UnloadMusicStream" func UnloadMusicStream(music: Music): void
export extern "PlayMusicStream" func PlayMusicStream(music: Music): void

View File

@@ -2,8 +2,10 @@ import "raylib"
module "main"
extern "main" func main(argc: i64, argv: [?]cstring): i64
extern "main" func main(argc: i64, argv: ^^i8): i64
{
let uwu: []i32 = [1, 2]
raylib::SetConfigFlags(raylib::ConfigFlags.FLAG_VSYNC_HINT | raylib::ConfigFlags.FLAG_WINDOW_RESIZABLE)
raylib::InitWindow(1600, 900, "Hi from nub-lang")