Skip to content

Commit

Permalink
Merge pull request #236 from refaktor/modwords
Browse files Browse the repository at this point in the history
added unpack builitn
  • Loading branch information
refaktor committed Jun 5, 2024
2 parents 5a51b2e + b88b627 commit 31383a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
36 changes: 12 additions & 24 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2596,39 +2596,27 @@ var builtins = map[string]*env.Builtin{
},
},

"unpack": { // ** WWWWWWWWWWWWWWWWWWWW ----
"unpack": {
Argsn: 1,
Doc: "Takes a block of Rye values and evaluates each value or expression.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch bloc := arg0.(type) {
case env.Block:
ser := ps.Ser
ps.Ser = bloc.Series
res := make([]env.Object, 0)
for ps.Ser.Pos() < ps.Ser.Len() {
// ps, injnow = EvalExpressionInj(ps, inj, injnow)
EvalExpression2(ps, false)
res = append(res, ps.Res)
// check and raise the flags if needed if true (error) return
//if checkFlagsAfterBlock(ps, 101) {
// return ps
//}
// if return flag was raised return ( errorflag I think would return in previous if anyway)
//if checkErrorReturnFlag(ps) {
// return ps
//}
// ps, injnow = MaybeAcceptComma(ps, inj, injnow)
for _, val := range bloc.Series.S {
switch val_ := val.(type) {
case env.Block:
res = append(res, val_.Series.S...)
//for _, val2 := range val_.Series.S {
// res = append(res, val2)
// }
default:
res = append(res, val)
}
}
ps.Ser = ser
return *env.NewBlock(*env.NewTSeries(res))
case env.Word:
val, found := ps.Ctx.Get(bloc.Index)
if found {
return val
}
return MakeBuiltinError(ps, "Value not found.", "vals")
default:
return MakeArgError(ps, 1, []env.Type{env.BlockType, env.WordType}, "vals")
return MakeArgError(ps, 1, []env.Type{env.BlockType}, "unpack")
}
},
},
Expand Down
6 changes: 6 additions & 0 deletions evaldo/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ func MaybeDisplayFailureOrError(es *env.ProgramState, genv *env.Idxs) {
fmt.Print(err.CodeBlock.PositionAndSurroundingElements(*genv))
}
fmt.Println("\x1b[0m")

// ENTER CONSOLE ON ERROR
es.ErrorFlag = false
es.FailureFlag = false
DoRyeRepl(es, "do", true)
}
// cebelca2659- vklopi kontne skupine
}

func MaybeDisplayFailureOrErrorWASM(es *env.ProgramState, genv *env.Idxs, printfn func(string)) {
Expand Down

0 comments on commit 31383a4

Please sign in to comment.