-
Notifications
You must be signed in to change notification settings - Fork 3
/
for.go
52 lines (41 loc) · 911 Bytes
/
for.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package stmt
import (
"github.com/viant/velty/est"
"github.com/viant/velty/est/op"
"unsafe"
)
type For struct {
Block est.Compute
Init est.Compute
Condition *op.Operand
Post est.Compute
}
func (f *For) compute(state *est.State) unsafe.Pointer {
var ptr unsafe.Pointer
f.Init(state)
for *(*bool)(f.Condition.Exec(state)) {
ptr = f.Block(state)
f.Post(state)
}
return ptr
}
func ForLoop(init, post est.New, condition *op.Expression, block est.Compute) (est.New, error) {
return func(control est.Control) (est.Compute, error) {
forLoop := &For{}
var err error
forLoop.Condition, err = condition.Operand(control)
if err != nil {
return nil, err
}
forLoop.Init, err = init(control)
if err != nil {
return nil, err
}
forLoop.Post, err = post(control)
if err != nil {
return nil, err
}
forLoop.Block = block
return forLoop.compute, nil
}, nil
}