Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Nov 29, 2024
1 parent d8589b0 commit 3e49f3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/op_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3e49f3e

Please sign in to comment.