examples/components: a few more cases
This commit is contained in:
@@ -9,6 +9,26 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
Package("github.com/mmcloughlin/avo/examples/components")
|
Package("github.com/mmcloughlin/avo/examples/components")
|
||||||
|
|
||||||
|
TEXT("StringLen", "func(s string) int")
|
||||||
|
strlen := Load(Param("s").Len(), GP64v())
|
||||||
|
Store(strlen, ReturnIndex(0))
|
||||||
|
RET()
|
||||||
|
|
||||||
|
TEXT("SliceLen", "func(s []int) int")
|
||||||
|
slicelen := Load(Param("s").Len(), GP64v())
|
||||||
|
Store(slicelen, ReturnIndex(0))
|
||||||
|
RET()
|
||||||
|
|
||||||
|
TEXT("SliceCap", "func(s []int) int")
|
||||||
|
slicecap := Load(Param("s").Cap(), GP64v())
|
||||||
|
Store(slicecap, ReturnIndex(0))
|
||||||
|
RET()
|
||||||
|
|
||||||
|
TEXT("ArrayThree", "func(a [7]uint64) uint64")
|
||||||
|
a3 := Load(Param("a").Index(3), GP64v())
|
||||||
|
Store(a3, ReturnIndex(0))
|
||||||
|
RET()
|
||||||
|
|
||||||
TEXT("FieldByte", "func(s Struct) byte")
|
TEXT("FieldByte", "func(s Struct) byte")
|
||||||
b := Load(Param("s").Field("Byte"), GP8v())
|
b := Load(Param("s").Field("Byte"), GP8v())
|
||||||
Store(b, ReturnIndex(0))
|
Store(b, ReturnIndex(0))
|
||||||
|
|||||||
@@ -2,6 +2,30 @@
|
|||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// func StringLen(s string) int
|
||||||
|
TEXT ·StringLen(SB),0,$0-24
|
||||||
|
MOVQ s_len+8(FP), AX
|
||||||
|
MOVQ AX, ret+16(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func SliceLen(s []int) int
|
||||||
|
TEXT ·SliceLen(SB),0,$0-32
|
||||||
|
MOVQ s_len+8(FP), AX
|
||||||
|
MOVQ AX, ret+24(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func SliceCap(s []int) int
|
||||||
|
TEXT ·SliceCap(SB),0,$0-32
|
||||||
|
MOVQ s_cap+16(FP), AX
|
||||||
|
MOVQ AX, ret+24(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func ArrayThree(a [7]uint64) uint64
|
||||||
|
TEXT ·ArrayThree(SB),0,$0-64
|
||||||
|
MOVQ a_3+24(FP), AX
|
||||||
|
MOVQ AX, ret+56(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
// func FieldByte(s Struct) byte
|
// func FieldByte(s Struct) byte
|
||||||
TEXT ·FieldByte(SB),0,$0-184
|
TEXT ·FieldByte(SB),0,$0-184
|
||||||
MOVB s_Byte(FP), AL
|
MOVB s_Byte(FP), AL
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ func TestFunctionsEqual(t *testing.T) {
|
|||||||
cases := []struct {
|
cases := []struct {
|
||||||
f, g interface{}
|
f, g interface{}
|
||||||
}{
|
}{
|
||||||
|
{StringLen, func(s string) int { return len(s) }},
|
||||||
|
{SliceLen, func(s []int) int { return len(s) }},
|
||||||
|
{SliceCap, func(s []int) int { return cap(s) }},
|
||||||
|
{ArrayThree, func(a [7]uint64) uint64 { return a[3] }},
|
||||||
{FieldByte, func(s Struct) byte { return s.Byte }},
|
{FieldByte, func(s Struct) byte { return s.Byte }},
|
||||||
{FieldInt8, func(s Struct) int8 { return s.Int8 }},
|
{FieldInt8, func(s Struct) int8 { return s.Int8 }},
|
||||||
{FieldUint16, func(s Struct) uint16 { return s.Uint16 }},
|
{FieldUint16, func(s Struct) uint16 { return s.Uint16 }},
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
package components
|
package components
|
||||||
|
|
||||||
|
func StringLen(s string) int
|
||||||
|
|
||||||
|
func SliceLen(s []int) int
|
||||||
|
|
||||||
|
func SliceCap(s []int) int
|
||||||
|
|
||||||
|
func ArrayThree(a [7]uint64) uint64
|
||||||
|
|
||||||
func FieldByte(s Struct) byte
|
func FieldByte(s Struct) byte
|
||||||
|
|
||||||
func FieldInt8(s Struct) int8
|
func FieldInt8(s Struct) int8
|
||||||
|
|||||||
Reference in New Issue
Block a user