mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 18:02:02 +01:00
shader: Parse function signatures
This commit is contained in:
parent
5ea5dfccfc
commit
ddba8a911f
@ -38,11 +38,9 @@ type constant struct {
|
||||
|
||||
type function struct {
|
||||
name string
|
||||
args []variable
|
||||
rets []variable
|
||||
in []string
|
||||
out []string
|
||||
block *block
|
||||
|
||||
ir shaderir.Func
|
||||
}
|
||||
|
||||
type compileState struct {
|
||||
@ -208,42 +206,44 @@ func (cs *compileState) parseFunc(d *ast.FuncDecl, block *block) function {
|
||||
return function{}
|
||||
}
|
||||
|
||||
var args []variable
|
||||
var in []string
|
||||
var inT []shaderir.Type
|
||||
for _, f := range d.Type.Params.List {
|
||||
t := cs.parseType(f.Type)
|
||||
for _, n := range f.Names {
|
||||
args = append(args, variable{
|
||||
name: n.Name,
|
||||
typ: t,
|
||||
})
|
||||
in = append(in, n.Name)
|
||||
inT = append(inT, t.ir)
|
||||
}
|
||||
}
|
||||
|
||||
var rets []variable
|
||||
var out []string
|
||||
var outT []shaderir.Type
|
||||
if d.Type.Results != nil {
|
||||
for _, f := range d.Type.Results.List {
|
||||
t := cs.parseType(f.Type)
|
||||
if len(f.Names) == 0 {
|
||||
rets = append(rets, variable{
|
||||
name: "",
|
||||
typ: t,
|
||||
})
|
||||
out = append(out, "")
|
||||
outT = append(outT, t.ir)
|
||||
} else {
|
||||
for _, n := range f.Names {
|
||||
rets = append(rets, variable{
|
||||
name: n.Name,
|
||||
typ: t,
|
||||
})
|
||||
out = append(out, n.Name)
|
||||
outT = append(outT, t.ir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cs.ir.Funcs = append(cs.ir.Funcs, shaderir.Func{
|
||||
Index: len(cs.ir.Funcs),
|
||||
InParams: inT,
|
||||
OutParams: outT,
|
||||
})
|
||||
|
||||
return function{
|
||||
name: d.Name.Name,
|
||||
args: args,
|
||||
rets: rets,
|
||||
//body: cs.parseBlock(block, d.Body),
|
||||
in: in,
|
||||
out: out,
|
||||
//block: cs.parseBlock(block, d.Body),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,17 @@ uniform vec4 U1;`,
|
||||
FS: `uniform vec2 U0;
|
||||
uniform vec4 U1;`,
|
||||
},
|
||||
{
|
||||
Name: "func",
|
||||
Src: `package main
|
||||
|
||||
func Foo(foo vec2) vec4 {
|
||||
}`,
|
||||
VS: `void F0(in vec2 l0, out vec4 l1) {
|
||||
}`,
|
||||
FS: `void F0(in vec2 l0, out vec4 l1) {
|
||||
}`,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
s, err := Compile([]byte(tc.Src))
|
||||
|
Loading…
Reference in New Issue
Block a user