提交 7cabaa4a 编写于 作者: chai2010's avatar chai2010

完善 wago 方法解析

上级 09ec7f4a
......@@ -3,6 +3,8 @@
package app
import (
"fmt"
"os"
"strings"
"wa-lang.org/wa/internal/backends/compiler_wat"
......@@ -10,6 +12,9 @@ import (
)
func (p *App) WASM(filename string) ([]byte, error) {
if _, err := os.Lstat(filename); err != nil {
return nil, fmt.Errorf("%q not found", filename)
}
cfg := p.opt.Config()
prog, err := loader.LoadProgram(cfg, filename)
if err != nil {
......
......@@ -2418,27 +2418,34 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
scope := ast.NewScope(p.topScope) // function scope
var recv *ast.FieldList
if p.tok == token.LPAREN {
recv = p.parseParameters(scope, false)
if p.wagoMode {
if p.tok == token.LPAREN {
recv = p.parseParameters(scope, false)
}
}
ident := p.parseIdent()
// func Type.method()
if recv == nil && p.tok == token.PERIOD {
thisIdent := &ast.Ident{Name: "this"}
thisField := &ast.Field{
Names: []*ast.Ident{thisIdent},
Type: &ast.StarExpr{X: ident},
}
recv = &ast.FieldList{
List: []*ast.Field{thisField},
}
if !p.wagoMode {
if recv != nil {
panic("unreachable")
}
if p.tok == token.PERIOD {
thisIdent := &ast.Ident{Name: "this"}
thisField := &ast.Field{
Names: []*ast.Ident{thisIdent},
Type: &ast.StarExpr{X: ident},
}
recv = &ast.FieldList{
List: []*ast.Field{thisField},
}
p.declare(thisField, nil, scope, ast.Var, thisIdent)
p.declare(thisField, nil, scope, ast.Var, thisIdent)
p.next()
ident = p.parseIdent()
p.next()
ident = p.parseIdent()
}
}
params, results, arrowPos := p.parseSignature(scope)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册