From 3e49f3ea031bfe597dbda4418bb6c6b98e6e724b Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Fri, 29 Nov 2024 13:27:21 +0100 Subject: [PATCH] save --- gnovm/pkg/gnolang/machine.go | 15 +++++++++++++++ gnovm/pkg/gnolang/op_eval.go | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 4f4c7c188f3..3ca7bd3cad9 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -761,6 +761,21 @@ func (m *Machine) EvalStatic(last BlockNode, x Expr) TypedValue { return res[0] } +func (m *Machine) emitCallArg(call *CallExpr, x Expr, staticType Type) { + // these functions are the only onces in the language were they could be + // called from a const context + var builtins = []string{"len", "cap", "real", "imag", "complex"} + dv := defaultTypedValue(m.Alloc, staticType) + + if slices.Contains(builtins, string(call.Func.(*ConstExpr).Source.(*NameExpr).Name)) { + m.PushExpr(&ConstExpr{TypedValue: dv}) + } else { + m.PushExpr(x) + } + + m.PushOp(OpEval) +} + // Evaluate the type of any preprocessed expression statically. // This is primiarily used by the preprocessor to evaluate // static types of nodes. diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 1beba1d6e3f..82deba8f0db 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -246,8 +246,8 @@ func (m *Machine) doOpEval() { // Eval args. args := x.Args for i := len(args) - 1; 0 <= i; i-- { - m.PushExpr(args[i]) - m.PushOp(OpEval) + t := m.EvalStaticTypeOf(m.LastBlock().GetSource(m.Store), args[i]) + m.emitCallArg(x, args[i], t) } // evaluate func m.PushExpr(x.Func)