index.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package rules
  2. import (
  3. "fmt"
  4. "fw/cp/node"
  5. "fw/rt2"
  6. "fw/rt2/context"
  7. "fw/rt2/frame"
  8. "fw/rt2/scope"
  9. "reflect"
  10. )
  11. func indexSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
  12. i := rt2.NodeOf(f)
  13. switch i.Right().(type) {
  14. case node.ConstantNode:
  15. seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
  16. sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
  17. rt2.ValueOf(f.Parent())[i.Adr()] = sc.Provide(i.Right())(nil)
  18. return frame.End()
  19. }
  20. ret = frame.NOW
  21. case node.VariableNode:
  22. seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
  23. sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
  24. rt2.ValueOf(f.Parent())[i.Adr()] = sc.Select(i.Right().Object().Adr())
  25. return frame.End()
  26. }
  27. ret = frame.NOW
  28. case node.OperationNode, node.CallNode:
  29. rt2.Push(rt2.New(i.Right()), f)
  30. rt2.Assert(f, func(f frame.Frame) (bool, int) {
  31. return rt2.ValueOf(f)[i.Right().Adr()] != nil, 60
  32. })
  33. seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
  34. rt2.ValueOf(f.Parent())[i.Adr()] = rt2.ValueOf(f)[i.Right().Adr()]
  35. return frame.End()
  36. }
  37. ret = frame.LATER
  38. default:
  39. panic(fmt.Sprintln("unsupported type", reflect.TypeOf(i.Right())))
  40. }
  41. return seq, ret
  42. }