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"
|
funcWAT := "(func $" + function.Name + "\n"
|
||||||
|
|
||||||
for _, local := range function.Locals {
|
for _, local := range function.Locals {
|
||||||
pfx := ""
|
if !local.IsParameter {
|
||||||
if local.IsParameter {
|
continue
|
||||||
pfx = "param"
|
|
||||||
} else {
|
|
||||||
pfx = "local"
|
|
||||||
}
|
}
|
||||||
funcWAT += "\t(" + pfx + " $" + strconv.Itoa(local.Index) + " " + getWATType(local.Type) + ")\n"
|
funcWAT += "\t(param $" + strconv.Itoa(local.Index) + " " + getWATType(local.Type) + ")\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tuples
|
// TODO: tuples
|
||||||
funcWAT += "\t(result " + getWATType(function.ReturnType) + ")\n"
|
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)
|
wat, err := compileBlockWAT(function.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -90,8 +90,7 @@ func validateExpression(expr *Expression, block *Block) []error {
|
|||||||
literal := expr.Value.(LiteralExpression)
|
literal := expr.Value.(LiteralExpression)
|
||||||
|
|
||||||
switch literal.Literal.Type {
|
switch literal.Literal.Type {
|
||||||
case Literal_Boolean:
|
case Literal_Boolean, Literal_Number:
|
||||||
case Literal_Number:
|
|
||||||
expr.ValueType = Type{Type: Type_Primitive, Value: literal.Literal.Primitive}
|
expr.ValueType = Type{Type: Type_Primitive, Value: literal.Literal.Primitive}
|
||||||
case Literal_String:
|
case Literal_String:
|
||||||
expr.ValueType = STRING_TYPE
|
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)}
|
local := Local{Name: dlv.Variable, Type: dlv.VariableType, IsParameter: false, Index: len(*functionLocals)}
|
||||||
block.Locals[dlv.Variable] = local
|
block.Locals[dlv.Variable] = local
|
||||||
*functionLocals = append(*functionLocals, local)
|
*functionLocals = append(*functionLocals, local)
|
||||||
|
|
||||||
|
// TODO: check if assignment of initializer is correct
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
|
Loading…
Reference in New Issue
Block a user