This commit is contained in:
nub31
2025-07-07 19:16:06 +02:00
parent 810cc03eed
commit 4fff98b010
2 changed files with 47 additions and 48 deletions

View File

@@ -1,41 +1,47 @@
// struct name struct name
// { {
// first: cstring first: cstring
// last: cstring last: cstring
// } }
// struct human struct human
// { {
// name: name name: name
// age: i64 age: i64
// } }
// trait printable trait printable
// { {
// func print() func print()
// } }
// impl printable for human impl printable for human
// { {
// func print() { func print() {
// c::puts(this.name.first) c::puts(this.name.first)
// } }
// } }
func main(args: []cstring): i64 func main(args: []cstring): i64
{ {
// let human = alloc human let human = alloc human
// { {
// name = alloc name { name = alloc name {
// first = "john" first = "john"
// last = "doe" last = "doe"
// } }
// age = 23 age = 23
// } }
// human.print() human.print()
print_result(12, func(num) { return num == 12 }) print_result(12, func(num) { return num == 12 })
let x: cstring = "test"
let addr = x&
c::puts(addr^)
return 0 return 0
} }

View File

@@ -97,28 +97,21 @@ public partial class QBEGenerator
return _writer.ToString(); return _writer.ToString();
} }
private string QBEAssign(NubType type) private static string QBEAssign(NubType type)
{ {
return type switch if (type.IsSimpleType(out var simpleType, out _))
{ {
NubComplexType => "=l", return simpleType.StorageSize switch
NubSimpleType simpleType => simpleType switch
{ {
NubFuncType or NubFuncType => "=l", StorageSize.I8 or StorageSize.U8 or StorageSize.I16 or StorageSize.U16 or StorageSize.I32 or StorageSize.U32 => "=w",
NubPrimitiveType primitiveType => primitiveType.Kind switch StorageSize.I64 or StorageSize.U64 => "=l",
{ StorageSize.F32 => "=s",
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 => "=l", StorageSize.F64 => "=d",
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "=w", _ => throw new ArgumentOutOfRangeException(nameof(simpleType.StorageSize))
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => "=w", };
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "=w", }
PrimitiveTypeKind.F64 => "=d",
PrimitiveTypeKind.F32 => "=s", return "=l";
_ => throw new ArgumentOutOfRangeException()
},
_ => throw new NotSupportedException($"'{type}' type cannot be used in variables")
},
_ => throw new UnreachableException()
};
} }
private void EmitStore(NubType type, string value, string destination) private void EmitStore(NubType type, string value, string destination)