Alternate signing constructs #1

Merged
lmika merged 12 commits from feature/assign into main 2025-05-24 00:12:24 +00:00
3 changed files with 36 additions and 0 deletions
Showing only changes of commit 53b05b5ba6 - Show all commits

View file

@ -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")

View file

@ -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))

View file

@ -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