github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/code_quality/function.go.expected (about)

     1  //
     2  //	Package - transpiled by c4go
     3  //
     4  //	If you have found any issues, please raise an issue at:
     5  //	https://github.com/Konstantin8105/c4go/
     6  //
     7  
     8  package code_quality
     9  
    10  import "reflect"
    11  import "runtime"
    12  import "unsafe"
    13  
    14  // sstr_s - transpiled function from  C4GO/tests/code_quality/function.c:1
    15  var sstr_s []byte
    16  
    17  // sstr_bufs - transpiled function from  C4GO/tests/code_quality/function.c:2
    18  var sstr_bufs []byte = make([]byte, 10)
    19  
    20  // sstr_n - transpiled function from  C4GO/tests/code_quality/function.c:3
    21  var sstr_n int32
    22  
    23  // sstr_pop - transpiled function from  C4GO/tests/code_quality/function.c:5
    24  func sstr_pop() []byte {
    25  	var ret []byte = sstr_s
    26  	sstr_s = sstr_bufs[func() int32 {
    27  		sstr_n--
    28  		return sstr_n
    29  	}():]
    30  	return ret
    31  }
    32  
    33  // sstr_next - transpiled function from  C4GO/tests/code_quality/function.c:12
    34  func sstr_next() int32 {
    35  	if int32(sstr_s[0]) != 0 {
    36  		return int32(uint8((func() []byte {
    37  			defer func() {
    38  				sstr_s = sstr_s[0+1:]
    39  			}()
    40  			return sstr_s
    41  		}())[0]))
    42  	}
    43  	return -1
    44  }
    45  
    46  // sstr_back - transpiled function from  C4GO/tests/code_quality/function.c:17
    47  func sstr_back(c int32) {
    48  	sstr_s = c4goPointerArithByteSlice(sstr_s, int(-1))
    49  }
    50  
    51  // sf1 - transpiled function from  C4GO/tests/code_quality/function.c:22
    52  func sf1() int32 {
    53  	sstr_n++
    54  	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
    55  		return 1
    56  	}
    57  	return 0
    58  }
    59  
    60  // st2 - transpiled function from  C4GO/tests/code_quality/function.c:27
    61  func st2() int32 {
    62  	sstr_n++
    63  	var s int32 = func() int32 {
    64  		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
    65  			return 1
    66  		}
    67  		return 0
    68  	}()
    69  	sstr_n--
    70  	return s
    71  }
    72  
    73  // st2a - transpiled function from  C4GO/tests/code_quality/function.c:34
    74  func st2a() int32 {
    75  	sstr_n++
    76  	var s int32
    77  	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
    78  		s = 1
    79  	} else {
    80  		s = 0
    81  	}
    82  	sstr_n--
    83  	return s
    84  }
    85  
    86  // st3 - transpiled function from  C4GO/tests/code_quality/function.c:42
    87  func st3() int32 {
    88  	sstr_n++
    89  	var s int32 = func() int32 {
    90  		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
    91  			return sstr_n + 1
    92  		}
    93  		return sstr_n - 1
    94  	}()
    95  	sstr_n--
    96  	return s
    97  }
    98  
    99  // st4 - transpiled function from  C4GO/tests/code_quality/function.c:49
   100  func st4() int32 {
   101  	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
   102  		return sstr_n + 1
   103  	}
   104  	return sstr_n - 1
   105  }
   106  
   107  // c4goPointerArithByteSlice - function of pointer arithmetic. generated by c4go
   108  func c4goPointerArithByteSlice(slice []byte, position int) []byte {
   109  	if position < 0 {
   110  		// invert sign
   111  		position = -position
   112  
   113  		// Example from: go101.org/article/unsafe.html
   114  		// repair size of slice
   115  		var hdr reflect.SliceHeader
   116  		sliceLen := len(slice)
   117  		hdr.Data = uintptr(unsafe.Pointer(&slice[0])) - (uintptr(position))*unsafe.Sizeof(slice[0])
   118  		runtime.KeepAlive(&slice[0]) // needed!
   119  		hdr.Len = sliceLen + int(position)
   120  		hdr.Cap = hdr.Len
   121  		slice = *((*[]byte)(unsafe.Pointer(&hdr)))
   122  		return slice
   123  	}
   124  	// position >= 0:
   125  	return slice[position:]
   126  }