From: DeaDDooMER Date: Sun, 8 Dec 2019 14:18:58 +0000 (+0300) Subject: add osx-ppc support via cpfront X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=2f6052eb7f36254f3f459addb169dd7c07786cf7;p=cpc.git add osx-ppc support via cpfront --- diff --git a/C/SYSTEM.h b/C/SYSTEM.h index f0d6a9f..9f36508 100644 --- a/C/SYSTEM.h +++ b/C/SYSTEM.h @@ -15,7 +15,7 @@ bh 20.12.1999 #ifdef __GNUC__ # include #endif -#include +#include #include /* extern char *memcpy(); */ @@ -24,33 +24,59 @@ bh 20.12.1999 #define import extern /* basic types */ +/* typedef unsigned char BOOLEAN; typedef unsigned char SHORTCHAR; typedef unsigned short CHAR; typedef signed char BYTE; typedef short SHORTINT; typedef int INTEGER; +*/ #if !defined(_WIN64) && ((__SIZEOF_POINTER__ == 8) || defined (_LP64) || defined(__LP64__)) - typedef long LONGINT; /* LP64 */ - typedef unsigned long __U_LONGINT; + /* typedef long LONGINT; */ /* LP64 */ + /* typedef unsigned long __U_LONGINT; */ #else - typedef long long LONGINT; /* ILP32 or LLP64 */ - typedef unsigned long long __U_LONGINT; + /* typedef long long LONGINT; */ /* ILP32 or LLP64 */ + /* typedef unsigned long long __U_LONGINT; */ #endif +/* typedef float SHORTREAL; typedef double REAL; typedef unsigned int SET; typedef void ANYREC; typedef void *ANYPTR; typedef void *SYSTEM_PTR; +*/ +typedef uint8_t BOOLEAN; +typedef uint8_t SHORTCHAR; +typedef uint16_t CHAR; +typedef int8_t BYTE; +typedef int16_t SHORTINT; +typedef int32_t INTEGER; +typedef int64_t LONGINT; +typedef float SHORTREAL; +typedef double REAL; +typedef uint32_t SET; +typedef void ANYREC; +typedef void *ANYPTR; +typedef void *SYSTEM_PTR; /* Unsigned variants are for use by shift and rotate macros */ +typedef uint8_t __U_SHORTCHAR; +typedef uint16_t __U_CHAR; +typedef uint8_t __U_BYTE; +typedef uint16_t __U_SHORTINT; +typedef uint32_t __U_INTEGER; +typedef uint64_t __U_LONGINT; +typedef uint32_t __U_SET; +/* typedef unsigned char __U_SHORTCHAR; typedef unsigned short __U_CHAR; typedef unsigned char __U_BYTE; typedef unsigned short __U_SHORTINT; typedef unsigned int __U_INTEGER; typedef unsigned int __U_SET; +*/ extern LONGINT SYSTEM_INF; extern INTEGER SYSTEM_INFS; diff --git a/make-all.sh b/make-all.sh index 71fc18e..1b5bb20 100755 --- a/make-all.sh +++ b/make-all.sh @@ -1,12 +1,16 @@ -#! /bin/sh +#! /bin/bash set -e +abspath() { + [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1" +} + ###^^^^^^^^^^^^^^^^^^### ### Global variables ### ###__________________### -_this="$(dirname "$(readlink -f "$0")")" +_this="$(dirname "$(abspath "$0")")" _exec="make-all.sh" _compiler= _linker= @@ -43,12 +47,14 @@ usage() { echo "Processors:" echo " 486 Intel 486+" echo " arm ARM 32-bit" + echo " powerpc PowerPC 32-bit" echo "Targets:" echo " native Native" echo " cpfront Generic C" echo "Operation systems:" echo " linux GNU/Linux" echo " cygwin Cygwin" + echo " osx Mac OS X" echo "Environment variables:" echo " CC C compiler binary" echo " CFLAGS C compiler options" @@ -72,6 +78,8 @@ make_stage() { local _ext= if [ "$_host_system" = "cygwin" ]; then _ext=".exe" + elif [ "$_host_system" = "osx" ]; then + _ext=".out" fi if [ "$_target" = "cpfront" ]; then _compiler="$_dir/cpfront${_ext}" @@ -162,12 +170,15 @@ fi ### Recompile itself ### ###__________________### -for _N in $(seq 1 "$_stages") -do - echo "==> Stage $_N" - make_verify_stage "$_N" -done -_N= +if [ "1" -le "$_stages" ]; then + echo "==> Stage 1" + make_verify_stage 1 +fi + +if [ "2" -le "$_stages" ]; then + echo "==> Stage 2" + make_verify_stage 2 +fi ###^^^^^^^^^^^^^^^### ### Cross compile ### diff --git a/make-bootstrap.sh b/make-bootstrap.sh index 7a5fe31..34069ec 100755 --- a/make-bootstrap.sh +++ b/make-bootstrap.sh @@ -1,13 +1,17 @@ -#! /bin/sh +#! /bin/bash set -e +abspath() { + [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1" +} + ###^^^^^^^^^^^^^^^^^^### ### Global variables ### ###__________________### _exec="make-bootstrap.sh" -_this="$(dirname "$(readlink -f "$0")")" +_this="$(dirname "$(abspath "$0")")" _version="v0.3" _sign=false @@ -70,8 +74,9 @@ fi rm -rf "$_this/bootstrap" mkdir -p "$_this/bootstrap" make_bootstrap 486 cpfront linux -make_bootstrap 486 cpfront cygwin -make_bootstrap arm cpfront linux +#make_bootstrap 486 cpfront cygwin +#make_bootstrap arm cpfront linux +make_bootstrap powerpc cpfront osx ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### ### Hack: remove temp files from v0.1 ### @@ -85,7 +90,7 @@ find "$_this/bootstrap" -type f -name '.new*' -delete rm -rf "$_this/cpc-$_version" mkdir -p "$_this/cpc-$_version" -cp -rt "$_this/cpc-$_version" -- \ +cp -r \ "$_this/CHANGELOG" \ "$_this/LICENSE" \ "$_this/README" \ @@ -96,7 +101,8 @@ cp -rt "$_this/cpc-$_version" -- \ "$_this/make-bootstrap.sh" \ "$_this/bootstrap" \ "$_this/src" \ - "$_this/C" + "$_this/C" \ + "$_this/cpc-$_version" tar czf "cpc-$_version.src.tar.gz" "cpc-$_version" ###^^^^^^^^^^^^^^^^### diff --git a/make.sh b/make.sh index 8b98cb2..0cd0960 100755 --- a/make.sh +++ b/make.sh @@ -1,13 +1,17 @@ -#! /bin/sh +#! /bin/bash set -e +abspath() { + [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1" +} + ###^^^^^^^^^^^^^^^^^^### ### Global variables ### ###__________________### _exec="make.sh" -_this="$(dirname "$(readlink -f "$0")")" +_this="$(dirname "$(abspath "$0")")" _cpu= _target= _system= @@ -37,12 +41,14 @@ usage() { echo "Processors:" echo " 486 Intel 486+" echo " arm ARM 32-bit" + echo " powerpc PowerPC 32-bit" echo "Targets:" echo " native Native" echo " cpfront Generic C" echo "Operation systems:" echo " linux GNU/Linux" echo " cygwin Cygwin" + echo " osx Mac OS X" echo "Environment variables:" echo " CC C compiler binary" echo " CFLAGS C compiler options" @@ -60,7 +66,7 @@ copy_source() { for _src do if test -d "$_this/src/$_src"; then - find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} + + find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -r {} "$_out" \; fi done } @@ -76,6 +82,8 @@ native_link() { if [ "$_system" = "cygwin" ]; then _outexe="${_outexe}.exe" _outsystem="win32" + elif [ "$_system" = "osx" ]; then + _outexe="${_outexe}.out" fi shift "$_linker" $CPLFALGS -os "$_outsystem" -kernel Kernel -main Kernel -legacycodedir . -o "$_outexe" "$@" @@ -124,6 +132,7 @@ cpfront_link() { local _cc_cflags= case "$CC" in *gcc) _cc_cflags="-std=c89 -Wno-int-conversion -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-implicit-function-declaration" ;; + *gcc-4.2) _cc_cflags="-std=c89 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-implicit-function-declaration" ;; clang|clang-*) _cc_cflags="-std=c89 -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses -Wno-pointer-sign -Wno-unused-value -Wno-return-type" ;; *tcc) _cc_cflags="-std=c89 -w -fsigned-char" ;; *) _cc_cflags="" ;; @@ -132,14 +141,22 @@ cpfront_link() { case "$_cpu" in 486) _cpu_cflags="-m32" ;; arm) _cpu_cflags="" ;; + powerpc) _cpu_cflags="-m32" ;; *) error "cpfront_link(): unsupported cpu $_cpu" ;; esac local _system_cflags= case "$_system" in cygwin) _system_cflags="-liconv" ;; + osx) _system_cflags="-D_DARWIN_C_SOURCE -liconv" ;; *) _system_cflags="" ;; esac - "$CC" -g -D_XOPEN_SOURCE=700 $_cc_cflags $_cpu_cflags $CFLAGS -o "${_main}" -I "$_this/C" "$_this/C/SYSTEM.c" $_list -lm -ldl -lffi $_system_cflags + local _out_exe="${_main}" + case "$_system" in + cygwin) _out_exe="${_main}.exe" ;; + osx) _out_exe="${_main}.out" ;; + *) ;; + esac + "$CC" -g -D_XOPEN_SOURCE=700 $_cc_cflags $_cpu_cflags $CFLAGS -o "${_out_exe}" -I "$_this/C" "$_this/C/SYSTEM.c" $_list -lm -ldl -lffi $_system_cflags fi } @@ -310,6 +327,7 @@ fi case "$_cpu" in 386|486|586|686) _cpu=486 ;; arm|armv6|armv7) _cpu=arm ;; + powerpc|ppc|ppc32) _cpu=powerpc ;; "") error "cpu not specified" ;; *) error "unsupported cpu $_cpu" ;; esac @@ -324,6 +342,7 @@ esac case "$_system" in linux) _useposix=true ;; cygwin) _useposix=true ;; + osx) _useposix=true ;; "") error "operation system not specified" ;; *) error "unsuported operation system $_system" ;; esac @@ -383,7 +402,7 @@ if $_docompile; then fi mkdir -p -- "$_out" -_out="$(readlink -f "$_out")" +_out="$(abspath "$_out")" copy_source "generic" "$_cpu" if $_useposix; then copy_source "posix/generic" "posix/$_cpu" diff --git a/src/cpfront/linux/generic/Posix/Mod/Cmacro.cp b/src/cpfront/linux/generic/Posix/Mod/Cmacro.cp new file mode 100644 index 0000000..7c49fde --- /dev/null +++ b/src/cpfront/linux/generic/Posix/Mod/Cmacro.cp @@ -0,0 +1,15 @@ +MODULE PosixCmacro; + + IMPORT SYSTEM, PosixCerrno, PosixCsys_stat; + + PROCEDURE errno* (): PosixCerrno.int; + BEGIN + RETURN PosixCerrno.__errno_location()[0] + END errno; + + PROCEDURE stat* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: PosixCsys_stat.struct_stat): PosixCsys_stat.int; + BEGIN + RETURN PosixCsys_stat.stat(path, buf) + END stat; + +END PosixCmacro. diff --git a/src/cpfront/osx/powerpc/Lib/Mod/FFI.cp b/src/cpfront/osx/powerpc/Lib/Mod/FFI.cp new file mode 100644 index 0000000..13cd421 --- /dev/null +++ b/src/cpfront/osx/powerpc/Lib/Mod/FFI.cp @@ -0,0 +1,83 @@ +MODULE LibFFI ["ffi/ffi.h"]; + + IMPORT SYSTEM, types := PosixCtypes, sys_types := PosixCsys_types; + + CONST + SIZEOF_ARG* = 4; + + CONST (* abi *) + FIRST_ABI* = 0; + AIX* = 1; + DARWIN* = 2; + DEFAULT_ABI* = DARWIN; + LAST_ABI* = DEFAULT_ABI + 1; + + CONST (* status *) + OK* = 0; BAD_TYPEDEF* = 1; BAD_ABI* = 2; + + CONST + TYPE_VOID* = 0; + TYPE_INT* = 1; + TYPE_FLOAT* = 2; + TYPE_DOUBLE* = 3; + TYPE_LONGDOUBLE* = 4; + TYPE_UINT8* = 5; + TYPE_SINT8* = 6; + TYPE_UINT16* = 7; + TYPE_SINT16* = 8; + TYPE_UINT32* = 9; + TYPE_SINT32* = 10; + TYPE_UINT64* = 11; + TYPE_SINT64* = 12; + TYPE_STRUCT* = 13; + TYPE_POINTER* = 14; + TYPE_COMPLEX* = 15; + TYPE_LAST* = TYPE_COMPLEX; + + TYPE + abi* ["ffi_abi"] = types.int; (* !!! enum *) + status* ["ffi_status"] = types.int; (* !!! enum *) + + (* Ptype* = POINTER [untagged] TO type; + PPtype* = POINTER [untagged] TO ARRAY [untagged] OF Ptype; *) + type* ["ffi_type"] = RECORD [untagged] + size*: sys_types.size_t; + alignment*: types.unsigned_short; + type*: types.unsigned_short; + elements*: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type; + END; + + (* Pcif* = POINTER TO cif; *) + cif* ["ffi_cif"] = RECORD [untagged] + abi*: abi; + nargs*: types.unsigned; + arg_type*: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type; + rtype*: POINTER TO type; + bytes*: types.unsigned; + flags*: types.unsigned; + END; + + VAR + type_void- ["ffi_type_void"]: type; + type_uint8- ["ffi_type_uint8"]: type; + type_sint8- ["ffi_type_sint8"]: type; + type_uint16- ["ffi_type_uint16"]: type; + type_sint16- ["ffi_type_sint16"]: type; + type_uint32- ["ffi_type_uint32"]: type; + type_sint32- ["ffi_type_sint32"]: type; + type_uint64- ["ffi_type_uint64"]: type; + type_sint64- ["ffi_type_sint64"]: type; + type_float- ["ffi_type_float"]: type; + type_double- ["ffi_type_double"]: type; + type_pointer- ["ffi_type_pointer"]: type; + type_longdouble- ["ffi_type_longdouble"]: type; + + type_complex_single- ["ffi_type_complex_single"]: type; + type_complex_double- ["ffi_type_complex_double"]: type; + type_complex_longdouble- ["ffi_type_complex_longdouble"]: type; + + PROCEDURE [ccall] prep_cif* ["ffi_prep_cif"] (VAR c: cif; a: abi; nargs: types.unsigned_int; rtype: POINTER TO type; atypes: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type): status; + PROCEDURE [ccall] prep_cif_var* ["ffi_prep_cif_var"] (VAR c: cif; a: abi; nfixedargs, ntotalargs: types.unsigned_int; rtype: POINTER TO type; atypes: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type): status; + PROCEDURE [ccall] call* ["ffi_call"] (VAR c: cif; fn, rvalue, avalue: INTEGER); + +END LibFFI. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cdirent.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cdirent.cp new file mode 100644 index 0000000..500882f --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cdirent.cp @@ -0,0 +1,64 @@ +MODULE PosixCdirent ['dirent.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + PDIR* = POINTER TO DIR; + DIR ['DIR'] = LIMITED RECORD [untagged] END; + + TYPE + Pstruct_dirent* = POINTER TO struct_dirent; + struct_dirent* ['struct dirent'] = RECORD [noalign] (* 264 *) + d_ino*: ino_t; (* 0+4 *) + d_name*: ARRAY [untagged] 256 OF SHORTCHAR; (* 8+256 *) + END; + + TYPE + ino_t* = PosixCsys_types.ino_t; + + PROCEDURE [ccall] alphasort* (IN a, b: Pstruct_dirent): int; + PROCEDURE [ccall] closedir* (dirp: PDIR): int; + PROCEDURE [ccall] dirfd* (dirp: PDIR): int; + PROCEDURE [ccall] fdopendir* (fd: int): PDIR; + PROCEDURE [ccall] opendir* (IN name: ARRAY [untagged] OF SHORTCHAR): PDIR; + PROCEDURE [ccall] readdir* (dirp: PDIR): Pstruct_dirent; + PROCEDURE [ccall] readdir_r* (dirp: PDIR; entry: Pstruct_dirent; VAR result: Pstruct_dirent): int; + PROCEDURE [ccall] rewinddir* (dirp: PDIR); + PROCEDURE [ccall] scandir* (IN dirp: ARRAY [untagged] OF SHORTCHAR; filter: PROCEDURE [ccall] (IN d: struct_dirent): int; compar: PROCEDURE [ccall] (IN a, b: Pstruct_dirent): int): int; + PROCEDURE [ccall] seekdir* (dirp: PDIR; loc: long); + PROCEDURE [ccall] telldir* (dirp: PDIR): long; + +END PosixCdirent. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cdlfcn.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cdlfcn.cp new file mode 100644 index 0000000..d1cc04e --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cdlfcn.cp @@ -0,0 +1,49 @@ +MODULE PosixCdlfcn ['dlfcn.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + RTLD_LAZY* = 1; + RTLD_NOW* = 2; + RTLD_GLOBAL* = 8; + RTLD_LOCAL* = 4; + + PROCEDURE [ccall] dlclose* (handle: PosixCtypes.Pvoid): int; + PROCEDURE [ccall] dlerror* (): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] dlopen* (IN [nil] filename: ARRAY [untagged] OF SHORTCHAR; flags: int): PosixCtypes.Pvoid; + PROCEDURE [ccall] dlsym* (handle: PosixCtypes.Pvoid; IN symbol: ARRAY [untagged] OF SHORTCHAR): PosixCtypes.Pvoid; + +END PosixCdlfcn. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cerrno.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cerrno.cp new file mode 100644 index 0000000..0ae744c --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cerrno.cp @@ -0,0 +1,123 @@ +MODULE PosixCerrno ['errno.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + E2BIG* = 7; + EACCES* = 13; + EADDRINUSE* = 48; + EADDRNOTAVAIL* = 49; + EAFNOSUPPORT* = 47; + EAGAIN* = 35; + EALREADY* = 37; + EBADF* = 9; + EBADMSG* = 94; + EBUSY* = 16; + ECANCELED* = 89; + ECHILD* = 10; + ECONNABORTED* = 53; + ECONNREFUSED* = 61; + ECONNRESET* = 54; + EDEADLK* = 11; + EDESTADDRREQ* = 39; + EDOM* = 33; + EDQUOT* = 69; + EEXIST* = 17; + EFAULT* = 14; + EFBIG* = 27; + EHOSTUNREACH* = 65; + EIDRM* = 90; + EILSEQ* = 92; + EINPROGRESS* = 36; + EINTR* = 4; + EINVAL* = 22; + EIO* = 5; + EISCONN* = 56; + EISDIR* = 21; + ELOOP* = 62; + EMFILE* = 24; + EMLINK* = 31; + EMSGSIZE* = 40; + EMULTIHOP* = 95; + ENAMETOOLONG* = 63; + ENETDOWN* = 50; + ENETRESET* = 52; + ENETUNREACH* = 51; + ENFILE* = 23; + ENOBUFS* = 55; + ENODATA* = 96; + ENODEV* = 19; + ENOENT* = 2; + ENOEXEC* = 8; + ENOLCK* = 77; + ENOLINK* = 97; + ENOMEM* = 12; + ENOMSG* = 91; + ENOPROTOOPT* = 42; + ENOSPC* = 28; + ENOSR* = 98; + ENOSTR* = 99; + ENOSYS* = 78; + ENOTCONN* = 57; + ENOTDIR* = 20; + ENOTEMPTY* = 66; + ENOTSOCK* = 38; + ENOTSUP* = 45; + ENOTTY* = 25; + ENXIO* = 6; + EOPNOTSUPP* = 102; + EOVERFLOW* = 84; + EPERM* = 1; + EPIPE* = 32; + EPROTO* = 100; + EPROTONOSUPPORT* = 43; + EPROTOTYPE* = 41; + ERANGE* = 34; + EROFS* = 30; + ESPIPE* = 29; + ESRCH* = 3; + ESTALE* = 70; + ETIME* = 101; + ETIMEDOUT* = 60; + ETXTBSY* = 26; + EWOULDBLOCK* = 35; + EXDEV* = 18; + + VAR + errno*: int; + + +END PosixCerrno. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cfcntl.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cfcntl.cp new file mode 100644 index 0000000..17bb317 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cfcntl.cp @@ -0,0 +1,97 @@ +MODULE PosixCfcntl ['fcntl.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + F_DUPFD* = 0; + F_GETFD* = 1; + F_SETFD* = 2; + F_GETFL* = 3; + F_SETFL* = 4; + F_GETLK* = 7; + F_SETLK* = 8; + F_SETLKW* = 9; + F_GETOWN* = 5; + F_SETOWN* = 6; + + CONST + F_RDLCK* = 1; + F_UNLCK* = 2; + F_WRLCK* = 3; + + CONST + SEEK_SET* = 0; + SEEK_CUR* = 1; + SEEK_END* = 2; + + CONST + O_CREAT* = 512; + O_DIRECTORY* = 1048576; + O_EXCL* = 2048; + O_NOCTTY* = 131072; + O_NOFOLLOW* = 256; + O_TRUNC* = 1024; + O_APPEND* = 8; + O_NONBLOCK* = 4; + O_SYNC* = 128; + O_ACCMODE* = 3; + O_RDONLY* = 0; + O_RDWR* = 2; + O_WRONLY* = 1; + + TYPE + Pstruct_flock* = POINTER TO struct_flock; + struct_flock* ['struct flock'] = RECORD [noalign] (* 24 *) + l_start*: off_t; (* 0+8 *) + l_len*: off_t; (* 8+8 *) + l_pid*: pid_t; (* 16+4 *) + l_type*: short; (* 20+2 *) + l_whence*: short; (* 22+2 *) + END; + + TYPE + mode_t* = PosixCsys_types.mode_t; + off_t* = PosixCsys_types.off_t; + pid_t* = PosixCsys_types.pid_t; + + PROCEDURE [ccall] creat* (IN pathname: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] fcntl* (fildes, cmd, arg: int): int; + PROCEDURE [ccall] open* (IN pathname: ARRAY [untagged] OF SHORTCHAR; flags: int; mode: mode_t): int; + PROCEDURE [ccall] openat* (fddir: int; IN pathname: ARRAY [untagged] OF SHORTCHAR; flags: int; mode: mode_t): int; + PROCEDURE [ccall] posix_fadvise* (fd: int; offset, len: off_t; advice: int): int; + PROCEDURE [ccall] posix_fallocate* (fd: int; offset, len: off_t): int; + +END PosixCfcntl. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Ciconv.cp b/src/cpfront/osx/powerpc/Posix/Mod/Ciconv.cp new file mode 100644 index 0000000..00dc3b2 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Ciconv.cp @@ -0,0 +1,48 @@ +MODULE PosixCiconv ['iconv.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + iconv_t* = INTEGER; + + TYPE + size_t* = PosixCsys_types.size_t; + + PROCEDURE [ccall] iconv* (cd: iconv_t; VAR [nil] inbuf: PosixCtypes.Pvoid; VAR inbytesleft: size_t; VAR [nil] outbuf: PosixCtypes.Pvoid; VAR outbytesleft: size_t): size_t; + PROCEDURE [ccall] iconv_open* (IN tocode, fromcode: ARRAY [untagged] OF SHORTCHAR): iconv_t; + PROCEDURE [ccall] iconv_close* (cd: iconv_t): int; + +END PosixCiconv. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Clibgen.cp b/src/cpfront/osx/powerpc/Posix/Mod/Clibgen.cp new file mode 100644 index 0000000..27897fe --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Clibgen.cp @@ -0,0 +1,41 @@ +MODULE PosixClibgen ['libgen.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + PROCEDURE [ccall] basename* (path: POINTER TO ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] dirname* (path: POINTER TO ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + +END PosixClibgen. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Clocale.cp b/src/cpfront/osx/powerpc/Posix/Mod/Clocale.cp new file mode 100644 index 0000000..195a4ff --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Clocale.cp @@ -0,0 +1,75 @@ +MODULE PosixClocale ['locale.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + Pstruct_lconv* = POINTER TO struct_lconv; + struct_lconv ['struct lconv'] = LIMITED RECORD [untagged] END; + + CONST + LC_ALL* = 0; + LC_COLLATE* = 1; + LC_CTYPE* = 2; + LC_MESSAGES* = 6; + LC_MONETARY* = 3; + LC_NUMERIC* = 4; + LC_TIME* = 5; + + CONST + LC_COLLATE_MASK* = 1; + LC_CTYPE_MASK* = 2; + LC_MESSAGES_MASK* = 4; + LC_MONETARY_MASK* = 8; + LC_NUMERIC_MASK* = 16; + LC_TIME_MASK* = 32; + + CONST + LC_ALL_MASK* = 63; + + CONST + LC_GLOBAL_LOCALE* = -1; + + TYPE + locale_t* = INTEGER; + + PROCEDURE [ccall] duplocale* (locobj: locale_t): locale_t; + PROCEDURE [ccall] freelocale* (locobj: locale_t); + PROCEDURE [ccall] localeconv* (): Pstruct_lconv; + PROCEDURE [ccall] newlocale* (category_mask: int; IN locale: ARRAY [untagged] OF SHORTCHAR; base: locale_t): locale_t; + PROCEDURE [ccall] setlocale* (category: int; IN [nil] locale: ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] uselocale* (newloc: locale_t): locale_t; + +END PosixClocale. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Csetjmp.cp b/src/cpfront/osx/powerpc/Posix/Mod/Csetjmp.cp new file mode 100644 index 0000000..8465faf --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Csetjmp.cp @@ -0,0 +1,49 @@ +MODULE PosixCsetjmp ['setjmp.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + jmp_buf* = ARRAY [untagged] 768 OF BYTE; + sigjmp_buf* = ARRAY [untagged] 772 OF BYTE; + + PROCEDURE [ccall] _longjmp* (IN env: jmp_buf; val: int); + PROCEDURE [ccall] longjmp* (IN env: jmp_buf; val: int); + PROCEDURE [ccall] siglongjmp* (IN env: sigjmp_buf; val: int); + PROCEDURE [ccall] _setjmp* (VAR env: jmp_buf): int; + PROCEDURE [ccall] setjmp* (VAR env: jmp_buf): int; + PROCEDURE [ccall] sigsetjmp* (VAR env: sigjmp_buf; savesigs: int): int; + +END PosixCsetjmp. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Csignal.cp b/src/cpfront/osx/powerpc/Posix/Mod/Csignal.cp new file mode 100644 index 0000000..91a810c --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Csignal.cp @@ -0,0 +1,259 @@ +MODULE PosixCsignal ['signal.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types, PosixCtime; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + SIG_DFL* = 0; + SIG_ERR* = -1; + SIG_IGN* = 1; + + TYPE + pthread_t* = PosixCsys_types.pthread_t; + pthread_attr_t* = PosixCsys_types.pthread_attr_t; + size_t* = PosixCsys_types.size_t; + uid_t* = PosixCsys_types.uid_t; + pid_t* = PosixCsys_types.pid_t; + + TYPE + struct_timespec* = PosixCtime.struct_timespec; + + TYPE + sig_atomic_t* = INTEGER; + sigset_t* = INTEGER; + + TYPE + Pstruct_sigevent* = POINTER TO struct_sigevent; + struct_sigevent* ['struct sigevent'] = RECORD [noalign] (* 20 *) + sigev_notify*: int; (* 0+4 *) + sigev_signo*: int; (* 4+4 *) + sigev_value*: union_sigval; (* 8+4 *) + sigev_notify_function*: PROCEDURE [ccall] (x: union_sigval); (* 12+4 *) + END; + + CONST + SIGEV_NONE* = 0; + SIGEV_SIGNAL* = 1; + SIGEV_THREAD* = 3; + + TYPE + Punion_sigval* = POINTER TO union_sigval; + union_sigval* ['union sigval'] = RECORD [union] (* 4 *) + sival_int*: int; (* 0+4 *) + sival_ptr*: PosixCtypes.Pvoid; (* 0+4 *) + END; + + CONST + SIGABRT* = 6; + SIGALRM* = 14; + SIGBUS* = 10; + SIGCHLD* = 20; + SIGCONT* = 19; + SIGFPE* = 8; + SIGHUP* = 1; + SIGILL* = 4; + SIGINT* = 2; + SIGKILL* = 9; + SIGPIPE* = 13; + SIGQUIT* = 3; + SIGSEGV* = 11; + SIGSTOP* = 17; + SIGTERM* = 15; + SIGTSTP* = 18; + SIGTTIN* = 21; + SIGTTOU* = 22; + SIGUSR1* = 30; + SIGUSR2* = 31; + SIGSYS* = 12; + SIGTRAP* = 5; + SIGURG* = 16; + SIGVTALRM* = 26; + SIGXCPU* = 24; + SIGXFSZ* = 25; + + TYPE + P_struct_sigaction* = POINTER TO _struct_sigaction; + _struct_sigaction* ['struct sigaction'] = RECORD [noalign] (* 12 *) + sa_handler*: PROCEDURE [ccall] (sig: int); (* 0+4 *) + sa_sigaction*: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *) + sa_mask*: sigset_t; (* 4+4 *) + sa_flags*: int; (* 8+4 *) + END; + + TYPE + Pstruct_sigaction* = POINTER TO struct_sigaction; + struct_sigaction* ['struct sigaction'] = RECORD [noalign] (* 12 *) + handler* ["/*handler"]: RECORD [union] (* 4 *) + sa_handler* ["*/sa_handler"]: PROCEDURE [ccall] (sig: int); (* 0+4 *) + sa_sigaction* ["*/sa_sigaction"]: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *) + END; (* 0+4 *) + sa_mask*: sigset_t; (* 4+4 *) + sa_flags*: int; (* 8+4 *) + END; + + CONST + SIG_BLOCK* = 1; + SIG_UNBLOCK* = 2; + SIG_SETMASK* = 3; + + CONST + SA_NOCLDSTOP* = 8; + SA_ONSTACK* = 1; + SA_RESETHAND* = 4; + SA_RESTART* = 2; + SA_SIGINFO* = 64; + SA_NODEFER* = 16; + SS_ONSTACK* = 1; + SS_DISABLE* = 4; + MINSIGSTKSZ* = 32768; + SIGSTKSZ* = 131072; + + TYPE + mcontext_t* = INTEGER; + + TYPE + Pucontext_t* = POINTER TO ucontext_t; + ucontext_t* ['ucontext_t'] = RECORD [noalign] (* 32 *) + uc_sigmask*: sigset_t; (* 4+4 *) + uc_stack*: stack_t; (* 8+12 *) + uc_link*: Pucontext_t; (* 20+4 *) + uc_mcontext*: mcontext_t; (* 28+4 *) + END; + + TYPE + Pstack_t* = POINTER TO stack_t; + stack_t* ['stack_t'] = RECORD [noalign] (* 12 *) + ss_sp*: PosixCtypes.Pvoid; (* 0+4 *) + ss_size*: size_t; (* 4+4 *) + ss_flags*: int; (* 8+4 *) + END; + + TYPE + Psiginfo_t* = POINTER TO siginfo_t; + siginfo_t* ['siginfo_t'] = RECORD [noalign] (* 64 *) + si_signo*: int; (* 0+4 *) + si_errno*: int; (* 4+4 *) + si_code*: int; (* 8+4 *) + info* ["/*info"]: RECORD [union] (* 12 *) + sigchld*: RECORD [noalign] (* 12 *) + si_pid* ["*/si_pid"]: pid_t; (* 0+4 *) + si_uid* ["*/si_uid"]: uid_t; (* 4+4 *) + si_status* ["*/si_status"]: int; (* 8+4 *) + END; (* 0+12 *) + sigfpe*: RECORD [noalign] (* 4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) + END; (* 12+4 *) + sigsegv*: RECORD [noalign] (* 4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) + END; (* 12+4 *) + sigbus*: RECORD [noalign] (* 4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) + END; (* 12+4 *) + sigill*: RECORD [noalign] (* 4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) + END; (* 12+4 *) + other*: RECORD [noalign] (* 4 *) + si_value* ["*/si_value"]: union_sigval; (* 0+4 *) + END; (* 16+4 *) + END; (* 12+12 *) + END; + + CONST + ILL_ILLOPC* = 1; + ILL_ILLOPN* = 4; + ILL_ILLADR* = 5; + ILL_ILLTRP* = 2; + ILL_PRVOPC* = 3; + ILL_PRVREG* = 6; + ILL_COPROC* = 7; + ILL_BADSTK* = 8; + + CONST + FPE_INTDIV* = 7; + FPE_INTOVF* = 8; + FPE_FLTDIV* = 1; + FPE_FLTOVF* = 2; + FPE_FLTUND* = 3; + FPE_FLTRES* = 4; + FPE_FLTINV* = 5; + FPE_FLTSUB* = 6; + + CONST + SEGV_MAPERR* = 1; + SEGV_ACCERR* = 2; + + CONST + BUS_ADRALN* = 1; + BUS_ADRERR* = 2; + BUS_OBJERR* = 3; + + CONST + CLD_EXITED* = 1; + CLD_KILLED* = 2; + CLD_DUMPED* = 3; + CLD_TRAPPED* = 4; + CLD_STOPPED* = 5; + CLD_CONTINUED* = 6; + + CONST + SI_USER* = 65537; + SI_QUEUE* = 65538; + SI_TIMER* = 65539; + SI_ASYNCIO* = 65540; + SI_MESGQ* = 65541; + + PROCEDURE [ccall] kill* (pid: pid_t; sig: int): int; + PROCEDURE [ccall] killpg* (pgrp, sig: int): int; + PROCEDURE [ccall] psiginfo* (IN pinfo: siginfo_t; IN [nil] s: ARRAY [untagged] OF SHORTCHAR); + PROCEDURE [ccall] psignal* (sig: int; IN [nil] s: ARRAY [untagged] OF SHORTCHAR); + PROCEDURE [ccall] pthread_kill* (thread: pthread_t; sig: int): int; + PROCEDURE [ccall] pthread_sigmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int; + PROCEDURE [ccall] raise* (sig: int): int; + PROCEDURE [ccall] sigaction* (sig: int; IN [nil] act: struct_sigaction; VAR [nil] oact: struct_sigaction): int; + PROCEDURE [ccall] sigaddset* (VAR set: sigset_t; signum: int): int; + PROCEDURE [ccall] sigaltstack* (IN [nil] ss: stack_t; VAR [nil] oss: stack_t): int; + PROCEDURE [ccall] sigdelset* (VAR set: sigset_t; signum: int): int; + PROCEDURE [ccall] sigemptyset* (VAR set: sigset_t): int; + PROCEDURE [ccall] sigfillset* (VAR set: sigset_t): int; + PROCEDURE [ccall] sigismember* (VAR set: sigset_t; signum: int): int; + PROCEDURE [ccall] sigpending* (VAR set: sigset_t): int; + PROCEDURE [ccall] sigprocmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): int; + PROCEDURE [ccall] sigqueue* (pid: pid_t; sig: int; IN value: union_sigval): int; + PROCEDURE [ccall] sigsuspend* (VAR sigmask: sigset_t): int; + PROCEDURE [ccall] sigtimedwait* (VAR set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int; + PROCEDURE [ccall] sigwait* (VAR set: sigset_t; VAR sig: int): int; + PROCEDURE [ccall] sigwaitinfo* (VAR set: sigset_t; VAR [nil] info: siginfo_t): int; + +END PosixCsignal. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cstdio.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cstdio.cp new file mode 100644 index 0000000..81991a9 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cstdio.cp @@ -0,0 +1,91 @@ +MODULE PosixCstdio ['stdio.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + PFILE* = POINTER TO FILE; + FILE ['FILE'] = LIMITED RECORD [untagged] END; + + TYPE + fpos_t* = LONGINT; + + TYPE + off_t* = PosixCsys_types.off_t; + ssize_t* = PosixCsys_types.ssize_t; + + TYPE + size_t* = INTEGER; + + TYPE + va_list* = INTEGER; + + CONST + BUFSIZ* = 1024; + L_ctermid* = 1024; + L_tmpnam* = 1024; + + CONST + _IOFBF* = 0; + _IOLBF* = 1; + _IONBF* = 2; + + CONST + SEEK_CUR* = 1; + SEEK_END* = 2; + SEEK_SET* = 0; + + CONST + FILENAME_MAX* = 1024; + FOPEN_MAX* = 20; + TMP_MAX* = 308915776; + + CONST + EOF* = -1; + + PROCEDURE [ccall] fclose* (stream: PFILE): int; + PROCEDURE [ccall] ferror* (stream: PFILE): int; + PROCEDURE [ccall] fflush* (stream: PFILE): int; + PROCEDURE [ccall] fopen* (IN pathname, mode: ARRAY [untagged] OF SHORTCHAR): PFILE; + PROCEDURE [ccall] fread* (ptr: PosixCtypes.Pvoid; size, n: size_t; stream: PFILE): size_t; + PROCEDURE [ccall] fseek* (stream: PFILE; offset: long; whence: int): int; + PROCEDURE [ccall] ftell* (stream: PFILE): long; + PROCEDURE [ccall] fwrite* (ptr: PosixCtypes.Pvoid; size, n: size_t; stream: PFILE): size_t; + PROCEDURE [ccall] feof* (stream: PFILE): int; + PROCEDURE [ccall] remove* (IN pathname: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] rename* (IN old, new: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] tmpfile* (): PFILE; + +END PosixCstdio. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cstdlib.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cstdlib.cp new file mode 100644 index 0000000..9ef98f3 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cstdlib.cp @@ -0,0 +1,66 @@ +MODULE PosixCstdlib ['stdlib.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + EXIT_FAILURE* = 1; + EXIT_SUCCESS* = 0; + RAND_MAX* = 2147483647; + + CONST + MB_CUR_MAX* = 1; + + TYPE + div_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + ldiv_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + lldiv_t* = RECORD [noalign] _: ARRAY [untagged] 16 OF BYTE END; + + TYPE + size_t* = INTEGER; + wchar_t* = INTEGER; + + PROCEDURE [ccall] _Exit* (status: int); + PROCEDURE [ccall] abort* ; + PROCEDURE [ccall] atexit* (function: PROCEDURE [ccall]): int; + PROCEDURE [ccall] exit* (status: int); + PROCEDURE [ccall] free* (ptr: PosixCtypes.Pvoid); + PROCEDURE [ccall] getenv* (IN name: ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] malloc* (size: size_t): PosixCtypes.Pvoid; + PROCEDURE [ccall] system* (IN command: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] mkstemp* (VAR template: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] realpath* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR [nil] resolved_path: ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + +END PosixCstdlib. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Csys_mman.cp b/src/cpfront/osx/powerpc/Posix/Mod/Csys_mman.cp new file mode 100644 index 0000000..b447bc7 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Csys_mman.cp @@ -0,0 +1,80 @@ +MODULE PosixCsys_mman ['sys/mman.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + PROT_EXEC* = 4; + PROT_NONE* = 0; + PROT_READ* = 1; + PROT_WRITE* = 2; + + CONST + MAP_FIXED* = 16; + MAP_PRIVATE* = 2; + MAP_SHARED* = 1; + + CONST + MS_ASYNC* = 1; + MS_INVALIDATE* = 2; + MS_SYNC* = 16; + + CONST + MAP_FAILED* = -1; + + CONST + POSIX_MADV_DONTNEED* = 4; + POSIX_MADV_NORMAL* = 0; + POSIX_MADV_RANDOM* = 1; + POSIX_MADV_SEQUENTIAL* = 2; + POSIX_MADV_WILLNEED* = 3; + + TYPE + mode_t* = PosixCsys_types.mode_t; + off_t* = PosixCsys_types.off_t; + size_t* = PosixCsys_types.size_t; + + PROCEDURE [ccall] mlock* (addr: PosixCtypes.Pvoid; len: size_t): int; + PROCEDURE [ccall] mmap* (addr: PosixCtypes.Pvoid; len: size_t; prot, flags, fildes: int; off: off_t): PosixCtypes.Pvoid; + PROCEDURE [ccall] mprotect* (addr: PosixCtypes.Pvoid; len: size_t; prot: int): int; + PROCEDURE [ccall] msync* (addr: PosixCtypes.Pvoid; len: size_t; flags: int): int; + PROCEDURE [ccall] munlock* (addr: PosixCtypes.Pvoid; len: size_t): int; + PROCEDURE [ccall] munmap* (addr: PosixCtypes.Pvoid; len: size_t): int; + PROCEDURE [ccall] posix_madvise* (addr: PosixCtypes.Pvoid; len: size_t; advice: int): int; + PROCEDURE [ccall] posix_mem_offset* (addr: PosixCtypes.Pvoid; len: size_t; VAR off: off_t; VAR contng_len: size_t; VAR fildes: int): int; + PROCEDURE [ccall] shm_open* (IN name: ARRAY [untagged] OF SHORTCHAR; oflag, mode: int): int; + PROCEDURE [ccall] shm_unlink* (IN name: ARRAY [untagged] OF SHORTCHAR): int; + +END PosixCsys_mman. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Csys_stat.cp b/src/cpfront/osx/powerpc/Posix/Mod/Csys_stat.cp new file mode 100644 index 0000000..0e699aa --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Csys_stat.cp @@ -0,0 +1,115 @@ +MODULE PosixCsys_stat ['sys/stat.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCtime, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + S_IFMT* = 61440; + S_IFBLK* = 24576; + S_IFCHR* = 8192; + S_IFIFO* = 4096; + S_IFREG* = 32768; + S_IFDIR* = 16384; + S_IFLNK* = 40960; + S_IFSOCK* = 49152; + + CONST + S_IRWXU* = 448; + S_IRUSR* = 256; + S_IWUSR* = 128; + S_IXUSR* = 64; + S_IRWXG* = 56; + S_IRGRP* = 32; + S_IWGRP* = 16; + S_IXGRP* = 8; + S_IRWXO* = 7; + S_IROTH* = 4; + S_IWOTH* = 2; + S_IXOTH* = 1; + S_ISUID* = 2048; + S_ISGID* = 1024; + S_ISVTX* = 512; + + TYPE + blkcnt_t* = PosixCsys_types.blkcnt_t; + blksize_t* = PosixCsys_types.blksize_t; + dev_t* = PosixCsys_types.dev_t; + ino_t* = PosixCsys_types.ino_t; + mode_t* = PosixCsys_types.mode_t; + nlink_t* = PosixCsys_types.nlink_t; + uid_t* = PosixCsys_types.uid_t; + gid_t* = PosixCsys_types.gid_t; + off_t* = PosixCsys_types.off_t; + time_t* = PosixCsys_types.time_t; + + TYPE + struct_timespec* = PosixCtime.struct_timespec; + + TYPE + Pstruct_stat* = POINTER TO struct_stat; + struct_stat* ['struct stat'] = RECORD [noalign] (* 96 *) + st_dev*: dev_t; (* 0+4 *) + st_ino*: ino_t; (* 4+4 *) + st_mode*: mode_t; (* 8+2 *) + st_nlink*: nlink_t; (* 10+2 *) + st_uid*: uid_t; (* 12+4 *) + st_gid*: gid_t; (* 16+4 *) + st_rdev*: dev_t; (* 20+4 *) + st_atim* ["st_atimespec"]: struct_timespec; (* 24+8 *) + st_mtim* ["st_mtimespec"]: struct_timespec; (* 32+8 *) + st_ctim* ["st_ctimespec"]: struct_timespec; (* 40+8 *) + st_size*: off_t; (* 48+8 *) + st_blocks*: blkcnt_t; (* 56+8 *) + st_blksize*: blksize_t; (* 64+4 *) + END; + + PROCEDURE [ccall] chmod* (IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] fchmod* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] fchmodat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t; flag: int): int; + PROCEDURE [ccall] fstat* (fd: int; VAR buf: struct_stat): int; + PROCEDURE [ccall] fstatat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: struct_stat; flag: int): int; + PROCEDURE [ccall] futimens* (fd: int; IN times: ARRAY [untagged] 2 OF struct_timespec): int; + PROCEDURE [ccall] lstat* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: struct_stat): int; + PROCEDURE [ccall] mkdir* (IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] mkdirat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] mkfifo* (IN pathname: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] mkfifoat* (dirfd: int; IN pathname: ARRAY [untagged] OF SHORTCHAR; mode: mode_t): int; + PROCEDURE [ccall] mknod* (IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t; dev: dev_t): int; + PROCEDURE [ccall] mknodat* (df: int; IN path: ARRAY [untagged] OF SHORTCHAR; mode: mode_t; dev: dev_t): int; + PROCEDURE [ccall] stat* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: struct_stat): int; + PROCEDURE [ccall] umask* (mode: mode_t): mode_t; + PROCEDURE [ccall] utimensat* (dirfd: int; IN pathname: ARRAY [untagged] OF SHORTCHAR; IN times: ARRAY [untagged] 2 OF struct_timespec; flags: int): int; + +END PosixCsys_stat. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Csys_types.cp b/src/cpfront/osx/powerpc/Posix/Mod/Csys_types.cp new file mode 100644 index 0000000..cf2b631 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Csys_types.cp @@ -0,0 +1,70 @@ +MODULE PosixCsys_types ['sys/types.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + blkcnt_t* = LONGINT; + blksize_t* = INTEGER; + clock_t* = INTEGER; + dev_t* = INTEGER; + fsblkcnt_t* = INTEGER; + fsfilcnt_t* = INTEGER; + gid_t* = INTEGER; + id_t* = INTEGER; + ino_t* = INTEGER; + key_t* = INTEGER; + mode_t* = SHORTINT; + nlink_t* = SHORTINT; + off_t* = LONGINT; + pid_t* = INTEGER; + pthread_attr_t* = RECORD [noalign] _: ARRAY [untagged] 40 OF BYTE END; + pthread_cond_t* = RECORD [noalign] _: ARRAY [untagged] 28 OF BYTE END; + pthread_condattr_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + pthread_key_t* = INTEGER; + pthread_mutex_t* = RECORD [noalign] _: ARRAY [untagged] 44 OF BYTE END; + pthread_mutexattr_t* = RECORD [noalign] _: ARRAY [untagged] 12 OF BYTE END; + pthread_once_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + pthread_rwlock_t* = RECORD [noalign] _: ARRAY [untagged] 128 OF BYTE END; + pthread_rwlockattr_t* = RECORD [noalign] _: ARRAY [untagged] 16 OF BYTE END; + pthread_t* = INTEGER; + size_t* = INTEGER; + ssize_t* = INTEGER; + suseconds_t* = INTEGER; + time_t* = INTEGER; + uid_t* = INTEGER; + + +END PosixCsys_types. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Ctime.cp b/src/cpfront/osx/powerpc/Posix/Mod/Ctime.cp new file mode 100644 index 0000000..b4bb545 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Ctime.cp @@ -0,0 +1,90 @@ +MODULE PosixCtime ['time.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types, PosixClocale; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + clock_t* = PosixCsys_types.clock_t; + size_t* = PosixCsys_types.size_t; + time_t* = PosixCsys_types.time_t; + pid_t* = PosixCsys_types.pid_t; + + TYPE + locale_t* = PosixClocale.locale_t; + + TYPE + Pstruct_tm* = POINTER TO struct_tm; + struct_tm* ['struct tm'] = RECORD [noalign] (* 44 *) + tm_sec*: int; (* 0+4 *) + tm_min*: int; (* 4+4 *) + tm_hour*: int; (* 8+4 *) + tm_mday*: int; (* 12+4 *) + tm_mon*: int; (* 16+4 *) + tm_year*: int; (* 20+4 *) + tm_wday*: int; (* 24+4 *) + tm_yday*: int; (* 28+4 *) + tm_isdst*: int; (* 32+4 *) + END; + + TYPE + Pstruct_timespec* = POINTER TO struct_timespec; + struct_timespec* ['struct timespec'] = RECORD [noalign] (* 8 *) + tv_sec*: time_t; (* 0+4 *) + tv_nsec*: long; (* 4+4 *) + END; + + CONST + CLOCKS_PER_SEC* = 1000000; + + PROCEDURE [ccall] asctime* (IN tm: struct_tm): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] asctime_r* (IN tm: struct_tm; buf: POINTER TO ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] clock* (): clock_t; + PROCEDURE [ccall] ctime* (VAR timep: time_t): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] ctime_r* (VAR timep: time_t; buf: POINTER TO ARRAY [untagged] OF SHORTCHAR): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] difftime* (time0, time1: time_t): double; + PROCEDURE [ccall] getdate* (IN string: ARRAY [untagged] OF SHORTCHAR): Pstruct_tm; + PROCEDURE [ccall] gmtime* (VAR timep: time_t): Pstruct_tm; + PROCEDURE [ccall] gmtime_r* (VAR timep: time_t; VAR result: struct_tm): Pstruct_tm; + PROCEDURE [ccall] localtime* (VAR timep: time_t): Pstruct_tm; + PROCEDURE [ccall] localtime_r* (VAR timep: time_t; VAR result: struct_tm): Pstruct_tm; + PROCEDURE [ccall] mktime* (VAR tm: struct_tm): time_t; + PROCEDURE [ccall] nanosleep* (IN [nil] rqtp: struct_timespec; VAR [nil] rmtp: struct_timespec): int; + PROCEDURE [ccall] strftime* (VAR s: ARRAY [untagged] OF SHORTCHAR; max: size_t; IN format: ARRAY [untagged] OF SHORTCHAR; IN tm: struct_tm): size_t; + PROCEDURE [ccall] strftime_l* (VAR s: ARRAY [untagged] OF SHORTCHAR; max: size_t; IN format: ARRAY [untagged] OF SHORTCHAR; IN tm: struct_tm; locale: locale_t): size_t; + PROCEDURE [ccall] strptime* (IN s, format: ARRAY [untagged] OF SHORTCHAR; VAR tm: struct_tm): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] time* (VAR [nil] tloc: time_t): time_t; + PROCEDURE [ccall] tzset* ; + +END PosixCtime. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Ctypes.cp b/src/cpfront/osx/powerpc/Posix/Mod/Ctypes.cp new file mode 100644 index 0000000..ca058ef --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Ctypes.cp @@ -0,0 +1,40 @@ +MODULE PosixCtypes; + + (* generated by genposix.sh, do not modify *) + +IMPORT SYSTEM; + + TYPE + char* = BYTE; + signed_char* = BYTE; + unsigned_char* = BYTE; + short* = SHORTINT; + short_int* = SHORTINT; + signed_short* = SHORTINT; + signed_short_int* = SHORTINT; + unsigned_short* = SHORTINT; + unsigned_short_int* = SHORTINT; + int* = INTEGER; + signed* = INTEGER; + signed_int* = INTEGER; + unsigned* = INTEGER; + unsigned_int* = INTEGER; + long* = INTEGER; + long_int* = INTEGER; + signed_long* = INTEGER; + signed_long_int* = INTEGER; + unsigned_long* = INTEGER; + unsigned_long_int* = INTEGER; + long_long* = LONGINT; + long_long_int* = LONGINT; + signed_long_long* = LONGINT; + signed_long_long_int* = LONGINT; + unsigned_long_long* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + unsigned_long_long_int* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END; + float* = SHORTREAL; + double* = REAL; + long_double* = RECORD [noalign] _: ARRAY [untagged] 16 OF BYTE END; + Pvoid* = INTEGER; + + +END PosixCtypes. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cunistd.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cunistd.cp new file mode 100644 index 0000000..1a842e7 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cunistd.cp @@ -0,0 +1,430 @@ +MODULE PosixCunistd ['unistd.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixCsys_types; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + CONST + _POSIX_VERSION* = 200112; + _POSIX2_VERSION* = 200112; + _XOPEN_VERSION* = 600; + + CONST + _POSIX_ADVISORY_INFO* = -1; + _POSIX_ASYNCHRONOUS_IO* = -1; + _POSIX_BARRIERS* = -1; + _POSIX_CHOWN_RESTRICTED* = 200112; + _POSIX_CLOCK_SELECTION* = -1; + _POSIX_CPUTIME* = -1; + _POSIX_FSYNC* = 200112; + _POSIX_IPV6* = 200112; + _POSIX_JOB_CONTROL* = 200112; + _POSIX_MAPPED_FILES* = 200112; + _POSIX_MEMLOCK* = -1; + _POSIX_MEMLOCK_RANGE* = -1; + _POSIX_MEMORY_PROTECTION* = 200112; + _POSIX_MESSAGE_PASSING* = -1; + _POSIX_MONOTONIC_CLOCK* = -1; + _POSIX_NO_TRUNC* = 200112; + _POSIX_PRIORITIZED_IO* = -1; + _POSIX_PRIORITY_SCHEDULING* = -1; + _POSIX_RAW_SOCKETS* = -1; + _POSIX_READER_WRITER_LOCKS* = 200112; + _POSIX_REALTIME_SIGNALS* = -1; + _POSIX_REGEXP* = 200112; + _POSIX_SAVED_IDS* = 200112; + _POSIX_SEMAPHORES* = -1; + _POSIX_SHARED_MEMORY_OBJECTS* = -1; + _POSIX_SHELL* = 200112; + _POSIX_SPAWN* = -1; + _POSIX_SPIN_LOCKS* = -1; + _POSIX_SPORADIC_SERVER* = -1; + _POSIX_SYNCHRONIZED_IO* = -1; + _POSIX_THREAD_ATTR_STACKADDR* = 200112; + _POSIX_THREAD_ATTR_STACKSIZE* = 200112; + _POSIX_THREAD_CPUTIME* = -1; + _POSIX_THREAD_PRIO_INHERIT* = -1; + _POSIX_THREAD_PRIO_PROTECT* = -1; + _POSIX_THREAD_PRIORITY_SCHEDULING* = -1; + _POSIX_THREAD_PROCESS_SHARED* = 200112; + _POSIX_THREAD_ROBUST_PRIO_INHERIT* = -1; + _POSIX_THREAD_ROBUST_PRIO_PROTECT* = -1; + _POSIX_THREAD_SAFE_FUNCTIONS* = 200112; + _POSIX_THREAD_SPORADIC_SERVER* = -1; + _POSIX_THREADS* = 200112; + _POSIX_TIMEOUTS* = -1; + _POSIX_TIMERS* = -1; + _POSIX_TRACE* = -1; + _POSIX_TRACE_EVENT_FILTER* = -1; + _POSIX_TRACE_INHERIT* = -1; + _POSIX_TRACE_LOG* = -1; + _POSIX_TYPED_MEMORY_OBJECTS* = -1; + _POSIX_V6_ILP32_OFF32* = -1; + _POSIX_V6_ILP32_OFFBIG* = -1; + _POSIX_V6_LP64_OFF64* = -1; + _POSIX_V6_LPBIG_OFFBIG* = -1; + _POSIX_V7_ILP32_OFF32* = -1; + _POSIX_V7_ILP32_OFFBIG* = -1; + _POSIX_V7_LP64_OFF64* = -1; + _POSIX_V7_LPBIG_OFFBIG* = -1; + _POSIX2_C_BIND* = 200112; + _POSIX2_C_DEV* = 200112; + _POSIX2_CHAR_TERM* = 200112; + _POSIX2_FORT_DEV* = -1; + _POSIX2_FORT_RUN* = 200112; + _POSIX2_LOCALEDEF* = 200112; + _POSIX2_PBS* = -1; + _POSIX2_PBS_ACCOUNTING* = -1; + _POSIX2_PBS_CHECKPOINT* = -1; + _POSIX2_PBS_LOCATE* = -1; + _POSIX2_PBS_MESSAGE* = -1; + _POSIX2_PBS_TRACK* = -1; + _POSIX2_SW_DEV* = 200112; + _POSIX2_UPE* = 200112; + _XOPEN_CRYPT* = 1; + _XOPEN_ENH_I18N* = 1; + _XOPEN_REALTIME* = -1; + _XOPEN_REALTIME_THREADS* = -1; + _XOPEN_SHM* = 1; + _XOPEN_STREAMS* = -1; + _XOPEN_UNIX* = 1; + _XOPEN_UUCP* = -1; + + CONST + _POSIX_ASYNC_IO* = -1; + _POSIX_PRIO_IO* = -1; + _POSIX_SYNC_IO* = -1; + _POSIX_TIMESTAMP_RESOLUTION* = -1; + _POSIX2_SYMLINKS* = -1; + + CONST + F_OK* = 0; + R_OK* = 4; + W_OK* = 2; + X_OK* = 1; + + CONST + _CS_PATH* = 1; + _CS_POSIX_V7_ILP32_OFF32_CFLAGS* = -1; + _CS_POSIX_V7_ILP32_OFF32_LDFLAGS* = -1; + _CS_POSIX_V7_ILP32_OFF32_LIBS* = -1; + _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS* = -1; + _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS* = -1; + _CS_POSIX_V7_ILP32_OFFBIG_LIBS* = -1; + _CS_POSIX_V7_LP64_OFF64_CFLAGS* = -1; + _CS_POSIX_V7_LP64_OFF64_LDFLAGS* = -1; + _CS_POSIX_V7_LP64_OFF64_LIBS* = -1; + _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS* = -1; + _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS* = -1; + _CS_POSIX_V7_LPBIG_OFFBIG_LIBS* = -1; + _CS_POSIX_V7_THREADS_CFLAGS* = -1; + _CS_POSIX_V7_THREADS_LDFLAGS* = -1; + _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS* = -1; + _CS_V7_ENV* = -1; + _CS_POSIX_V6_ILP32_OFF32_CFLAGS* = 2; + _CS_POSIX_V6_ILP32_OFF32_LDFLAGS* = 3; + _CS_POSIX_V6_ILP32_OFF32_LIBS* = 4; + _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS* = 5; + _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS* = 6; + _CS_POSIX_V6_ILP32_OFFBIG_LIBS* = 7; + _CS_POSIX_V6_LP64_OFF64_CFLAGS* = 8; + _CS_POSIX_V6_LP64_OFF64_LDFLAGS* = 9; + _CS_POSIX_V6_LP64_OFF64_LIBS* = 10; + _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS* = 11; + _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS* = 12; + _CS_POSIX_V6_LPBIG_OFFBIG_LIBS* = 13; + _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS* = 14; + _CS_V6_ENV* = -1; + + CONST + SEEK_CUR* = 1; + SEEK_END* = 2; + SEEK_SET* = 0; + + CONST + F_LOCK* = 1; + F_TEST* = 3; + F_TLOCK* = 2; + F_ULOCK* = 0; + + CONST + _PC_2_SYMLINKS* = 15; + _PC_ALLOC_SIZE_MIN* = 16; + _PC_ASYNC_IO* = 17; + _PC_CHOWN_RESTRICTED* = 7; + _PC_FILESIZEBITS* = 18; + _PC_LINK_MAX* = 1; + _PC_MAX_CANON* = 2; + _PC_MAX_INPUT* = 3; + _PC_NAME_MAX* = 4; + _PC_NO_TRUNC* = 8; + _PC_PATH_MAX* = 5; + _PC_PIPE_BUF* = 6; + _PC_PRIO_IO* = 19; + _PC_REC_INCR_XFER_SIZE* = 20; + _PC_REC_MAX_XFER_SIZE* = 21; + _PC_REC_MIN_XFER_SIZE* = 22; + _PC_REC_XFER_ALIGN* = 23; + _PC_SYMLINK_MAX* = 24; + _PC_SYNC_IO* = 25; + _PC_TIMESTAMP_RESOLUTION* = -1; + _PC_VDISABLE* = 9; + + CONST + _SC_2_C_BIND* = 18; + _SC_2_C_DEV* = 19; + _SC_2_CHAR_TERM* = 20; + _SC_2_FORT_DEV* = 21; + _SC_2_FORT_RUN* = 22; + _SC_2_LOCALEDEF* = 23; + _SC_2_PBS* = 59; + _SC_2_PBS_ACCOUNTING* = 60; + _SC_2_PBS_CHECKPOINT* = 61; + _SC_2_PBS_LOCATE* = 62; + _SC_2_PBS_MESSAGE* = 63; + _SC_2_PBS_TRACK* = 64; + _SC_2_SW_DEV* = 24; + _SC_2_UPE* = 25; + _SC_2_VERSION* = 17; + _SC_ADVISORY_INFO* = 65; + _SC_AIO_LISTIO_MAX* = 42; + _SC_AIO_MAX* = 43; + _SC_AIO_PRIO_DELTA_MAX* = 44; + _SC_ARG_MAX* = 1; + _SC_ASYNCHRONOUS_IO* = 28; + _SC_ATEXIT_MAX* = 107; + _SC_BARRIERS* = 66; + _SC_BC_BASE_MAX* = 9; + _SC_BC_DIM_MAX* = 10; + _SC_BC_SCALE_MAX* = 11; + _SC_BC_STRING_MAX* = 12; + _SC_CHILD_MAX* = 2; + _SC_CLK_TCK* = 3; + _SC_CLOCK_SELECTION* = 67; + _SC_COLL_WEIGHTS_MAX* = 13; + _SC_CPUTIME* = 68; + _SC_DELAYTIMER_MAX* = 45; + _SC_EXPR_NEST_MAX* = 14; + _SC_FSYNC* = 38; + _SC_GETGR_R_SIZE_MAX* = 70; + _SC_GETPW_R_SIZE_MAX* = 71; + _SC_HOST_NAME_MAX* = 72; + _SC_IOV_MAX* = 56; + _SC_IPV6* = 118; + _SC_JOB_CONTROL* = 6; + _SC_LINE_MAX* = 15; + _SC_LOGIN_NAME_MAX* = 73; + _SC_MAPPED_FILES* = 47; + _SC_MEMLOCK* = 30; + _SC_MEMLOCK_RANGE* = 31; + _SC_MEMORY_PROTECTION* = 32; + _SC_MESSAGE_PASSING* = 33; + _SC_MONOTONIC_CLOCK* = 74; + _SC_MQ_OPEN_MAX* = 46; + _SC_MQ_PRIO_MAX* = 75; + _SC_NGROUPS_MAX* = 4; + _SC_OPEN_MAX* = 5; + _SC_PAGE_SIZE* = 29; + _SC_PAGESIZE* = 29; + _SC_PRIORITIZED_IO* = 34; + _SC_PRIORITY_SCHEDULING* = 35; + _SC_RAW_SOCKETS* = 119; + _SC_RE_DUP_MAX* = 16; + _SC_READER_WRITER_LOCKS* = 76; + _SC_REALTIME_SIGNALS* = 36; + _SC_REGEXP* = 77; + _SC_RTSIG_MAX* = 48; + _SC_SAVED_IDS* = 7; + _SC_SEM_NSEMS_MAX* = 49; + _SC_SEM_VALUE_MAX* = 50; + _SC_SEMAPHORES* = 37; + _SC_SHARED_MEMORY_OBJECTS* = 39; + _SC_SHELL* = 78; + _SC_SIGQUEUE_MAX* = 51; + _SC_SPAWN* = 79; + _SC_SPIN_LOCKS* = 80; + _SC_SPORADIC_SERVER* = 81; + _SC_SS_REPL_MAX* = 126; + _SC_STREAM_MAX* = 26; + _SC_SYMLOOP_MAX* = 120; + _SC_SYNCHRONIZED_IO* = 40; + _SC_THREAD_ATTR_STACKADDR* = 82; + _SC_THREAD_ATTR_STACKSIZE* = 83; + _SC_THREAD_CPUTIME* = 84; + _SC_THREAD_DESTRUCTOR_ITERATIONS* = 85; + _SC_THREAD_KEYS_MAX* = 86; + _SC_THREAD_PRIO_INHERIT* = 87; + _SC_THREAD_PRIO_PROTECT* = 88; + _SC_THREAD_PRIORITY_SCHEDULING* = 89; + _SC_THREAD_PROCESS_SHARED* = 90; + _SC_THREAD_ROBUST_PRIO_INHERIT* = -1; + _SC_THREAD_ROBUST_PRIO_PROTECT* = -1; + _SC_THREAD_SAFE_FUNCTIONS* = 91; + _SC_THREAD_SPORADIC_SERVER* = 92; + _SC_THREAD_STACK_MIN* = 93; + _SC_THREAD_THREADS_MAX* = 94; + _SC_THREADS* = 96; + _SC_TIMEOUTS* = 95; + _SC_TIMER_MAX* = 52; + _SC_TIMERS* = 41; + _SC_TRACE* = 97; + _SC_TRACE_EVENT_FILTER* = 98; + _SC_TRACE_EVENT_NAME_MAX* = 127; + _SC_TRACE_INHERIT* = 99; + _SC_TRACE_LOG* = 100; + _SC_TRACE_NAME_MAX* = 128; + _SC_TRACE_SYS_MAX* = 129; + _SC_TRACE_USER_EVENT_MAX* = 130; + _SC_TTY_NAME_MAX* = 101; + _SC_TYPED_MEMORY_OBJECTS* = 102; + _SC_TZNAME_MAX* = 27; + _SC_V7_ILP32_OFF32* = -1; + _SC_V7_ILP32_OFFBIG* = -1; + _SC_V7_LP64_OFF64* = -1; + _SC_V7_LPBIG_OFFBIG* = -1; + _SC_V6_ILP32_OFF32* = 103; + _SC_V6_ILP32_OFFBIG* = 104; + _SC_V6_LP64_OFF64* = 105; + _SC_V6_LPBIG_OFFBIG* = 106; + _SC_VERSION* = 8; + _SC_XOPEN_CRYPT* = 108; + _SC_XOPEN_ENH_I18N* = 109; + _SC_XOPEN_REALTIME* = 111; + _SC_XOPEN_REALTIME_THREADS* = 112; + _SC_XOPEN_SHM* = 113; + _SC_XOPEN_STREAMS* = 114; + _SC_XOPEN_UNIX* = 115; + _SC_XOPEN_UUCP* = -1; + _SC_XOPEN_VERSION* = 116; + + CONST + STDERR_FILENO* = 2; + STDIN_FILENO* = 0; + STDOUT_FILENO* = 1; + + CONST + _POSIX_VDISABLE* = 255; + + TYPE + size_t* = PosixCsys_types.size_t; + ssize_t* = PosixCsys_types.ssize_t; + uid_t* = PosixCsys_types.uid_t; + gid_t* = PosixCsys_types.gid_t; + off_t* = PosixCsys_types.off_t; + pid_t* = PosixCsys_types.pid_t; + + TYPE + intptr_t* = INTEGER; + + PROCEDURE [ccall] access* (IN path: ARRAY [untagged] OF SHORTCHAR; amode: int): int; + PROCEDURE [ccall] alarm* (seconds: unsigned): unsigned; + PROCEDURE [ccall] chdir* (IN path: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] chown* (IN path: ARRAY [untagged] OF SHORTCHAR; owner: uid_t; group: gid_t): int; + PROCEDURE [ccall] close* (fd: int): int; + PROCEDURE [ccall] confstr* (name: int; VAR buf: ARRAY [untagged] OF SHORTCHAR; len: size_t); + PROCEDURE [ccall] crypt* (IN key, salt: ARRAY [untagged] OF SHORTCHAR); + PROCEDURE [ccall] dup* (oldfd: int): int; + PROCEDURE [ccall] dup2* (oldfd, newfd: int): int; + PROCEDURE [ccall] _exit* (status: int); + PROCEDURE [ccall] encrypt* (VAR block: ARRAY [untagged] 64 OF SHORTCHAR; edflag: int); + PROCEDURE [ccall] execv* (IN path: ARRAY [untagged] OF SHORTCHAR; IN argv: ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] execve* (IN path: ARRAY [untagged] OF SHORTCHAR; IN argv, envp: ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] execvp* (IN file: ARRAY [untagged] OF SHORTCHAR; IN argv, envp: ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] faccessat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; amode, flag: int): int; + PROCEDURE [ccall] fchdir* (fildes: int): int; + PROCEDURE [ccall] fchown* (fildes: int; owner: uid_t; group: gid_t): int; + PROCEDURE [ccall] fchownat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; owner: uid_t; group: gid_t; flag: int): int; + PROCEDURE [ccall] fdatasync* (fildes: int): int; + PROCEDURE [ccall] fexecve* (fd: int; IN argv, envp: ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] fork* (): pid_t; + PROCEDURE [ccall] fpathconf* (fd, name: int): long; + PROCEDURE [ccall] fsync* (fildes: int): int; + PROCEDURE [ccall] ftruncate* (fildes: int; length: off_t): int; + PROCEDURE [ccall] getcwd* (VAR [nil] buf: ARRAY [untagged] OF SHORTCHAR; size: size_t): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] getegid* (): gid_t; + PROCEDURE [ccall] geteuid* (): uid_t; + PROCEDURE [ccall] getgid* (): gid_t; + PROCEDURE [ccall] getgroups* (gidsetsize: int; VAR grouplist: ARRAY [untagged] OF gid_t): int; + PROCEDURE [ccall] gethostid* (): long; + PROCEDURE [ccall] gethostname* (VAR name: ARRAY [untagged] OF SHORTCHAR; namelen: size_t): int; + PROCEDURE [ccall] getlogin* (): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] getlogin_r* (VAR buf: ARRAY [untagged] OF SHORTCHAR; bufsize: size_t): int; + PROCEDURE [ccall] getopt* (argc: int; IN argv: ARRAY [untagged] OF POINTER TO ARRAY [untagged] OF SHORTCHAR; IN optstring: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] getpgid* (pid: pid_t): pid_t; + PROCEDURE [ccall] getpgrp* (): pid_t; + PROCEDURE [ccall] getpid* (): pid_t; + PROCEDURE [ccall] getppid* (): pid_t; + PROCEDURE [ccall] getsid* (): pid_t; + PROCEDURE [ccall] getuid* (): uid_t; + PROCEDURE [ccall] isatty* (fd: int): int; + PROCEDURE [ccall] lchown* (IN path: ARRAY [untagged] OF SHORTCHAR; owner: uid_t; group: gid_t): int; + PROCEDURE [ccall] link* (IN path1, path2: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] linkat* (fd1: int; IN path1: ARRAY [untagged] OF SHORTCHAR; fd2: int; IN path2: ARRAY [untagged] OF SHORTCHAR; flag: int): int; + PROCEDURE [ccall] lockf* (fd, cmd: int; len: off_t): int; + PROCEDURE [ccall] lseek* (fildes: int; offset: off_t; whence: int): off_t; + PROCEDURE [ccall] nice* (incr: int): int; + PROCEDURE [ccall] pathconf* (IN path: ARRAY [untagged] OF SHORTCHAR; name: int): long; + PROCEDURE [ccall] pause* (): int; + PROCEDURE [ccall] pipe* (VAR fildes: ARRAY [untagged] 2 OF int): int; + PROCEDURE [ccall] pread* (fildes: int; buf: PosixCtypes.Pvoid; nbyte: size_t; offset: off_t): ssize_t; + PROCEDURE [ccall] pwrite* (fildes: int; buf: PosixCtypes.Pvoid; nbyte: size_t; offset: off_t): ssize_t; + PROCEDURE [ccall] read* (fildes: int; buf: PosixCtypes.Pvoid; nbyte: size_t): ssize_t; + PROCEDURE [ccall] readlink* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: ARRAY [untagged] OF SHORTCHAR; bufsize: size_t): ssize_t; + PROCEDURE [ccall] readlinkat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: ARRAY [untagged] OF SHORTCHAR; bufsize: size_t): ssize_t; + PROCEDURE [ccall] rmdir* (IN path: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] setegid* (gid: gid_t): int; + PROCEDURE [ccall] seteuid* (uid: uid_t): int; + PROCEDURE [ccall] setgid* (gid: gid_t): int; + PROCEDURE [ccall] setpgid* (pid, pgid: pid_t): int; + PROCEDURE [ccall] setpgrp* (): pid_t; + PROCEDURE [ccall] setregid* (rgid, egid: pid_t): int; + PROCEDURE [ccall] setreuid* (ruid, euid: uid_t): int; + PROCEDURE [ccall] setsid* (): pid_t; + PROCEDURE [ccall] setuid* (uid: uid_t): int; + PROCEDURE [ccall] sleep* (seconds: unsigned): unsigned; + PROCEDURE [ccall] swab* (from, to: PosixCtypes.Pvoid; n: ssize_t); + PROCEDURE [ccall] symlink* (IN path1, path2: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] symlinkat* (IN path1: ARRAY [untagged] OF SHORTCHAR; fd: int; IN path2: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] sync* ; + PROCEDURE [ccall] sysconf* (name: int): long; + PROCEDURE [ccall] tcgetpgrp* (fd: int): pid_t; + PROCEDURE [ccall] tcsetpgrp* (fd: int; pgrp: pid_t): int; + PROCEDURE [ccall] truncate* (IN path: ARRAY [untagged] OF SHORTCHAR; length: off_t): int; + PROCEDURE [ccall] ttyname* (fd: int): POINTER TO ARRAY [untagged] OF SHORTCHAR; + PROCEDURE [ccall] ttyname_r* (fd: int; VAR buf: ARRAY [untagged] OF SHORTCHAR; buflen: size_t): int; + PROCEDURE [ccall] unlink* (IN path: ARRAY [untagged] OF SHORTCHAR): int; + PROCEDURE [ccall] unlinkat* (fd: int; IN path: ARRAY [untagged] OF SHORTCHAR; flag: int): int; + PROCEDURE [ccall] write* (fildes: int; buf: PosixCtypes.Pvoid; nbyte: size_t): int; + +END PosixCunistd. diff --git a/src/cpfront/osx/powerpc/Posix/Mod/Cwctype.cp b/src/cpfront/osx/powerpc/Posix/Mod/Cwctype.cp new file mode 100644 index 0000000..3bce926 --- /dev/null +++ b/src/cpfront/osx/powerpc/Posix/Mod/Cwctype.cp @@ -0,0 +1,58 @@ +MODULE PosixCwctype ['wctype.h']; + + (* generated by genposix.sh, do not modify *) + + IMPORT SYSTEM, PosixCtypes, PosixClocale; + + TYPE + char* = PosixCtypes.char; + signed_char* = PosixCtypes.signed_char; + unsigned_char* = PosixCtypes.unsigned_char; + short* = PosixCtypes.short; + short_int* = PosixCtypes.short_int; + signed_short* = PosixCtypes.signed_short; + signed_short_int* = PosixCtypes.signed_short_int; + unsigned_short* = PosixCtypes.unsigned_short; + unsigned_short_int* = PosixCtypes.unsigned_short_int; + int* = PosixCtypes.int; + signed* = PosixCtypes.signed; + signed_int* = PosixCtypes.signed_int; + unsigned* = PosixCtypes.unsigned; + unsigned_int* = PosixCtypes.unsigned_int; + long* = PosixCtypes.long; + long_int* = PosixCtypes.long_int; + signed_long* = PosixCtypes.signed_long; + signed_long_int* = PosixCtypes.signed_long_int; + unsigned_long* = PosixCtypes.unsigned_long; + unsigned_long_int* = PosixCtypes.unsigned_long_int; + long_long* = PosixCtypes.long_long; + long_long_int* = PosixCtypes.long_long_int; + signed_long_long* = PosixCtypes.signed_long_long; + signed_long_long_int* = PosixCtypes.signed_long_long_int; + unsigned_long_long* = PosixCtypes.unsigned_long_long; + unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int; + float* = PosixCtypes.float; + double* = PosixCtypes.double; + long_double* = PosixCtypes.long_double; + + TYPE + wint_t* = INTEGER; + wctype_t* = INTEGER; + + TYPE + wctrans_t* = INTEGER; + + TYPE + locale_t* = PosixClocale.locale_t; + + CONST + WEOF* = -1; + + PROCEDURE [ccall] iswalpha* (wc: wint_t): int; + PROCEDURE [ccall] iswdigit* (wc: wint_t): int; + PROCEDURE [ccall] iswlower* (wc: wint_t): int; + PROCEDURE [ccall] iswupper* (wc: wint_t): int; + PROCEDURE [ccall] towlower* (wc: wint_t): wint_t; + PROCEDURE [ccall] towupper* (wc: wint_t): wint_t; + +END PosixCwctype. diff --git a/src/cpfront/posix/generic/System/Mod/Kernel.cp b/src/cpfront/posix/486/System/Mod/Kernel.cp similarity index 100% rename from src/cpfront/posix/generic/System/Mod/Kernel.cp rename to src/cpfront/posix/486/System/Mod/Kernel.cp diff --git a/src/cpfront/posix/generic/Posix/Mod/Cmacro.cp b/src/cpfront/posix/generic/Posix/Mod/Cmacro.cp index 7c49fde..05bfb61 100644 --- a/src/cpfront/posix/generic/Posix/Mod/Cmacro.cp +++ b/src/cpfront/posix/generic/Posix/Mod/Cmacro.cp @@ -4,7 +4,7 @@ MODULE PosixCmacro; PROCEDURE errno* (): PosixCerrno.int; BEGIN - RETURN PosixCerrno.__errno_location()[0] + RETURN PosixCerrno.errno END errno; PROCEDURE stat* (IN path: ARRAY [untagged] OF SHORTCHAR; VAR buf: PosixCsys_stat.struct_stat): PosixCsys_stat.int; diff --git a/src/cpfront/posix/powerpc/System/Mod/Kernel.cp b/src/cpfront/posix/powerpc/System/Mod/Kernel.cp new file mode 100644 index 0000000..5656ed0 --- /dev/null +++ b/src/cpfront/posix/powerpc/System/Mod/Kernel.cp @@ -0,0 +1,1903 @@ +MODULE Kernel; + + IMPORT S := SYSTEM, stdlib := PosixCstdlib, stdio := PosixCstdio, + time := PosixCtime, wctype := PosixCwctype, sysmman := PosixCsys_mman, + dlfcn := PosixCdlfcn, fcntl := PosixCfcntl, types := PosixCtypes, + unistd := PosixCunistd, signal := PosixCsignal, setjmp := PosixCsetjmp, + macro := PosixCmacro, + LibFFI; + + (* init fpu? *) + (* add signal blocking to avoid race conditions in Try/Trap/TrapHandler *) + (* add BeepHook for Beep *) + + CONST + nameLen* = 256; + + littleEndian* = FALSE; + timeResolution* = 1000; (* ticks per second *) + + processor* = 1; (* generic c *) + + objType* = "ocf"; (* file types *) + symType* = "osf"; + docType* = "odc"; + + (* loader constants *) + done* = 0; + fileNotFound* = 1; + syntaxError* = 2; + objNotFound* = 3; + illegalFPrint* = 4; + cyclicImport* = 5; + noMem* = 6; + commNotFound* = 7; + commSyntaxError* = 8; + moduleNotFound* = 9; + + any = 1000000; + + strictStackSweep = FALSE; + N = 128 DIV 16; (* free lists *) + + (* kernel flags in module desc *) + init = 16; dyn = 17; dll = 24; iptrs = 30; + + (* meta interface consts *) + mConst = 1; mTyp = 2; mVar = 3; mProc = 4; mField = 5; + + TYPE + Name* = ARRAY nameLen OF CHAR; + Utf8Name* = ARRAY nameLen OF SHORTCHAR; + Command* = PROCEDURE; + + Module* = POINTER TO RECORD [untagged] + next-: Module; + opts-: SET; (* 0..15: compiler opts, 16..31: kernel flags *) + refcnt-: INTEGER; (* <0: module invalidated *) + compTime-, loadTime-: ARRAY 6 OF SHORTINT; + ext-: INTEGER; (* currently not used *) + term-: Command; (* terminator *) + nofimps-, nofptrs-: INTEGER; + csize-, dsize-, rsize-: INTEGER; + code-, data-, refs-: INTEGER; + procBase-, varBase-: INTEGER; (* meta base addresses *) + names-: POINTER TO ARRAY [untagged] OF SHORTCHAR; (* names[0] = 0X *) + ptrs-: POINTER TO ARRAY [untagged] OF INTEGER; + imports-: POINTER TO ARRAY [untagged] OF Module; + export-: Directory; (* exported objects (name sorted) *) + name-: Utf8Name + END; + + Type* = POINTER TO RECORD [untagged] + (* record: ptr to method n at offset - 4 * (n+1) *) + size-: INTEGER; (* record: size, array: #elem, dyn array: 0, proc: sigfp *) + mod-: Module; + id-: INTEGER; (* name idx * 256 + lev * 16 + attr * 4 + form *) + base-: ARRAY 16 OF Type; (* signature if form = ProcTyp *) + fields-: Directory; (* new fields (declaration order) *) + ptroffs-: ARRAY any OF INTEGER (* array of any length *) + END; + + Object* = POINTER TO ObjDesc; + + ObjDesc* = RECORD [untagged] + fprint-: INTEGER; + offs-: INTEGER; (* pvfprint for record types *) + id-: INTEGER; (* name idx * 256 + vis * 16 + mode *) + struct-: Type (* id of basic type or pointer to typedesc/signature *) + END; + + Directory* = POINTER TO RECORD [untagged] + num-: INTEGER; (* number of entries *) + obj-: ARRAY any OF ObjDesc (* array of any length *) + END; + + Signature* = POINTER TO RECORD [untagged] + retStruct-: Type; (* id of basic type or pointer to typedesc or 0 *) + num-: INTEGER; (* number of parameters *) + par-: ARRAY any OF RECORD [untagged] (* parameters *) + id-: INTEGER; (* name idx * 256 + kind *) + struct-: Type (* id of basic type or pointer to typedesc *) + END + END; + + Handler* = PROCEDURE; + + Reducer* = POINTER TO ABSTRACT RECORD + next: Reducer + END; + + Identifier* = ABSTRACT RECORD + typ*: INTEGER; + obj-: ANYPTR + END; + + TrapCleaner* = POINTER TO ABSTRACT RECORD + next: TrapCleaner + END; + + TryHandler* = PROCEDURE (a, b, c: INTEGER); + + (* meta extension suport *) + + ItemExt* = POINTER TO ABSTRACT RECORD END; + + ItemAttr* = RECORD + obj*, vis*, typ*, adr*: INTEGER; + mod*: Module; + desc*: Type; + ptr*: S.PTR; + ext*: ItemExt + END; + + Hook* = POINTER TO ABSTRACT RECORD END; + + LoaderHook* = POINTER TO ABSTRACT RECORD (Hook) + res*: INTEGER; + importing*, imported*, object*: ARRAY 256 OF CHAR + END; + + Block = POINTER TO RECORD [untagged] + tag: Type; + last: INTEGER; (* arrays: last element *) + actual: INTEGER; (* arrays: used during mark phase *) + first: INTEGER (* arrays: first element *) + END; + + FreeBlock = POINTER TO FreeDesc; + + FreeDesc = RECORD [untagged] + tag: Type; (* f.tag = ADR(f.size) *) + size: INTEGER; + next: FreeBlock + END; + + Cluster = POINTER TO RECORD [untagged] + size: INTEGER; (* total size *) + next: Cluster; + max: INTEGER (* exe: reserved size, dll: original address *) + (* start of first block *) + END; + + FList = POINTER TO RECORD + next: FList; + blk: Block; + iptr, aiptr: BOOLEAN + END; + + CList = POINTER TO RECORD + next: CList; + do: Command; + trapped: BOOLEAN + END; + + + PtrType = RECORD v: S.PTR END; (* used for array of pointer *) + Char8Type = RECORD v: SHORTCHAR END; + Char16Type = RECORD v: CHAR END; + Int8Type = RECORD v: BYTE END; + Int16Type = RECORD v: SHORTINT END; + Int32Type = RECORD v: INTEGER END; + Int64Type = RECORD v: LONGINT END; + BoolType = RECORD v: BOOLEAN END; + SetType = RECORD v: SET END; + Real32Type = RECORD v: SHORTREAL END; + Real64Type = RECORD v: REAL END; + ProcType = RECORD v: PROCEDURE END; + UPtrType = RECORD v: INTEGER END; + StrPtr = POINTER TO ARRAY [untagged] OF SHORTCHAR; + + (* SYSTEM.h -> SYSTEM_DLINK *) + DLink = POINTER TO RECORD [untagged] + next: DLink; + name: StrPtr + END; + ArrStrPtr = POINTER TO ARRAY [untagged] OF StrPtr; + + ADDRESS* = types.Pvoid; + + VAR + baseStack: INTEGER; + root: Cluster; + modList-: Module; + trapCount-: INTEGER; + err-, pc-, sp-, fp-, stack-, val-: INTEGER; + + isTry, checkReadable: BOOLEAN; + startEnv, checkReadableEnv: setjmp.sigjmp_buf; + tryEnv: setjmp.jmp_buf; + startDLink, tryDLink: DLink; + + argc-: INTEGER; + argv-: ArrStrPtr; + pagesize: unistd.long; + + free: ARRAY N OF FreeBlock; (* free list *) + sentinelBlock: FreeDesc; + sentinel: FreeBlock; + candidates: ARRAY 1024 OF INTEGER; + nofcand: INTEGER; + allocated: INTEGER; (* bytes allocated on BlackBox heap *) + total: INTEGER; (* current total size of BlackBox heap *) + used: INTEGER; (* bytes allocated on system heap *) + finalizers: FList; + hotFinalizers: FList; + cleaners: CList; + reducers: Reducer; + trapStack: TrapCleaner; + actual: Module; (* valid during module initialization *) + + trapViewer, trapChecker: Handler; + trapped, guarded, secondTrap: BOOLEAN; + interrupted: BOOLEAN; + static, inDll, terminating: BOOLEAN; + restart: Command; + + loader: LoaderHook; + loadres: INTEGER; + + wouldFinalize: BOOLEAN; + + watcher*: PROCEDURE (event: INTEGER); (* for debugging *) + + intTrap*: BOOLEAN; + + PROCEDURE Erase (adr, words: INTEGER); + BEGIN + ASSERT(words >= 0, 20); + WHILE words > 0 DO + S.PUT(adr, 0); + INC(adr, 4); + DEC(words) + END + END Erase; + + + PROCEDURE (VAR id: Identifier) Identified* (): BOOLEAN, NEW, ABSTRACT; + PROCEDURE (r: Reducer) Reduce* (full: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (c: TrapCleaner) Cleanup*, NEW, EMPTY; + + (* meta extension suport *) + + PROCEDURE (e: ItemExt) Lookup* (name: ARRAY OF CHAR; VAR i: ANYREC), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) Index* (index: INTEGER; VAR elem: ANYREC), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) Deref* (VAR ref: ANYREC), NEW, ABSTRACT; + + PROCEDURE (e: ItemExt) Valid* (): BOOLEAN, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) Size* (): INTEGER, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) BaseTyp* (): INTEGER, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) Len* (): INTEGER, NEW, ABSTRACT; + + PROCEDURE (e: ItemExt) Call* (OUT ok: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) BoolVal* (): BOOLEAN, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutBoolVal* (x: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) CharVal* (): CHAR, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutCharVal* (x: CHAR), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) IntVal* (): INTEGER, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutIntVal* (x: INTEGER), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) LongVal* (): LONGINT, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutLongVal* (x: LONGINT), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) RealVal* (): REAL, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutRealVal* (x: REAL), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) SetVal* (): SET, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutSetVal* (x: SET), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PtrVal* (): ANYPTR, NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutPtrVal* (x: ANYPTR), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) GetSStringVal* (OUT x: ARRAY OF SHORTCHAR; + OUT ok: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutSStringVal* (IN x: ARRAY OF SHORTCHAR; + OUT ok: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) GetStringVal* (OUT x: ARRAY OF CHAR; OUT ok: BOOLEAN), NEW, ABSTRACT; + PROCEDURE (e: ItemExt) PutStringVal* (IN x: ARRAY OF CHAR; OUT ok: BOOLEAN), NEW, ABSTRACT; + + (* -------------------- miscellaneous tools -------------------- *) + + PROCEDURE IsUpper* (ch: CHAR): BOOLEAN; + BEGIN + RETURN wctype.iswupper(ORD(ch)) # 0 + END IsUpper; + + PROCEDURE Upper* (ch: CHAR): CHAR; + BEGIN + RETURN CHR(wctype.towupper(ORD(ch))) + END Upper; + + PROCEDURE IsLower* (ch: CHAR): BOOLEAN; + BEGIN + RETURN wctype.iswlower(ORD(ch)) # 0 + END IsLower; + + PROCEDURE Lower* (ch: CHAR): CHAR; + BEGIN + RETURN CHR(wctype.towlower(ORD(ch))) + END Lower; + + PROCEDURE IsAlpha* (ch: CHAR): BOOLEAN; + BEGIN + RETURN wctype.iswalpha(ORD(ch)) # 0 + END IsAlpha; + + PROCEDURE Utf8ToString* (IN in: ARRAY OF SHORTCHAR; OUT out: ARRAY OF CHAR; OUT res: INTEGER); + VAR i, j, val, max: INTEGER; ch: SHORTCHAR; + + PROCEDURE FormatError(); + BEGIN out := in$; res := 2 (*format error*) + END FormatError; + + BEGIN + ch := in[0]; i := 1; j := 0; max := LEN(out) - 1; + WHILE (ch # 0X) & (j < max) DO + IF ch < 80X THEN + out[j] := ch; INC(j) + ELSIF ch < 0E0X THEN + val := ORD(ch) - 192; + IF val < 0 THEN FormatError; RETURN END ; + ch := in[i]; INC(i); val := val * 64 + ORD(ch) - 128; + IF (ch < 80X) OR (ch >= 0E0X) THEN FormatError; RETURN END ; + out[j] := CHR(val); INC(j) + ELSIF ch < 0F0X THEN + val := ORD(ch) - 224; + ch := in[i]; INC(i); val := val * 64 + ORD(ch) - 128; + IF (ch < 80X) OR (ch >= 0E0X) THEN FormatError; RETURN END ; + ch := in[i]; INC(i); val := val * 64 + ORD(ch) - 128; + IF (ch < 80X) OR (ch >= 0E0X) THEN FormatError; RETURN END ; + out[j] := CHR(val); INC(j) + ELSE + FormatError; RETURN + END ; + ch := in[i]; INC(i) + END; + out[j] := 0X; + IF ch = 0X THEN res := 0 (*ok*) ELSE res := 1 (*truncated*) END + END Utf8ToString; + + PROCEDURE StringToUtf8* (IN in: ARRAY OF CHAR; OUT out: ARRAY OF SHORTCHAR; OUT res: INTEGER); + VAR i, j, val, max: INTEGER; + BEGIN + i := 0; j := 0; max := LEN(out) - 3; + WHILE (in[i] # 0X) & (j < max) DO + val := ORD(in[i]); INC(i); + IF val < 128 THEN + out[j] := SHORT(CHR(val)); INC(j) + ELSIF val < 2048 THEN + out[j] := SHORT(CHR(val DIV 64 + 192)); INC(j); + out[j] := SHORT(CHR(val MOD 64 + 128)); INC(j) + ELSE + out[j] := SHORT(CHR(val DIV 4096 + 224)); INC(j); + out[j] := SHORT(CHR(val DIV 64 MOD 64 + 128)); INC(j); + out[j] := SHORT(CHR(val MOD 64 + 128)); INC(j) + END; + END; + out[j] := 0X; + IF in[i] = 0X THEN res := 0 (*ok*) ELSE res := 1 (*truncated*) END + END StringToUtf8; + + PROCEDURE SplitName* (name: ARRAY OF CHAR; VAR head, tail: ARRAY OF CHAR); + (* portable *) + VAR i, j: INTEGER; ch, lch: CHAR; + BEGIN + i := 0; ch := name[0]; + IF ch # 0X THEN + REPEAT + head[i] := ch; lch := ch; INC(i); ch := name[i] + UNTIL (ch = 0X) OR (ch = ".") OR IsUpper(ch) & ~IsUpper(lch); + IF ch = "." THEN i := 0; ch := name[0] END; + head[i] := 0X; j := 0; + WHILE ch # 0X DO tail[j] := ch; INC(i); INC(j); ch := name[i] END; + tail[j] := 0X; + IF tail = "" THEN tail := head$; head := "" END + ELSE head := ""; tail := "" + END + END SplitName; + + PROCEDURE MakeFileName* (VAR name: ARRAY OF CHAR; type: ARRAY OF CHAR); + VAR i, j: INTEGER; ext: ARRAY 8 OF CHAR; ch: CHAR; + BEGIN + i := 0; + WHILE (name[i] # 0X) & (name[i] # ".") DO INC(i) END; + IF name[i] = "." THEN + IF name[i + 1] = 0X THEN name[i] := 0X END + ELSE + IF type = "" THEN ext := docType ELSE ext := type$ END; + IF i < LEN(name) - LEN(ext$) - 1 THEN + name[i] := "."; INC(i); j := 0; ch := ext[0]; + WHILE ch # 0X DO + name[i] := Lower(ch); INC(i); INC(j); ch := ext[j] + END; + name[i] := 0X + END + END + END MakeFileName; + +(* + PROCEDURE Time* (): LONGINT; + VAR res: time.int; tp: time.struct_timespec; + BEGIN + ASSERT(timeResolution >= 1); + ASSERT(timeResolution <= 1000000000); + res := time.clock_gettime(time.CLOCK_MONOTONIC, tp); + ASSERT(res = 0, 100); + RETURN tp.tv_sec * LONG(timeResolution) + tp.tv_nsec DIV LONG(1000000000 DIV timeResolution) + END Time; +*) + + PROCEDURE Time* (): LONGINT; + BEGIN + RETURN 0 (* !!! *) + END Time; + + PROCEDURE Beep*; + (* !!! *) + END Beep; + + PROCEDURE SearchProcVar* (var: INTEGER; VAR m: Module; VAR adr: INTEGER); + BEGIN + adr := var; m := NIL; + IF var # 0 THEN + m := modList; + WHILE (m # NIL) & ((var < m.code) OR (var >= m.code + m.csize)) DO m := m.next END; + IF m # NIL THEN DEC(adr, m.code) END + END + END SearchProcVar; + + (* -------------------- system memory management --------------------- *) + + PROCEDURE AllocMem (size: sysmman.size_t; VAR max: sysmman.size_t): ADDRESS; + CONST msgstr = "mmap failed errno "; idx = LEN(msgstr); + VAR fd, flags, res: fcntl.int; ptr: ADDRESS; msg: ARRAY idx + 5 OF SHORTCHAR; + BEGIN + max := (size + pagesize - 1) DIV pagesize * pagesize; + fd := fcntl.open("/dev/zero", fcntl.O_RDWR, 0); + IF fd # -1 THEN + flags := sysmman.PROT_READ + sysmman.PROT_WRITE; + ptr := sysmman.mmap(0, max, flags, sysmman.MAP_PRIVATE, fd, 0); + IF ptr = sysmman.MAP_FAILED THEN + res := macro.errno(); + msg := msgstr; + msg[idx + 0] := SHORT(CHR(ORD("0") + res DIV 100 MOD 10)); + msg[idx + 1] := SHORT(CHR(ORD("0") + res DIV 10 MOD 10)); + msg[idx + 2] := SHORT(CHR(ORD("0") + res MOD 10)); + msg[idx + 3] := 0AX; + msg[idx + 4] := 0X; + res := unistd.write(2, S.ADR(msg), LEN(msg$)); + ptr := 0 + END; + res := unistd.close(fd); + ASSERT(res = 0, 100) + ELSE + ptr := 0 + END; + RETURN ptr + END AllocMem; + + PROCEDURE FreeMem (adr: ADDRESS; size: sysmman.size_t); + VAR res: sysmman.int; + BEGIN + size := (size + pagesize - 1) DIV pagesize * pagesize; + res := sysmman.munmap(adr, size); + ASSERT(res = 0, 100) + END FreeMem; + + PROCEDURE AllocHeapMem (size: INTEGER; VAR c: Cluster); + CONST N = 65536; (* cluster size for dll *) + VAR adr, allocated, newsize: INTEGER; + BEGIN + INC(size, 16); + ASSERT(size > 0, 100); adr := 0; + IF size < N THEN + adr := AllocMem(N, newsize); + allocated := newsize + END; + IF adr = 0 THEN + adr := AllocMem(size, newsize); + allocated := newsize + END; + IF adr = 0 THEN c := NIL + ELSE + c := S.VAL(Cluster, (adr + 15) DIV 16 * 16); c.max := adr; + c.size := allocated - (S.VAL(INTEGER, c) - adr); + INC(used, c.size); INC(total, c.size) + END; + ASSERT((adr = 0) OR (adr MOD 16 = 0) & (c.size >= size), 101); + (* post: (c = NIL) OR (c MOD 16 = 0) & (c.size >= size) *) + END AllocHeapMem; + + PROCEDURE FreeHeapMem (c: Cluster); + BEGIN + DEC(used, c.size); DEC(total, c.size); + FreeMem(S.VAL(ADDRESS, c.max), c.size) + END FreeHeapMem; + + PROCEDURE HeapFull (size: INTEGER): BOOLEAN; + BEGIN + RETURN TRUE + END HeapFull; + + PROCEDURE AllocModMem* (descSize, modSize: INTEGER; VAR descAdr, modAdr: INTEGER); + BEGIN + descAdr := 0; modAdr := 0; + descAdr := AllocMem(descSize, descSize); + IF descAdr # 0 THEN + modAdr := AllocMem(modSize, modSize); + IF modAdr = 0 THEN + FreeMem(descAdr, descSize) + ELSE + INC(used, descSize + modSize) + END + END + END AllocModMem; + + PROCEDURE DeallocModMem* (descSize, modSize, descAdr, modAdr: INTEGER); + BEGIN + FreeMem(descAdr, descSize); + FreeMem(modAdr, modSize); + DEC(used, descSize + modSize) + END DeallocModMem; + + PROCEDURE InvalModMem (modSize, modAdr: INTEGER); + BEGIN + FreeMem(modAdr, modSize) + END InvalModMem; + + PROCEDURE IsReadable* (from, to: INTEGER): BOOLEAN; + VAR r: BOOLEAN; jmp: setjmp.sigjmp_buf; res: setjmp.int; i: INTEGER; x: BYTE; + BEGIN + r := checkReadable; + jmp := checkReadableEnv; + checkReadable := TRUE; + res := setjmp.sigsetjmp(checkReadableEnv, 1); + IF res = 0 THEN + IF from <= to THEN + FOR i := from TO to DO + S.GET(i, x) + END + ELSE + FOR i := to TO from BY -1 DO + S.GET(i, x) + END + END + END; + checkReadableEnv := jmp; + checkReadable := r; + RETURN res = 0 + END IsReadable; + + (* --------------------- NEW implementation (portable) -------------------- *) + + PROCEDURE^ NewBlock (size: INTEGER): Block; + + PROCEDURE NewRec* (typ: INTEGER): INTEGER; (* implementation of NEW(ptr) *) + VAR size, adr: INTEGER; b: Block; tag: Type; l: FList; + BEGIN + IF ~ODD(typ) THEN + tag := S.VAL(Type, typ); + b := NewBlock(tag.size); + IF b # NIL THEN + b.tag := tag; + S.GET(typ - 4, size); + IF size # 0 THEN (* record uses a finalizer *) + l := S.VAL(FList, S.ADR(b.last)); (* anchor new object! *) + l := S.VAL(FList, NewRec(S.TYP(FList))); (* NEW(l) *) + l.blk := b; l.next := finalizers; finalizers := l + END; + adr := S.ADR(b.last) + ELSE + adr := 0 + END + ELSE + HALT(100) (* COM interface pointers not supported *) + END; + RETURN adr + END NewRec; + + PROCEDURE NewArr* (eltyp, nofelem, nofdim: INTEGER): INTEGER; (* impl. of NEW(ptr, dim0, dim1, ...) *) + VAR b: Block; size, headSize: INTEGER; t: Type; + BEGIN + CASE eltyp OF + | -1: HALT(100) (* COM interface pointers not supported *) + | 0: eltyp := S.ADR(PtrType) + | 1: eltyp := S.ADR(Char8Type) + | 2: eltyp := S.ADR(Int16Type) + | 3: eltyp := S.ADR(Int8Type) + | 4: eltyp := S.ADR(Int32Type) + | 5: eltyp := S.ADR(BoolType) + | 6: eltyp := S.ADR(SetType) + | 7: eltyp := S.ADR(Real32Type) + | 8: eltyp := S.ADR(Real64Type) + | 9: eltyp := S.ADR(Char16Type) + | 10: eltyp := S.ADR(Int64Type) + | 11: eltyp := S.ADR(ProcType) + | 12: HALT(101) (* COM interface pointers not supported *) + ELSE + ASSERT(~ODD(eltyp), 102) (* COM interface pointers not supported *) + END; + t := S.VAL(Type, eltyp); + headSize := 4 * nofdim + 12; + size := headSize + nofelem * t.size; + b := NewBlock(size); + IF b # NIL THEN + b.tag := S.VAL(Type, eltyp + 2); (* tag + array mark *) + b.last := S.ADR(b.last) + size - t.size; (* pointer to last elem *) + b.first := S.ADR(b.last) + headSize; (* pointer to first elem *) + RETURN S.ADR(b.last) + ELSE + RETURN 0 + END; + END NewArr; + + (* -------------------- handler installation (portable) --------------------- *) + + PROCEDURE ThisFinObj* (VAR id: Identifier): ANYPTR; + VAR l: FList; + BEGIN + ASSERT(id.typ # 0, 100); + l := finalizers; + WHILE l # NIL DO + IF S.VAL(INTEGER, l.blk.tag) = id.typ THEN + id.obj := S.VAL(ANYPTR, S.ADR(l.blk.last)); + IF id.Identified() THEN RETURN id.obj END + END; + l := l.next + END; + RETURN NIL + END ThisFinObj; + + PROCEDURE InstallReducer* (r: Reducer); + BEGIN + r.next := reducers; reducers := r + END InstallReducer; + + PROCEDURE InstallTrapViewer* (h: Handler); + BEGIN + trapViewer := h + END InstallTrapViewer; + + PROCEDURE InstallTrapChecker* (h: Handler); + BEGIN + trapChecker := h + END InstallTrapChecker; + + PROCEDURE PushTrapCleaner* (c: TrapCleaner); + VAR t: TrapCleaner; + BEGIN + t := trapStack; WHILE (t # NIL) & (t # c) DO t := t.next END; + ASSERT(t = NIL, 20); + c.next := trapStack; trapStack := c + END PushTrapCleaner; + + PROCEDURE PopTrapCleaner* (c: TrapCleaner); + VAR t: TrapCleaner; + BEGIN + t := NIL; + WHILE (trapStack # NIL) & (t # c) DO + t := trapStack; trapStack := trapStack.next + END + END PopTrapCleaner; + + PROCEDURE InstallCleaner* (p: Command); + VAR c: CList; + BEGIN + c := S.VAL(CList, NewRec(S.TYP(CList))); (* NEW(c) *) + c.do := p; c.trapped := FALSE; c.next := cleaners; cleaners := c + END InstallCleaner; + + PROCEDURE RemoveCleaner* (p: Command); + VAR c0, c: CList; + BEGIN + c := cleaners; c0 := NIL; + WHILE (c # NIL) & (c.do # p) DO c0 := c; c := c.next END; + IF c # NIL THEN + IF c0 = NIL THEN cleaners := cleaners.next ELSE c0.next := c.next END + END + END RemoveCleaner; + + PROCEDURE Cleanup*; + VAR c, c0: CList; + BEGIN + c := cleaners; c0 := NIL; + WHILE c # NIL DO + IF ~c.trapped THEN + c.trapped := TRUE; c.do; c.trapped := FALSE; c0 := c + ELSE + IF c0 = NIL THEN cleaners := cleaners.next + ELSE c0.next := c.next + END + END; + c := c.next + END + END Cleanup; + + (* -------------------- meta information (portable) --------------------- *) + + PROCEDURE (h: LoaderHook) ThisMod* (IN name: ARRAY OF CHAR): Module, NEW, ABSTRACT; + + PROCEDURE SetLoaderHook*(h: LoaderHook); + BEGIN + loader := h + END SetLoaderHook; + + PROCEDURE InitModule (mod: Module); (* initialize linked modules *) + VAR body: Command; + BEGIN + IF ~(dyn IN mod.opts) & (mod.next # NIL) & ~(init IN mod.next.opts) THEN InitModule(mod.next) END; + IF ~(init IN mod.opts) THEN + body := S.VAL(Command, mod.code); + INCL(mod.opts, init); + actual := mod; + body(); actual := NIL + END + END InitModule; + + PROCEDURE ThisLoadedMod* (IN name: ARRAY OF CHAR): Module; (* loaded modules only *) + VAR m: Module; res: INTEGER; n: Utf8Name; + BEGIN + StringToUtf8(name, n, res); ASSERT(res = 0); + loadres := done; + m := modList; + WHILE (m # NIL) & ((m.name # n) OR (m.refcnt < 0)) DO m := m.next END; + IF (m # NIL) & ~(init IN m.opts) THEN InitModule(m) END; + IF m = NIL THEN loadres := moduleNotFound END; + RETURN m + END ThisLoadedMod; + + PROCEDURE ThisMod* (IN name: ARRAY OF CHAR): Module; + BEGIN + IF loader # NIL THEN + loader.res := done; + RETURN loader.ThisMod(name) + ELSE + RETURN ThisLoadedMod(name) + END + END ThisMod; + + PROCEDURE LoadMod* (IN name: ARRAY OF CHAR); + VAR m: Module; + BEGIN + m := ThisMod(name) + END LoadMod; + + PROCEDURE GetLoaderResult* (OUT res: INTEGER; OUT importing, imported, object: ARRAY OF CHAR); + BEGIN + IF loader # NIL THEN + res := loader.res; + importing := loader.importing$; + imported := loader.imported$; + object := loader.object$ + ELSE + res := loadres; + importing := ""; + imported := ""; + object := "" + END + END GetLoaderResult; + + PROCEDURE ThisObject* (mod: Module; IN name: ARRAY OF CHAR): Object; + VAR l, r, m, res: INTEGER; p: StrPtr; n: Utf8Name; + BEGIN + StringToUtf8(name, n, res); ASSERT(res = 0); + l := 0; r := mod.export.num; + WHILE l < r DO (* binary search *) + m := (l + r) DIV 2; + p := S.VAL(StrPtr, S.ADR(mod.names[mod.export.obj[m].id DIV 256])); + IF p^ = n THEN RETURN S.VAL(Object, S.ADR(mod.export.obj[m])) END; + IF p^ < n THEN l := m + 1 ELSE r := m END + END; + RETURN NIL + END ThisObject; + + PROCEDURE ThisDesc* (mod: Module; fprint: INTEGER): Object; + VAR i, n: INTEGER; + BEGIN + i := 0; n := mod.export.num; + WHILE (i < n) & (mod.export.obj[i].id DIV 256 = 0) DO + IF mod.export.obj[i].offs = fprint THEN RETURN S.VAL(Object, S.ADR(mod.export.obj[i])) END; + INC(i) + END; + RETURN NIL + END ThisDesc; + + PROCEDURE ThisField* (rec: Type; IN name: ARRAY OF CHAR): Object; + VAR n, res: INTEGER; p: StrPtr; obj: Object; m: Module; nn: Utf8Name; + BEGIN + StringToUtf8(name, nn, res); ASSERT(res = 0); + m := rec.mod; + obj := S.VAL(Object, S.ADR(rec.fields.obj[0])); n := rec.fields.num; + WHILE n > 0 DO + p := S.VAL(StrPtr, S.ADR(m.names[obj.id DIV 256])); + IF p^ = nn THEN RETURN obj END; + DEC(n); INC(S.VAL(INTEGER, obj), 16) + END; + RETURN NIL + END ThisField; + + PROCEDURE ThisCommand* (mod: Module; IN name: ARRAY OF CHAR): Command; + VAR x: Object; sig: Signature; + BEGIN + x := ThisObject(mod, name); + IF (x # NIL) & (x.id MOD 16 = mProc) THEN + sig := S.VAL(Signature, x.struct); + IF (sig.retStruct = NIL) & (sig.num = 0) THEN RETURN S.VAL(Command, mod.procBase + x.offs) END + END; + RETURN NIL + END ThisCommand; + + PROCEDURE ThisType* (mod: Module; IN name: ARRAY OF CHAR): Type; + VAR x: Object; + BEGIN + x := ThisObject(mod, name); + IF (x # NIL) & (x.id MOD 16 = mTyp) & (S.VAL(INTEGER, x.struct) DIV 256 # 0) THEN + RETURN x.struct + ELSE + RETURN NIL + END + END ThisType; + + PROCEDURE TypeOf* (IN rec: ANYREC): Type; + BEGIN + RETURN S.VAL(Type, S.TYP(rec)) + END TypeOf; + + PROCEDURE LevelOf* (t: Type): SHORTINT; + BEGIN + RETURN SHORT(t.id DIV 16 MOD 16) + END LevelOf; + + PROCEDURE NewObj* (VAR o: S.PTR; t: Type); + VAR i: INTEGER; + BEGIN + IF t.size = -1 THEN o := NIL + ELSE + i := 0; WHILE t.ptroffs[i] >= 0 DO INC(i) END; + IF t.ptroffs[i+1] >= 0 THEN INC(S.VAL(INTEGER, t)) END; (* with interface pointers *) + o := S.VAL(S.PTR, NewRec(S.VAL(INTEGER, t))) (* generic NEW *) + END + END NewObj; + + PROCEDURE GetModName* (mod: Module; OUT name: Name); + VAR res: INTEGER; + BEGIN + Utf8ToString(mod.name, name, res); ASSERT(res = 0) + END GetModName; + + PROCEDURE GetObjName* (mod: Module; obj: Object; OUT name: Name); + VAR p: StrPtr; res: INTEGER; + BEGIN + p := S.VAL(StrPtr, S.ADR(mod.names[obj.id DIV 256])); + Utf8ToString(p^$, name, res); ASSERT(res = 0) + END GetObjName; + + PROCEDURE GetTypeName* (t: Type; OUT name: Name); + VAR p: StrPtr; res: INTEGER; + BEGIN + p := S.VAL(StrPtr, S.ADR(t.mod.names[t.id DIV 256])); + Utf8ToString(p^$, name, res); ASSERT(res = 0) + END GetTypeName; + + PROCEDURE RegisterMod* (mod: Module); + VAR i: INTEGER; epoch: time.time_t; tm: time.struct_tm; ptm: time.Pstruct_tm; + BEGIN + mod.next := modList; modList := mod; mod.refcnt := 0; INCL(mod.opts, dyn); i := 0; + WHILE i < mod.nofimps DO + IF mod.imports[i] # NIL THEN INC(mod.imports[i].refcnt) END; + INC(i) + END; + epoch := time.time(NIL); + ptm := time.localtime_r(epoch, tm); + IF ptm # NIL THEN + mod.loadTime[0] := SHORT(tm.tm_year + 1900); + mod.loadTime[1] := SHORT(tm.tm_mon + 1); + mod.loadTime[2] := SHORT(tm.tm_mday); + mod.loadTime[3] := SHORT(tm.tm_hour); + mod.loadTime[4] := SHORT(tm.tm_min); + mod.loadTime[5] := SHORT(tm.tm_sec) + ELSE + mod.loadTime[0] := 0; + mod.loadTime[1] := 0; + mod.loadTime[2] := 0; + mod.loadTime[3] := 0; + mod.loadTime[4] := 0; + mod.loadTime[5] := 0 + END; + IF ~(init IN mod.opts) THEN InitModule(mod) END + END RegisterMod; + + PROCEDURE^ Collect*; + + PROCEDURE UnloadMod* (mod: Module); + VAR i: INTEGER; t: Command; + BEGIN + IF mod.refcnt = 0 THEN + t := mod.term; mod.term := NIL; + IF t # NIL THEN t() END; (* terminate module *) + i := 0; + WHILE i < mod.nofptrs DO (* release global pointers *) + S.PUT(mod.varBase + mod.ptrs[i], 0); INC(i) + END; + Collect; (* call finalizers *) + i := 0; + WHILE i < mod.nofimps DO (* release imported modules *) + IF mod.imports[i] # NIL THEN DEC(mod.imports[i].refcnt) END; + INC(i) + END; + mod.refcnt := -1; + IF dyn IN mod.opts THEN (* release memory *) + InvalModMem(mod.data + mod.dsize - mod.refs, mod.refs) + END + END + END UnloadMod; + + (* -------------------- dynamic procedure call --------------------- *) + + (* + type par + 32 bit scalar value + 64 bit scalar low hi + var scalar address + record address tag + array address size + open array address length .. length + *) + + PROCEDURE Call* (adr: ADDRESS; sig: Signature; IN par: ARRAY OF INTEGER; n: INTEGER): LONGINT; + CONST + (* obj.id MOD 16 *) + mConst = 1; mTyp = 2; mVar = 3; mProc = 4; mField = 5; + (* typ *) + mBool = 1; mChar8 = 2; mChar16 = 3; mInt8 = 4; mInt16 = 5; mInt32 = 6; + mReal32 = 7; mReal64 = 8; mSet = 9; mInt64 = 10; mAnyRec = 11; mAnyPtr = 12; mSysPtr = 13; + (* typ.id MOD 4 *) + mProctyp = 0; mRecord = 1; mArray = 2; mPointer = 3; + (* ??? obj.id DIV 16 MOD 16 *) + mInternal = 1; mReadonly = 2; mPrivate = 3; mExported = 4; + (* sig.par[].id MOD 16 *) + mValue = 10; mInPar = 11; mOutPar = 12; mVarPar = 13; + mInterface = 32; mGuid = 33; mResult = 34; + (* implementation restrictions *) + maxPars = 127; + maxStrs = 127; + maxElms = 256; + TYPE + Ptype = POINTER TO LibFFI.type; + PPtype = POINTER TO ARRAY [untagged] OF Ptype; + VAR + status: LibFFI.status; + kind, form, size: INTEGER; + i, p, d, cn, ut, ue: INTEGER; + fret: Ptype; + vret: LONGINT; + earg: ARRAY maxElms OF Ptype; + targ: ARRAY maxStrs OF LibFFI.type; + farg: ARRAY maxPars OF Ptype; + varg: ARRAY maxPars OF ADDRESS; + typ: Type; + cif: LibFFI.cif; + + PROCEDURE SetType (IN typ: LibFFI.type); + BEGIN + farg[cn] := S.VAL(Ptype, S.ADR(typ)); + END SetType; + + PROCEDURE PushAdr (size: INTEGER); + BEGIN + ASSERT(size IN {1, 2, 4, 8}, 20); + ASSERT(littleEndian OR (size <= 4), 100); (* !!! swap 64bit value *) + varg[cn] := S.ADR(par[d]); + INC(cn); INC(d, MAX(1, size DIV 4)) + END PushAdr; + + PROCEDURE PushVal (size: INTEGER); + BEGIN + ASSERT(size IN {1, 2, 4, 8}, 20); + ASSERT(littleEndian OR (size <= 4), 100); (* !!! swap 64bit value *) + varg[cn] := par[d]; + INC(cn); INC(d, MAX(1, size DIV 4)) + END PushVal; + + PROCEDURE Push (IN typ: LibFFI.type); + BEGIN + SetType(typ); PushAdr(typ.size) + END Push; + + BEGIN + p := 0; cn := 0; d := 0; ut := 0; ue := 0; + WHILE p < sig.num DO + typ := sig.par[p].struct; + kind := sig.par[p].id MOD 16; + IF S.VAL(ADDRESS, typ) DIV 256 = 0 THEN (* basic types *) + form := S.VAL(ADDRESS, typ) MOD 256; + IF kind = mValue THEN + CASE form OF + | mBool, mChar8: Push(LibFFI.type_uint8) + | mChar16: Push(LibFFI.type_uint16) + | mInt8: Push(LibFFI.type_sint8) + | mInt16: Push(LibFFI.type_sint16) + | mInt32: Push(LibFFI.type_sint32) + | mReal32: Push(LibFFI.type_float) + | mReal64: Push(LibFFI.type_double) + | mSet: Push(LibFFI.type_uint32) + | mInt64: Push(LibFFI.type_sint64) + | mAnyPtr, mSysPtr: Push(LibFFI.type_pointer) + ELSE HALT(100) (* unsupported type *) + END; + ELSIF kind IN {mInPar..mVarPar} THEN + CASE form OF + | mBool..mInt64, mAnyPtr, mSysPtr: Push(LibFFI.type_pointer) + | mAnyRec: Push(LibFFI.type_pointer); Push(LibFFI.type_pointer) (* address + tag *) + ELSE HALT(101) (* unsupported type *) + END + ELSE + HALT(102) (* unsupported parameter kind *) + END + ELSE + CASE typ.id MOD 4 OF + | mProctyp, mPointer: + Push(LibFFI.type_pointer) + | mRecord: + IF kind = mValue THEN + targ[ut].size := 0; + targ[ut].alignment := 0; + targ[ut].type := LibFFI.TYPE_STRUCT; + targ[ut].elements := S.VAL(PPtype, S.ADR(earg[ue])); + SetType(targ[ut]); INC(ut); + size := MAX(1, typ.size); + (* !!! better to pass original layout *) + WHILE size >= 8 DO + earg[ue] := S.VAL(Ptype, S.ADR(LibFFI.type_uint64)); + INC(ue); DEC(size, 8) + END; + IF size >= 4 THEN + earg[ue] := S.VAL(Ptype, S.ADR(LibFFI.type_uint32)); + INC(ue); DEC(size, 4) + END; + IF size >= 2 THEN + earg[ue] := S.VAL(Ptype, S.ADR(LibFFI.type_uint16)); + INC(ue); DEC(size, 2) + END; + IF size >= 1 THEN + earg[ue] := S.VAL(Ptype, S.ADR(LibFFI.type_uint32)); + INC(ue); DEC(size) + END; + earg[ue] := NIL; + INC(ue); + PushVal(LibFFI.type_pointer.size); + INC(d) (* skip tag *) + ELSIF kind IN {mInPar..mVarPar} THEN + Push(LibFFI.type_pointer); (* address *) + Push(LibFFI.type_pointer); (* tag *) + ELSE HALT(103) (* unsupported parameter kind *) + END + | mArray: + Push(LibFFI.type_pointer); + ASSERT(kind IN {mValue..mVarPar}, 104); (* unsupported parameter kind *) + (* array copying generated by CPfront, so we can just pass address *) + IF typ.size = 0 THEN (* open array *) + FOR i := 0 TO typ.id DIV 16 - 1 DO + Push(LibFFI.type_sint32) (* dim size *) + END + ELSE (* fix array *) + INC(d) (* skip size *) + END + END + END; + INC(p) + END; + ASSERT(d = n, 105); + typ := sig.retStruct; + IF typ = NIL THEN fret := S.VAL(Ptype, S.ADR(LibFFI.type_void)) + ELSIF S.VAL(ADDRESS, typ) DIV 256 = 0 THEN + form := S.VAL(ADDRESS, typ) MOD 256; + CASE form OF + | mBool, mChar8: fret := S.VAL(Ptype, S.ADR(LibFFI.type_uint8)) + | mChar16: fret := S.VAL(Ptype, S.ADR(LibFFI.type_uint16)) + | mInt8: fret := S.VAL(Ptype, S.ADR(LibFFI.type_sint8)) + | mInt16: fret := S.VAL(Ptype, S.ADR(LibFFI.type_sint16)) + | mInt32: fret := S.VAL(Ptype, S.ADR(LibFFI.type_sint32)) + | mReal32: fret := S.VAL(Ptype, S.ADR(LibFFI.type_float)) + | mReal64: fret := S.VAL(Ptype, S.ADR(LibFFI.type_double)) + | mSet: fret := S.VAL(Ptype, S.ADR(LibFFI.type_uint32)) + | mInt64: fret := S.VAL(Ptype, S.ADR(LibFFI.type_sint64)) + | mAnyPtr, mSysPtr: fret := S.VAL(Ptype, S.ADR(LibFFI.type_pointer)) + ELSE HALT(106) (* unsupported type *) + END + ELSE + CASE typ.id MOD 4 OF + | mProctyp, mPointer: fret := S.VAL(Ptype, S.ADR(LibFFI.type_pointer)) + ELSE HALT(107) (* unsupported type *) + END + END; + status := LibFFI.prep_cif(cif, LibFFI.DEFAULT_ABI, cn, fret, farg); + ASSERT(status = LibFFI.OK, 108); + vret := 0; + IF littleEndian THEN LibFFI.call(cif, adr, S.ADR(vret), S.ADR(varg)) + ELSE LibFFI.call(cif, adr, S.ADR(vret) + (8 - fret.size), S.ADR(varg)) + END; + RETURN vret + END Call; + + (* -------------------- reference information (portable) --------------------- *) + + PROCEDURE RefCh (VAR ref: INTEGER; OUT ch: SHORTCHAR); + BEGIN + S.GET(ref, ch); INC(ref) + END RefCh; + + PROCEDURE RefNum (VAR ref: INTEGER; OUT x: INTEGER); + VAR s, n: INTEGER; ch: SHORTCHAR; + BEGIN + s := 0; n := 0; RefCh(ref, ch); + WHILE ORD(ch) >= 128 DO INC(n, ASH(ORD(ch) - 128, s) ); INC(s, 7); RefCh(ref, ch) END; + x := n + ASH(ORD(ch) MOD 64 - ORD(ch) DIV 64 * 64, s) + END RefNum; + + PROCEDURE RefName (VAR ref: INTEGER; OUT n: Utf8Name); + VAR i: INTEGER; ch: SHORTCHAR; + BEGIN + i := 0; RefCh(ref, ch); + WHILE ch # 0X DO n[i] := ch; INC(i); RefCh(ref, ch) END; + n[i] := 0X + END RefName; + + PROCEDURE GetRefProc* (VAR ref: INTEGER; OUT adr: INTEGER; OUT name: Utf8Name); + VAR ch: SHORTCHAR; + BEGIN + S.GET(ref, ch); + WHILE ch >= 0FDX DO (* skip variables *) + INC(ref); RefCh(ref, ch); + IF ch = 10X THEN INC(ref, 4) END; + RefNum(ref, adr); RefName(ref, name); S.GET(ref, ch) + END; + WHILE (ch > 0X) & (ch < 0FCX) DO (* skip source refs *) + INC(ref); RefNum(ref, adr); S.GET(ref, ch) + END; + IF ch = 0FCX THEN INC(ref); RefNum(ref, adr); RefName(ref, name) + ELSE adr := 0 + END + END GetRefProc; + + PROCEDURE GetRefVar* (VAR ref: INTEGER; OUT mode, form: SHORTCHAR; OUT desc: Type; OUT adr: INTEGER; OUT name: Utf8Name); + BEGIN + S.GET(ref, mode); desc := NIL; + IF mode >= 0FDX THEN + mode := SHORT(CHR(ORD(mode) - 0FCH)); + INC(ref); RefCh(ref, form); + IF form = 10X THEN + S.GET(ref, desc); INC(ref, 4); form := SHORT(CHR(16 + desc.id MOD 4)) + END; + RefNum(ref, adr); RefName(ref, name) + ELSE + mode := 0X; form := 0X; adr := 0 + END + END GetRefVar; + + PROCEDURE SourcePos* (mod: Module; codePos: INTEGER): INTEGER; + VAR ref, pos, ad, d: INTEGER; ch: SHORTCHAR; name: Utf8Name; + BEGIN + IF mod # NIL THEN (* mf, 12.02.04 *) + ref := mod.refs; pos := 0; ad := 0; S.GET(ref, ch); + WHILE ch # 0X DO + WHILE (ch > 0X) & (ch < 0FCX) DO (* srcref: {dAdr,dPos} *) + INC(ad, ORD(ch)); INC(ref); RefNum(ref, d); + IF ad > codePos THEN RETURN pos END; + INC(pos, d); S.GET(ref, ch) + END; + IF ch = 0FCX THEN (* proc: 0FCX,Adr,Name *) + INC(ref); RefNum(ref, d); RefName(ref, name); S.GET(ref, ch); + IF (d > codePos) & (pos > 0) THEN RETURN pos END + END; + WHILE ch >= 0FDX DO (* skip variables: Mode, Form, adr, Name *) + INC(ref); RefCh(ref, ch); + IF ch = 10X THEN INC(ref, 4) END; + RefNum(ref, d); RefName(ref, name); S.GET(ref, ch) + END + END; + END; + RETURN -1 + END SourcePos; + + PROCEDURE LoadDll* (IN name: ARRAY OF CHAR; VAR ok: BOOLEAN); + VAR h: ADDRESS; file: Utf8Name; res: INTEGER; + BEGIN + StringToUtf8(name, file, res); + IF res = 0 THEN + h := dlfcn.dlopen(file, dlfcn.RTLD_LAZY + dlfcn.RTLD_GLOBAL); + ok := h # 0 + ELSE + ok := FALSE + END + END LoadDll; + + PROCEDURE ThisDllObj* (mode, fprint: INTEGER; IN dll, name: ARRAY OF CHAR): INTEGER; + VAR h, p: ADDRESS; file, sym: Utf8Name; res: INTEGER; err: dlfcn.int; + BEGIN + StringToUtf8(dll, file, res); + IF res = 0 THEN + h := dlfcn.dlopen(file, dlfcn.RTLD_LAZY + dlfcn.RTLD_GLOBAL); + IF h # 0 THEN + StringToUtf8(name, sym, res); + IF res = 0 THEN + p := dlfcn.dlsym(h, sym) + ELSE + p := 0 + END; + err := dlfcn.dlclose(h); + ASSERT(err = 0, 100) + ELSE + p := 0 + END + ELSE + p := 0 + END; + RETURN p + END ThisDllObj; + + (* -------------------- garbage collector (portable) --------------------- *) + + PROCEDURE Mark (this: Block); + VAR father, son: Block; tag: Type; flag, offset, actual: INTEGER; + BEGIN + IF ~ODD(S.VAL(INTEGER, this.tag)) THEN + father := NIL; + LOOP + INC(S.VAL(INTEGER, this.tag)); + flag := S.VAL(INTEGER, this.tag) MOD 4; + tag := S.VAL(Type, S.VAL(INTEGER, this.tag) - flag); + IF flag >= 2 THEN actual := this.first; this.actual := actual + ELSE actual := S.ADR(this.last) + END; + LOOP + offset := tag.ptroffs[0]; + IF offset < 0 THEN + INC(S.VAL(INTEGER, tag), offset + 4); (* restore tag *) + IF (flag >= 2) & (actual < this.last) & (offset < -4) THEN (* next array element *) + INC(actual, tag.size); this.actual := actual + ELSE (* up *) + this.tag := S.VAL(Type, S.VAL(INTEGER, tag) + flag); + IF father = NIL THEN RETURN END; + son := this; this := father; + flag := S.VAL(INTEGER, this.tag) MOD 4; + tag := S.VAL(Type, S.VAL(INTEGER, this.tag) - flag); + offset := tag.ptroffs[0]; + IF flag >= 2 THEN actual := this.actual ELSE actual := S.ADR(this.last) END; + S.GET(actual + offset, father); S.PUT(actual + offset, S.ADR(son.last)); + INC(S.VAL(INTEGER, tag), 4) + END + ELSE + S.GET(actual + offset, son); + IF son # NIL THEN + DEC(S.VAL(INTEGER, son), 4); + IF ~ODD(S.VAL(INTEGER, son.tag)) THEN (* down *) + this.tag := S.VAL(Type, S.VAL(INTEGER, tag) + flag); + S.PUT(actual + offset, father); father := this; this := son; + EXIT + END + END; + INC(S.VAL(INTEGER, tag), 4) + END + END + END + END + END Mark; + + PROCEDURE MarkGlobals; + VAR m: Module; i, p: INTEGER; + BEGIN + m := modList; + WHILE m # NIL DO + IF m.refcnt >= 0 THEN + i := 0; + WHILE i < m.nofptrs DO + S.GET(m.varBase + m.ptrs[i], p); INC(i); + IF p # 0 THEN Mark(S.VAL(Block, p - 4)) END + END + END; + m := m.next + END + END MarkGlobals; + + PROCEDURE Next (b: Block): Block; (* next block in same cluster *) + VAR size: INTEGER; + BEGIN + S.GET(S.VAL(INTEGER, b.tag) DIV 4 * 4, size); + IF ODD(S.VAL(INTEGER, b.tag) DIV 2) THEN INC(size, b.last - S.ADR(b.last)) END; + RETURN S.VAL(Block, S.VAL(INTEGER, b) + (size + 19) DIV 16 * 16) + END Next; + + PROCEDURE CheckCandidates; + (* pre: nofcand > 0 *) + VAR i, j, h, p, end: INTEGER; c: Cluster; blk, next: Block; + BEGIN + (* sort candidates (shellsort) *) + h := 1; REPEAT h := h*3 + 1 UNTIL h > nofcand; + REPEAT h := h DIV 3; i := h; + WHILE i < nofcand DO p := candidates[i]; j := i; + WHILE (j >= h) & (candidates[j-h] > p) DO + candidates[j] := candidates[j-h]; j := j-h + END; + candidates[j] := p; INC(i) + END + UNTIL h = 1; + (* sweep *) + c := root; i := 0; + WHILE c # NIL DO + blk := S.VAL(Block, S.VAL(INTEGER, c) + 12); + end := S.VAL(INTEGER, blk) + (c.size - 12) DIV 16 * 16; + WHILE candidates[i] < S.VAL(INTEGER, blk) DO + INC(i); + IF i = nofcand THEN RETURN END + END; + WHILE S.VAL(INTEGER, blk) < end DO + next := Next(blk); + IF candidates[i] < S.VAL(INTEGER, next) THEN + IF (S.VAL(INTEGER, blk.tag) # S.ADR(blk.last)) (* not a free block *) + & (~strictStackSweep OR (candidates[i] = S.ADR(blk.last))) THEN + Mark(blk) + END; + REPEAT + INC(i); + IF i = nofcand THEN RETURN END + UNTIL candidates[i] >= S.VAL(INTEGER, next) + END; + IF (S.VAL(INTEGER, blk.tag) MOD 4 = 0) & (S.VAL(INTEGER, blk.tag) # S.ADR(blk.last)) + & (blk.tag.base[0] = NIL) & (blk.actual > 0) THEN (* referenced interface record *) + Mark(blk) + END; + blk := next + END; + c := c.next + END + END CheckCandidates; + + PROCEDURE MarkLocals; + VAR sp, p, min, max: INTEGER; c: Cluster; + BEGIN + sp := S.ADR(sp); nofcand := 0; c := root; + WHILE c.next # NIL DO c := c.next END; + min := S.VAL(INTEGER, root); max := S.VAL(INTEGER, c) + c.size; + WHILE sp < baseStack DO + S.GET(sp, p); + IF (p > min) & (p < max) & (~strictStackSweep OR (p MOD 16 = 0)) THEN + candidates[nofcand] := p; INC(nofcand); + IF nofcand = LEN(candidates) - 1 THEN CheckCandidates; nofcand := 0 END + END; + INC(sp, 4) + END; + candidates[nofcand] := max; INC(nofcand); (* ensure complete scan for interface mark*) + IF nofcand > 0 THEN CheckCandidates END + END MarkLocals; + + PROCEDURE MarkFinObj; + VAR f: FList; + BEGIN + wouldFinalize := FALSE; + f := finalizers; + WHILE f # NIL DO + IF ~ODD(S.VAL(INTEGER, f.blk.tag)) THEN wouldFinalize := TRUE END; + Mark(f.blk); + f := f.next + END; + f := hotFinalizers; + WHILE f # NIL DO IF ~ODD(S.VAL(INTEGER, f.blk.tag)) THEN wouldFinalize := TRUE END; + Mark(f.blk); + f := f.next + END + END MarkFinObj; + + PROCEDURE CheckFinalizers; + VAR f, g, h, k: FList; + BEGIN + f := finalizers; g := NIL; + IF hotFinalizers = NIL THEN k := NIL + ELSE + k := hotFinalizers; + WHILE k.next # NIL DO k := k.next END + END; + WHILE f # NIL DO + h := f; f := f.next; + IF ~ODD(S.VAL(INTEGER, h.blk.tag)) THEN + IF g = NIL THEN finalizers := f ELSE g.next := f END; + IF k = NIL THEN hotFinalizers := h ELSE k.next := h END; + k := h; h.next := NIL + ELSE g := h + END + END; + h := hotFinalizers; + WHILE h # NIL DO Mark(h.blk); h := h.next END + END CheckFinalizers; + + PROCEDURE ExecFinalizer (a, b, c: INTEGER); + VAR f: FList; fin: PROCEDURE(this: ANYPTR); + BEGIN + f := S.VAL(FList, a); + S.GET(S.VAL(INTEGER, f.blk.tag) - 4, fin); (* method 0 *) + IF (fin # NIL) & (f.blk.tag.mod.refcnt >= 0) THEN fin(S.VAL(ANYPTR, S.ADR(f.blk.last))) END; + END ExecFinalizer; + + PROCEDURE^ Try* (h: TryHandler; a, b, c: INTEGER); (* COMPILER DEPENDENT *) + + PROCEDURE CallFinalizers; + VAR f: FList; + BEGIN + WHILE hotFinalizers # NIL DO + f := hotFinalizers; hotFinalizers := hotFinalizers.next; + Try(ExecFinalizer, S.VAL(INTEGER, f), 0, 0) + END; + wouldFinalize := FALSE + END CallFinalizers; + + PROCEDURE Insert (blk: FreeBlock; size: INTEGER); (* insert block in free list *) + VAR i: INTEGER; + BEGIN + blk.size := size - 4; blk.tag := S.VAL(Type, S.ADR(blk.size)); + i := MIN(N - 1, (blk.size DIV 16)); + blk.next := free[i]; free[i] := blk + END Insert; + + PROCEDURE Sweep (dealloc: BOOLEAN); + VAR cluster, last, c: Cluster; blk, next: Block; fblk, b, t: FreeBlock; end, i: INTEGER; + BEGIN + cluster := root; last := NIL; allocated := 0; + i := N; + REPEAT DEC(i); free[i] := sentinel UNTIL i = 0; + WHILE cluster # NIL DO + blk := S.VAL(Block, S.VAL(INTEGER, cluster) + 12); + end := S.VAL(INTEGER, blk) + (cluster.size - 12) DIV 16 * 16; + fblk := NIL; + WHILE S.VAL(INTEGER, blk) < end DO + next := Next(blk); + IF ODD(S.VAL(INTEGER, blk.tag)) THEN + IF fblk # NIL THEN + Insert(fblk, S.VAL(INTEGER, blk) - S.VAL(INTEGER, fblk)); + fblk := NIL + END; + DEC(S.VAL(INTEGER, blk.tag)); (* unmark *) + INC(allocated, S.VAL(INTEGER, next) - S.VAL(INTEGER, blk)) + ELSIF fblk = NIL THEN + fblk := S.VAL(FreeBlock, blk) + END; + blk := next + END; + IF dealloc & (S.VAL(INTEGER, fblk) = S.VAL(INTEGER, cluster) + 12) THEN (* deallocate cluster *) + c := cluster; cluster := cluster.next; + IF last = NIL THEN root := cluster ELSE last.next := cluster END; + FreeHeapMem(c) + ELSE + IF fblk # NIL THEN Insert(fblk, end - S.VAL(INTEGER, fblk)) END; + last := cluster; cluster := cluster.next + END + END; + (* reverse free list *) + i := N; + REPEAT + DEC(i); + b := free[i]; fblk := sentinel; + WHILE b # sentinel DO t := b; b := t.next; t.next := fblk; fblk := t END; + free[i] := fblk + UNTIL i = 0 + END Sweep; + + PROCEDURE Collect*; + BEGIN + IF root # NIL THEN + CallFinalizers; (* trap cleanup *) + MarkGlobals; + MarkLocals; + CheckFinalizers; + Sweep(TRUE); + CallFinalizers + END + END Collect; + + PROCEDURE FastCollect*; + BEGIN + IF root # NIL THEN + MarkGlobals; + MarkLocals; + MarkFinObj; + Sweep(FALSE) + END + END FastCollect; + + PROCEDURE WouldFinalize* (): BOOLEAN; + BEGIN + RETURN wouldFinalize + END WouldFinalize; + + (* --------------------- memory allocation (portable) -------------------- *) + + PROCEDURE OldBlock (size: INTEGER): FreeBlock; (* size MOD 16 = 0 *) + VAR b, l: FreeBlock; s, i: INTEGER; + BEGIN + s := size - 4; + i := MIN(N - 1, s DIV 16); + WHILE (i # N - 1) & (free[i] = sentinel) DO INC(i) END; + b := free[i]; l := NIL; + WHILE b.size < s DO l := b; b := b.next END; + IF b # sentinel THEN + IF l = NIL THEN free[i] := b.next ELSE l.next := b.next END + ELSE b := NIL + END; + RETURN b + END OldBlock; + + PROCEDURE LastBlock (limit: INTEGER): FreeBlock; (* size MOD 16 = 0 *) + VAR b, l: FreeBlock; s, i: INTEGER; + BEGIN + s := limit - 4; + i := 0; + REPEAT + b := free[i]; l := NIL; + WHILE (b # sentinel) & (S.VAL(INTEGER, b) + b.size # s) DO l := b; b := b.next END; + IF b # sentinel THEN + IF l = NIL THEN free[i] := b.next ELSE l.next := b.next END + ELSE b := NIL + END; + INC(i) + UNTIL (b # NIL) OR (i = N); + RETURN b + END LastBlock; + + PROCEDURE NewBlock (size: INTEGER): Block; + VAR tsize, a, s: INTEGER; b: FreeBlock; new, c: Cluster; r: Reducer; + BEGIN + ASSERT(size >= 0, 20); + IF size > MAX(INTEGER) - 19 THEN RETURN NIL END; + tsize := (size + 19) DIV 16 * 16; + b := OldBlock(tsize); (* 1) search for free block *) + IF b = NIL THEN + FastCollect; b := OldBlock(tsize); (* 2) collect *) + IF b = NIL THEN + Collect; b := OldBlock(tsize); (* 2a) fully collect *) + END; + IF b = NIL THEN + AllocHeapMem(tsize + 12, new); (* 3) allocate new cluster *) + IF new # NIL THEN + IF (root = NIL) OR (S.VAL(INTEGER, new) < S.VAL(INTEGER, root)) THEN + new.next := root; root := new + ELSE + c := root; + WHILE (c.next # NIL) & (S.VAL(INTEGER, new) > S.VAL(INTEGER, c.next)) DO c := c.next END; + new.next := c.next; c.next := new + END; + b := S.VAL(FreeBlock, S.VAL(INTEGER, new) + 12); + b.size := (new.size - 12) DIV 16 * 16 - 4 + ELSE + RETURN NIL (* 4) give up *) + END + END + END; + (* b # NIL *) + a := b.size + 4 - tsize; + IF a > 0 THEN Insert(S.VAL(FreeBlock, S.VAL(INTEGER, b) + tsize), a) END; + IF size > 0 THEN Erase(S.ADR(b.size), (size + 3) DIV 4) END; + INC(allocated, tsize); + RETURN S.VAL(Block, b) + END NewBlock; + + PROCEDURE Allocated* (): INTEGER; + BEGIN + RETURN allocated + END Allocated; + + PROCEDURE Used* (): INTEGER; + BEGIN + RETURN used + END Used; + + PROCEDURE Root* (): INTEGER; + BEGIN + RETURN S.VAL(INTEGER, root) + END Root; + + (* -------------------- Trap Handling --------------------- *) + + PROCEDURE [code] GetDLink (): DLink "(Kernel_DLink)SYSTEM_dlink"; + PROCEDURE [code] SetDLink (dl: DLink) "SYSTEM_dlink = (SYSTEM_DLINK*)dl"; + + PROCEDURE Start* (code: Command); + VAR res: setjmp.int; dl: DLink; + BEGIN + restart := code; + baseStack := S.ADR(code); (* XXX: expected that target uses one stack *) + startDLink := GetDLink(); + res := setjmp.sigsetjmp(startEnv, 1); + restart + END Start; + + PROCEDURE Quit* (exitCode: INTEGER); + VAR m: Module; term: Command; t: BOOLEAN; + BEGIN + trapViewer := NIL; trapChecker := NIL; restart := NIL; + t := terminating; terminating := TRUE; m := modList; + WHILE m # NIL DO (* call terminators *) + IF ~static OR ~t THEN + term := m.term; m.term := NIL; + IF term # NIL THEN term() END + END; + m := m.next + END; + CallFinalizers; + hotFinalizers := finalizers; finalizers := NIL; + CallFinalizers; + stdlib.exit(exitCode) + END Quit; + + PROCEDURE FatalError* (id: INTEGER; str: ARRAY OF CHAR); + VAR res: stdio.int; title: ARRAY 16 OF CHAR; text: ARRAY 256 OF SHORTCHAR; + BEGIN + title := "Error xy"; + title[6] := CHR(id DIV 10 + ORD("0")); + title[7] := CHR(id MOD 10 + ORD("0")); + res := unistd.write(2, S.ADR(title), 8); + stdlib.abort + END FatalError; + + PROCEDURE DefaultTrapViewer; + VAR out: ARRAY 256 OF SHORTCHAR; c, len: INTEGER; res: unistd.int; dl: DLink; + + PROCEDURE WriteString (IN s: ARRAY OF SHORTCHAR); + VAR i: INTEGER; + BEGIN + i := 0; + WHILE (len < LEN(out) - 1) & (s[i] # 0X) DO out[len] := s[i]; INC(i); INC(len) END + END WriteString; + + PROCEDURE WriteHex (x, n: INTEGER); + VAR i, y: INTEGER; + BEGIN + IF len + n < LEN(out) THEN + i := len + n - 1; + WHILE i >= len DO + y := x MOD 16; x := x DIV 16; + IF y > 9 THEN y := y + (ORD("A") - ORD("0") - 10) END; + out[i] := SHORT(CHR(y + ORD("0"))); DEC(i) + END; + INC(len, n) + END + END WriteHex; + + PROCEDURE WriteLn; + BEGIN + IF len < LEN(out) - 1 THEN out[len] := 0AX; INC(len) END + END WriteLn; + + BEGIN + len := 0; + WriteString("====== "); + IF err = 129 THEN WriteString("invalid with") + ELSIF err = 130 THEN WriteString("invalid case") + ELSIF err = 131 THEN WriteString("function without return") + ELSIF err = 132 THEN WriteString("type guard") + ELSIF err = 133 THEN WriteString("implied type guard") + ELSIF err = 134 THEN WriteString("value out of range") + ELSIF err = 135 THEN WriteString("index out of range") + ELSIF err = 136 THEN WriteString("string too long") + ELSIF err = 137 THEN WriteString("stack overflow") + ELSIF err = 138 THEN WriteString("integer overflow") + ELSIF err = 139 THEN WriteString("division by zero") + ELSIF err = 140 THEN WriteString("infinite real result") + ELSIF err = 141 THEN WriteString("real underflow") + ELSIF err = 142 THEN WriteString("real overflow") + ELSIF err = 143 THEN WriteString("undefined real result") + ELSIF err = 144 THEN WriteString("not a number") + ELSIF err = 200 THEN WriteString("keyboard interrupt") + ELSIF err = 201 THEN WriteString("NIL dereference") + ELSIF err = 202 THEN WriteString("illegal instruction: "); + WriteHex(val, 4) + ELSIF err = 203 THEN WriteString("illegal memory read [ad = "); + WriteHex(val, 8); WriteString("]") + ELSIF err = 204 THEN WriteString("illegal memory write [ad = "); + WriteHex(val, 8); WriteString("]") + ELSIF err = 205 THEN WriteString("illegal execution [ad = "); + WriteHex(val, 8); WriteString("]") + ELSIF err = 257 THEN WriteString("out of memory") + ELSIF err = 10001H THEN WriteString("bus error") + ELSIF err = 10002H THEN WriteString("address error") + ELSIF err = 10007H THEN WriteString("fpu error") + ELSIF err < 0 THEN WriteString("exception #"); WriteHex(-err, 2) + ELSE err := err DIV 100 * 256 + err DIV 10 MOD 10 * 16 + err MOD 10; + WriteString("trap #"); WriteHex(err, 3) + END; + WriteString(" ======"); + WriteLn; + dl := GetDLink(); + (* skip Kernel.DefaultTrapViewer & Kernel.Trap/Kernel.TrapHandler *) + c := 2; + WHILE (c > 0) & (dl # NIL) DO + dl := dl.next; + DEC(c) + END; + (* stack trace *) + c := 16; + WHILE (c > 0) & (dl # NIL) DO + WriteString("- "); WriteString(dl.name$); WriteLn; + dl := dl.next; + DEC(c) + END; + out[len] := 0X; + res := unistd.write(2, S.ADR(out), len) + END DefaultTrapViewer; + + PROCEDURE TrapCleanup; + VAR t: TrapCleaner; + BEGIN + WHILE trapStack # NIL DO + t := trapStack; trapStack := trapStack.next; t.Cleanup + END; + IF (trapChecker # NIL) & (err # 128) THEN trapChecker END + END TrapCleanup; + + PROCEDURE SetTrapGuard* (on: BOOLEAN); + BEGIN + guarded := on + END SetTrapGuard; + + PROCEDURE Try* (h: TryHandler; a, b, c: INTEGER); + VAR oldIsTry: BOOLEAN; oldTryEnv: setjmp.jmp_buf; oldTryDLink: DLink; res: setjmp.int; + BEGIN + oldIsTry := isTry; oldTryEnv := tryEnv; oldTryDLink := tryDLink; + isTry := TRUE; tryDLink := GetDLink(); + res := setjmp._setjmp(tryEnv); + IF res = 0 THEN h(a, b, c) END; + isTry := oldIsTry; tryEnv := oldTryEnv; tryDLink := oldTryDLink + END Try; + + PROCEDURE Trap* (n: INTEGER); + BEGIN + IF trapped THEN + DefaultTrapViewer; + IF ~secondTrap THEN trapped := FALSE; secondTrap := TRUE END + END; + IF n >= 0 THEN err := n + ELSE err := -n + 128 + END; + pc := 0; sp := 0; fp := 0; stack := 0; val := 0; + INC(trapCount); + (* !!! InitFPU *) + TrapCleanup; + IF isTry THEN + SetDLink(tryDLink); + setjmp._longjmp(tryEnv, 1) + END; + IF (err = 128) OR (err = 200) & ~intTrap THEN (* do nothing *) + ELSIF (trapViewer # NIL) & (restart # NIL) & ~trapped & ~guarded THEN + trapped := TRUE; trapViewer() + ELSE DefaultTrapViewer + END; + trapped := FALSE; secondTrap := FALSE; + IF restart # NIL THEN + SetDLink(startDLink); + setjmp.siglongjmp(startEnv, 1) + END; + stdlib.abort + END Trap; + + PROCEDURE [ccall] TrapHandler (signo: signal.int; IN info: signal.siginfo_t; context: ADDRESS); + VAR res: signal.int; + BEGIN + IF checkReadable THEN + setjmp.siglongjmp(checkReadableEnv, 1) + END; + IF trapped THEN + DefaultTrapViewer; + IF ~secondTrap THEN trapped := FALSE; secondTrap := TRUE END + END; + err := -signo; pc := 0; sp := 0; fp := 0; stack := baseStack; val := 0; + CASE signo OF + | signal.SIGFPE: + val := info.si_code; + pc := info.info.sigfpe.si_addr; + CASE info.si_code OF + | signal.FPE_INTDIV: err := 139 (* division by zero *) + | signal.FPE_INTOVF: err := 138 (* integer overflow *) + | signal.FPE_FLTDIV: err := 140 (* fpu: division by zero *) + | signal.FPE_FLTOVF: err := 142 (* fpu: overflow *) + | signal.FPE_FLTUND: err := 141 (* fpu: underflow *) + (* !!! | signal.FPE_FLTRES: err := ??? (* fpu: *) *) + | signal.FPE_FLTINV: err := 143 (* val := opcode *) (* fpu: invalid op *) + (* !!! | signal.FPE_FLTSUB: err := ??? (* fpu: *) *) + ELSE (* unknown *) + END + | signal.SIGINT: + val := info.si_code; + err := 200 (* keyboard interrupt *) + | signal.SIGSEGV: + val := info.info.sigsegv.si_addr; + err := 203 (* illigal read *) + | signal.SIGBUS: + val := info.info.sigbus.si_addr; + err := 10001H (* bus error *) + | signal.SIGILL: + pc := info.info.sigill.si_addr; + err := 202; (* illigal instruction *) + IF IsReadable(pc, pc + 4) THEN + S.GET(pc, val) + END; + ELSE (* unknown *) + END; + INC(trapCount); + (* !!! InitFPU *) + TrapCleanup; + IF isTry THEN + setjmp._longjmp(tryEnv, 1) + END; + IF (err = 128) OR (err = 200) & ~intTrap THEN (* do nothing *) + ELSIF (trapViewer # NIL) & (restart # NIL) & ~trapped & ~guarded THEN + trapped := TRUE; trapViewer() + ELSE DefaultTrapViewer + END; + trapped := FALSE; secondTrap := FALSE; + IF restart # NIL THEN + setjmp.siglongjmp(startEnv, 1) + END; + stdlib.abort + END TrapHandler; + + (* -------------------- Initialization --------------------- *) + + PROCEDURE InstallTrap (signo: signal.int); + VAR act: signal._struct_sigaction; (* !!! CPfront hack *) res: signal.int; + BEGIN + act.sa_handler := NIL; + res := signal.sigemptyset(act.sa_mask); + act.sa_flags := signal.SA_NODEFER + signal.SA_SIGINFO; + act.sa_sigaction := TrapHandler; + res := signal.sigaction(signo, S.VAL(signal.struct_sigaction, act), NIL); + END InstallTrap; + + PROCEDURE InstallTrapVectors; + BEGIN + InstallTrap(signal.SIGFPE); + InstallTrap(signal.SIGINT); + InstallTrap(signal.SIGSEGV); + InstallTrap(signal.SIGBUS); + InstallTrap(signal.SIGILL) + END InstallTrapVectors; + + PROCEDURE RemoveTrapVectors; + END RemoveTrapVectors; + + PROCEDURE Init; + VAR i: INTEGER; + BEGIN + intTrap := TRUE; + baseStack := S.ADR(i); (* XXX *) + pagesize := unistd.sysconf(unistd._SC_PAGESIZE); + + (* init heap *) + allocated := 0; total := 0; used := 0; + sentinelBlock.size := MAX(INTEGER); + sentinel := S.ADR(sentinelBlock); + i := N; + REPEAT DEC(i); free[i] := sentinel UNTIL i = 0; + + IF ~inDll THEN + InstallTrapVectors + END; + + (* !!! InitFPU *) + IF ~static THEN + InitModule(modList); + IF ~inDll THEN Quit(1) END + END + END Init; + + PROCEDURE [code] SYSTEM_argCount (): INTEGER "SYSTEM_argCount"; + PROCEDURE [code] SYSTEM_argVector (): ArrStrPtr "(Kernel_ArrStrPtr)SYSTEM_argVector"; + PROCEDURE [code] SYSTEM_modlist (): Module "(Kernel_Module)SYSTEM_modlist"; + +BEGIN + IF modList = NIL THEN (* only once *) + argc := SYSTEM_argCount(); + argv := SYSTEM_argVector(); + modList := SYSTEM_modlist(); + static := init IN modList.opts; + inDll := dll IN modList.opts; + Init + END +CLOSE + IF ~terminating THEN + terminating := TRUE; + Quit(0) + END +END Kernel. diff --git a/src/posix/generic/Host/Mod/Files.cp b/src/posix/generic/Host/Mod/Files.cp index e9a1e49..76c7a5b 100644 --- a/src/posix/generic/Host/Mod/Files.cp +++ b/src/posix/generic/Host/Mod/Files.cp @@ -340,7 +340,7 @@ MODULE HostFiles; VAR i: INTEGER; sep: BOOLEAN; err: unistd.int; s: sysstat.struct_stat; mode: sysstat.mode_t; BEGIN i := 0; err := 0; - mode := ORD(BITS(511(*a=rwx*)) - BITS(sysstat.umask(0))); + mode := S.VAL((*!!!*)sysstat.mode_t, ORD(BITS(511(*a=rwx*)) - BITS(sysstat.umask(0)))); WHILE (err = 0) & (path[i] # 0X) DO WHILE (path[i] # "/") & (path[i] # 0X) DO INC(i) END; sep := path[i] = "/"; @@ -429,7 +429,7 @@ MODULE HostFiles; IF IsRegFile(s) THEN if := GetFileByInode(s.st_ino); IF (if = NIL) OR isShared & (if.state = shared) THEN - mode := ORD(BITS(rwrwrw) - BITS(sysstat.umask(0))); + mode := S.VAL((*!!!*)sysstat.mode_t, ORD(BITS(rwrwrw) - BITS(sysstat.umask(0)))); IF isShared THEN flags := fcntl.O_RDONLY ELSE flags := fcntl.O_RDWR END;