diff --git a/backend_wat.go b/backend_wat.go index 4b77920..165313c 100644 --- a/backend_wat.go +++ b/backend_wat.go @@ -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 diff --git a/validator.go b/validator.go index 0242ca4..328158d 100644 --- a/validator.go +++ b/validator.go @@ -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