Skip to content

Commit

Permalink
Merge branch 'refaktor:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xypwn committed Sep 7, 2024
2 parents 65e7c3f + c1a0c4d commit bfbc073
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine AS builder
FROM golang:1.23-alpine AS builder

RUN apk add --no-cache git sqlite-dev bash gcc libc-dev

Expand Down
9 changes: 9 additions & 0 deletions env/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ func NewUri1(index *Idxs, path string) *Uri {
return &nat
}

func NewFileUri(index *Idxs, path string) *Uri {
scheme := "file" // + "-schema" // TODO -- this is just temporary .. so we test it further, make proper once at that level
idxSch := index.IndexWord(scheme)
kind := scheme + "-schema"
idxKind := index.IndexWord(kind)
nat := Uri{Word{idxSch}, path, Word{idxKind}}
return &nat
}

func NewUri(index *Idxs, scheme Word, path string) *Uri {
scheme2 := strings.Split(path, "://")
kindstr := strings.Split(path, "://")[0] + "-schema" // TODO -- this is just temporary .. so we test it further, make proper once at that level
Expand Down
38 changes: 31 additions & 7 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,10 @@ var builtins = map[string]*env.Builtin{
Pure: true,
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
return *env.NewFileUri(ps.Idx, strconv.Itoa(int(val.Value))) // TODO turn to switch
case env.String:
return *env.NewUri1(ps.Idx, "file://"+val.Value) // TODO turn to switch
return *env.NewFileUri(ps.Idx, val.Value) // TODO turn to switch
default:
return MakeArgError(ps, 1, []env.Type{env.StringType}, "to-file")
}
Expand Down Expand Up @@ -2884,7 +2886,7 @@ var builtins = map[string]*env.Builtin{
},
},

"ls": {
"lc": {
Argsn: 0,
Doc: "Lists words in current context",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand All @@ -2893,7 +2895,7 @@ var builtins = map[string]*env.Builtin{
},
},

"lsp": {
"lcp": {
Argsn: 0,
Doc: "Lists words in current context",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand All @@ -2906,7 +2908,7 @@ var builtins = map[string]*env.Builtin{
},
},

"ls\\": {
"lc\\": {
Argsn: 1,
Doc: "Lists words in current context with string filter",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand All @@ -2922,7 +2924,7 @@ var builtins = map[string]*env.Builtin{
}
},
},
"lsp\\": {
"lcp\\": {
Argsn: 1,
Doc: "Lists words in current context with string filter",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand Down Expand Up @@ -7855,7 +7857,8 @@ func RegisterBuiltins(ps *env.ProgramState) {
RegisterBuiltins2(Builtins_ssh, ps, "ssh")
RegisterBuiltins2(Builtins_console, ps, "console")
RegisterBuiltinsInContext(Builtins_math, ps, "math")
RegisterBuiltinsInContext(Builtins_devops, ps, "devops")
osctx := RegisterBuiltinsInContext(Builtins_os, ps, "os")
RegisterBuiltinsInSubContext(Builtins_pipes, ps, osctx, "pipes")
// ## Archived modules
// RegisterBuiltins2(Builtins_gtk, ps, "gtk")
// RegisterBuiltins2(Builtins_nats, ps, "nats")
Expand All @@ -7875,7 +7878,7 @@ func RegisterBuiltins2(builtins map[string]*env.Builtin, ps *env.ProgramState, n
}
}

func RegisterBuiltinsInContext(builtins map[string]*env.Builtin, ps *env.ProgramState, name string) {
func RegisterBuiltinsInContext(builtins map[string]*env.Builtin, ps *env.ProgramState, name string) *env.RyeCtx {
BuiltinNames[name] = len(builtins)

ctx := ps.Ctx
Expand All @@ -7890,6 +7893,27 @@ func RegisterBuiltinsInContext(builtins map[string]*env.Builtin, ps *env.Program

wordIdx := ps.Idx.IndexWord(name)
ps.Ctx.Mod(wordIdx, *newctx)

return newctx
}

func RegisterBuiltinsInSubContext(builtins map[string]*env.Builtin, ps *env.ProgramState, parent *env.RyeCtx, name string) *env.RyeCtx {
BuiltinNames[name] = len(builtins)

ctx := ps.Ctx
ps.Ctx = env.NewEnv(parent) // make new context with no parent

for k, v := range builtins {
bu := env.NewBuiltin(v.Fn, v.Argsn, v.AcceptFailure, v.Pure, v.Doc+" ("+k+")")
registerBuiltin(ps, k, *bu)
}
newctx := ps.Ctx
ps.Ctx = ctx

wordIdx := ps.Idx.IndexWord(name)
ps.Ctx.Mod(wordIdx, *newctx)

return newctx
}

func registerBuiltin(ps *env.ProgramState, word string, builtin env.Builtin) {
Expand Down
18 changes: 17 additions & 1 deletion evaldo/builtins_eyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ func Eyr_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toL
var arg1 env.Object // := bi.Cur1
var arg2 env.Object

if bi.Argsn == 0 && bi.Cur0 == nil {
if checkFlagsBi(bi, ps, 0) {
return ps
}
if ps.ErrorFlag || ps.ReturnFlag {
return ps
}
if bi.Argsn == 0 {
// fmt.Println("** CALL BI")
ps.Res = bi.Fn(ps, nil, nil, nil, nil, nil)
// stack.Push(ps.Res)
}
}
if bi.Argsn > 0 && bi.Cur0 == nil {
if checkFlagsBi(bi, ps, 0) {
return ps
Expand Down Expand Up @@ -301,8 +314,11 @@ func Eyr_EvalExpression(ps *env.ProgramState) *env.ProgramState {
return ps
}

func Eyr_EvalBlockInside(ps *env.ProgramState) *env.ProgramState {
func Eyr_EvalBlockInside(ps *env.ProgramState, inj env.Object, injnow bool) *env.ProgramState {
// fmt.Println("** EVALB INSIDE")
if injnow {
ps.Stack.Push(ps, inj)
}
for ps.Ser.Pos() < ps.Ser.Len() {
// fmt.Println(ps.Ser.Pos())
ps = Eyr_EvalExpression(ps)
Expand Down
Loading

0 comments on commit bfbc073

Please sign in to comment.