You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

var.go 907 B

6 months ago
6 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package ops
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/dag"
  4. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  5. )
  6. func init() {
  7. exec.UseOp[*ConstVar]()
  8. }
  9. type ConstVar struct {
  10. ID exec.VarID `json:"id"`
  11. Value exec.VarValue `json:"value"`
  12. }
  13. func (o *ConstVar) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  14. e.PutVar(o.ID, o.Value)
  15. return nil
  16. }
  17. func (o *ConstVar) String() string {
  18. return "ConstVar"
  19. }
  20. type ConstNode struct {
  21. dag.NodeBase
  22. Value exec.VarValue
  23. }
  24. func (b *GraphNodeBuilder) NewConst(val exec.VarValue) *ConstNode {
  25. node := &ConstNode{
  26. Value: val,
  27. }
  28. b.AddNode(node)
  29. node.OutputValues().Init(node, 1)
  30. return node
  31. }
  32. func (t *ConstNode) Output() dag.ValueOutputSlot {
  33. return dag.ValueOutputSlot{
  34. Node: t,
  35. Index: 0,
  36. }
  37. }
  38. func (t *ConstNode) GenerateOp() (exec.Op, error) {
  39. return &DropStream{
  40. Input: t.Output().Var().VarID,
  41. }, nil
  42. }