Fix bugs, Add TODOs
This commit is contained in:
parent
ea7c4b73b6
commit
8519f38bab
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user