[svn r5] Initial commit. Most things are very rough.

This commit is contained in:
Tomas Lindquist Olsen
2007-09-01 21:43:27 +02:00
parent 1c23dd2cdc
commit 34699bbb07
227 changed files with 84269 additions and 0 deletions

112
lphobos/std/c/fenv.d Normal file
View File

@@ -0,0 +1,112 @@
/**
* C's <fenv.h>
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCFenv
*/
module std.c.fenv;
extern (C):
/// Entire floating point environment
struct fenv_t
{
version (Windows)
{
ushort status;
ushort control;
ushort round;
ushort reserved[2];
}
else version (linux)
{
ushort __control_word;
ushort __unused1;
ushort __status_word;
ushort __unused2;
ushort __tags;
ushort __unused3;
uint __eip;
ushort __cs_selector;
ushort __opcode;
uint __data_offset;
ushort __data_selector;
ushort __unused5;
}
else
{
static assert(0);
}
}
alias int fexcept_t; /// Floating point status flags
/// The various floating point exceptions
enum
{
FE_INVALID = 1, ///
FE_DENORMAL = 2, ///
FE_DIVBYZERO = 4, ///
FE_OVERFLOW = 8, ///
FE_UNDERFLOW = 0x10, ///
FE_INEXACT = 0x20, ///
FE_ALL_EXCEPT = 0x3F, /// Mask of all the exceptions
}
/// Rounding modes
enum
{
FE_TONEAREST = 0, ///
FE_UPWARD = 0x800, ///
FE_DOWNWARD = 0x400, ///
FE_TOWARDZERO = 0xC00, ///
}
version (Windows)
{
extern fenv_t _FE_DFL_ENV;
/// Default floating point environment
fenv_t* FE_DFL_ENV = &_FE_DFL_ENV;
}
else version (linux)
{
/// Default floating point environment
fenv_t* FE_DFL_ENV = cast(fenv_t*)(-1);
}
else
{
static assert(0);
}
/// Floating point precision
enum
{
FE_FLTPREC = 0, ///
FE_DBLPREC = 0x200, ///
FE_LDBLPREC = 0x300, ///
}
int fetestexcept(int excepts); ///
int feraiseexcept(int excepts); ///
int feclearexcept(int excepts); ///
//int fegetexcept(fexcept_t *flagp,int excepts); ///
//int fesetexcept(fexcept_t *flagp,int excepts); ///
int fegetround(); ///
int fesetround(int round); ///
int fegetprec(); ///
int fesetprec(int prec); ///
int fegetenv(fenv_t *envp); ///
int fesetenv(fenv_t *envp); ///
//void feprocentry(fenv_t *envp); ///
//void feprocexit(const fenv_t *envp); ///
int fegetexceptflag(fexcept_t *flagp,int excepts); ///
int fesetexceptflag(fexcept_t *flagp,int excepts); ///
int feholdexcept(fenv_t *envp); ///
int feupdateenv(fenv_t *envp); ///

478
lphobos/std/c/linux/linux.d Normal file
View File

@@ -0,0 +1,478 @@
/* Written by Walter Bright, Christopher E. Miller, and many others.
* www.digitalmars.com
* Placed into public domain.
* Linux(R) is the registered trademark of Linus Torvalds in the U.S. and other
* countries.
*/
module std.c.linux.linux;
public import std.c.linux.linuxextern;
public import std.c.linux.pthread;
private import std.c.stdio;
alias int pid_t;
alias int off_t;
alias uint mode_t;
alias uint uid_t;
alias uint gid_t;
static if (size_t.sizeof == 4)
alias int ssize_t;
else
alias long ssize_t;
enum : int
{
SIGHUP = 1,
SIGINT = 2,
SIGQUIT = 3,
SIGILL = 4,
SIGTRAP = 5,
SIGABRT = 6,
SIGIOT = 6,
SIGBUS = 7,
SIGFPE = 8,
SIGKILL = 9,
SIGUSR1 = 10,
SIGSEGV = 11,
SIGUSR2 = 12,
SIGPIPE = 13,
SIGALRM = 14,
SIGTERM = 15,
SIGSTKFLT = 16,
SIGCHLD = 17,
SIGCONT = 18,
SIGSTOP = 19,
SIGTSTP = 20,
SIGTTIN = 21,
SIGTTOU = 22,
SIGURG = 23,
SIGXCPU = 24,
SIGXFSZ = 25,
SIGVTALRM = 26,
SIGPROF = 27,
SIGWINCH = 28,
SIGPOLL = 29,
SIGIO = 29,
SIGPWR = 30,
SIGSYS = 31,
SIGUNUSED = 31,
}
enum
{
O_RDONLY = 0,
O_WRONLY = 1,
O_RDWR = 2,
O_CREAT = 0100,
O_EXCL = 0200,
O_TRUNC = 01000,
O_APPEND = 02000,
}
struct struct_stat // distinguish it from the stat() function
{
ulong st_dev; /// device
ushort __pad1;
uint st_ino; /// file serial number
uint st_mode; /// file mode
uint st_nlink; /// link count
uint st_uid; /// user ID of file's owner
uint st_gid; /// user ID of group's owner
ulong st_rdev; /// if device then device number
ushort __pad2;
int st_size; /// file size in bytes
int st_blksize; /// optimal I/O block size
int st_blocks; /// number of allocated 512 byte blocks
int st_atime;
uint st_atimensec;
int st_mtime;
uint st_mtimensec;
int st_ctime;
uint st_ctimensec;
uint __unused4;
uint __unused5;
}
static assert(struct_stat.sizeof == 88);
enum : int
{
S_IFIFO = 0010000,
S_IFCHR = 0020000,
S_IFDIR = 0040000,
S_IFBLK = 0060000,
S_IFREG = 0100000,
S_IFLNK = 0120000,
S_IFSOCK = 0140000,
S_IFMT = 0170000,
S_IREAD = 0000400,
S_IWRITE = 0000200,
S_IEXEC = 0000100,
}
extern (C)
{
int access(char*, int);
int open(char*, int, ...);
int read(int, void*, int);
int write(int, void*, int);
int close(int);
int lseek(int, int, int);
int fstat(int, struct_stat*);
int lstat(char*, struct_stat*);
int stat(char*, struct_stat*);
int chdir(char*);
int mkdir(char*, int);
int rmdir(char*);
char* getcwd(char*, int);
int chmod(char*, mode_t);
int fork();
int dup(int);
int dup2(int, int);
int pipe(int[2]);
pid_t wait(int*);
int waitpid(pid_t, int*, int);
uint alarm(uint);
char* basename(char*);
//wint_t btowc(int);
int chown(char*, uid_t, gid_t);
int chroot(char*);
size_t confstr(int, char*, size_t);
int creat(char*, mode_t);
char* ctermid(char*);
int dirfd(DIR*);
char* dirname(char*);
int fattach(int, char*);
int fchmod(int, mode_t);
int fdatasync(int);
int ffs(int);
int fmtmsg(int, char*, int, char*, char*, char*);
int fpathconf(int, int);
int fseeko(FILE*, off_t, int);
off_t ftello(FILE*);
extern char** environ;
}
struct timeval
{
int tv_sec;
int tv_usec;
}
struct struct_timezone
{
int tz_minuteswest;
int tz_dstime;
}
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
int tm_gmtoff;
int tm_zone;
}
extern (C)
{
int gettimeofday(timeval*, struct_timezone*);
__time_t time(__time_t*);
char* asctime(tm*);
char* ctime(__time_t*);
tm* gmtime(__time_t*);
tm* localtime(__time_t*);
__time_t mktime(tm*);
char* asctime_r(tm* t, char* buf);
char* ctime_r(__time_t* timep, char* buf);
tm* gmtime_r(__time_t* timep, tm* result);
tm* localtime_r(__time_t* timep, tm* result);
}
/**************************************************************/
// Memory mapping from <sys/mman.h> and <bits/mman.h>
enum
{
PROT_NONE = 0,
PROT_READ = 1,
PROT_WRITE = 2,
PROT_EXEC = 4,
}
// Memory mapping sharing types
enum
{ MAP_SHARED = 1,
MAP_PRIVATE = 2,
MAP_TYPE = 0x0F,
MAP_FIXED = 0x10,
MAP_FILE = 0,
MAP_ANONYMOUS = 0x20,
MAP_ANON = 0x20,
MAP_GROWSDOWN = 0x100,
MAP_DENYWRITE = 0x800,
MAP_EXECUTABLE = 0x1000,
MAP_LOCKED = 0x2000,
MAP_NORESERVE = 0x4000,
MAP_POPULATE = 0x8000,
MAP_NONBLOCK = 0x10000,
}
// Values for msync()
enum
{ MS_ASYNC = 1,
MS_INVALIDATE = 2,
MS_SYNC = 4,
}
// Values for mlockall()
enum
{
MCL_CURRENT = 1,
MCL_FUTURE = 2,
}
// Values for mremap()
enum
{
MREMAP_MAYMOVE = 1,
}
// Values for madvise
enum
{ MADV_NORMAL = 0,
MADV_RANDOM = 1,
MADV_SEQUENTIAL = 2,
MADV_WILLNEED = 3,
MADV_DONTNEED = 4,
}
extern (C)
{
void* mmap(void*, size_t, int, int, int, off_t);
const void* MAP_FAILED = cast(void*)-1;
int munmap(void*, size_t);
int mprotect(void*, size_t, int);
int msync(void*, size_t, int);
int madvise(void*, size_t, int);
int mlock(void*, size_t);
int munlock(void*, size_t);
int mlockall(int);
int munlockall();
void* mremap(void*, size_t, size_t, int);
int mincore(void*, size_t, ubyte*);
int remap_file_pages(void*, size_t, int, size_t, int);
int shm_open(char*, int, int);
int shm_unlink(char*);
}
extern(C)
{
enum
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14,
}
struct dirent
{
int d_ino;
off_t d_off;
ushort d_reclen;
ubyte d_type;
char[256] d_name;
}
struct DIR
{
// Managed by OS.
}
DIR* opendir(char* name);
int closedir(DIR* dir);
dirent* readdir(DIR* dir);
void rewinddir(DIR* dir);
off_t telldir(DIR* dir);
void seekdir(DIR* dir, off_t offset);
}
extern(C)
{
private import std.intrinsic;
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, timeval* timeout);
int fcntl(int s, int f, ...);
enum
{
EINTR = 4,
EINPROGRESS = 115,
}
const uint FD_SETSIZE = 1024;
//const uint NFDBITS = 8 * int.sizeof; // DMD 0.110: 8 * (int).sizeof is not an expression
const int NFDBITS = 32;
struct fd_set
{
int[FD_SETSIZE / NFDBITS] fds_bits;
alias fds_bits __fds_bits;
}
int FDELT(int d)
{
return d / NFDBITS;
}
int FDMASK(int d)
{
return 1 << (d % NFDBITS);
}
// Removes.
void FD_CLR(int fd, fd_set* set)
{
btr(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Tests.
int FD_ISSET(int fd, fd_set* set)
{
return bt(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Adds.
void FD_SET(int fd, fd_set* set)
{
bts(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Resets to zero.
void FD_ZERO(fd_set* set)
{
set.fds_bits[] = 0;
}
}
extern (C)
{
/* From <dlfcn.h>
* See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
*/
const int RTLD_NOW = 0x00002; // Correct for Red Hat 8
void* dlopen(char* file, int mode);
int dlclose(void* handle);
void* dlsym(void* handle, char* name);
char* dlerror();
}
extern (C)
{
/* from <pwd.h>
*/
struct passwd
{
char *pw_name;
char *pw_passwd;
uid_t pw_uid;
gid_t pw_gid;
char *pw_gecos;
char *pw_dir;
char *pw_shell;
}
const size_t _SIGSET_NWORDS = 1024 / (8 * uint.sizeof);
struct sigset_t
{
uint[_SIGSET_NWORDS] __val;
}
int getpwnam_r(char*, passwd*, void*, size_t, passwd**);
passwd* getpwnam(char*);
passwd* getpwuid(uid_t);
int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
int kill(pid_t, int);
int sem_close(sem_t*);
int sigemptyset(sigset_t*);
int sigfillset(sigset_t*);
int sigismember(sigset_t*, int);
int sigsuspend(sigset_t*);
}
extern (C)
{
/* from semaphore.h
*/
struct sem_t
{
_pthread_fastlock __sem_lock;
int __sem_value;
void* __sem_waiting;
}
int sem_init(sem_t*, int, uint);
int sem_wait(sem_t*);
int sem_trywait(sem_t*);
int sem_post(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_destroy(sem_t*);
}
extern (C)
{
/* from utime.h
*/
struct utimbuf
{
__time_t actime;
__time_t modtime;
}
int utime(char* filename, utimbuf* buf);
}

View File

@@ -0,0 +1,25 @@
/* Written by Walter Bright.
* www.digitalmars.com
* Placed into public domain.
* Linux(R) is the registered trademark of Linus Torvalds in the U.S. and other
* countries.
*/
/* These are all the globals defined by the linux C runtime library.
* Put them separate so they'll be externed - do not link in linuxextern.o
*/
module std.c.linux.linuxextern;
extern (C)
{
void* __libc_stack_end;
int __data_start;
int _end;
int timezone;
void *_deh_beg;
void *_deh_end;
}

View File

@@ -0,0 +1,257 @@
/* Written by Walter Bright, Christopher E. Miller, and many others.
* www.digitalmars.com
* Placed into public domain.
*/
module std.c.linux.pthread;
extern (C)
{
/* pthread declarations taken from pthread headers and
http://svn.dsource.org/projects/bindings/trunk/pthreads.d
*/
/* from bits/types.h
*/
typedef int __time_t;
/* from time.h
*/
struct timespec
{
__time_t tv_sec; /* seconds */
int tv_nsec; /* nanosecs. */
}
/* from bits/pthreadtypes.h
*/
alias uint pthread_t;
alias uint pthread_key_t;
alias int pthread_once_t;
alias int clockid_t;
alias int pthread_spinlock_t; // volatile
struct _pthread_descr_struct
{
/* Not defined in the headers ???
Just needed here to typedef
the _pthread_descr pointer
*/
}
typedef _pthread_descr_struct* _pthread_descr;
struct _pthread_fastlock
{
int __status;
int __spinlock;
}
typedef long __pthread_cond_align_t;
struct pthread_cond_t
{
_pthread_fastlock __c_lock;
_pthread_descr __c_waiting;
char[48
- _pthread_fastlock.sizeof
- _pthread_descr.sizeof
- __pthread_cond_align_t.sizeof
] __padding;
__pthread_cond_align_t __align;
}
struct pthread_condattr_t
{
int __dummy;
}
struct pthread_mutex_t
{
int __m_reserved;
int __m_count;
_pthread_descr __m_owner;
int __m_kind;
_pthread_fastlock __m_lock;
}
struct pthread_mutexattr_t
{
int __mutexkind;
}
/* from pthread.h
*/
struct _pthread_cleanup_buffer
{
void function(void*) __routine;
void* __arg;
int __canceltype;
_pthread_cleanup_buffer* __prev;
}
struct __sched_param // bits/sched.h
{
int __sched_priority;
}
struct pthread_attr_t
{
int __detachstate;
int __schedpolicy;
__sched_param schedparam;
int __inheritshed;
int __scope;
size_t __guardsize;
int __stackaddr_set;
void* __stackaddr;
size_t __stacksize;
}
struct pthread_barrier_t
{
_pthread_fastlock __ba_lock;
int __ba_required;
int __ba_present;
_pthread_descr __ba_waiting;
}
struct pthread_barrierattr_t
{
int __pshared;
}
struct pthread_rwlockattr_t
{
int __lockkind;
int __pshared;
}
struct pthread_rwlock_t
{
_pthread_fastlock __rw_lock;
int __rw_readers;
_pthread_descr __rw_writer;
_pthread_descr __rw_read_waiting;
_pthread_descr __rw_write_waiting;
int __rw_kind;
int __rw_pshared;
}
int pthread_mutex_init(pthread_mutex_t*, pthread_mutexattr_t*);
int pthread_mutex_destroy(pthread_mutex_t*);
int pthread_mutex_trylock(pthread_mutex_t*);
int pthread_mutex_lock(pthread_mutex_t*);
int pthread_mutex_unlock(pthread_mutex_t*);
int pthread_mutexattr_init(pthread_mutexattr_t*);
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
int pthread_cond_init(pthread_cond_t*, pthread_condattr_t*);
int pthread_cond_destroy(pthread_cond_t*);
int pthread_cond_signal(pthread_cond_t*);
int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, timespec*);
int pthread_attr_init(pthread_attr_t*);
int pthread_attr_destroy(pthread_attr_t*);
int pthread_attr_setdetachstate(pthread_attr_t*, int);
int pthread_attr_getdetachstate(pthread_attr_t*, int*);
int pthread_attr_setinheritsched(pthread_attr_t*, int);
int pthread_attr_getinheritsched(pthread_attr_t*, int*);
int pthread_attr_setschedparam(pthread_attr_t*, __sched_param*);
int pthread_attr_getschedparam(pthread_attr_t*, __sched_param*);
int pthread_attr_setschedpolicy(pthread_attr_t*, int);
int pthread_attr_getschedpolicy(pthread_attr_t*, int*);
int pthread_attr_setscope(pthread_attr_t*, int);
int pthread_attr_getscope(pthread_attr_t*, int*);
int pthread_attr_setguardsize(pthread_attr_t*, size_t);
int pthread_attr_getguardsize(pthread_attr_t*, size_t*);
int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
int pthread_attr_getstack(pthread_attr_t*, void**, size_t*);
int pthread_attr_setstackaddr(pthread_attr_t*, void*);
int pthread_attr_getstackaddr(pthread_attr_t*, void**);
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
int pthread_attr_getstacksize(pthread_attr_t*, size_t*);
int pthread_barrierattr_init(pthread_barrierattr_t*);
int pthread_barrierattr_getpshared(pthread_barrierattr_t*, int*);
int pthread_barrierattr_destroy(pthread_barrierattr_t*);
int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
int pthread_barrier_init(pthread_barrier_t*, pthread_barrierattr_t*, uint);
int pthread_barrier_destroy(pthread_barrier_t*);
int pthread_barrier_wait(pthread_barrier_t*);
int pthread_condattr_init(pthread_condattr_t*);
int pthread_condattr_destroy(pthread_condattr_t*);
int pthread_condattr_getpshared(pthread_condattr_t*, int*);
int pthread_condattr_setpshared(pthread_condattr_t*, int);
int pthread_detach(pthread_t);
void pthread_exit(void*);
int pthread_getattr_np(pthread_t, pthread_attr_t*);
int pthread_getconcurrency();
int pthread_getcpuclockid(pthread_t, clockid_t*);
int pthread_mutexattr_getpshared(pthread_mutexattr_t*, int*);
int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
int pthread_mutexattr_gettype(pthread_mutexattr_t*, int*);
int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
int pthread_yield();
int pthread_rwlock_init(pthread_rwlock_t*, pthread_rwlockattr_t*);
int pthread_rwlock_destroy(pthread_rwlock_t*);
int pthread_rwlock_rdlock(pthread_rwlock_t*);
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
int pthread_rwlock_timedrdlock(pthread_rwlock_t*, timespec*);
int pthread_rwlock_wrlock(pthread_rwlock_t*);
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
int pthread_rwlock_timedwrlock(pthread_rwlock_t*, timespec*);
int pthread_rwlock_unlock(pthread_rwlock_t*);
int pthread_rwlockattr_init(pthread_rwlockattr_t*);
int pthread_rwlockattr_destroy(pthread_rwlockattr_t*);
int pthread_rwlockattr_getpshared(pthread_rwlockattr_t*, int*);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
int pthread_rwlockattr_getkind_np(pthread_rwlockattr_t*, int*);
int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int);
int pthread_spin_init(pthread_spinlock_t*, int);
int pthread_spin_destroy(pthread_spinlock_t*);
int pthread_spin_lock(pthread_spinlock_t*);
int pthread_spin_trylock(pthread_spinlock_t*);
int pthread_spin_unlock(pthread_spinlock_t*);
int pthread_cancel(pthread_t);
void pthread_testcancel();
int pthread_once(pthread_once_t*, void function());
int pthread_join(pthread_t, void**);
int pthread_create(pthread_t*, pthread_attr_t*, void*function(void*), void*);
pthread_t pthread_self();
int pthread_equal(pthread_t, pthread_t);
int pthread_atfork(void function(), void function(), void function());
void pthread_kill_other_threads_np();
int pthread_setschedparam(pthread_t, int, __sched_param*);
int pthread_getschedparam(pthread_t, int*, __sched_param*);
int pthread_cond_broadcast(pthread_cond_t*);
int pthread_key_create(pthread_key_t*, void function(void*));
int pthread_key_delete(pthread_key_t);
int pthread_setconcurrency(int);
int pthread_setspecific(pthread_key_t, void*);
void* pthread_getspecific(pthread_key_t);
int pthread_setcanceltype(int, int*);
int pthread_setcancelstate(int, int*);
void _pthread_cleanup_push(_pthread_cleanup_buffer*, void function(void*), void*);
void _pthread_cleanup_push_defer(_pthread_cleanup_buffer*, void function(void*), void*);
void _pthread_cleanup_pop(_pthread_cleanup_buffer*, int);
void _pthread_cleanup_pop_restore(_pthread_cleanup_buffer*, int);
}

View File

@@ -0,0 +1,396 @@
/*
Written by Christopher E. Miller
Placed into public domain.
*/
module std.c.linux.socket;
private import std.stdint;
extern(C):
alias int socklen_t;
const int F_GETFL = 3;
const int F_SETFL = 4;
const int O_NONBLOCK = 0x800;
int socket(int af, int type, int protocol);
int bind(int s, sockaddr* name, int namelen);
int connect(int s, sockaddr* name, int namelen);
int listen(int s, int backlog);
int accept(int s, sockaddr* addr, int* addrlen);
int shutdown(int s, int how);
int getpeername(int s, sockaddr* name, int* namelen);
int getsockname(int s, sockaddr* name, int* namelen);
int send(int s, void* buf, int len, int flags);
int sendto(int s, void* buf, int len, int flags, sockaddr* to, int tolen);
int recv(int s, void* buf, int len, int flags);
int recvfrom(int s, void* buf, int len, int flags, sockaddr* from, int* fromlen);
int getsockopt(int s, int level, int optname, void* optval, int* optlen);
int setsockopt(int s, int level, int optname, void* optval, int optlen);
uint inet_addr(char* cp);
char* inet_ntoa(in_addr ina);
hostent* gethostbyname(char* name);
int gethostbyname_r(char* name, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
int gethostbyname2_r(char* name, int af, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
hostent* gethostbyaddr(void* addr, int len, int type);
protoent* getprotobyname(char* name);
protoent* getprotobynumber(int number);
servent* getservbyname(char* name, char* proto);
servent* getservbyport(int port, char* proto);
int gethostname(char* name, int namelen);
int getaddrinfo(char* nodename, char* servname, addrinfo* hints, addrinfo** res);
void freeaddrinfo(addrinfo* ai);
int getnameinfo(sockaddr* sa, socklen_t salen, char* node, socklen_t nodelen, char* service, socklen_t servicelen, int flags);
enum: int
{
AF_UNSPEC = 0,
AF_UNIX = 1,
AF_INET = 2,
AF_IPX = 4,
AF_APPLETALK = 5,
AF_INET6 = 10,
// ...
PF_UNSPEC = AF_UNSPEC,
PF_UNIX = AF_UNIX,
PF_INET = AF_INET,
PF_IPX = AF_IPX,
PF_APPLETALK = AF_APPLETALK,
PF_INET6 = AF_INET6,
}
version(X86)
version=SOL_SOCKET_IS_1;
else version(X86_64)
version=SOL_SOCKET_IS_1;
else version(PPC)
version=SOL_SOCKET_IS_1;
else version(PPC64)
version=SOL_SOCKET_IS_1;
else
static assert(0, "Unsupported architecture");
version(SOL_SOCKET_IS_1)
{
enum: int
{
SOL_SOCKET = 1,
}
}
else
{
// Different values on other platforms.
static assert(0);
}
enum: int
{
SO_DEBUG = 1,
SO_BROADCAST = 6,
SO_REUSEADDR = 2,
SO_LINGER = 13,
SO_DONTLINGER = ~SO_LINGER,
SO_OOBINLINE = 10,
SO_SNDBUF = 7,
SO_RCVBUF = 8,
SO_ACCEPTCONN = 30,
SO_DONTROUTE = 5,
SO_TYPE = 3,
TCP_NODELAY = 1,
IP_MULTICAST_LOOP = 34,
IP_ADD_MEMBERSHIP = 35,
IP_DROP_MEMBERSHIP = 36,
// ...
IPV6_ADDRFORM = 1,
IPV6_PKTINFO = 2,
IPV6_HOPOPTS = 3,
IPV6_DSTOPTS = 4,
IPV6_RTHDR = 5,
IPV6_PKTOPTIONS = 6,
IPV6_CHECKSUM = 7,
IPV6_HOPLIMIT = 8,
IPV6_NEXTHOP = 9,
IPV6_AUTHHDR = 10,
IPV6_UNICAST_HOPS = 16,
IPV6_MULTICAST_IF = 17,
IPV6_MULTICAST_HOPS = 18,
IPV6_MULTICAST_LOOP = 19,
IPV6_JOIN_GROUP = 20,
IPV6_LEAVE_GROUP = 21,
IPV6_ROUTER_ALERT = 22,
IPV6_MTU_DISCOVER = 23,
IPV6_MTU = 24,
IPV6_RECVERR = 25,
IPV6_V6ONLY = 26,
IPV6_JOIN_ANYCAST = 27,
IPV6_LEAVE_ANYCAST = 28,
IPV6_IPSEC_POLICY = 34,
IPV6_XFRM_POLICY = 35,
}
struct linger
{
int32_t l_onoff;
int32_t l_linger;
}
struct protoent
{
char* p_name;
char** p_aliases;
int32_t p_proto;
}
struct servent
{
char* s_name;
char** s_aliases;
int32_t s_port;
char* s_proto;
}
version(BigEndian)
{
uint16_t htons(uint16_t x)
{
return x;
}
uint32_t htonl(uint32_t x)
{
return x;
}
}
else version(LittleEndian)
{
private import std.intrinsic;
uint16_t htons(uint16_t x)
{
return cast(uint16_t)((x >> 8) | (x << 8));
}
uint32_t htonl(uint32_t x)
{
return bswap(x);
}
}
else
{
static assert(0);
}
uint16_t ntohs(uint16_t x)
{
return htons(x);
}
uint32_t ntohl(uint32_t x)
{
return htonl(x);
}
enum: int
{
SOCK_STREAM = 1,
SOCK_DGRAM = 2,
SOCK_RAW = 3,
SOCK_RDM = 4,
SOCK_SEQPACKET = 5,
}
enum: int
{
IPPROTO_IP = 0,
IPPROTO_ICMP = 1,
IPPROTO_IGMP = 2,
IPPROTO_GGP = 3,
IPPROTO_TCP = 6,
IPPROTO_PUP = 12,
IPPROTO_UDP = 17,
IPPROTO_IDP = 22,
IPPROTO_IPV6 = 41,
IPPROTO_ND = 77,
IPPROTO_RAW = 255,
IPPROTO_MAX = 256,
}
enum: int
{
MSG_OOB = 0x1,
MSG_PEEK = 0x2,
MSG_DONTROUTE = 0x4,
}
enum: int
{
SD_RECEIVE = 0,
SD_SEND = 1,
SD_BOTH = 2,
}
enum: uint
{
INADDR_ANY = 0,
INADDR_LOOPBACK = 0x7F000001,
INADDR_BROADCAST = 0xFFFFFFFF,
INADDR_NONE = 0xFFFFFFFF,
ADDR_ANY = INADDR_ANY,
}
enum: int
{
AI_PASSIVE = 0x1,
AI_CANONNAME = 0x2,
AI_NUMERICHOST = 0x4,
}
union in_addr
{
private union _S_un_t
{
private struct _S_un_b_t
{
uint8_t s_b1, s_b2, s_b3, s_b4;
}
_S_un_b_t S_un_b;
private struct _S_un_w_t
{
uint16_t s_w1, s_w2;
}
_S_un_w_t S_un_w;
uint32_t S_addr;
}
_S_un_t S_un;
uint32_t s_addr;
struct
{
uint8_t s_net, s_host;
union
{
uint16_t s_imp;
struct
{
uint8_t s_lh, s_impno;
}
}
}
}
union in6_addr
{
private union _in6_u_t
{
uint8_t[16] u6_addr8;
uint16_t[8] u6_addr16;
uint32_t[4] u6_addr32;
}
_in6_u_t in6_u;
uint8_t[16] s6_addr8;
uint16_t[8] s6_addr16;
uint32_t[4] s6_addr32;
}
const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
const in6_addr IN6ADDR_LOOPBACK = { s6_addr8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] };
//alias IN6ADDR_ANY IN6ADDR_ANY_INIT;
//alias IN6ADDR_LOOPBACK IN6ADDR_LOOPBACK_INIT;
const uint INET_ADDRSTRLEN = 16;
const uint INET6_ADDRSTRLEN = 46;
struct sockaddr
{
int16_t sa_family;
ubyte[14] sa_data;
}
struct sockaddr_in
{
int16_t sin_family = AF_INET;
uint16_t sin_port;
in_addr sin_addr;
ubyte[8] sin_zero;
}
struct sockaddr_in6
{
int16_t sin6_family = AF_INET6;
uint16_t sin6_port;
uint32_t sin6_flowinfo;
in6_addr sin6_addr;
uint32_t sin6_scope_id;
}
struct addrinfo
{
int32_t ai_flags;
int32_t ai_family;
int32_t ai_socktype;
int32_t ai_protocol;
size_t ai_addrlen;
sockaddr* ai_addr;
char* ai_canonname;
addrinfo* ai_next;
}
struct hostent
{
char* h_name;
char** h_aliases;
int32_t h_addrtype;
int32_t h_length;
char** h_addr_list;
char* h_addr()
{
return h_addr_list[0];
}
}

151
lphobos/std/c/locale.d Normal file
View File

@@ -0,0 +1,151 @@
/**
* C's &lt;locale.h&gt;
* License: Public Domain
* Standards:
* ISO/IEC 9899:1999 7.11
* Macros:
* WIKI=Phobos/StdCLocale
*/
module std.c.locale;
extern(C):
/// Structure giving information about numeric and monetary notation.
struct lconv{
/// The decimal-point character used to format nonmonetary quantities.
char* decimal_point;
/** The character used to separate groups of digits before the
* decimal-point character in formatted nonmonetary quantities.
**/
char* thousands_sep;
/** A string whose elements indicate the size of each group of digits
* in formatted nonmonetary quantities.
**/
char* grouping;
/** The international currency symbol applicable to the current locale.
* The first three characters contain the alphabetic international
* currency symbol in accordance with those specified in ISO 4217.
* The fourth character (immediately preceding the null character)
* is the character used to separate the international currency symbol
* from the monetary quantity.
**/
char* int_curr_symbol;
/// The local currency symbol applicable to the current locale.
char* currency_symbol;
/// The decimal-point used to format monetary quantities.
char* mon_decimal_point;
/** The separator for groups of digits before the decimal-point in
* formatted monetary quantities.
**/
char* mon_thousands_sep;
/** A string whose elements indicate the size of each group of digits
* in formatted monetary quantities.
**/
char* mon_grouping;
/** The string used to indicate a nonnegative-valued formatted
* monetary quantity.
**/
char* positive_sign;
/** The string used to indicate a negative-valued formatted monetary
* quantity.
**/
char* negative_sign;
/** The number of fractional digits (those after the decimal-point) to
* be displayed in an internationally formatted monetary quantity.
**/
char int_frac_digits;
/** The number of fractional digits (those after the decimal-point) to
* be displayed in a locally formatted monetary quantity.
**/
char frac_digits;
/// 1 if currency_symbol precedes a positive value, 0 if succeeds.
char p_cs_precedes;
/// 1 if a space separates currency_symbol from a positive value.
char p_sep_by_space;
/// 1 if currency_symbol precedes a negative value, 0 if succeeds.
char n_cs_precedes;
/// 1 if a space separates currency_symbol from a negative value.
char n_sep_by_space;
/* Positive and negative sign positions:
0 Parentheses surround the quantity and currency_symbol.
1 The sign string precedes the quantity and currency_symbol.
2 The sign string follows the quantity and currency_symbol.
3 The sign string immediately precedes the currency_symbol.
4 The sign string immediately follows the currency_symbol. */
char p_sign_posn;
char n_sign_posn;
/// 1 if int_curr_symbol precedes a positive value, 0 if succeeds.
char int_p_cs_precedes;
/// 1 iff a space separates int_curr_symbol from a positive value.
char int_p_sep_by_space;
/// 1 if int_curr_symbol precedes a negative value, 0 if succeeds.
char int_n_cs_precedes;
/// 1 iff a space separates int_curr_symbol from a negative value.
char int_n_sep_by_space;
/* Positive and negative sign positions:
0 Parentheses surround the quantity and int_curr_symbol.
1 The sign string precedes the quantity and int_curr_symbol.
2 The sign string follows the quantity and int_curr_symbol.
3 The sign string immediately precedes the int_curr_symbol.
4 The sign string immediately follows the int_curr_symbol. */
char int_p_sign_posn;
char int_n_sign_posn;
}
/** Affects the behavior of C's character handling functions and C's multibyte
* and wide character functions.
**/
const LC_CTYPE = 0;
/** Affects the decimal-point character for C's formatted input/output functions
* and C's string conversion functions, as well as C's nonmonetary formatting
* information returned by the localeconv function.
**/
const LC_NUMERIC = 1;
/// Affects the behavior of the strftime and wcsftime functions.
const LC_TIME = 2;
/// Affects the behavior of the strcoll and strxfrm functions.
const LC_COLLATE = 3;
/** Affects the monetary formatting information returned by the localeconv
* function.
**/
const LC_MONETARY = 4;
/// The program's entire locale.
const LC_ALL = 6;
/** The setlocale function selects the appropriate portion of the program's
* locale as specified by the category and locale arguments.
**/
char* setlocale(int category, char* locale);
/** The localeconv function sets the components of an object with type
* lconv with values appropriate for the formatting of numeric quantities
* (monetary and otherwise) according to the rules of the current locale.
**/
lconv* localeconv();

291
lphobos/std/c/math.d Normal file
View File

@@ -0,0 +1,291 @@
/**
* C's &lt;math.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCMath
*/
module std.c.math;
extern (C):
alias float float_t; ///
alias double double_t; ///
const double HUGE_VAL = double.infinity; ///
const float HUGE_VALF = float.infinity; /// ditto
const real HUGE_VALL = real.infinity; /// ditto
const float INFINITY = float.infinity; ///
const float NAN = float.nan; ///
enum
{
FP_NANS, // extension
FP_NANQ, // extension
FP_INFINITE, ///
FP_NAN = FP_NANQ, ///
FP_NORMAL = 3, ///
FP_SUBNORMAL = 4, ///
FP_ZERO = 5, ///
FP_EMPTY = 6, // extension
FP_UNSUPPORTED = 7, // extension
}
enum
{
FP_FAST_FMA = 0, ///
FP_FAST_FMAF = 0, ///
FP_FAST_FMAL = 0, ///
}
const int FP_ILOGB0 = int.min; ///
const int FP_ILOGBNAN = int.min; ///
const int MATH_ERRNO = 1; ///
const int MATH_ERREXCEPT = 2; ///
const int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT; ///
double acos(double x); ///
float acosf(float x); /// ditto
real acosl(real x); /// ditto
double asin(double x); ///
float asinf(float x); /// ditto
real asinl(real x); /// ditto
double atan(double x); ///
float atanf(float x); /// ditto
real atanl(real x); /// ditto
double atan2(double y, double x); ///
float atan2f(float y, float x); /// ditto
real atan2l(real y, real x); /// ditto
double cos(double x); ///
float cosf(float x); /// ditto
real cosl(real x); /// ditto
double sin(double x); ///
float sinf(float x); /// ditto
real sinl(real x); /// ditto
double tan(double x); ///
float tanf(float x); /// ditto
real tanl(real x); /// ditto
double acosh(double x); ///
float acoshf(float x); /// ditto
real acoshl(real x); /// ditto
double asinh(double x); ///
float asinhf(float x); /// ditto
real asinhl(real x); /// ditto
double atanh(double x); ///
float atanhf(float x); /// ditto
real atanhl(real x); /// ditto
double cosh(double x); ///
float coshf(float x); /// ditto
real coshl(real x); /// ditto
double sinh(double x); ///
float sinhf(float x); /// ditto
real sinhl(real x); /// ditto
double tanh(double x); ///
float tanhf(float x); /// ditto
real tanhl(real x); /// ditto
double exp(double x); ///
float expf(float x); /// ditto
real expl(real x); /// ditto
double exp2(double x); ///
float exp2f(float x); /// ditto
real exp2l(real x); /// ditto
double expm1(double x); ///
float expm1f(float x); /// ditto
real expm1l(real x); /// ditto
double frexp(double value, int *exp); ///
float frexpf(float value, int *exp); /// ditto
real frexpl(real value, int *exp); /// ditto
int ilogb(double x); ///
int ilogbf(float x); /// ditto
int ilogbl(real x); /// ditto
double ldexp(double x, int exp); ///
float ldexpf(float x, int exp); /// ditto
real ldexpl(real x, int exp); /// ditto
double log(double x); ///
float logf(float x); /// ditto
real logl(real x); /// ditto
double log10(double x); ///
float log10f(float x); /// ditto
real log10l(real x); /// ditto
double log1p(double x); ///
float log1pf(float x); /// ditto
real log1pl(real x); /// ditto
double log2(double x); ///
float log2f(float x); /// ditto
real log2l(real x); /// ditto
double logb(double x); ///
float logbf(float x); /// ditto
real logbl(real x); /// ditto
double modf(double value, double *iptr); ///
float modff(float value, float *iptr); /// ditto
real modfl(real value, real *iptr); /// ditto
double scalbn(double x, int n); ///
float scalbnf(float x, int n); /// ditto
real scalbnl(real x, int n); /// ditto
double scalbln(double x, int n); ///
float scalblnf(float x, int n); /// ditto
real scalblnl(real x, int n); /// ditto
double cbrt(double x); ///
float cbrtf(float x); /// ditto
real cbrtl(real x); /// ditto
double fabs(double x); ///
float fabsf(float x); /// ditto
real fabsl(real x); /// ditto
double hypot(double x, double y); ///
float hypotf(float x, float y); /// ditto
real hypotl(real x, real y); /// ditto
double pow(double x, double y); ///
float powf(float x, float y); /// ditto
real powl(real x, real y); /// ditto
double sqrt(double x); ///
float sqrtf(float x); /// ditto
real sqrtl(real x); /// ditto
double erf(double x); ///
float erff(float x); /// ditto
real erfl(real x); /// ditto
double erfc(double x); ///
float erfcf(float x); /// ditto
real erfcl(real x); /// ditto
double lgamma(double x); ///
float lgammaf(float x); /// ditto
real lgammal(real x); /// ditto
double tgamma(double x); ///
float tgammaf(float x); /// ditto
real tgammal(real x); /// ditto
double ceil(double x); ///
float ceilf(float x); /// ditto
real ceill(real x); /// ditto
double floor(double x); ///
float floorf(float x); /// ditto
real floorl(real x); /// ditto
double nearbyint(double x); ///
float nearbyintf(float x); /// ditto
real nearbyintl(real x); /// ditto
double rint(double x); ///
float rintf(float x); /// ditto
real rintl(real x); /// ditto
int lrint(double x); ///
int lrintf(float x); /// ditto
int lrintl(real x); /// ditto
long llrint(double x); ///
long llrintf(float x); /// ditto
long llrintl(real x); /// ditto
double round(double x); ///
float roundf(float x); /// ditto
real roundl(real x); /// ditto
int lround(double x); ///
int lroundf(float x); /// ditto
int lroundl(real x); /// ditto
long llround(double x); ///
long llroundf(float x); /// ditto
long llroundl(real x); /// ditto
double trunc(double x); ///
float truncf(float x); /// ditto
real truncl(real x); /// ditto
double fmod(double x, double y); ///
float fmodf(float x, float y); /// ditto
real fmodl(real x, real y); /// ditto
double remainder(double x, double y); ///
float remainderf(float x, float y); /// ditto
real remainderl(real x, real y); /// ditto
double remquo(double x, double y, int *quo); ///
float remquof(float x, float y, int *quo); /// ditto
real remquol(real x, real y, int *quo); /// ditto
double copysign(double x, double y); ///
float copysignf(float x, float y); /// ditto
real copysignl(real x, real y); /// ditto
double nan(char *tagp); ///
float nanf(char *tagp); /// ditto
real nanl(char *tagp); /// ditto
double nextafter(double x, double y); ///
float nextafterf(float x, float y); /// ditto
real nextafterl(real x, real y); /// ditto
double nexttoward(double x, real y); ///
float nexttowardf(float x, real y); /// ditto
real nexttowardl(real x, real y); /// ditto
double fdim(double x, double y); ///
float fdimf(float x, float y); /// ditto
real fdiml(real x, real y); /// ditto
double fmax(double x, double y); ///
float fmaxf(float x, float y); /// ditto
real fmaxl(real x, real y); /// ditto
double fmin(double x, double y); ///
float fminf(float x, float y); /// ditto
real fminl(real x, real y); /// ditto
double fma(double x, double y, double z); ///
float fmaf(float x, float y, float z); /// ditto
real fmal(real x, real y, real z); /// ditto
///
int isgreater(real x, real y) { return !(x !> y); }
///
int isgreaterequal(real x, real y) { return !(x !>= y); }
///
int isless(real x, real y) { return !(x !< y); }
///
int islessequal(real x, real y) { return !(x !<= y); }
///
int islessgreater(real x, real y) { return !(x !<> y); }
///
int isunordered(real x, real y) { return (x !<>= y); }

86
lphobos/std/c/process.d Normal file
View File

@@ -0,0 +1,86 @@
/**
* C's &lt;process.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCProcess
*/
module std.c.process;
private import std.c.stddef;
extern (C):
void exit(int);
void _c_exit();
void _cexit();
void _exit(int);
void abort();
void _dodtors();
int getpid();
int system(char *);
enum { _P_WAIT, _P_NOWAIT, _P_OVERLAY };
int execl(char *, char *,...);
int execle(char *, char *,...);
int execlp(char *, char *,...);
int execlpe(char *, char *,...);
int execv(char *, char **);
int execve(char *, char **, char **);
int execvp(char *, char **);
int execvpe(char *, char **, char **);
enum { WAIT_CHILD, WAIT_GRANDCHILD }
int cwait(int *,int,int);
int wait(int *);
version (Windows)
{
uint _beginthread(void function(void *),uint,void *);
extern (Windows) alias uint (*stdfp)(void *);
uint _beginthreadex(void* security, uint stack_size,
stdfp start_addr, void* arglist, uint initflag,
uint* thrdaddr);
void _endthread();
void _endthreadex(uint);
int spawnl(int, char *, char *,...);
int spawnle(int, char *, char *,...);
int spawnlp(int, char *, char *,...);
int spawnlpe(int, char *, char *,...);
int spawnv(int, char *, char **);
int spawnve(int, char *, char **, char **);
int spawnvp(int, char *, char **);
int spawnvpe(int, char *, char **, char **);
int _wsystem(wchar_t *);
int _wspawnl(int, wchar_t *, wchar_t *, ...);
int _wspawnle(int, wchar_t *, wchar_t *, ...);
int _wspawnlp(int, wchar_t *, wchar_t *, ...);
int _wspawnlpe(int, wchar_t *, wchar_t *, ...);
int _wspawnv(int, wchar_t *, wchar_t **);
int _wspawnve(int, wchar_t *, wchar_t **, wchar_t **);
int _wspawnvp(int, wchar_t *, wchar_t **);
int _wspawnvpe(int, wchar_t *, wchar_t **, wchar_t **);
int _wexecl(wchar_t *, wchar_t *, ...);
int _wexecle(wchar_t *, wchar_t *, ...);
int _wexeclp(wchar_t *, wchar_t *, ...);
int _wexeclpe(wchar_t *, wchar_t *, ...);
int _wexecv(wchar_t *, wchar_t **);
int _wexecve(wchar_t *, wchar_t **, wchar_t **);
int _wexecvp(wchar_t *, wchar_t **);
int _wexecvpe(wchar_t *, wchar_t **, wchar_t **);
}

42
lphobos/std/c/stdarg.d Normal file
View File

@@ -0,0 +1,42 @@
/**
* C's &lt;stdarg.h&gt;
* Authors: Hauke Duden and Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCStdarg
*/
/* This is for use with extern(C) variable argument lists. */
module std.c.stdarg;
alias void* va_list;
template va_start(T)
{
void va_start(out va_list ap, inout T parmn)
{
ap = cast(va_list)(cast(void*)&parmn + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)));
}
}
template va_arg(T)
{
T va_arg(inout va_list ap)
{
T arg = *cast(T*)ap;
ap = cast(va_list)(cast(void*)ap + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)));
return arg;
}
}
void va_end(va_list ap)
{
}
void va_copy(out va_list dest, va_list src)
{
dest = src;
}

23
lphobos/std/c/stddef.d Normal file
View File

@@ -0,0 +1,23 @@
/**
* C's &lt;stddef.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCStddef
*/
module std.c.stddef;
version (Win32)
{
alias wchar wchar_t;
}
else version (linux)
{
alias dchar wchar_t;
}
else
{
static assert(0);
}

300
lphobos/std/c/stdio.d Normal file
View File

@@ -0,0 +1,300 @@
/**
* C's &lt;stdio.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCStdio
*/
module std.c.stdio;
import std.c.stddef;
private import std.c.stdarg;
extern (C):
version (Win32)
{
const int _NFILE = 60; ///
const int BUFSIZ = 0x4000; ///
const int EOF = -1; ///
const int FOPEN_MAX = 20; ///
const int FILENAME_MAX = 256; /// 255 plus NULL
const int TMP_MAX = 32767; ///
const int _SYS_OPEN = 20; ///
const int SYS_OPEN = _SYS_OPEN; ///
const wchar WEOF = 0xFFFF; ///
}
version (linux)
{
const int EOF = -1;
const int FOPEN_MAX = 16;
const int FILENAME_MAX = 4095;
const int TMP_MAX = 238328;
const int L_tmpnam = 20;
}
enum { SEEK_SET, SEEK_CUR, SEEK_END }
struct _iobuf
{
align (1):
version (Win32)
{
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
int __tmpnum;
}
version (linux)
{
char* _read_ptr;
char* _read_end;
char* _read_base;
char* _write_base;
char* _write_ptr;
char* _write_end;
char* _buf_base;
char* _buf_end;
char* _save_base;
char* _backup_base;
char* _save_end;
void* _markers;
_iobuf* _chain;
int _fileno;
int _blksize;
int _old_offset;
ushort _cur_column;
byte _vtable_offset;
char[1] _shortbuf;
void* _lock;
}
}
alias _iobuf FILE; ///
enum
{
_F_RDWR = 0x0003,
_F_READ = 0x0001,
_F_WRIT = 0x0002,
_F_BUF = 0x0004,
_F_LBUF = 0x0008,
_F_ERR = 0x0010,
_F_EOF = 0x0020,
_F_BIN = 0x0040,
_F_IN = 0x0080,
_F_OUT = 0x0100,
_F_TERM = 0x0200,
}
version (Win32)
{
extern FILE _iob[_NFILE];
extern void function() _fcloseallp;
extern ubyte __fhnd_info[_NFILE];
enum
{
FHND_APPEND = 0x04,
FHND_DEVICE = 0x08,
FHND_TEXT = 0x10,
FHND_BYTE = 0x20,
FHND_WCHAR = 0x40,
}
}
version (Win32)
{
enum
{
_IOREAD = 1,
_IOWRT = 2,
_IONBF = 4,
_IOMYBUF = 8,
_IOEOF = 0x10,
_IOERR = 0x20,
_IOLBF = 0x40,
_IOSTRG = 0x40,
_IORW = 0x80,
_IOFBF = 0,
_IOAPP = 0x200,
_IOTRAN = 0x100,
}
}
version (linux)
{
enum
{
_IOFBF = 0,
_IOLBF = 1,
_IONBF = 2,
}
}
version (Win32)
{
const FILE *stdin = &_iob[0]; ///
const FILE *stdout = &_iob[1]; ///
const FILE *stderr = &_iob[2]; ///
const FILE *stdaux = &_iob[3]; ///
const FILE *stdprn = &_iob[4]; ///
}
version (linux)
{
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
}
version (Win32)
{
const char[] _P_tmpdir = "\\";
const wchar[] _wP_tmpdir = "\\";
const int L_tmpnam = _P_tmpdir.length + 12;
}
alias int fpos_t; ///
char * tmpnam(char *); ///
FILE * fopen(char *,char *); ///
FILE * _fsopen(char *,char *,int ); ///
FILE * freopen(char *,char *,FILE *); ///
int fseek(FILE *,int,int); ///
int ftell(FILE *); ///
char * fgets(char *,int,FILE *); ///
int fgetc(FILE *); ///
int _fgetchar(); ///
int fflush(FILE *); ///
int fclose(FILE *); ///
int fputs(char *,FILE *); ///
char * gets(char *); ///
int fputc(int,FILE *); ///
int _fputchar(int); ///
int puts(char *); ///
int ungetc(int,FILE *); ///
size_t fread(void *,size_t,size_t,FILE *); ///
size_t fwrite(void *,size_t,size_t,FILE *); ///
//int printf(char *,...); ///
int fprintf(FILE *,char *,...); ///
int vfprintf(FILE *,char *,va_list); ///
int vprintf(char *,va_list); ///
int sprintf(char *,char *,...); ///
int vsprintf(char *,char *,va_list); ///
int scanf(char *,...); ///
int fscanf(FILE *,char *,...); ///
int sscanf(char *,char *,...); ///
void setbuf(FILE *,char *); ///
int setvbuf(FILE *,char *,int,size_t); ///
int remove(char *); ///
int rename(char *,char *); ///
void perror(char *); ///
int fgetpos(FILE *,fpos_t *); ///
int fsetpos(FILE *,fpos_t *); ///
FILE * tmpfile(); ///
int _rmtmp();
int _fillbuf(FILE *);
int _flushbu(int, FILE *);
int getw(FILE *FHdl); ///
int putw(int Word, FILE *FilePtr); ///
///
int getchar() { return getc(stdin); }
///
int putchar(int c) { return putc(c,stdout); }
///
int getc(FILE *fp) { return fgetc(fp); }
///
int putc(int c,FILE *fp) { return fputc(c,fp); }
version (Win32)
{
///
int ferror(FILE *fp) { return fp._flag&_IOERR; }
///
int feof(FILE *fp) { return fp._flag&_IOEOF; }
///
void clearerr(FILE *fp) { fp._flag &= ~(_IOERR|_IOEOF); }
///
void rewind(FILE *fp) { fseek(fp,0L,SEEK_SET); fp._flag&=~_IOERR; }
int _bufsize(FILE *fp) { return fp._bufsiz; }
///
int fileno(FILE *fp) { return fp._file; }
int _snprintf(char *,size_t,char *,...);
int _vsnprintf(char *,size_t,char *,va_list);
}
version (linux)
{
int ferror(FILE *fp);
int feof(FILE *fp);
void clearerr(FILE *fp);
void rewind(FILE *fp);
int _bufsize(FILE *fp);
int fileno(FILE *fp);
int snprintf(char *,size_t,char *,...);
int vsnprintf(char *,size_t,char *,va_list);
}
int unlink(char *); ///
FILE * fdopen(int, char *); ///
int fgetchar(); ///
int fputchar(int); ///
int fcloseall(); ///
int filesize(char *); ///
int flushall(); ///
int getch(); ///
int getche(); ///
int kbhit(); ///
char * tempnam (char *dir, char *pfx); ///
wchar_t * _wtmpnam(wchar_t *); ///
FILE * _wfopen(wchar_t *, wchar_t *);
FILE * _wfsopen(wchar_t *, wchar_t *, int);
FILE * _wfreopen(wchar_t *, wchar_t *, FILE *);
wchar_t * fgetws(wchar_t *, int, FILE *); ///
int fputws(wchar_t *, FILE *); ///
wchar_t * _getws(wchar_t *);
int _putws(wchar_t *);
int wprintf(wchar_t *, ...); ///
int fwprintf(FILE *, wchar_t *, ...); ///
int vwprintf(wchar_t *, va_list); ///
int vfwprintf(FILE *, wchar_t *, va_list); ///
int swprintf(wchar_t *, wchar_t *, ...); ///
int vswprintf(wchar_t *, wchar_t *, va_list); ///
int _snwprintf(wchar_t *, size_t, wchar_t *, ...);
int _vsnwprintf(wchar_t *, size_t, wchar_t *, va_list);
int wscanf(wchar_t *, ...); ///
int fwscanf(FILE *, wchar_t *, ...); ///
int swscanf(wchar_t *, wchar_t *, ...); ///
int _wremove(wchar_t *);
void _wperror(wchar_t *);
FILE * _wfdopen(int, wchar_t *);
wchar_t * _wtempnam(wchar_t *, wchar_t *);
wchar_t fgetwc(FILE *); ///
wchar_t _fgetwchar_t();
wchar_t fputwc(wchar_t, FILE *); ///
wchar_t _fputwchar_t(wchar_t);
wchar_t ungetwc(wchar_t, FILE *); ///
///
wchar_t getwchar_t() { return fgetwc(stdin); }
///
wchar_t putwchar_t(wchar_t c) { return fputwc(c,stdout); }
///
wchar_t getwc(FILE *fp) { return fgetwc(fp); }
///
wchar_t putwc(wchar_t c, FILE *fp) { return fputwc(c, fp); }
int fwide(FILE* fp, int mode); ///

90
lphobos/std/c/stdlib.d Normal file
View File

@@ -0,0 +1,90 @@
/**
* C's &lt;stdlib.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCStdlib
*/
module std.c.stdlib;
private import std.c.stddef;
extern (C):
enum
{
_MAX_PATH = 260,
_MAX_DRIVE = 3,
_MAX_DIR = 256,
_MAX_FNAME = 256,
_MAX_EXT = 256,
}
///
struct div_t { int quot,rem; }
///
struct ldiv_t { int quot,rem; }
///
struct lldiv_t { long quot,rem; }
div_t div(int,int); ///
ldiv_t ldiv(int,int); /// ditto
lldiv_t lldiv(long, long); /// ditto
const int EXIT_SUCCESS = 0; ///
const int EXIT_FAILURE = 1; /// ditto
int atexit(void (*)()); ///
void exit(int); /// ditto
void _exit(int); /// ditto
int system(char *);
void *alloca(uint); ///
void *calloc(size_t, size_t); ///
void *malloc(size_t); /// ditto
void *realloc(void *, size_t); /// ditto
void free(void *); /// ditto
void *bsearch(void *,void *,size_t,size_t,
int function(void *,void *)); ///
void qsort(void *base, size_t nelems, size_t elemsize,
int (*compare)(void *elem1, void *elem2)); /// ditto
char* getenv(char*); ///
int setenv(char*, char*, int); /// extension to ISO C standard, not available on all platforms
void unsetenv(char*); /// extension to ISO C standard, not available on all platforms
int rand(); ///
void srand(uint); /// ditto
int random(int num); /// ditto
void randomize(); /// ditto
int getErrno(); /// ditto
int setErrno(int); /// ditto
const int ERANGE = 34; // on both Windows and linux
double atof(char *); ///
int atoi(char *); /// ditto
int atol(char *); /// ditto
float strtof(char *,char **); /// ditto
double strtod(char *,char **); /// ditto
real strtold(char *,char **); /// ditto
long strtol(char *,char **,int); /// ditto
uint strtoul(char *,char **,int); /// ditto
long atoll(char *); /// ditto
long strtoll(char *,char **,int); /// ditto
ulong strtoull(char *,char **,int); /// ditto
char* itoa(int, char*, int); ///
char* ultoa(uint, char*, int); /// ditto
int mblen(char *s, size_t n); ///
int mbtowc(wchar_t *pwc, char *s, size_t n); /// ditto
int wctomb(char *s, wchar_t wc); /// ditto
size_t mbstowcs(wchar_t *pwcs, char *s, size_t n); /// ditto
size_t wcstombs(char *s, wchar_t *pwcs, size_t n); /// ditto

40
lphobos/std/c/string.d Normal file
View File

@@ -0,0 +1,40 @@
/**
* C's &lt;string.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCString
*/
module std.c.string;
extern (C):
void* memcpy(void* s1, void* s2, size_t n); ///
void* memmove(void* s1, void* s2, size_t n); ///
char* strcpy(char* s1, char* s2); ///
char* strncpy(char* s1, char* s2, size_t n); ///
char* strncat(char* s1, char* s2, size_t n); ///
int strcoll(char* s1, char* s2); ///
int strncmp(char* s1, char* s2, size_t n); ///
size_t strxfrm(char* s1, char* s2, size_t n); ///
void* memchr(void* s, int c, size_t n); ///
char* strchr(char* s, int c); ///
size_t strcspn(char* s1, char* s2); ///
char* strpbrk(char* s1, char* s2); ///
char* strrchr(char* s, int c); ///
size_t strspn(char* s1, char* s2); ///
char* strstr(char* s1, char* s2); ///
char* strtok(char* s1, char* s2); ///
void* memset(void* s, int c, size_t n); ///
char* strerror(int errnum); ///
size_t strlen(char* s); ///
int strcmp(char* s1, char* s2); ///
char* strcat(char* s1, char* s2); ///
int memcmp(void* s1, void* s2, size_t n); ///
version (Windows)
{
int memicmp(char* s1, char* s2, size_t n); ///
}

94
lphobos/std/c/time.d Normal file
View File

@@ -0,0 +1,94 @@
/**
* C's &lt;time.h&gt;
* Authors: Walter Bright, Digital Mars, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCTime
*/
module std.c.time;
private import std.c.stddef;
extern (C):
alias int clock_t;
version (Windows)
{ const clock_t CLOCKS_PER_SEC = 1000;
}
else version (linux)
{ const clock_t CLOCKS_PER_SEC = 1000000;
}
else version (darwin)
{
const clock_t CLOCKS_PER_SEC = 100;
}
else
{
static assert(0);
}
version (Windows)
{
const clock_t CLK_TCK = 1000;
}
else version (linux)
{
extern (C) int sysconf(int);
extern clock_t CLK_TCK;
/*static this()
{
CLK_TCK = cast(clock_t) sysconf(2);
}*/
}
else
{
static assert(0);
}
const uint TIMEOFFSET = 315558000;
alias int time_t;
extern int daylight;
extern int timezone;
extern int altzone;
extern char *tzname[2];
struct tm
{ int tm_sec,
tm_min,
tm_hour,
tm_mday,
tm_mon,
tm_year,
tm_wday,
tm_yday,
tm_isdst;
}
clock_t clock();
time_t time(time_t *);
time_t mktime(tm *);
char *asctime(tm *);
char *ctime(time_t *);
tm *localtime(time_t *);
tm *gmtime(time_t *);
size_t strftime(char *, size_t, char *, tm *);
char *_strdate(char *dstring);
char *_strtime(char *timestr);
double difftime(time_t t1, time_t t2);
void _tzset();
void tzset();
void sleep(time_t);
void usleep(uint);
void msleep(uint);
wchar_t *_wasctime(tm *);
wchar_t *_wctime(time_t *);
size_t wcsftime(wchar_t *, size_t, wchar_t *, tm *);
wchar_t *_wstrdate(wchar_t *);
wchar_t *_wstrtime(wchar_t *);

265
lphobos/std/intrinsic.d Normal file
View File

@@ -0,0 +1,265 @@
// written by Walter Bright
// www.digitalmars.com
// Placed into the public domain
/* NOTE: This file has been patched from the original DMD distribution to
work with the GDC compiler.
NOTE: This file has been patched from the original GDC distribution to
work with the LLVMDC compiler.
Modified by David Friedman, May 2006
Modified by Tomas Lindquist Olsen, August 2007
*/
/** These functions are built-in intrinsics to the compiler.
*
Intrinsic functions are functions built in to the compiler,
usually to take advantage of specific CPU features that
are inefficient to handle via external functions.
The compiler's optimizer and code generator are fully
integrated in with intrinsic functions, bringing to bear
their full power on them.
This can result in some surprising speedups.
* Macros:
* WIKI=Phobos/StdIntrinsic
*/
module std.intrinsic;
/**
* Scans the bits in v starting with bit 0, looking
* for the first set bit.
* Returns:
* The bit number of the first bit set.
* The return value is undefined if v is zero.
*/
version (LLVM)
int bsf(uint v)
{
uint m = 1;
uint i;
for (i = 0; i < 32; i++,m<<=1) {
if (v&m)
return i;
}
return i; // supposed to be undefined
}
else
int bsf(uint v);
/**
* Scans the bits in v from the most significant bit
* to the least significant bit, looking
* for the first set bit.
* Returns:
* The bit number of the first bit set.
* The return value is undefined if v is zero.
* Example:
* ---
* import std.intrinsic;
*
* int main()
* {
* uint v;
* int x;
*
* v = 0x21;
* x = bsf(v);
* printf("bsf(x%x) = %d\n", v, x);
* x = bsr(v);
* printf("bsr(x%x) = %d\n", v, x);
* return 0;
* }
* ---
* Output:
* bsf(x21) = 0<br>
* bsr(x21) = 5
*/
version (LLVM)
int bsr(uint v)
{
uint m = 0x80000000;
uint i;
for (i = 32; i ; i--,m>>>=1) {
if (v&m)
return i-1;
}
return i; // supposed to be undefined
}
else
int bsr(uint v);
/**
* Tests the bit.
*/
version (LLVM)
int bt(uint *p, uint bitnum)
{
return (p[bitnum / (uint.sizeof*8)] & (1<<(bitnum & ((uint.sizeof*8)-1)))) ? -1 : 0 ;
}
else
int bt(uint *p, uint bitnum);
/**
* Tests and complements the bit.
*/
version (LLVM)
int btc(uint *p, uint bitnum)
{
uint * q = p + (bitnum / (uint.sizeof*8));
uint mask = 1 << (bitnum & ((uint.sizeof*8) - 1));
int result = *q & mask;
*q ^= mask;
return result ? -1 : 0;
}
else
int btc(uint *p, uint bitnum);
/**
* Tests and resets (sets to 0) the bit.
*/
version (LLVM)
int btr(uint *p, uint bitnum)
{
uint * q = p + (bitnum / (uint.sizeof*8));
uint mask = 1 << (bitnum & ((uint.sizeof*8) - 1));
int result = *q & mask;
*q &= ~mask;
return result ? -1 : 0;
}
else
int btr(uint *p, uint bitnum);
/**
* Tests and sets the bit.
* Params:
* p = a non-NULL pointer to an array of uints.
* index = a bit number, starting with bit 0 of p[0],
* and progressing. It addresses bits like the expression:
---
p[index / (uint.sizeof*8)] & (1 << (index & ((uint.sizeof*8) - 1)))
---
* Returns:
* A non-zero value if the bit was set, and a zero
* if it was clear.
*
* Example:
* ---
import std.intrinsic;
int main()
{
uint array[2];
array[0] = 2;
array[1] = 0x100;
printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35));
printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35));
printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
printf("bts(array, 35) = %d\n", <b>bts</b>(array, 35));
printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
printf("btr(array, 35) = %d\n", <b>btr</b>(array, 35));
printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
printf("bt(array, 1) = %d\n", <b>bt</b>(array, 1));
printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
return 0;
}
* ---
* Output:
<pre>
btc(array, 35) = 0
array = [0]:x2, [1]:x108
btc(array, 35) = -1
array = [0]:x2, [1]:x100
bts(array, 35) = 0
array = [0]:x2, [1]:x108
btr(array, 35) = -1
array = [0]:x2, [1]:x100
bt(array, 1) = -1
array = [0]:x2, [1]:x100
</pre>
*/
version (LLVM)
int bts(uint *p, uint bitnum)
{
uint * q = p + (bitnum / (uint.sizeof*8));
uint mask = 1 << (bitnum & ((uint.sizeof*8) - 1));
int result = *q & mask;
*q |= mask;
return result ? -1 : 0;
}
else
int bts(uint *p, uint bitnum);
/**
* Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes
byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3
becomes byte 0.
*/
version (LLVM)
pragma(LLVM_internal, "intrinsic", "llvm.bswap.i32.i32")
uint bswap(uint val);
else
uint bswap(uint v);
/**
* Reads I/O port at port_address.
*/
version (LLVM)
ubyte inp(uint p) { return 0; }
else
ubyte inp(uint port_address);
/**
* ditto
*/
version (LLVM)
ushort inpw(uint p) { return 0; }
else
ushort inpw(uint port_address);
/**
* ditto
*/
version (LLVM)
uint inpl(uint p) { return 0; }
else
uint inpl(uint port_address);
/**
* Writes and returns value to I/O port at port_address.
*/
version (LLVM)
ubyte outp(uint p, ubyte v) { return v; }
else
ubyte outp(uint port_address, ubyte value);
/**
* ditto
*/
version (LLVM)
ushort outpw(uint p, ushort v) { return v; }
else
ushort outpw(uint port_address, ushort value);
/**
* ditto
*/
version (LLVM)
uint outpl(uint p, uint v) { return v; }
else
uint outpl(uint port_address, uint value);

177
lphobos/std/stdint.d Normal file
View File

@@ -0,0 +1,177 @@
/**
*
D constrains integral types to specific sizes. But efficiency
of different sizes varies from machine to machine,
pointer sizes vary, and the maximum integer size varies.
<b>stdint</b> offers a portable way of trading off size
vs efficiency, in a manner compatible with the <tt>stdint.h</tt>
definitions in C.
The exact aliases are types of exactly the specified number of bits.
The at least aliases are at least the specified number of bits
large, and can be larger.
The fast aliases are the fastest integral type supported by the
processor that is at least as wide as the specified number of bits.
The aliases are:
<table border=1 cellspacing=0 cellpadding=5>
<th>Exact Alias
<th>Description
<th>At Least Alias
<th>Description
<th>Fast Alias
<th>Description
<tr>
<td>int8_t
<td>exactly 8 bits signed
<td>int_least8_t
<td>at least 8 bits signed
<td>int_fast8_t
<td>fast 8 bits signed
<tr>
<td>uint8_t
<td>exactly 8 bits unsigned
<td>uint_least8_t
<td>at least 8 bits unsigned
<td>uint_fast8_t
<td>fast 8 bits unsigned
<tr>
<td>int16_t
<td>exactly 16 bits signed
<td>int_least16_t
<td>at least 16 bits signed
<td>int_fast16_t
<td>fast 16 bits signed
<tr>
<td>uint16_t
<td>exactly 16 bits unsigned
<td>uint_least16_t
<td>at least 16 bits unsigned
<td>uint_fast16_t
<td>fast 16 bits unsigned
<tr>
<td>int32_t
<td>exactly 32 bits signed
<td>int_least32_t
<td>at least 32 bits signed
<td>int_fast32_t
<td>fast 32 bits signed
<tr>
<td>uint32_t
<td>exactly 32 bits unsigned
<td>uint_least32_t
<td>at least 32 bits unsigned
<td>uint_fast32_t
<td>fast 32 bits unsigned
<tr>
<td>int64_t
<td>exactly 64 bits signed
<td>int_least64_t
<td>at least 64 bits signed
<td>int_fast64_t
<td>fast 64 bits signed
<tr>
<td>uint64_t
<td>exactly 64 bits unsigned
<td>uint_least64_t
<td>at least 64 bits unsigned
<td>uint_fast64_t
<td>fast 64 bits unsigned
</table>
The ptr aliases are integral types guaranteed to be large enough
to hold a pointer without losing bits:
<table border=1 cellspacing=0 cellpadding=5>
<th>Alias
<th>Description
<tr>
<td>intptr_t
<td>signed integral type large enough to hold a pointer
<tr>
<td>uintptr_t
<td>unsigned integral type large enough to hold a pointer
</table>
The max aliases are the largest integral types:
<table border=1 cellspacing=0 cellpadding=5>
<th>Alias
<th>Description
<tr>
<td>intmax_t
<td>the largest signed integral type
<tr>
<td>uintmax_t
<td>the largest unsigned integral type
</table>
* Authors: Walter Bright, www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdStdint
*/
/*
NOTE: This file has been patched from the original DMD distribution to
work with the LLVMDC compiler.
Modified by Tomas Lindquist Olsen, August 2007
*/
module std.stdint;
/* Exact sizes */
alias byte int8_t;
alias ubyte uint8_t;
alias short int16_t;
alias ushort uint16_t;
alias int int32_t;
alias uint uint32_t;
alias long int64_t;
alias ulong uint64_t;
/* At least sizes */
alias byte int_least8_t;
alias ubyte uint_least8_t;
alias short int_least16_t;
alias ushort uint_least16_t;
alias int int_least32_t;
alias uint uint_least32_t;
alias long int_least64_t;
alias ulong uint_least64_t;
/* Fastest minimum width sizes */
alias byte int_fast8_t;
alias ubyte uint_fast8_t;
alias int int_fast16_t;
alias uint uint_fast16_t;
alias int int_fast32_t;
alias uint uint_fast32_t;
alias long int_fast64_t;
alias ulong uint_fast64_t;
/* Integer pointer holders */
version(LLVM64) {
alias long intptr_t;
alias ulong uintptr_t;
}
else {
alias int intptr_t;
alias uint uintptr_t;
}
/* Greatest width integer types */
alias long intmax_t;
alias ulong uintmax_t;

View File

@@ -0,0 +1,111 @@
module std.typeinfo.ti_Aint;
private import std.c.string;
// int[]
class TypeInfo_Ai : TypeInfo
{
char[] toString() { return "int[]"; }
hash_t getHash(void *p)
{ int[] s = *cast(int[]*)p;
auto len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += *cast(uint *)str;
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
int[] s1 = *cast(int[]*)p1;
int[] s2 = *cast(int[]*)p2;
return s1.length == s2.length &&
memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0;
}
int compare(void *p1, void *p2)
{
int[] s1 = *cast(int[]*)p1;
int[] s2 = *cast(int[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (int[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(int);
}
}
// uint[]
class TypeInfo_Ak : TypeInfo_Ai
{
char[] toString() { return "uint[]"; }
int compare(void *p1, void *p2)
{
uint[] s1 = *cast(uint[]*)p1;
uint[] s2 = *cast(uint[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
TypeInfo next()
{
return typeid(uint);
}
}
// dchar[]
class TypeInfo_Aw : TypeInfo_Ak
{
char[] toString() { return "dchar[]"; }
TypeInfo next()
{
return typeid(dchar);
}
}

View File

@@ -0,0 +1,39 @@
// byte
module std.typeinfo.ti_byte;
class TypeInfo_g : TypeInfo
{
char[] toString() { return "byte"; }
hash_t getHash(void *p)
{
return *cast(byte *)p;
}
int equals(void *p1, void *p2)
{
return *cast(byte *)p1 == *cast(byte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(byte *)p1 - *cast(byte *)p2;
}
size_t tsize()
{
return byte.sizeof;
}
void swap(void *p1, void *p2)
{
byte t;
t = *cast(byte *)p1;
*cast(byte *)p1 = *cast(byte *)p2;
*cast(byte *)p2 = t;
}
}

View File

@@ -0,0 +1,43 @@
module std.typeinfo.ti_char;
class TypeInfo_a : TypeInfo
{
char[] toString() { return "char"; }
hash_t getHash(void *p)
{
return *cast(char *)p;
}
int equals(void *p1, void *p2)
{
return *cast(char *)p1 == *cast(char *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(char *)p1 - *cast(char *)p2;
}
size_t tsize()
{
return char.sizeof;
}
void swap(void *p1, void *p2)
{
char t;
t = *cast(char *)p1;
*cast(char *)p1 = *cast(char *)p2;
*cast(char *)p2 = t;
}
void[] init()
{ static char c;
return (cast(char *)&c)[0 .. 1];
}
}

View File

@@ -0,0 +1,43 @@
// int
module std.typeinfo.ti_int;
class TypeInfo_i : TypeInfo
{
char[] toString() { return "int"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
int equals(void *p1, void *p2)
{
return *cast(uint *)p1 == *cast(uint *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(int*) p1 < *cast(int*) p2)
return -1;
else if (*cast(int*) p1 > *cast(int*) p2)
return 1;
return 0;
}
size_t tsize()
{
return int.sizeof;
}
void swap(void *p1, void *p2)
{
int t;
t = *cast(int *)p1;
*cast(int *)p1 = *cast(int *)p2;
*cast(int *)p2 = t;
}
}

View File

@@ -0,0 +1,42 @@
// pointer
module std.typeinfo.ti_ptr;
class TypeInfo_P : TypeInfo
{
hash_t getHash(void *p)
{
return cast(uint)*cast(void* *)p;
}
int equals(void *p1, void *p2)
{
return *cast(void* *)p1 == *cast(void* *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(void* *)p1 - *cast(void* *)p2;
}
size_t tsize()
{
return (void*).sizeof;
}
void swap(void *p1, void *p2)
{
void* t;
t = *cast(void* *)p1;
*cast(void* *)p1 = *cast(void* *)p2;
*cast(void* *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,39 @@
// short
module std.typeinfo.ti_short;
class TypeInfo_s : TypeInfo
{
char[] toString() { return "short"; }
hash_t getHash(void *p)
{
return *cast(short *)p;
}
int equals(void *p1, void *p2)
{
return *cast(short *)p1 == *cast(short *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(short *)p1 - *cast(short *)p2;
}
size_t tsize()
{
return short.sizeof;
}
void swap(void *p1, void *p2)
{
short t;
t = *cast(short *)p1;
*cast(short *)p1 = *cast(short *)p2;
*cast(short *)p2 = t;
}
}

View File

@@ -0,0 +1,43 @@
// ubyte
module std.typeinfo.ti_ubyte;
class TypeInfo_h : TypeInfo
{
char[] toString() { return "ubyte"; }
hash_t getHash(void *p)
{
return *cast(ubyte *)p;
}
int equals(void *p1, void *p2)
{
return *cast(ubyte *)p1 == *cast(ubyte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(ubyte *)p1 - *cast(ubyte *)p2;
}
size_t tsize()
{
return ubyte.sizeof;
}
void swap(void *p1, void *p2)
{
ubyte t;
t = *cast(ubyte *)p1;
*cast(ubyte *)p1 = *cast(ubyte *)p2;
*cast(ubyte *)p2 = t;
}
}
class TypeInfo_b : TypeInfo_h
{
char[] toString() { return "bool"; }
}

View File

@@ -0,0 +1,43 @@
// uint
module std.typeinfo.ti_uint;
class TypeInfo_k : TypeInfo
{
char[] toString() { return "uint"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
int equals(void *p1, void *p2)
{
return *cast(uint *)p1 == *cast(uint *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(uint*) p1 < *cast(uint*) p2)
return -1;
else if (*cast(uint*) p1 > *cast(uint*) p2)
return 1;
return 0;
}
size_t tsize()
{
return uint.sizeof;
}
void swap(void *p1, void *p2)
{
int t;
t = *cast(uint *)p1;
*cast(uint *)p1 = *cast(uint *)p2;
*cast(uint *)p2 = t;
}
}

View File

@@ -0,0 +1,39 @@
// ushort
module std.typeinfo.ti_ushort;
class TypeInfo_t : TypeInfo
{
char[] toString() { return "ushort"; }
hash_t getHash(void *p)
{
return *cast(ushort *)p;
}
int equals(void *p1, void *p2)
{
return *cast(ushort *)p1 == *cast(ushort *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(ushort *)p1 - *cast(ushort *)p2;
}
size_t tsize()
{
return ushort.sizeof;
}
void swap(void *p1, void *p2)
{
ushort t;
t = *cast(ushort *)p1;
*cast(ushort *)p1 = *cast(ushort *)p2;
*cast(ushort *)p2 = t;
}
}

View File

@@ -0,0 +1,92 @@
module std.typeinfo.ti_AC;
// Object[]
class TypeInfo_AC : TypeInfo
{
hash_t getHash(void *p)
{ Object[] s = *cast(Object[]*)p;
hash_t hash = 0;
foreach (Object o; s)
{
if (o)
hash += o.toHash();
}
return hash;
}
int equals(void *p1, void *p2)
{
Object[] s1 = *cast(Object[]*)p1;
Object[] s2 = *cast(Object[]*)p2;
if (s1.length == s2.length)
{
for (size_t u = 0; u < s1.length; u++)
{ Object o1 = s1[u];
Object o2 = s2[u];
// Do not pass null's to Object.opEquals()
if (o1 is o2 ||
(!(o1 is null) && !(o2 is null) && o1.opEquals(o2)))
continue;
return 0;
}
return 1;
}
return 0;
}
int compare(void *p1, void *p2)
{
Object[] s1 = *cast(Object[]*)p1;
Object[] s2 = *cast(Object[]*)p2;
int c;
c = cast(int)s1.length - cast(int)s2.length;
if (c == 0)
{
for (size_t u = 0; u < s1.length; u++)
{ Object o1 = s1[u];
Object o2 = s2[u];
if (o1 is o2)
continue;
// Regard null references as always being "less than"
if (o1)
{
if (!o2)
{ c = 1;
break;
}
c = o1.opCmp(o2);
if (c)
break;
}
else
{ c = -1;
break;
}
}
}
return c;
}
size_t tsize()
{
return (Object[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(Object);
}
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Acdouble;
private import std.typeinfo.ti_cdouble;
// cdouble[]
class TypeInfo_Ar : TypeInfo
{
char[] toString() { return "cdouble[]"; }
hash_t getHash(void *p)
{ cdouble[] s = *cast(cdouble[]*)p;
size_t len = s.length;
cdouble *str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += (cast(uint *)str)[0];
hash += (cast(uint *)str)[1];
hash += (cast(uint *)str)[2];
hash += (cast(uint *)str)[3];
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
cdouble[] s1 = *cast(cdouble[]*)p1;
cdouble[] s2 = *cast(cdouble[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_r._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
cdouble[] s1 = *cast(cdouble[]*)p1;
cdouble[] s2 = *cast(cdouble[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_r._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (cdouble[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(cdouble);
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Acfloat;
private import std.typeinfo.ti_cfloat;
// cfloat[]
class TypeInfo_Aq : TypeInfo
{
char[] toString() { return "cfloat[]"; }
hash_t getHash(void *p)
{ cfloat[] s = *cast(cfloat[]*)p;
size_t len = s.length;
cfloat *str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += (cast(uint *)str)[0];
hash += (cast(uint *)str)[1];
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
cfloat[] s1 = *cast(cfloat[]*)p1;
cfloat[] s2 = *cast(cfloat[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_q._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
cfloat[] s1 = *cast(cfloat[]*)p1;
cfloat[] s2 = *cast(cfloat[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_q._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (cfloat[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(cfloat);
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Acreal;
private import std.typeinfo.ti_creal;
// creal[]
class TypeInfo_Ac : TypeInfo
{
char[] toString() { return "creal[]"; }
hash_t getHash(void *p)
{ creal[] s = *cast(creal[]*)p;
size_t len = s.length;
creal *str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += (cast(uint *)str)[0];
hash += (cast(uint *)str)[1];
hash += (cast(uint *)str)[2];
hash += (cast(uint *)str)[3];
hash += (cast(uint *)str)[4];
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
creal[] s1 = *cast(creal[]*)p1;
creal[] s2 = *cast(creal[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_c._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
creal[] s1 = *cast(creal[]*)p1;
creal[] s2 = *cast(creal[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_c._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (creal[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(creal);
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Adouble;
private import std.typeinfo.ti_double;
// double[]
class TypeInfo_Ad : TypeInfo
{
char[] toString() { return "double[]"; }
hash_t getHash(void *p)
{ double[] s = *cast(double[]*)p;
size_t len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += (cast(uint *)str)[0];
hash += (cast(uint *)str)[1];
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
double[] s1 = *cast(double[]*)p1;
double[] s2 = *cast(double[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_d._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
double[] s1 = *cast(double[]*)p1;
double[] s2 = *cast(double[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_d._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (double[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(double);
}
}
// idouble[]
class TypeInfo_Ap : TypeInfo_Ad
{
char[] toString() { return "idouble[]"; }
TypeInfo next()
{
return typeid(idouble);
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Afloat;
private import std.typeinfo.ti_float;
// float[]
class TypeInfo_Af : TypeInfo
{
char[] toString() { return "float[]"; }
hash_t getHash(void *p)
{ float[] s = *cast(float[]*)p;
size_t len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += *cast(uint *)str;
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
float[] s1 = *cast(float[]*)p1;
float[] s2 = *cast(float[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_f._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
float[] s1 = *cast(float[]*)p1;
float[] s2 = *cast(float[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_f._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (float[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(float);
}
}
// ifloat[]
class TypeInfo_Ao : TypeInfo_Af
{
char[] toString() { return "ifloat[]"; }
TypeInfo next()
{
return typeid(ifloat);
}
}

View File

@@ -0,0 +1,202 @@
module std.typeinfo.ti_Ag;
private import std.string;
private import std.c.string;
// byte[]
class TypeInfo_Ag : TypeInfo
{
char[] toString() { return "byte[]"; }
hash_t getHash(void *p)
{ byte[] s = *cast(byte[]*)p;
size_t len = s.length;
byte *str = s.ptr;
hash_t hash = 0;
while (1)
{
switch (len)
{
case 0:
return hash;
case 1:
hash *= 9;
hash += *cast(ubyte *)str;
return hash;
case 2:
hash *= 9;
hash += *cast(ushort *)str;
return hash;
case 3:
hash *= 9;
hash += (*cast(ushort *)str << 8) +
(cast(ubyte *)str)[2];
return hash;
default:
hash *= 9;
hash += *cast(uint *)str;
str += 4;
len -= 4;
break;
}
}
return hash;
}
int equals(void *p1, void *p2)
{
byte[] s1 = *cast(byte[]*)p1;
byte[] s2 = *cast(byte[]*)p2;
return s1.length == s2.length &&
memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0;
}
int compare(void *p1, void *p2)
{
byte[] s1 = *cast(byte[]*)p1;
byte[] s2 = *cast(byte[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (byte[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(byte);
}
}
// ubyte[]
class TypeInfo_Ah : TypeInfo_Ag
{
char[] toString() { return "ubyte[]"; }
int compare(void *p1, void *p2)
{
char[] s1 = *cast(char[]*)p1;
char[] s2 = *cast(char[]*)p2;
return std.string.cmp(s1, s2);
}
TypeInfo next()
{
return typeid(ubyte);
}
}
// void[]
class TypeInfo_Av : TypeInfo_Ah
{
char[] toString() { return "void[]"; }
TypeInfo next()
{
return typeid(void);
}
}
// bool[]
class TypeInfo_Ab : TypeInfo_Ah
{
char[] toString() { return "bool[]"; }
TypeInfo next()
{
return typeid(bool);
}
}
// char[]
class TypeInfo_Aa : TypeInfo_Ag
{
char[] toString() { return "char[]"; }
hash_t getHash(void *p)
{ char[] s = *cast(char[]*)p;
hash_t hash = 0;
version (all)
{
foreach (char c; s)
hash = hash * 11 + c;
}
else
{
size_t len = s.length;
char *str = s;
while (1)
{
switch (len)
{
case 0:
return hash;
case 1:
hash *= 9;
hash += *cast(ubyte *)str;
return hash;
case 2:
hash *= 9;
hash += *cast(ushort *)str;
return hash;
case 3:
hash *= 9;
hash += (*cast(ushort *)str << 8) +
(cast(ubyte *)str)[2];
return hash;
default:
hash *= 9;
hash += *cast(uint *)str;
str += 4;
len -= 4;
break;
}
}
}
return hash;
}
TypeInfo next()
{
return typeid(char);
}
}

View File

@@ -0,0 +1,111 @@
module std.typeinfo.ti_Aint;
private import std.c.string;
// int[]
class TypeInfo_Ai : TypeInfo
{
char[] toString() { return "int[]"; }
hash_t getHash(void *p)
{ int[] s = *cast(int[]*)p;
auto len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += *cast(uint *)str;
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
int[] s1 = *cast(int[]*)p1;
int[] s2 = *cast(int[]*)p2;
return s1.length == s2.length &&
memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0;
}
int compare(void *p1, void *p2)
{
int[] s1 = *cast(int[]*)p1;
int[] s2 = *cast(int[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (int[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(int);
}
}
// uint[]
class TypeInfo_Ak : TypeInfo_Ai
{
char[] toString() { return "uint[]"; }
int compare(void *p1, void *p2)
{
uint[] s1 = *cast(uint[]*)p1;
uint[] s2 = *cast(uint[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
TypeInfo next()
{
return typeid(uint);
}
}
// dchar[]
class TypeInfo_Aw : TypeInfo_Ak
{
char[] toString() { return "dchar[]"; }
TypeInfo next()
{
return typeid(dchar);
}
}

View File

@@ -0,0 +1,103 @@
module std.typeinfo.ti_Along;
private import std.c.string;
// long[]
class TypeInfo_Al : TypeInfo
{
char[] toString() { return "long[]"; }
hash_t getHash(void *p)
{ long[] s = *cast(long[]*)p;
size_t len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += *cast(uint *)str + *(cast(uint *)str + 1);
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
long[] s1 = *cast(long[]*)p1;
long[] s2 = *cast(long[]*)p2;
return s1.length == s2.length &&
memcmp(cast(void *)s1, cast(void *)s2, s1.length * long.sizeof) == 0;
}
int compare(void *p1, void *p2)
{
long[] s1 = *cast(long[]*)p1;
long[] s2 = *cast(long[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
if (s1[u] < s2[u])
return -1;
else if (s1[u] > s2[u])
return 1;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (long[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(long);
}
}
// ulong[]
class TypeInfo_Am : TypeInfo_Al
{
char[] toString() { return "ulong[]"; }
int compare(void *p1, void *p2)
{
ulong[] s1 = *cast(ulong[]*)p1;
ulong[] s2 = *cast(ulong[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
if (s1[u] < s2[u])
return -1;
else if (s1[u] > s2[u])
return 1;
}
return cast(int)s1.length - cast(int)s2.length;
}
TypeInfo next()
{
return typeid(ulong);
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_Areal;
private import std.typeinfo.ti_real;
// real[]
class TypeInfo_Ae : TypeInfo
{
char[] toString() { return "real[]"; }
hash_t getHash(void *p)
{ real[] s = *cast(real[]*)p;
size_t len = s.length;
auto str = s.ptr;
hash_t hash = 0;
while (len)
{
hash *= 9;
hash += (cast(uint *)str)[0];
hash += (cast(uint *)str)[1];
hash += (cast(ushort *)str)[4];
str++;
len--;
}
return hash;
}
int equals(void *p1, void *p2)
{
real[] s1 = *cast(real[]*)p1;
real[] s2 = *cast(real[]*)p2;
size_t len = s1.length;
if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_e._equals(s1[u], s2[u]);
if (c == 0)
return 0;
}
return 1;
}
int compare(void *p1, void *p2)
{
real[] s1 = *cast(real[]*)p1;
real[] s2 = *cast(real[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_e._compare(s1[u], s2[u]);
if (c)
return c;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (real[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(real);
}
}
// ireal[]
class TypeInfo_Aj : TypeInfo_Ae
{
char[] toString() { return "ireal[]"; }
TypeInfo next()
{
return typeid(ireal);
}
}

View File

@@ -0,0 +1,126 @@
module std.typeinfo.ti_Ashort;
private import std.c.string;
// short[]
class TypeInfo_As : TypeInfo
{
char[] toString() { return "short[]"; }
hash_t getHash(void *p)
{ short[] s = *cast(short[]*)p;
size_t len = s.length;
short *str = s.ptr;
hash_t hash = 0;
while (1)
{
switch (len)
{
case 0:
return hash;
case 1:
hash *= 9;
hash += *cast(ushort *)str;
return hash;
default:
hash *= 9;
hash += *cast(uint *)str;
str += 2;
len -= 2;
break;
}
}
return hash;
}
int equals(void *p1, void *p2)
{
short[] s1 = *cast(short[]*)p1;
short[] s2 = *cast(short[]*)p2;
return s1.length == s2.length &&
memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
}
int compare(void *p1, void *p2)
{
short[] s1 = *cast(short[]*)p1;
short[] s2 = *cast(short[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
size_t tsize()
{
return (short[]).sizeof;
}
uint flags()
{
return 1;
}
TypeInfo next()
{
return typeid(short);
}
}
// ushort[]
class TypeInfo_At : TypeInfo_As
{
char[] toString() { return "ushort[]"; }
int compare(void *p1, void *p2)
{
ushort[] s1 = *cast(ushort[]*)p1;
ushort[] s2 = *cast(ushort[]*)p2;
size_t len = s1.length;
if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
return cast(int)s1.length - cast(int)s2.length;
}
TypeInfo next()
{
return typeid(ushort);
}
}
// wchar[]
class TypeInfo_Au : TypeInfo_At
{
char[] toString() { return "wchar[]"; }
TypeInfo next()
{
return typeid(wchar);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, in both source and binary form, subject to the following
* restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
module std.typeinfo.ti_C;
// Object
class TypeInfo_C : TypeInfo
{
hash_t getHash(void *p)
{
Object o = *cast(Object*)p;
assert(o);
return o.toHash();
}
int equals(void *p1, void *p2)
{
Object o1 = *cast(Object*)p1;
Object o2 = *cast(Object*)p2;
return o1 == o2;
}
int compare(void *p1, void *p2)
{
Object o1 = *cast(Object*)p1;
Object o2 = *cast(Object*)p2;
int c = 0;
// Regard null references as always being "less than"
if (!(o1 is o2))
{
if (o1)
{ if (!o2)
c = 1;
else
c = o1.opCmp(o2);
}
else
c = -1;
}
return c;
}
size_t tsize()
{
return Object.sizeof;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,39 @@
// byte
module std.typeinfo.ti_byte;
class TypeInfo_g : TypeInfo
{
char[] toString() { return "byte"; }
hash_t getHash(void *p)
{
return *cast(byte *)p;
}
int equals(void *p1, void *p2)
{
return *cast(byte *)p1 == *cast(byte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(byte *)p1 - *cast(byte *)p2;
}
size_t tsize()
{
return byte.sizeof;
}
void swap(void *p1, void *p2)
{
byte t;
t = *cast(byte *)p1;
*cast(byte *)p1 = *cast(byte *)p2;
*cast(byte *)p2 = t;
}
}

View File

@@ -0,0 +1,67 @@
// cdouble
module std.typeinfo.ti_cdouble;
class TypeInfo_r : TypeInfo
{
char[] toString() { return "cdouble"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1] +
(cast(uint *)p)[2] + (cast(uint *)p)[3];
}
static int _equals(cdouble f1, cdouble f2)
{
return f1 == f2;
}
static int _compare(cdouble f1, cdouble f2)
{ int result;
if (f1.re < f2.re)
result = -1;
else if (f1.re > f2.re)
result = 1;
else if (f1.im < f2.im)
result = -1;
else if (f1.im > f2.im)
result = 1;
else
result = 0;
return result;
}
int equals(void *p1, void *p2)
{
return _equals(*cast(cdouble *)p1, *cast(cdouble *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(cdouble *)p1, *cast(cdouble *)p2);
}
size_t tsize()
{
return cdouble.sizeof;
}
void swap(void *p1, void *p2)
{
cdouble t;
t = *cast(cdouble *)p1;
*cast(cdouble *)p1 = *cast(cdouble *)p2;
*cast(cdouble *)p2 = t;
}
void[] init()
{ static cdouble r;
return (cast(cdouble *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,66 @@
// cfloat
module std.typeinfo.ti_cfloat;
class TypeInfo_q : TypeInfo
{
char[] toString() { return "cfloat"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1];
}
static int _equals(cfloat f1, cfloat f2)
{
return f1 == f2;
}
static int _compare(cfloat f1, cfloat f2)
{ int result;
if (f1.re < f2.re)
result = -1;
else if (f1.re > f2.re)
result = 1;
else if (f1.im < f2.im)
result = -1;
else if (f1.im > f2.im)
result = 1;
else
result = 0;
return result;
}
int equals(void *p1, void *p2)
{
return _equals(*cast(cfloat *)p1, *cast(cfloat *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(cfloat *)p1, *cast(cfloat *)p2);
}
size_t tsize()
{
return cfloat.sizeof;
}
void swap(void *p1, void *p2)
{
cfloat t;
t = *cast(cfloat *)p1;
*cast(cfloat *)p1 = *cast(cfloat *)p2;
*cast(cfloat *)p2 = t;
}
void[] init()
{ static cfloat r;
return (cast(cfloat *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,43 @@
module std.typeinfo.ti_char;
class TypeInfo_a : TypeInfo
{
char[] toString() { return "char"; }
hash_t getHash(void *p)
{
return *cast(char *)p;
}
int equals(void *p1, void *p2)
{
return *cast(char *)p1 == *cast(char *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(char *)p1 - *cast(char *)p2;
}
size_t tsize()
{
return char.sizeof;
}
void swap(void *p1, void *p2)
{
char t;
t = *cast(char *)p1;
*cast(char *)p1 = *cast(char *)p2;
*cast(char *)p2 = t;
}
void[] init()
{ static char c;
return (cast(char *)&c)[0 .. 1];
}
}

View File

@@ -0,0 +1,68 @@
// creal
module std.typeinfo.ti_creal;
class TypeInfo_c : TypeInfo
{
char[] toString() { return "creal"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1] +
(cast(uint *)p)[2] + (cast(uint *)p)[3] +
(cast(uint *)p)[4];
}
static int _equals(creal f1, creal f2)
{
return f1 == f2;
}
static int _compare(creal f1, creal f2)
{ int result;
if (f1.re < f2.re)
result = -1;
else if (f1.re > f2.re)
result = 1;
else if (f1.im < f2.im)
result = -1;
else if (f1.im > f2.im)
result = 1;
else
result = 0;
return result;
}
int equals(void *p1, void *p2)
{
return _equals(*cast(creal *)p1, *cast(creal *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(creal *)p1, *cast(creal *)p2);
}
size_t tsize()
{
return creal.sizeof;
}
void swap(void *p1, void *p2)
{
creal t;
t = *cast(creal *)p1;
*cast(creal *)p1 = *cast(creal *)p2;
*cast(creal *)p2 = t;
}
void[] init()
{ static creal r;
return (cast(creal *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,45 @@
// dchar
module std.typeinfo.ti_dchar;
class TypeInfo_w : TypeInfo
{
char[] toString() { return "dchar"; }
hash_t getHash(void *p)
{
return *cast(dchar *)p;
}
int equals(void *p1, void *p2)
{
return *cast(dchar *)p1 == *cast(dchar *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(dchar *)p1 - *cast(dchar *)p2;
}
size_t tsize()
{
return dchar.sizeof;
}
void swap(void *p1, void *p2)
{
dchar t;
t = *cast(dchar *)p1;
*cast(dchar *)p1 = *cast(dchar *)p2;
*cast(dchar *)p2 = t;
}
void[] init()
{ static dchar c;
return (cast(dchar *)&c)[0 .. 1];
}
}

View File

@@ -0,0 +1,40 @@
// delegate
module std.typeinfo.ti_delegate;
alias void delegate(int) dg;
class TypeInfo_D : TypeInfo
{
hash_t getHash(void *p)
{ long l = *cast(long *)p;
return cast(uint)(l + (l >> 32));
}
int equals(void *p1, void *p2)
{
return *cast(dg *)p1 == *cast(dg *)p2;
}
size_t tsize()
{
return dg.sizeof;
}
void swap(void *p1, void *p2)
{
dg t;
t = *cast(dg *)p1;
*cast(dg *)p1 = *cast(dg *)p2;
*cast(dg *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,67 @@
// double
module std.typeinfo.ti_double;
private import std.math;
class TypeInfo_d : TypeInfo
{
char[] toString() { return "double"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1];
}
static int _equals(double f1, double f2)
{
return f1 == f2 ||
(isnan(f1) && isnan(f2));
}
static int _compare(double d1, double d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (isnan(d1))
{ if (isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(double *)p1, *cast(double *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(double *)p1, *cast(double *)p2);
}
size_t tsize()
{
return double.sizeof;
}
void swap(void *p1, void *p2)
{
double t;
t = *cast(double *)p1;
*cast(double *)p1 = *cast(double *)p2;
*cast(double *)p2 = t;
}
void[] init()
{ static double r;
return (cast(double *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,67 @@
// float
module std.typeinfo.ti_float;
private import std.math;
class TypeInfo_f : TypeInfo
{
char[] toString() { return "float"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
static int _equals(float f1, float f2)
{
return f1 == f2 ||
(isnan(f1) && isnan(f2));
}
static int _compare(float d1, float d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (isnan(d1))
{ if (isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(float *)p1, *cast(float *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(float *)p1, *cast(float *)p2);
}
size_t tsize()
{
return float.sizeof;
}
void swap(void *p1, void *p2)
{
float t;
t = *cast(float *)p1;
*cast(float *)p1 = *cast(float *)p2;
*cast(float *)p2 = t;
}
void[] init()
{ static float r;
return (cast(float *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,12 @@
// idouble
module std.typeinfo.ti_idouble;
private import std.typeinfo.ti_double;
class TypeInfo_p : TypeInfo_d
{
char[] toString() { return "idouble"; }
}

View File

@@ -0,0 +1,12 @@
// ifloat
module std.typeinfo.ti_ifloat;
private import std.typeinfo.ti_float;
class TypeInfo_o : TypeInfo_f
{
char[] toString() { return "ifloat"; }
}

View File

@@ -0,0 +1,43 @@
// int
module std.typeinfo.ti_int;
class TypeInfo_i : TypeInfo
{
char[] toString() { return "int"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
int equals(void *p1, void *p2)
{
return *cast(uint *)p1 == *cast(uint *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(int*) p1 < *cast(int*) p2)
return -1;
else if (*cast(int*) p1 > *cast(int*) p2)
return 1;
return 0;
}
size_t tsize()
{
return int.sizeof;
}
void swap(void *p1, void *p2)
{
int t;
t = *cast(int *)p1;
*cast(int *)p1 = *cast(int *)p2;
*cast(int *)p2 = t;
}
}

View File

@@ -0,0 +1,12 @@
// ireal
module std.typeinfo.ti_ireal;
private import std.typeinfo.ti_real;
class TypeInfo_j : TypeInfo_e
{
char[] toString() { return "ireal"; }
}

View File

@@ -0,0 +1,43 @@
// long
module std.typeinfo.ti_long;
class TypeInfo_l : TypeInfo
{
char[] toString() { return "long"; }
hash_t getHash(void *p)
{
return *cast(uint *)p + (cast(uint *)p)[1];
}
int equals(void *p1, void *p2)
{
return *cast(long *)p1 == *cast(long *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(long *)p1 < *cast(long *)p2)
return -1;
else if (*cast(long *)p1 > *cast(long *)p2)
return 1;
return 0;
}
size_t tsize()
{
return long.sizeof;
}
void swap(void *p1, void *p2)
{
long t;
t = *cast(long *)p1;
*cast(long *)p1 = *cast(long *)p2;
*cast(long *)p2 = t;
}
}

View File

@@ -0,0 +1,42 @@
// pointer
module std.typeinfo.ti_ptr;
class TypeInfo_P : TypeInfo
{
hash_t getHash(void *p)
{
return cast(uint)*cast(void* *)p;
}
int equals(void *p1, void *p2)
{
return *cast(void* *)p1 == *cast(void* *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(void* *)p1 - *cast(void* *)p2;
}
size_t tsize()
{
return (void*).sizeof;
}
void swap(void *p1, void *p2)
{
void* t;
t = *cast(void* *)p1;
*cast(void* *)p1 = *cast(void* *)p2;
*cast(void* *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,67 @@
// real
module std.typeinfo.ti_real;
private import std.math;
class TypeInfo_e : TypeInfo
{
char[] toString() { return "real"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1] + (cast(ushort *)p)[4];
}
static int _equals(real f1, real f2)
{
return f1 == f2 ||
(isnan(f1) && isnan(f2));
}
static int _compare(real d1, real d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (isnan(d1))
{ if (isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(real *)p1, *cast(real *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(real *)p1, *cast(real *)p2);
}
size_t tsize()
{
return real.sizeof;
}
void swap(void *p1, void *p2)
{
real t;
t = *cast(real *)p1;
*cast(real *)p1 = *cast(real *)p2;
*cast(real *)p2 = t;
}
void[] init()
{ static real r;
return (cast(real *)&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,39 @@
// short
module std.typeinfo.ti_short;
class TypeInfo_s : TypeInfo
{
char[] toString() { return "short"; }
hash_t getHash(void *p)
{
return *cast(short *)p;
}
int equals(void *p1, void *p2)
{
return *cast(short *)p1 == *cast(short *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(short *)p1 - *cast(short *)p2;
}
size_t tsize()
{
return short.sizeof;
}
void swap(void *p1, void *p2)
{
short t;
t = *cast(short *)p1;
*cast(short *)p1 = *cast(short *)p2;
*cast(short *)p2 = t;
}
}

View File

@@ -0,0 +1,43 @@
// ubyte
module std.typeinfo.ti_ubyte;
class TypeInfo_h : TypeInfo
{
char[] toString() { return "ubyte"; }
hash_t getHash(void *p)
{
return *cast(ubyte *)p;
}
int equals(void *p1, void *p2)
{
return *cast(ubyte *)p1 == *cast(ubyte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(ubyte *)p1 - *cast(ubyte *)p2;
}
size_t tsize()
{
return ubyte.sizeof;
}
void swap(void *p1, void *p2)
{
ubyte t;
t = *cast(ubyte *)p1;
*cast(ubyte *)p1 = *cast(ubyte *)p2;
*cast(ubyte *)p2 = t;
}
}
class TypeInfo_b : TypeInfo_h
{
char[] toString() { return "bool"; }
}

View File

@@ -0,0 +1,43 @@
// uint
module std.typeinfo.ti_uint;
class TypeInfo_k : TypeInfo
{
char[] toString() { return "uint"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
int equals(void *p1, void *p2)
{
return *cast(uint *)p1 == *cast(uint *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(uint*) p1 < *cast(uint*) p2)
return -1;
else if (*cast(uint*) p1 > *cast(uint*) p2)
return 1;
return 0;
}
size_t tsize()
{
return uint.sizeof;
}
void swap(void *p1, void *p2)
{
int t;
t = *cast(uint *)p1;
*cast(uint *)p1 = *cast(uint *)p2;
*cast(uint *)p2 = t;
}
}

View File

@@ -0,0 +1,43 @@
// ulong
module std.typeinfo.ti_ulong;
class TypeInfo_m : TypeInfo
{
char[] toString() { return "ulong"; }
hash_t getHash(void *p)
{
return *cast(uint *)p + (cast(uint *)p)[1];
}
int equals(void *p1, void *p2)
{
return *cast(ulong *)p1 == *cast(ulong *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(ulong *)p1 < *cast(ulong *)p2)
return -1;
else if (*cast(ulong *)p1 > *cast(ulong *)p2)
return 1;
return 0;
}
size_t tsize()
{
return ulong.sizeof;
}
void swap(void *p1, void *p2)
{
ulong t;
t = *cast(ulong *)p1;
*cast(ulong *)p1 = *cast(ulong *)p2;
*cast(ulong *)p2 = t;
}
}

View File

@@ -0,0 +1,39 @@
// ushort
module std.typeinfo.ti_ushort;
class TypeInfo_t : TypeInfo
{
char[] toString() { return "ushort"; }
hash_t getHash(void *p)
{
return *cast(ushort *)p;
}
int equals(void *p1, void *p2)
{
return *cast(ushort *)p1 == *cast(ushort *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(ushort *)p1 - *cast(ushort *)p2;
}
size_t tsize()
{
return ushort.sizeof;
}
void swap(void *p1, void *p2)
{
ushort t;
t = *cast(ushort *)p1;
*cast(ushort *)p1 = *cast(ushort *)p2;
*cast(ushort *)p2 = t;
}
}

View File

@@ -0,0 +1,44 @@
// void
module std.typeinfo.ti_void;
class TypeInfo_v : TypeInfo
{
char[] toString() { return "void"; }
hash_t getHash(void *p)
{
assert(0);
}
int equals(void *p1, void *p2)
{
return *cast(byte *)p1 == *cast(byte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(byte *)p1 - *cast(byte *)p2;
}
size_t tsize()
{
return void.sizeof;
}
void swap(void *p1, void *p2)
{
byte t;
t = *cast(byte *)p1;
*cast(byte *)p1 = *cast(byte *)p2;
*cast(byte *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,44 @@
module std.typeinfo.ti_wchar;
class TypeInfo_u : TypeInfo
{
char[] toString() { return "wchar"; }
hash_t getHash(void *p)
{
return *cast(wchar *)p;
}
int equals(void *p1, void *p2)
{
return *cast(wchar *)p1 == *cast(wchar *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(wchar *)p1 - *cast(wchar *)p2;
}
size_t tsize()
{
return wchar.sizeof;
}
void swap(void *p1, void *p2)
{
wchar t;
t = *cast(wchar *)p1;
*cast(wchar *)p1 = *cast(wchar *)p2;
*cast(wchar *)p2 = t;
}
void[] init()
{ static wchar c;
return (cast(wchar *)&c)[0 .. 1];
}
}