This commit is contained in:
nub31
2025-05-12 21:46:45 +02:00
parent 90ef9fb8e8
commit 0a9442c044
2 changed files with 78 additions and 49 deletions

View File

@@ -1,5 +1,16 @@
import c; import c;
global func main() { struct Human {
printf("something %s\n", "your mom"); age: i64;
name: string;
}
global func main() {
me = new Human
{
age = 21;
name = "Oliver";
};
printf("My name is %s and i am %d years old\n", me.name, me.age);
} }

View File

@@ -42,9 +42,11 @@ public class Generator
return _builder.ToString(); return _builder.ToString();
} }
private string QbeTypeName(NubType type) private static string QbeTypeName(NubType type)
{ {
if (type is NubPrimitiveType primitiveType) switch (type)
{
case NubPrimitiveType primitiveType:
{ {
switch (primitiveType.Kind) switch (primitiveType.Kind)
{ {
@@ -69,13 +71,22 @@ public class Generator
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
} }
case NubCustomType nubCustomType:
{
return "l";
}
default:
{
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
}
private int QbeTypeSize(NubType type) private static int QbeTypeSize(NubType type)
{ {
if (type is NubPrimitiveType primitiveType) switch (type)
{
case NubPrimitiveType primitiveType:
{ {
switch (primitiveType.Kind) switch (primitiveType.Kind)
{ {
@@ -100,9 +111,16 @@ public class Generator
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
} }
case NubCustomType nubCustomType:
{
return 8;
}
default:
{
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
}
private void GenerateFuncDefinition(LocalFuncDefinitionNode node) private void GenerateFuncDefinition(LocalFuncDefinitionNode node)
{ {