Skip to content

Commit

Permalink
Merge pull request #292 from refaktor/allin
Browse files Browse the repository at this point in the history
Allin - made allmost all builtins included by defalut as per issue #277
  • Loading branch information
refaktor authored Aug 4, 2024
2 parents aa62ed9 + fbeccbc commit 70fa6ca
Show file tree
Hide file tree
Showing 38 changed files with 241 additions and 583 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ jobs:
- name: Build
# Enable all features for CI builds.
# TODO: add currently problematic tags: b_cayley,b_nng,b_qframe,b_ebitengine,b_webview
run: |
go build -v -tags "b_sqlite,b_http,b_sql,b_postgres,b_bson,b_crypto,b_smtpd,b_mail,b_bcrypt,b_telegram,b_html,b_contrib,b_openai,b_email,b_mail,b_mysql,b_psql,b_psutil,b_sxml,b_echo" -o bin/rye
go build -v -o bin/rye
ls -l bin/rye
file bin/rye
go version -m bin/rye
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

# - name: Build
# run: |
# go build -v -tags "b_sqlite,b_http,b_sql,b_postgres,b_bson,b_crypto,b_smtpd,b_mail,b_bcrypt,b_telegram,b_html,b_contrib,b_openai,b_email,b_mail,b_mysql,b_nats,b_psql,b_psutil,b_sxml,b_echo" -o bin/rye
# go build -v -o bin/rye

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go build -tags "b_sqlite,b_http,b_sql,b_postgres,b_bson,b_mail,b_bcrypt,b_telegram,b_html,b_email,b_mail,b_mysql,b_fyne,b_contrib,b_bleve,b_devops,b_ssh," -o bin/rye
go build -o bin/rye
12 changes: 6 additions & 6 deletions evaldo/builtins_bcrypt.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build b_bcrypt
// +build b_bcrypt
//go:build !no_bcrypt
// +build !no_bcrypt

package evaldo

Expand All @@ -20,7 +20,7 @@ func __bcrypt_hash(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2
ps.FailureFlag = true
return MakeBuiltinError(ps, "Problem in hashing.", "__bcrypt_hash")
}
return env.String{string(bytes)}
return env.NewString(string(bytes))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.StringType}, "__bcrypt_hash")
Expand All @@ -34,9 +34,9 @@ func __bcrypt_check(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2
case env.String:
err := bcrypt.CompareHashAndPassword([]byte(hash.Value), []byte(password.Value))
if err == nil {
return env.Integer{1}
return env.NewInteger(1)
} else {
return env.Integer{0}
return env.NewInteger(0)
}
default:
ps.FailureFlag = true
Expand All @@ -55,7 +55,7 @@ func __generate_token(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, ar
if _, err := rand.Read(b); err != nil {
return MakeBuiltinError(ps, "Problem reading random stream.", "__generate_token")
}
return env.String{hex.EncodeToString(b)}
return env.NewString(hex.EncodeToString(b))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.IntegerType}, "__generate_token")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_bcrypt_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !b_bcrypt
// +build !b_bcrypt
//go:build no_bcrypt
// +build no_bcrypt

package evaldo

Expand Down
30 changes: 10 additions & 20 deletions evaldo/builtins_bson.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build b_bson
// +build b_bson
//go:build !no_bson
// +build !no_bson

package evaldo

Expand All @@ -22,7 +22,7 @@ func ValueToBSON(arg0 env.Object, topLevel bool) any {
case env.Integer:
val = obj.Value
case env.Decimal:
val = float64(obj.Value)
val = obj.Value
case env.String:
val = obj.Value
case env.Vector:
Expand Down Expand Up @@ -82,22 +82,20 @@ func ValueToBSON(arg0 env.Object, topLevel bool) any {
}

func BsonToValue_Map(ps *env.ProgramState, val any, typ string, meta any, topLevel bool) env.Object {

/*fmt.Println("BSONToVALUE_MAP")
fmt.Println(val)
fmt.Println(typ)
fmt.Println(meta)
fmt.Printf("Type: %T\n", val)*/

switch rval := val.(type) {
case int64:
return env.Integer{int64(rval)}
return *env.NewInteger(rval)
case float32:
return env.Decimal{float64(rval)}
return *env.NewDecimal(float64(rval))
case float64:
return env.Decimal{float64(rval)}
return *env.NewDecimal(rval)
case string:
return env.String{rval}
return *env.NewString(rval)
case bson.M:
return BsonToValue_Map(ps, rval["val"], rval["typ"].(string), rval["met"], false)
case map[string]any:
Expand All @@ -111,24 +109,20 @@ func BsonToValue_Map(ps *env.ProgramState, val any, typ string, meta any, topLev
case bson.A:
rcols := make([]string, len(cols))
for i, rr := range cols {
rcols[i] = string(rr.(string))
rcols[i] = rr.(string)
}
spr := env.NewSpreadsheet(rcols)
//rows := make([]interface{}, len(spr.Cols))
for ii := 0; ii < len(rval); ii++ {

//fmt.Printf("Type: %T\n", rval[ii])
//fmt.Println(rval[ii])

switch rrval := rval[ii].(type) {
case bson.A:
cells := make([]any, len(rrval))
for iii, rrrval := range rrval {
cells[iii] = BsonToValue_Map(ps, rrrval, "", nil, false)
}
spr.AddRow(env.SpreadsheetRow{cells, spr})
spr.AddRow(*env.NewSpreadsheetRow(cells, spr))
case []any:
spr.AddRow(env.SpreadsheetRow{rrval, spr})
spr.AddRow(*env.NewSpreadsheetRow(rrval, spr))
}
}
return *spr
Expand Down Expand Up @@ -162,10 +156,6 @@ func BsonToValue_Map(ps *env.ProgramState, val any, typ string, meta any, topLev
}

func BsonToValue_Val(ps *env.ProgramState, val any, topLevel bool) env.Object {

//fmt.Printf("Type: %T\n", val)
//fmt.Println(val)

switch rval := val.(type) {
case bson.M:
/*fmt.Println("~~")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_bson_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !b_bson
// +build !b_bson
//go:build no_bson
// +build no_bson

package evaldo

Expand Down
16 changes: 8 additions & 8 deletions evaldo/builtins_crypto.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build b_crypto
// +build b_crypto
//go:build !no_crypto
// +build !no_crypto

package evaldo

Expand Down Expand Up @@ -74,7 +74,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.([]byte))}
return env.NewString(hex.EncodeToString(addr.Value.([]byte)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Go-bytes//to-string")
Expand All @@ -88,7 +88,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.(ed25519.PublicKey))}
return env.NewString(hex.EncodeToString(addr.Value.(ed25519.PublicKey)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Ed25519-pub-key//to-string")
Expand All @@ -102,7 +102,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.(ed25519.PrivateKey))}
return env.NewString(hex.EncodeToString(addr.Value.(ed25519.PrivateKey)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Ed25519-priv-key//to-string")
Expand All @@ -120,8 +120,8 @@ var Builtins_crypto = map[string]*env.Builtin{
ps.FailureFlag = true
return MakeBuiltinError(ps, "Failed to generate keys.", "ed25519-generate-keys")
}
keys[0] = *env.NewNative(ps.Idx, ed25519.PublicKey(puk), "Ed25519-pub-key")
keys[1] = *env.NewNative(ps.Idx, ed25519.PrivateKey(pvk), "Ed25519-priv-key")
keys[0] = *env.NewNative(ps.Idx, puk, "Ed25519-pub-key")
keys[1] = *env.NewNative(ps.Idx, pvk, "Ed25519-priv-key")
ser := *env.NewTSeries(keys)
return *env.NewBlock(ser)
},
Expand Down Expand Up @@ -208,7 +208,7 @@ var Builtins_crypto = map[string]*env.Builtin{
h := sha512.New()
h.Write([]byte(s.Value))
bs := h.Sum(nil)
return env.String{hex.EncodeToString(bs[:])}
return env.NewString(hex.EncodeToString(bs[:]))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.StringType}, "sha512")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_crypto_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !b_crypto
// +build !b_crypto
//go:build no_crypto
// +build no_crypto

package evaldo

Expand Down
5 changes: 2 additions & 3 deletions evaldo/builtins_email.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build b_email
// +build b_email
//go:build !no_email
// +build !no_email

package evaldo

Expand Down Expand Up @@ -115,7 +115,6 @@ func __attach(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.O
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "gomail-message//attach")
}

}

func __addAlternative(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_email_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !b_email
// +build !b_email
//go:build no_email
// +build no_email

package evaldo

Expand Down
22 changes: 8 additions & 14 deletions evaldo/builtins_html.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build b_html
// +build b_html
//go:build !no_html
// +build !no_html

package evaldo

Expand Down Expand Up @@ -53,7 +53,6 @@ type HtmlDialectNode struct {
// xwords after another or conditions mean that we dive deeper, like a block { } would be

func load_html_Dict(es *env.ProgramState, block env.Block) (env.Dict, *env.Error) {

var key string
var condition *HtmlNavigCondition
var keys []string // keys
Expand Down Expand Up @@ -153,7 +152,6 @@ func load_html_Dict(es *env.ProgramState, block env.Block) (env.Dict, *env.Error
}

func do_html(es *env.ProgramState, reader io.Reader, dmap env.Dict) env.Object {

trace8("**** DO HTML **** ")
// fmt.Println(dmap)

Expand Down Expand Up @@ -181,9 +179,7 @@ func do_html(es *env.ProgramState, reader io.Reader, dmap env.Dict) env.Object {

myloop:
for {

//fmt.Println(dmap)

// Read tokens from the XML document in a stream.
rawtoken := decoder.Next()
// Inspect the type of the token just read.
Expand Down Expand Up @@ -315,7 +311,7 @@ myloop:
// fmt.Println("IN BLOCK")
ser := es.Ser // TODO -- make helper function that "does" a block
es.Ser = node.Code.Series
EvalBlockInj(es, env.String{string(tok.Data)}, true)
EvalBlockInj(es, env.NewString(tok.Data), true)
if es.ErrorFlag {
return es.Res
}
Expand Down Expand Up @@ -359,10 +355,8 @@ myloop:
m := len(tags) - 1 // Top element
curtag = tags[m]
tags = tags[:m] // Pop

// fmt.Println(stack)
// fmt.Println(tags)

}
case html.ErrorToken:
break myloop
Expand Down Expand Up @@ -426,14 +420,14 @@ var Builtins_html = map[string]*env.Builtin{
switch n := arg1.(type) {
case env.Integer:
if int(n.Value) < len(tok.Attr) {
return env.String{tok.Attr[int(n.Value)].Val}
return env.NewString(tok.Attr[int(n.Value)].Val)
} else {
return env.Void{}
}
case env.Word:
for _, a := range tok.Attr {
if a.Key == ps.Idx.GetWord(n.Index) {
return env.String{a.Val}
return env.NewString(a.Val)
}
}
return env.Void{}
Expand All @@ -457,9 +451,9 @@ var Builtins_html = map[string]*env.Builtin{
case env.Native:
switch tok := tok1.Value.(type) {
case html.Token:
return env.String{tok.Data}
return env.NewString(tok.Data)
default:
return MakeBuiltinError(ps, "Not xml-strat element.", "rye-html-start//name?")
return MakeBuiltinError(ps, "Not xml-start element.", "rye-html-start//name?")
}
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "rye-html-start//name?")
Expand All @@ -476,7 +470,7 @@ var Builtins_html = map[string]*env.Builtin{
case xml.StartElement:
return env.String{obj1.Name.Local}
default:
return env.NewError("Not xml-strat element")
return env.NewError("Not xml-start element")
}
default:
return env.NewError("first argument should be native")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_html_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !b_html
// +build !b_html
//go:build no_html
// +build no_html

package evaldo

Expand Down
Loading

0 comments on commit 70fa6ca

Please sign in to comment.