mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
75158feccf
commit
185e367295
@ -220,13 +220,13 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
|
||||
// For built-in functions, we can call this in this position. Return an expression for the function
|
||||
// call.
|
||||
if callee.Type == shaderir.BuiltinFuncExpr {
|
||||
if callee.BuiltinFunc == shaderir.Len {
|
||||
if callee.BuiltinFunc == shaderir.Len || callee.BuiltinFunc == shaderir.Cap {
|
||||
if len(args) != 1 {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("number of len's arguments must be 1 but %d", len(args)))
|
||||
cs.addError(e.Pos(), fmt.Sprintf("number of %s's arguments must be 1 but %d", callee.BuiltinFunc, len(args)))
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
if argts[0].Main != shaderir.Array {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("len takes an array but %s", argts[0].String()))
|
||||
cs.addError(e.Pos(), fmt.Sprintf("%s takes an array but %s", callee.BuiltinFunc, argts[0].String()))
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
return []shaderir.Expr{
|
||||
|
10
internal/shader/testdata/len.expected.vs
vendored
10
internal/shader/testdata/len.expected.vs
vendored
@ -1,4 +1,5 @@
|
||||
void F0(in vec2 l0, out int l1);
|
||||
void F1(in vec2 l0, out int l1);
|
||||
|
||||
void F0(in vec2 l0, out int l1) {
|
||||
int l2[2];
|
||||
@ -7,3 +8,12 @@ void F0(in vec2 l0, out int l1) {
|
||||
l1 = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
void F1(in vec2 l0, out int l1) {
|
||||
int l2[3];
|
||||
l2[0] = 0;
|
||||
l2[1] = 0;
|
||||
l2[2] = 0;
|
||||
l1 = 3;
|
||||
return;
|
||||
}
|
||||
|
5
internal/shader/testdata/len.go
vendored
5
internal/shader/testdata/len.go
vendored
@ -4,3 +4,8 @@ func Foo(foo vec2) int {
|
||||
var a [2]int
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func Bar(foo vec2) int {
|
||||
var a [3]int
|
||||
return cap(a)
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ type BuiltinFunc string
|
||||
|
||||
const (
|
||||
Len BuiltinFunc = "len"
|
||||
Cap BuiltinFunc = "cap"
|
||||
BoolF BuiltinFunc = "bool"
|
||||
IntF BuiltinFunc = "int"
|
||||
FloatF BuiltinFunc = "float"
|
||||
@ -257,6 +258,7 @@ const (
|
||||
func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
|
||||
switch BuiltinFunc(str) {
|
||||
case Len,
|
||||
Cap,
|
||||
BoolF,
|
||||
IntF,
|
||||
FloatF,
|
||||
|
Loading…
Reference in New Issue
Block a user