Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
support ./src/prng/*.c
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 19, 2022
1 parent 1fff43b commit a779c1d
Show file tree
Hide file tree
Showing 18 changed files with 475 additions and 112 deletions.
7 changes: 7 additions & 0 deletions c2go.a.pub
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ frexpl
fwrite
getenv
gid_t
initstate
ino_t
int16_t
int32_t
Expand Down Expand Up @@ -78,13 +79,19 @@ pthread_spinlock_t
pthread_t
ptrdiff_t
qsort
rand
rand_r
random
scalbn
scalbnf
scalbnl
setstate
sigset_t
size_t
snprintf
sprintf
srand
srandom
ssize_t
stderr
stdin
Expand Down
1 change: 1 addition & 0 deletions c2go.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
]
},
"dirs": [
"./src/prng",
"./src/ctype",
"./src/string"
],
Expand Down
7 changes: 7 additions & 0 deletions c2go.pub
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ __signbit
__signbitl
__FLOAT_BITS
__DOUBLE_BITS
initstate
setstate
srandom
srand
random
rand
rand_r
abort
feclearexcept
feraiseexcept
Expand Down
200 changes: 100 additions & 100 deletions c2go_header.i.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@ package libc

import unsafe "unsafe"

type uintptr_t = uint64
type Uintptr_t = uint64
type intptr_t = int64
type Intptr_t = int64
type int8_t = int8
type Int8_t = int8
type int16_t = int16
type Int16_t = int16
type int32_t = int32
type Int32_t = int32
type int64_t = int64
type Int64_t = int64
type intmax_t = int64
type Intmax_t = int64
type uint8_t = uint8
type Uint8_t = uint8
type uint16_t = uint16
type Uint16_t = uint16
type uint32_t = uint32
type Uint32_t = uint32
type uint64_t = uint64
type Uint64_t = uint64
type uintmax_t = uint64
type Uintmax_t = uint64
type int_fast8_t = int8
type int_fast64_t = int64
type int_least8_t = int8
type int_least16_t = int16
type int_least32_t = int32
type int_least64_t = int64
type uint_fast8_t = uint8
type uint_fast64_t = uint64
type uint_least8_t = uint8
type uint_least16_t = uint16
type uint_least32_t = uint32
type uint_least64_t = uint64
type int_fast16_t = int32
type int_fast32_t = int32
type uint_fast16_t = uint32
type uint_fast32_t = uint32
type size_t = uint64
type Size_t = uint64
type time_t = int64
Expand All @@ -22,71 +62,71 @@ type pthread_key_t = uint32
type Pthread_key_t = uint32
type pthread_spinlock_t = int32
type Pthread_spinlock_t = int32
type _cgoa_1___ctype_b_loc struct {
type _cgoa_1___rand48_step struct {
__attr uint32
}
type pthread_mutexattr_t = _cgoa_1___ctype_b_loc
type Pthread_mutexattr_t = _cgoa_1___ctype_b_loc
type _cgoa_2___ctype_b_loc struct {
type pthread_mutexattr_t = _cgoa_1___rand48_step
type Pthread_mutexattr_t = _cgoa_1___rand48_step
type _cgoa_2___rand48_step struct {
__attr uint32
}
type pthread_condattr_t = _cgoa_2___ctype_b_loc
type Pthread_condattr_t = _cgoa_2___ctype_b_loc
type _cgoa_3___ctype_b_loc struct {
type pthread_condattr_t = _cgoa_2___rand48_step
type Pthread_condattr_t = _cgoa_2___rand48_step
type _cgoa_3___rand48_step struct {
__attr uint32
}
type pthread_barrierattr_t = _cgoa_3___ctype_b_loc
type Pthread_barrierattr_t = _cgoa_3___ctype_b_loc
type _cgoa_4___ctype_b_loc struct {
type pthread_barrierattr_t = _cgoa_3___rand48_step
type Pthread_barrierattr_t = _cgoa_3___rand48_step
type _cgoa_4___rand48_step struct {
__attr [2]uint32
}
type pthread_rwlockattr_t = _cgoa_4___ctype_b_loc
type Pthread_rwlockattr_t = _cgoa_4___ctype_b_loc
type pthread_rwlockattr_t = _cgoa_4___rand48_step
type Pthread_rwlockattr_t = _cgoa_4___rand48_step
type struct___sigset_t struct {
__bits [16]uint64
}
type sigset_t = struct___sigset_t
type Sigset_t = struct___sigset_t
type _cgoa_6___ctype_b_loc struct {
type _cgoa_6___rand48_step struct {
__i [14]int32
}
type _cgoa_5___ctype_b_loc struct {
__u _cgoa_6___ctype_b_loc
type _cgoa_5___rand48_step struct {
__u _cgoa_6___rand48_step
}
type pthread_attr_t = _cgoa_5___ctype_b_loc
type Pthread_attr_t = _cgoa_5___ctype_b_loc
type _cgoa_8___ctype_b_loc struct {
type pthread_attr_t = _cgoa_5___rand48_step
type Pthread_attr_t = _cgoa_5___rand48_step
type _cgoa_8___rand48_step struct {
__i [10]int32
}
type _cgoa_7___ctype_b_loc struct {
__u _cgoa_8___ctype_b_loc
type _cgoa_7___rand48_step struct {
__u _cgoa_8___rand48_step
}
type pthread_mutex_t = _cgoa_7___ctype_b_loc
type Pthread_mutex_t = _cgoa_7___ctype_b_loc
type _cgoa_10___ctype_b_loc struct {
type pthread_mutex_t = _cgoa_7___rand48_step
type Pthread_mutex_t = _cgoa_7___rand48_step
type _cgoa_10___rand48_step struct {
__i [12]int32
}
type _cgoa_9___ctype_b_loc struct {
__u _cgoa_10___ctype_b_loc
type _cgoa_9___rand48_step struct {
__u _cgoa_10___rand48_step
}
type pthread_cond_t = _cgoa_9___ctype_b_loc
type Pthread_cond_t = _cgoa_9___ctype_b_loc
type _cgoa_12___ctype_b_loc struct {
type pthread_cond_t = _cgoa_9___rand48_step
type Pthread_cond_t = _cgoa_9___rand48_step
type _cgoa_12___rand48_step struct {
__i [14]int32
}
type _cgoa_11___ctype_b_loc struct {
__u _cgoa_12___ctype_b_loc
type _cgoa_11___rand48_step struct {
__u _cgoa_12___rand48_step
}
type pthread_rwlock_t = _cgoa_11___ctype_b_loc
type Pthread_rwlock_t = _cgoa_11___ctype_b_loc
type _cgoa_14___ctype_b_loc struct {
type pthread_rwlock_t = _cgoa_11___rand48_step
type Pthread_rwlock_t = _cgoa_11___rand48_step
type _cgoa_14___rand48_step struct {
__i [8]int32
}
type _cgoa_13___ctype_b_loc struct {
__u _cgoa_14___ctype_b_loc
type _cgoa_13___rand48_step struct {
__u _cgoa_14___rand48_step
}
type pthread_barrier_t = _cgoa_13___ctype_b_loc
type Pthread_barrier_t = _cgoa_13___ctype_b_loc
type pthread_barrier_t = _cgoa_13___rand48_step
type Pthread_barrier_t = _cgoa_13___rand48_step
type pid_t = int32
type Pid_t = int32
type struct_sched_param struct {
Expand Down Expand Up @@ -129,40 +169,39 @@ type struct___pthread struct {
sys_r1 int64
locale *struct___locale_struct
}
type uint16_t = uint16
type Uint16_t = uint16
type uint32_t = uint32
type Uint32_t = uint32
type uint64_t = uint64
type Uint64_t = uint64

func __bswap16(__x uint16) uint16 {
return uint16(int32(__x)<<int32(8) | int32(__x)>>int32(8))
}
func __bswap32(__x uint32) uint32 {
return __x>>int32(24) | __x>>int32(8)&uint32(65280) | __x<<int32(8)&uint32(16711680) | __x<<int32(24)
}
func __bswap64(__x uint64) uint64 {
return (uint64(__bswap32(uint32(__x)))+uint64(0))<<int32(32) | uint64(__bswap32(uint32(__x>>int32(32))))
}

type wchar_t = uint32
type Wchar_t = uint32
type _cgoa_15___ctype_get_mb_cur_max struct {
type _cgoa_15_drand48 struct {
quot int32
rem int32
}
type div_t = _cgoa_15___ctype_get_mb_cur_max
type _cgoa_16___ctype_get_mb_cur_max struct {
type div_t = _cgoa_15_drand48
type _cgoa_16_drand48 struct {
quot int64
rem int64
}
type ldiv_t = _cgoa_16___ctype_get_mb_cur_max
type _cgoa_17___ctype_get_mb_cur_max struct {
type ldiv_t = _cgoa_16_drand48
type _cgoa_17_drand48 struct {
quot int64
rem int64
}
type lldiv_t = _cgoa_17___ctype_get_mb_cur_max
type lldiv_t = _cgoa_17_drand48
type _cgoa_18_drand48 struct {
quot int64
rem int64
}
type imaxdiv_t = _cgoa_18_drand48

func __bswap16(__x uint16) uint16 {
return uint16(int32(__x)<<int32(8) | int32(__x)>>int32(8))
}
func __bswap32(__x uint32) uint32 {
return __x>>int32(24) | __x>>int32(8)&uint32(65280) | __x<<int32(8)&uint32(16711680) | __x<<int32(24)
}
func __bswap64(__x uint64) uint64 {
return (uint64(__bswap32(uint32(__x)))+uint64(0))<<int32(32) | uint64(__bswap32(uint32(__x>>int32(32))))
}

type struct_lconv struct {
decimal_point *int8
thousands_sep *int8
Expand Down Expand Up @@ -235,40 +274,6 @@ type struct___locale_map struct {
name [24]int8
next *struct___locale_map
}
type uintptr_t = uint64
type Uintptr_t = uint64
type intptr_t = int64
type Intptr_t = int64
type int8_t = int8
type Int8_t = int8
type int16_t = int16
type Int16_t = int16
type int32_t = int32
type Int32_t = int32
type int64_t = int64
type Int64_t = int64
type intmax_t = int64
type Intmax_t = int64
type uint8_t = uint8
type Uint8_t = uint8
type uintmax_t = uint64
type Uintmax_t = uint64
type int_fast8_t = int8
type int_fast64_t = int64
type int_least8_t = int8
type int_least16_t = int16
type int_least32_t = int32
type int_least64_t = int64
type uint_fast8_t = uint8
type uint_fast64_t = uint64
type uint_least8_t = uint8
type uint_least16_t = uint16
type uint_least32_t = uint32
type uint_least64_t = uint64
type int_fast16_t = int32
type int_fast32_t = int32
type uint_fast16_t = uint32
type uint_fast32_t = uint32

func __isspace(_c int32) int32 {
return func() int32 {
Expand Down Expand Up @@ -432,7 +437,7 @@ type struct_sigaction struct {
}
type _cgoa_30_strsignal struct {
sigev_notify_function func(union_sigval)
sigev_notify_attributes *_cgoa_5___ctype_b_loc
sigev_notify_attributes *_cgoa_5___rand48_step
}
type _cgoa_29_strsignal struct {
__pad [48]int8
Expand Down Expand Up @@ -2037,8 +2042,3 @@ type struct_winsize struct {
ws_xpixel uint16
ws_ypixel uint16
}
type _cgoa_19_vfprintf struct {
quot int64
rem int64
}
type imaxdiv_t = _cgoa_19_vfprintf
15 changes: 15 additions & 0 deletions drand48.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package libc

import unsafe "unsafe"

func erand48(s *uint16) float64 {
type _cgoa_19_drand48 struct {
u uint64
}
var x _cgoa_19_drand48
x.u = uint64(4607182418800017408) | __rand48_step(s, (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))))+uintptr(int32(3))*2)))<<int32(4)
return *(*float64)(unsafe.Pointer(&x)) - 1
}
func drand48() float64 {
return erand48((*uint16)(unsafe.Pointer(&__seed48)))
}
7 changes: 7 additions & 0 deletions lcong48.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package libc

import unsafe "unsafe"

func lcong48(p *uint16) {
Memcpy(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))), unsafe.Pointer(p), 14)
}
10 changes: 10 additions & 0 deletions lrand48.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package libc

import unsafe "unsafe"

func nrand48(s *uint16) int64 {
return int64(__rand48_step(s, (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))))+uintptr(int32(3))*2))) >> int32(17))
}
func lrand48() int64 {
return nrand48((*uint16)(unsafe.Pointer(&__seed48)))
}
10 changes: 10 additions & 0 deletions mrand48.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package libc

import unsafe "unsafe"

func jrand48(s *uint16) int64 {
return int64(int32(__rand48_step(s, (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))))+uintptr(int32(3))*2))) >> int32(16)))
}
func mrand48() int64 {
return jrand48((*uint16)(unsafe.Pointer(&__seed48)))
}
11 changes: 11 additions & 0 deletions rand.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package libc

var seed_cgo18_rand uint64

func Srand(s uint32) {
seed_cgo18_rand = uint64(s - uint32(1))
}
func Rand() int32 {
seed_cgo18_rand = uint64(6364136223846793005)*seed_cgo18_rand + uint64(1)
return int32(seed_cgo18_rand >> int32(33))
}
Loading

0 comments on commit a779c1d

Please sign in to comment.