Example #1
0
func composeFloat32s(expr *ast.Expr) (funcs.Float32s, error) {
	uniq, err := prep(expr, types.LIST_FLOAT)
	if err != nil {
		return nil, err
	}
	if expr.List != nil {
		vs, err := newValues(expr.GetList().GetElems())
		if err != nil {
			return nil, err
		}
		bs := make([]funcs.Float32, len(vs))
		var ok bool
		for i := range vs {
			bs[i], ok = vs[i].(funcs.Float32)
			if !ok {
				return nil, &errExpected{types.SINGLE_FLOAT.String(), expr.String()}
			}
		}
		return funcs.NewListOfFloat32(bs), nil
	}
	values, err := newValues(expr.GetFunction().GetParams())
	if err != nil {
		return nil, err
	}
	return funcs.NewFloat32sFunc(uniq, values...)
}
Example #2
0
func prep(expr *ast.Expr, expType types.Type) (uniq string, err error) {
	if expr.Function != nil {
		fnc := expr.GetFunction()
		uniq, err = WhichFunc(fnc)
		if err != nil {
			return "", err
		}
		typ, err := funcs.Out(uniq)
		if err != nil {
			return "", err
		}
		if typ != expType {
			return "", &errExpected{expType.String(), expr.String()}
		}
		return uniq, err
	}
	if expr.List != nil {
		if !types.IsList(expType) {
			return "", &errExpected{expType.String(), expr.String()}
		}
	}
	typ, err := Which(expr)
	if err != nil {
		return "", err
	}
	if typ != expType {
		return "", &errExpected{expType.String(), expr.String()}
	}
	return "", nil
}