-
Notifications
You must be signed in to change notification settings - Fork 6
/
fallback.go
51 lines (44 loc) · 954 Bytes
/
fallback.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
package mm
const FallbackDef = `
package xxx
import "github.com/egonelbre/exp/mm"
type Fallback struct {
Primary {{ .Primary.Type }}
Fallback {{ .Fallback.Type }}
}
func (m *Fallback) Alignment() int {
return {{ min .Primary.Alignment .Fallback.Alignment }}
}
func (m *Fallback) Alloc(size int) unsafe.Pointer {
if size == 0 {
return nil
}
p := m.Primary.Allocate(size)
if p == nil {
p = m.Fallback.Allocate(size)
}
return p
}
{{ if and .Primary.Owns (or .Primary.Dealloc .Fallback.Dealloc) }}
func (m *Fallback) Dealloc(p unsafe.Pointer) {
if m.Primary.Owns(p) {
{{ if .Primary.Dealloc }}
return m.Primary.Dealloc(p)
{{ else }}
return false
{{ end }}
} else {
{{ if .Fallback.Dealloc }}
return m.Fallback.Dealloc(p)
{{ else }}
return false
{{ end }}
}
}
{{ end }}
{{ if and .Primary.Empty .Fallback.Empty }}
func (m *Fallback) Empty() bool {
return m.Primary.Empty() && m.Fallback.Empty()
}
{{ end }}
`