github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/basic.go (about)

     1  package main
     2  
     3  // Basic tests that don't need to be split into a separate file.
     4  
     5  func addInt(x, y int) int {
     6  	return x + y
     7  }
     8  
     9  func equalInt(x, y int) bool {
    10  	return x == y
    11  }
    12  
    13  func divInt(x, y int) int {
    14  	return x / y
    15  }
    16  
    17  func divUint(x, y uint) uint {
    18  	return x / y
    19  }
    20  
    21  func remInt(x, y int) int {
    22  	return x % y
    23  }
    24  
    25  func remUint(x, y uint) uint {
    26  	return x % y
    27  }
    28  
    29  func floatEQ(x, y float32) bool {
    30  	return x == y
    31  }
    32  
    33  func floatNE(x, y float32) bool {
    34  	return x != y
    35  }
    36  
    37  func floatLower(x, y float32) bool {
    38  	return x < y
    39  }
    40  
    41  func floatLowerEqual(x, y float32) bool {
    42  	return x <= y
    43  }
    44  
    45  func floatGreater(x, y float32) bool {
    46  	return x > y
    47  }
    48  
    49  func floatGreaterEqual(x, y float32) bool {
    50  	return x >= y
    51  }
    52  
    53  func complexReal(x complex64) float32 {
    54  	return real(x)
    55  }
    56  
    57  func complexImag(x complex64) float32 {
    58  	return imag(x)
    59  }
    60  
    61  func complexAdd(x, y complex64) complex64 {
    62  	return x + y
    63  }
    64  
    65  func complexSub(x, y complex64) complex64 {
    66  	return x - y
    67  }
    68  
    69  func complexMul(x, y complex64) complex64 {
    70  	return x * y
    71  }
    72  
    73  // TODO: complexDiv (requires runtime call)
    74  
    75  // A type 'kv' also exists in function foo. Test that these two types don't
    76  // conflict with each other.
    77  type kv struct {
    78  	v       float32
    79  	x, y, z int
    80  }
    81  
    82  var kvGlobal kv
    83  
    84  func foo() {
    85  	// Define a new 'kv' type.
    86  	type kv struct {
    87  		v       byte
    88  		x, y, z int
    89  	}
    90  	// Use this type.
    91  	func(b kv) {}(kv{})
    92  }
    93  
    94  type T1 []T1
    95  type T2 [2]*T2
    96  
    97  var a T1
    98  var b T2