github.com/urso/go-structform@v0.0.2/gotype/stacks.yml (about)

     1  data.stacks:
     2  - name: unfolderStack
     3    type: unfolder
     4  - name: reflectValueStack
     5    type: reflect.Value
     6  - name: ptrStack
     7    init: 'nil'
     8    type: unsafe.Pointer
     9  - name: keyStack
    10    type: string
    11    init: '""'
    12  - name: idxStack
    13    type: int
    14    init: -1
    15  - name: structformTypeStack
    16    type: structform.BaseType
    17    init: structform.AnyType
    18  
    19  main: |
    20    package gotype
    21  
    22    {{ range .stacks }}
    23    type {{ .name }} struct {
    24      current {{ .type  }}
    25      stack []{{ .type }}
    26      stack0 [{{ if .size0 }}{{ .size0 }}{{ else }}32{{ end }}]{{ .type }}
    27    }
    28    {{ end }}
    29    
    30    {{ range .stacks }}
    31    func (s *{{ .name }}) init({{ if isnil .init }}v {{ .type }}{{end}}) {
    32      s.current = {{ if isnil .init }}v{{ else }}{{ .init }}{{end}}
    33      s.stack = s.stack0[:0]
    34    }
    35    
    36    func (s *{{ .name }}) push(v {{ .type }}) {
    37      s.stack = append(s.stack, s.current)
    38      s.current = v
    39    }
    40    
    41    func (s *{{ .name }}) pop() {{ .type }} {
    42      old := s.current
    43      last := len(s.stack) - 1
    44      s.current = s.stack[last]
    45      s.stack = s.stack[:last]
    46      return old
    47    }
    48    {{ end }}