Skip to content

Commit 1844609

Browse files
authored
Merge pull request #116 from cosmos72/stable
update vendored gomacro - merge 'stable' branch
2 parents c702f1b + 2ad243b commit 1844609

File tree

538 files changed

+81371
-44497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

538 files changed

+81371
-44497
lines changed

kernel.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
424424
// Check if the last node is an expression. If the last node is not an expression then nothing
425425
// is returned as a value. For example evaluating a function declaration shouldn't return a value but
426426
// just have the side effect of declaring the function.
427+
//
428+
// This is actually needed only for gomacro classic interpreter
429+
// (the fast interpreter already returns values only for expressions)
430+
// but retained for compatibility.
427431
var srcEndsWithExpr bool
428432
if len(nodes) > 0 {
429433
_, srcEndsWithExpr = nodes[len(nodes)-1].(ast.Expr)
@@ -433,34 +437,26 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
433437
compiledSrc := ir.CompileAst(srcAst)
434438

435439
// Evaluate the code.
436-
result, results := ir.RunExpr(compiledSrc)
440+
results, _ := ir.RunExpr(compiledSrc)
437441

438442
// If the source ends with an expression, then the result of the execution is the value of the expression. In the
439443
// event that all return values are nil, the result is also nil.
440444
if srcEndsWithExpr {
441-
// `len(results) == 0` implies a single result stored in `result`.
442-
if len(results) == 0 {
443-
if val := base.ValueInterface(result); val != nil {
444-
return []interface{}{val}, nil
445-
}
446-
return nil, nil
447-
}
448445

449446
// Count the number of non-nil values in the output. If they are all nil then the output is skipped.
450447
nonNilCount := 0
451-
var values []interface{}
452-
for _, result := range results {
448+
values := make([]interface{}, len(results))
449+
for i, result := range results {
453450
val := base.ValueInterface(result)
454451
if val != nil {
455452
nonNilCount++
456453
}
457-
values = append(values, val)
454+
values[i] = val
458455
}
459456

460457
if nonNilCount > 0 {
461458
return values, nil
462459
}
463-
return nil, nil
464460
}
465461

466462
return nil, nil

vendor/github.com/cosmos72/gomacro/.gitignore

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)