This commit is contained in:
MrLetsplay 2024-03-25 16:58:23 +01:00
parent 06be5bc35e
commit a53b294392
Signed by: mr
SSH Key Fingerprint: SHA256:0zWNiRisbQ4dq/CCQAaMLoF3UfkF5wKPXO7DcjfFBEU
3 changed files with 15 additions and 2 deletions

View File

@ -134,6 +134,8 @@ func castPrimitiveWAT(from PrimitiveType, to PrimitiveType) (string, error) {
if getBits(to) < getBits(from) { if getBits(to) < getBits(from) {
return getTypeCast(to), nil return getTypeCast(to), nil
} }
return "", nil
} }
if getBits(from) < 64 && getBits(to) == 64 { if getBits(from) < 64 && getBits(to) == 64 {
@ -334,7 +336,6 @@ func compileStatementWAT(stmt Statement, block *Block) (string, error) {
} }
// TODO: upcast to return type for non-primitive types // TODO: upcast to return type for non-primitive types
return wat + "return\n", nil return wat + "return\n", nil
case Statement_DeclareLocalVariable: case Statement_DeclareLocalVariable:
dlv := stmt.Value.(DeclareLocalVariableStatement) dlv := stmt.Value.(DeclareLocalVariableStatement)
@ -347,7 +348,15 @@ func compileStatementWAT(stmt Statement, block *Block) (string, error) {
return "", err return "", err
} }
// TODO: make sure to upcast to target type if dlv.VariableType.Type == Type_Primitive {
castWAT, err := castPrimitiveWAT(dlv.Initializer.ValueType.Value.(PrimitiveType), dlv.VariableType.Value.(PrimitiveType))
if err != nil {
return "", err
}
wat += castWAT
}
return wat + "local.set $" + strconv.Itoa(block.Locals[dlv.Variable].Index) + "\n", nil return wat + "local.set $" + strconv.Itoa(block.Locals[dlv.Variable].Index) + "\n", nil
case Statement_If: case Statement_If:
ifS := stmt.Value.(IfStatement) ifS := stmt.Value.(IfStatement)

View File

@ -8,6 +8,7 @@ void a() {
(u8, u8) doNothing(u8 a, u8 b) { (u8, u8) doNothing(u8 a, u8 b) {
a = b; a = b;
u16 c = 1u8;
return a, b; return a, b;
} }

3
example/test.lang Normal file
View File

@ -0,0 +1,3 @@
void doNothing() {
u64 sus = 1u8;
}