From 847d85605efce265031314821110a29b249cc927 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Wed, 5 Jun 2024 05:53:02 +0200 Subject: [PATCH] removed unused commented code --- fraction-type.go | 42 ------------------- operand-func.go | 16 ------- operator-assign.go | 101 ++++----------------------------------------- simple-store.go | 1 - 4 files changed, 8 insertions(+), 152 deletions(-) diff --git a/fraction-type.go b/fraction-type.go index da0c59a..617fabd 100644 --- a/fraction-type.go +++ b/fraction-type.go @@ -33,52 +33,10 @@ func float64ToFraction(f float64) (fract *FractionType, err error) { } dec := fmt.Sprintf("%.12f", decPart) s := fmt.Sprintf("%s%.f%s", sign, intPart, dec[1:]) - // fmt.Printf("S: '%s'\n",s) return makeGeneratingFraction(s) } // Based on https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/math/big/rat.go;l=39 -/* -func _float64ToFraction(f float64) (num, den int64, err error) { - const expMask = 1<<11 - 1 - bits := math.Float64bits(f) - mantissa := bits & (1<<52 - 1) - exp := int((bits >> 52) & expMask) - switch exp { - case expMask: // non-finite - err = errors.New("infite") - return - case 0: // denormal - exp -= 1022 - default: // normal - mantissa |= 1 << 52 - exp -= 1023 - } - - shift := 52 - exp - - // Optimization (?): partially pre-normalise. - for mantissa&1 == 0 && shift > 0 { - mantissa >>= 1 - shift-- - } - - if f < 0 { - num = -int64(mantissa) - } else { - num = int64(mantissa) - } - den = int64(1) - - if shift > 0 { - den = den << shift - } else { - num = num << (-shift) - } - return -} -*/ - func makeGeneratingFraction(s string) (f *FractionType, err error) { var num, den int64 var sign int64 = 1 diff --git a/operand-func.go b/operand-func.go index 9bb3dfd..d149ee9 100644 --- a/operand-func.go +++ b/operand-func.go @@ -40,7 +40,6 @@ func checkFunctionCall(ctx ExprContext, name string, varParams *[]any) (err erro err = errTooMuchParams(name, info.MaxArgs(), len(*varParams)) } if err == nil && owner != ctx { - // ctx.RegisterFunc(name, info.Functor(), info.MinArgs(), info.MaxArgs()) ctx.RegisterFuncInfo(info) } } else { @@ -52,7 +51,6 @@ func checkFunctionCall(ctx ExprContext, name string, varParams *[]any) (err erro func evalFuncCall(parentCtx ExprContext, self *term) (v any, err error) { ctx := cloneContext(parentCtx) name, _ := self.tk.Value.(string) - // fmt.Printf("Call %s(), context: %p\n", name, ctx) params := make([]any, len(self.children), len(self.children)+5) for i, tree := range self.children { var param any @@ -85,20 +83,6 @@ func newFuncDefTerm(tk *Token, args []*term) *term { } // -------- eval func def -// func _evalFuncDef(ctx ExprContext, self *term) (v any, err error) { -// bodySpec := self.value() -// if expr, ok := bodySpec.(*ast); ok { -// paramList := make([]string, 0, len(self.children)) -// for _, param := range self.children { -// paramList = append(paramList, param.source()) -// } -// v = newExprFunctor(expr, paramList, ctx) -// } else { -// err = errors.New("invalid function definition: the body specification must be an expression") -// } -// return -// } - func evalFuncDef(ctx ExprContext, self *term) (v any, err error) { bodySpec := self.value() if expr, ok := bodySpec.(*ast); ok { diff --git a/operator-assign.go b/operator-assign.go index 3c511d0..fb21069 100644 --- a/operator-assign.go +++ b/operator-assign.go @@ -16,10 +16,6 @@ func newAssignTerm(tk *Token) (inst *term) { } } -func assignListItem(list *ListType, index int64, value any) (err error) { - return list.setItem(index, value) -} - func assignCollectionItem(ctx ExprContext, collectionTerm, keyListTerm *term, value any) (err error) { var collectionValue, keyListValue, keyValue any var keyList *ListType @@ -35,17 +31,20 @@ func assignCollectionItem(ctx ExprContext, collectionTerm, keyListTerm *term, va err = keyListTerm.Errorf("index/key specification expected, got %v [%s]", keyListValue, typeName(keyListValue)) return } - keyValue = (*keyList)[0] + if keyValue = (*keyList)[0]; keyValue == nil { + err = keyListTerm.Errorf("index/key is nil") + return + } switch collection := collectionValue.(type) { case *ListType: if index, ok := keyValue.(int64); ok { - err = assignListItem(collection, index, value) + err = collection.setItem(index, value) } else { err = keyListTerm.Errorf("integer expected, got %v [%s]", keyValue, typeName(keyValue)) } case *DictType: - collection.setItem(keyValue, value) + err = collection.setItem(keyValue, value) default: err = collectionTerm.Errorf("collection expected") } @@ -61,40 +60,6 @@ func assignValue(ctx ExprContext, leftTerm *term, v any) (err error) { return } -func _assignValue(ctx ExprContext, leftTerm *term, v any) (err error) { - if leftTerm.symbol() == SymIndex { - var collection, indexListAny any - var list *ListType - var index int64 - if collection, err = leftTerm.children[0].compute(ctx); err != nil { - return - } else if IsList(collection) { - list, _ = collection.(*ListType) - } else { - err = leftTerm.children[0].Errorf("expected collection") - return - } - - if indexListAny, err = leftTerm.children[1].compute(ctx); err != nil { - return - } else if indexList, ok := indexListAny.(*ListType); ok && len(*indexList) == 1 { - if indexAny := (*indexList)[0]; IsInteger(indexAny) { - index, _ = indexAny.(int64) - } else { - err = leftTerm.children[1].Errorf("expected integer, got %v [%T]", indexAny, indexAny) - } - } else { - err = leftTerm.children[1].Errorf("expected index spec, got %v [%T]", indexListAny, indexListAny) - return - } - list.setItem(index, v) - } else { - ctx.UnsafeSetVar(leftTerm.source(), v) - } - return -} - -/* func evalAssign(ctx ExprContext, self *term) (v any, err error) { if err = self.checkOperands(); err != nil { return @@ -103,43 +68,7 @@ func evalAssign(ctx ExprContext, self *term) (v any, err error) { leftTerm := self.children[0] leftSym := leftTerm.symbol() if leftSym != SymVariable && leftSym != SymIndex { - err = leftTerm.tk.Errorf("left operand of %q must be a variable", self.tk.source) - return - } - - rightChild := self.children[1] - - if v, err = rightChild.compute(ctx); err == nil { - if functor, ok := v.(Functor); ok { - funcName := rightChild.source() - if info, exists, _ := GetFuncInfo(ctx, funcName); exists { - // ctx.RegisterFuncInfo(info) - ctx.RegisterFunc(leftTerm.source(), info.Functor(), info.ReturnType(), info.Params()) - } else if funcDef, ok := functor.(*exprFunctor); ok { - // paramSpecs := ForAll(funcDef.params, newFuncParam) - paramSpecs := ForAll(funcDef.params, func(p ExprFuncParam) ExprFuncParam { return p }) - - ctx.RegisterFunc(leftTerm.source(), functor, typeAny, paramSpecs) - } else { - err = self.Errorf("unknown function %s()", funcName) - } - } else { - ctx.UnsafeSetVar(leftTerm.source(), v) - } - } - return -} -*/ - -func evalAssign(ctx ExprContext, self *term) (v any, err error) { - if err = self.checkOperands(); err != nil { - return - } - - leftTerm := self.children[0] - leftSym := leftTerm.symbol() - if leftSym != SymVariable && leftSym != SymIndex { - err = leftTerm.tk.Errorf("left operand of %q must be a variable", self.tk.source) + err = leftTerm.tk.Errorf("left operand of %q must be a variable or a collection's item", self.tk.source) return } @@ -150,32 +79,18 @@ func evalAssign(ctx ExprContext, self *term) (v any, err error) { if info := functor.GetFunc(); info != nil { ctx.RegisterFunc(leftTerm.source(), info.Functor(), info.ReturnType(), info.Params()) } else if funcDef, ok := functor.(*exprFunctor); ok { - // paramSpecs := ForAll(funcDef.params, newFuncParam) paramSpecs := ForAll(funcDef.params, func(p ExprFuncParam) ExprFuncParam { return p }) ctx.RegisterFunc(leftTerm.source(), functor, typeAny, paramSpecs) - /* - } - funcName := rightChild.source() - if info, exists, _ := GetFuncInfo(ctx, funcName); exists { - // ctx.RegisterFuncInfo(info) - ctx.RegisterFunc(leftTerm.source(), info.Functor(), info.ReturnType(), info.Params()) - } else if funcDef, ok := functor.(*exprFunctor); ok { - // paramSpecs := ForAll(funcDef.params, newFuncParam) - paramSpecs := ForAll(funcDef.params, func(p ExprFuncParam) ExprFuncParam { return p }) - - ctx.RegisterFunc(leftTerm.source(), functor, typeAny, paramSpecs) - */ } else { err = self.Errorf("unknown function %s()", rightChild.source()) } } else { err = assignValue(ctx, leftTerm, v) - //ctx.UnsafeSetVar(leftTerm.source(), v) } } if err != nil { - v=nil + v = nil } return } diff --git a/simple-store.go b/simple-store.go index 7ad1e18..3cdef8b 100644 --- a/simple-store.go +++ b/simple-store.go @@ -173,7 +173,6 @@ func (ctx *SimpleStore) EnumFuncs(acceptor func(name string) (accept bool)) (fun func (ctx *SimpleStore) Call(name string, args []any) (result any, err error) { if info, exists := GetLocalFuncInfo(ctx, name); exists { - // if info, exists := ctx.funcStore[name]; exists { functor := info.Functor() result, err = functor.Invoke(ctx, name, args) } else {