Alternate signing constructs #1
|
@ -1103,6 +1103,31 @@ func returnBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
|||
return nil, errReturn{ret: args.args[0]}
|
||||
}
|
||||
|
||||
// TODO - add tests
|
||||
|
||||
func errorBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
if len(args.args) < 1 {
|
||||
return nil, errors.New("need at least one arguments")
|
||||
}
|
||||
return nil, ErrRuntime{args.args[0].String()}
|
||||
}
|
||||
|
||||
func assertBuiltin(ctx context.Context, args invocationArgs) (Object, error) {
|
||||
if len(args.args) < 1 {
|
||||
return nil, errors.New("need at least one arguments")
|
||||
}
|
||||
|
||||
if isTruthy(args.args[0]) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if len(args.args) > 1 {
|
||||
return nil, ErrRuntime{args.args[1].String()}
|
||||
}
|
||||
|
||||
return nil, ErrRuntime{"assertion failed"}
|
||||
}
|
||||
|
||||
func procBuiltin(ctx context.Context, args macroArgs) (Object, error) {
|
||||
if args.nargs() < 1 {
|
||||
return nil, errors.New("need at least one arguments")
|
||||
|
|
|
@ -96,6 +96,9 @@ func New(opts ...InstOption) *Inst {
|
|||
rootEC.addCmd("continue", invokableFunc(continueBuiltin))
|
||||
rootEC.addCmd("return", invokableFunc(returnBuiltin))
|
||||
|
||||
rootEC.addCmd("error", invokableFunc(errorBuiltin))
|
||||
rootEC.addCmd("assert", invokableFunc(assertBuiltin))
|
||||
|
||||
rootEC.addMacro("if", macroFunc(ifBuiltin))
|
||||
rootEC.addMacro("foreach", macroFunc(foreachBuiltin))
|
||||
rootEC.addMacro("for", macroFunc(foreachBuiltin))
|
||||
|
|
|
@ -643,6 +643,14 @@ func (p OpaqueObject) Truthy() bool {
|
|||
return p.v != nil
|
||||
}
|
||||
|
||||
type ErrRuntime struct {
|
||||
errStr string
|
||||
}
|
||||
|
||||
func (e ErrRuntime) Error() string {
|
||||
return e.errStr
|
||||
}
|
||||
|
||||
type errBreak struct {
|
||||
isCont bool
|
||||
ret Object
|
||||
|
|
Loading…
Reference in a new issue