mirror of
https://github.com/MontFerret/ferret.git
synced 2025-08-15 20:02:56 +02:00
Refactor loop compilation; update initialization logic for zero/one registers and adjust range iteration handling, restructure range iterator tests, and align imports for consistency
This commit is contained in:
@@ -74,15 +74,15 @@ func (cc *LoopCollectCompiler) compileGlobalAggregation(c fql.ICollectAggregator
|
|||||||
cc.ctx.Symbols.ExitScope()
|
cc.ctx.Symbols.ExitScope()
|
||||||
|
|
||||||
// Now we can iterate over the grouped items
|
// Now we can iterate over the grouped items
|
||||||
zero := loadConstant(cc.ctx, runtime.Int(0))
|
zero := cc.ctx.Registers.Allocate(core.Temp)
|
||||||
one := loadConstant(cc.ctx, runtime.Int(1))
|
cc.ctx.Emitter.EmitA(vm.OpLoadZero, zero)
|
||||||
// We move the aggregator to a temporary register to access it later from the new loop
|
// We move the aggregator to a temporary register to access it later from the new loop
|
||||||
aggregator := cc.ctx.Registers.Allocate(core.Temp)
|
aggregator := cc.ctx.Registers.Allocate(core.Temp)
|
||||||
cc.ctx.Emitter.EmitAB(vm.OpMove, aggregator, parentLoop.Dst)
|
cc.ctx.Emitter.EmitAB(vm.OpMove, aggregator, parentLoop.Dst)
|
||||||
|
|
||||||
// CreateFor new loop with 1 iteration only
|
// CreateFor new loop with 1 iteration only
|
||||||
cc.ctx.Symbols.EnterScope()
|
cc.ctx.Symbols.EnterScope()
|
||||||
cc.ctx.Emitter.EmitABC(vm.OpRange, parentLoop.Src, zero, one)
|
cc.ctx.Emitter.EmitABC(vm.OpRange, parentLoop.Src, zero, zero)
|
||||||
loop := cc.ctx.Loops.CreateFor(core.TemporalLoop, parentLoop.Src, parentLoop.Distinct)
|
loop := cc.ctx.Loops.CreateFor(core.TemporalLoop, parentLoop.Src, parentLoop.Distinct)
|
||||||
loop.Dst = parentLoop.Dst
|
loop.Dst = parentLoop.Dst
|
||||||
loop.Allocate = true
|
loop.Allocate = true
|
||||||
|
@@ -2,6 +2,7 @@ package internal_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/MontFerret/ferret/pkg/vm/internal"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/MontFerret/ferret/pkg/runtime"
|
"github.com/MontFerret/ferret/pkg/runtime"
|
||||||
@@ -12,8 +13,8 @@ import (
|
|||||||
func TestRangeIterator(t *testing.T) {
|
func TestRangeIterator(t *testing.T) {
|
||||||
Convey("Zero value", t, func() {
|
Convey("Zero value", t, func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(0, 0)
|
r := internal.NewRange(0, 0)
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
hasNext, err := iter.HasNext(ctx)
|
hasNext, err := iter.HasNext(ctx)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@@ -32,8 +33,8 @@ func TestRangeIterator(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Two values", t, func() {
|
Convey("Two values", t, func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(0, 1)
|
r := internal.NewRange(0, 1)
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
hasNext, err := iter.HasNext(ctx)
|
hasNext, err := iter.HasNext(ctx)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@@ -58,8 +59,8 @@ func TestRangeIterator(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Two values (2)", t, func() {
|
Convey("Two values (2)", t, func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(1, 2)
|
r := internal.NewRange(1, 2)
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
hasNext, err := iter.HasNext(ctx)
|
hasNext, err := iter.HasNext(ctx)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@@ -84,8 +85,8 @@ func TestRangeIterator(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Multiple ascending values", t, func() {
|
Convey("Multiple ascending values", t, func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(0, 10)
|
r := internal.NewRange(0, 10)
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
actual := make([]runtime.Int, 0, 10)
|
actual := make([]runtime.Int, 0, 10)
|
||||||
|
|
||||||
@@ -104,8 +105,8 @@ func TestRangeIterator(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Multiple descending values", t, func() {
|
Convey("Multiple descending values", t, func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(10, 0)
|
r := internal.NewRange(10, 0)
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
actual := make([]runtime.Int, 0, 10)
|
actual := make([]runtime.Int, 0, 10)
|
||||||
|
|
||||||
@@ -126,8 +127,8 @@ func TestRangeIterator(t *testing.T) {
|
|||||||
func BenchmarkRangeIterator(b *testing.B) {
|
func BenchmarkRangeIterator(b *testing.B) {
|
||||||
size := 100
|
size := 100
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := NewRange(0, int64(size))
|
r := internal.NewRange(0, int64(size))
|
||||||
iter := NewRangeIterator(r)
|
iter := internal.NewRangeIterator(r)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user