Skip to content

Commit

Permalink
eyr functions improved
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Aug 18, 2024
1 parent 252c25e commit afa4a94
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
5 changes: 5 additions & 0 deletions env/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,11 @@ func (i Comma) Dump(e Idxs) string {

type Void struct{}

func NewVoid() *Void {
o := Void{}
return &o
}

func (i Void) Type() Type {
return VoidType
}
Expand Down
9 changes: 9 additions & 0 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,15 @@ var builtins = map[string]*env.Builtin{
},
},

"_.": { // ***
Argsn: 1,
Doc: "Accepts argument and returns void, meant to be used as drop in Eyr, void is not a valid runtime value.",
Pure: true,
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
return *env.NewVoid()
},
},

"_+": { // **
Argsn: 2,
Doc: "Adds or joins two values together (Integers, Strings, Uri-s and Blocks)",
Expand Down
31 changes: 20 additions & 11 deletions evaldo/builtins_eyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package evaldo

import (
"fmt"
// "fmt"

"github.com/refaktor/rye/env"
)
Expand Down Expand Up @@ -80,7 +80,7 @@ func Eyr_CallFunction(fn env.Function, es *env.ProgramState, leftVal env.Object,

var arg0 env.Object = nil
for i := fn.Argsn - 1; i >= 0; i-- {
var stackElem = es.Stack.Peek(es, i)
var stackElem = es.Stack.Pop(es)
// TODO: Consider doing check once outside of loop once this version is ready as a correctness comparison point
if es.ErrorFlag {
return es
Expand Down Expand Up @@ -108,9 +108,10 @@ func Eyr_CallFunction(fn env.Function, es *env.ProgramState, leftVal env.Object,
var result *env.ProgramState */
// es.Ser.SetPos(0)
fmt.Println("***")
// fmt.Println("***")
if fn.Argsn > 0 {
EvalBlockInjMultiDialect(es, arg0, arg0 != nil)
EvalBlock(es)
// EvalBlockInjMultiDialect(es, arg0, arg0 != nil)
} else {
EvalBlock(es)
}
Expand Down Expand Up @@ -141,14 +142,16 @@ func Eyr_EvalObject(es *env.ProgramState, object env.Object, leftVal env.Object,
return es
}
es := Eyr_CallBuiltin(bu, es, leftVal, toLeft)

Check failure on line 144 in evaldo/builtins_eyr.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "es" shadows declaration at line 133 (govet)
es.Stack.Push(es, es.Res)
if es.Res.Type() != env.VoidType {
es.Stack.Push(es, es.Res)
}
return es
case env.FunctionType:
fn := object.(env.Function)
return Eyr_CallFunction(fn, es, leftVal, toLeft, session)

default:
es.Res = object
es.Stack.Push(es, es.Res)
return es
}
}
Expand Down Expand Up @@ -185,6 +188,7 @@ func Eyr_EvalExpression(ps *env.ProgramState) *env.ProgramState {
if object != nil {
switch object.Type() {
case env.IntegerType:
// fmt.Println("** INTEGER")
ps.Stack.Push(ps, object)
case env.DecimalType:
ps.Stack.Push(ps, object)
Expand All @@ -197,9 +201,11 @@ func Eyr_EvalExpression(ps *env.ProgramState) *env.ProgramState {
case env.EmailType:
ps.Stack.Push(ps, object)
case env.WordType:
// fmt.Println("** WORD")
rr := Eyr_EvalWord(ps, object.(env.Word), nil, false)
return rr
case env.OpwordType: // + and other operators are basically opwords too
// fmt.Println("** OPWORD")
rr := Eyr_EvalWord(ps, object.(env.Opword), nil, false)
return rr
case env.CPathType:
Expand All @@ -209,8 +215,9 @@ func Eyr_EvalExpression(ps *env.ProgramState) *env.ProgramState {
// print(stack)
rr := Eyr_EvalLSetword(ps, object.(env.LSetword), nil, false)
return rr
// case env.BuiltinType:
// return Eyr_EvalObject(ps, object, nil, false, nil, false) //ww0128a *
case env.BuiltinType:
// fmt.Println("** BUILTIN")
return Eyr_EvalObject(ps, object, nil, false, nil, false) //ww0128a *
default:
ps.ErrorFlag = true
ps.Res = env.NewError("Not known type for Eyr")
Expand All @@ -225,14 +232,16 @@ func Eyr_EvalExpression(ps *env.ProgramState) *env.ProgramState {

func Eyr_EvalBlock(ps *env.ProgramState, full bool) *env.ProgramState {
for ps.Ser.Pos() < ps.Ser.Len() {
fmt.Println(ps.Ser.Pos())
// fmt.Println(ps.Ser.Pos())
ps = Eyr_EvalExpression(ps)
if checkFlagsAfterBlock(ps, 101) {
fmt.Println("yy")
// fmt.Println("yy")
return ps
}
if ps.ReturnFlag || ps.ErrorFlag {
fmt.Println("xx")
// fmt.Println(ps.ReturnFlag)
// fmt.Println(ps.ErrorFlag)
// fmt.Println("xx")
return ps
}
}
Expand Down
16 changes: 16 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,22 @@ var Builtins_math = map[string]*env.Builtin{
return *env.NewDecimal(float64(math.Pi))
},
},
"deg->rad": {
Argsn: 1,
Doc: "Convert degrees to radians.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
var fa float64
switch a := arg0.(type) {
case env.Decimal:
fa = a.Value
case env.Integer:
fa = float64(a.Value)
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "deg->rad")
}
return *env.NewDecimal(fa * float64(math.Pi) / 180.0)
},
},
"is-near": {
Argsn: 2,
Doc: "Returns true if two decimals are close.",
Expand Down

0 comments on commit afa4a94

Please sign in to comment.