Fix bugs, Add TODOs

This commit is contained in:
MrLetsplay 2024-03-19 12:48:06 +01:00
parent ea7c4b73b6
commit 8519f38bab
Signed by: mr
SSH Key Fingerprint: SHA256:0zWNiRisbQ4dq/CCQAaMLoF3UfkF5wKPXO7DcjfFBEU
2 changed files with 13 additions and 8 deletions

View File

@ -279,18 +279,22 @@ func compileFunctionWAT(function ParsedFunction) (string, error) {
funcWAT := "(func $" + function.Name + "\n"
for _, local := range function.Locals {
pfx := ""
if local.IsParameter {
pfx = "param"
} else {
pfx = "local"
if !local.IsParameter {
continue
}
funcWAT += "\t(" + pfx + " $" + strconv.Itoa(local.Index) + " " + getWATType(local.Type) + ")\n"
funcWAT += "\t(param $" + strconv.Itoa(local.Index) + " " + getWATType(local.Type) + ")\n"
}
// TODO: tuples
funcWAT += "\t(result " + getWATType(function.ReturnType) + ")\n"
for _, local := range function.Locals {
if local.IsParameter {
continue
}
funcWAT += "\t(local $" + strconv.Itoa(local.Index) + " " + getWATType(local.Type) + ")\n"
}
wat, err := compileBlockWAT(function.Body)
if err != nil {
return "", err

View File

@ -90,8 +90,7 @@ func validateExpression(expr *Expression, block *Block) []error {
literal := expr.Value.(LiteralExpression)
switch literal.Literal.Type {
case Literal_Boolean:
case Literal_Number:
case Literal_Boolean, Literal_Number:
expr.ValueType = Type{Type: Type_Primitive, Value: literal.Literal.Primitive}
case Literal_String:
expr.ValueType = STRING_TYPE
@ -192,6 +191,8 @@ func validateStatement(stmt *Statement, block *Block, functionLocals *[]Local) [
local := Local{Name: dlv.Variable, Type: dlv.VariableType, IsParameter: false, Index: len(*functionLocals)}
block.Locals[dlv.Variable] = local
*functionLocals = append(*functionLocals, local)
// TODO: check if assignment of initializer is correct
}
return errors