/* Construct. */
"args-var" = empty_list();"constructs"
- callback_run_handler ((int)ID, "args-var");
+ callback_run_handler ((long)ID, "args-var");
callback_return ("tos-var");
}"))))
"ret-decl"
Scm_"name" ("arglist")
\{"saves"
- callback_run_kernel ((int)ID, (CallbackKernel)&Scm_kernel_"name");"return"
+ callback_run_kernel ((long)ID, (CallbackKernel)&Scm_kernel_"name");"return"
}
")))))
(decl (decl-string name))
(name (symbol-name name)))
(string-append "
- fprintf (out, \" ((sizeof "name") . %d)\\n\", sizeof ("decl"));")))
+ fprintf (out, \" ((sizeof "name") . %ld)\\n\", (long) sizeof ("decl"));")))
peek-poke-primitives))
"
\}
"fname" (FILE * out)
\{
"decl" S;
- fprintf (out, \" (")(write key)(_" . %d)\\n\", sizeof ("decl"));"))
+ fprintf (out, \" (")(write key)(_" . %ld)\\n\", (long) sizeof ("decl"));"))
(for-each-member-path
ctype includes
(lambda (path brief-type)
"" "." "" (map symbol-name path)))
(key (cons* 'OFFSET name path)))
(_ "
- fprintf (out, \" (")(write key)(_" %d . ")(write brief-type)(_")\\n\", (char*)&(S."path") - (char*)&S);"))))
+ fprintf (out, \" (")(write key)(_" %ld . ")(write brief-type)(_")\\n\", (long)((char*)&(S."path") - (char*)&S));"))))
(_ "
\}
")
static SCM return_to_c = SHARP_F;
void
-callback_run_kernel (int callback_id, CallbackKernel kernel)
+callback_run_kernel (long callback_id, CallbackKernel kernel)
{
/* Used by callback trampolines.
if (run_callback == SHARP_F || return_to_c == SHARP_F)
{
outf_error
- ("\nWarning: punted callback #%d. Missing primitives!\n",
+ ("\nWarning: punted callback #%ld. Missing primitives!\n",
callback_id);
outf_flush_error ();
SET_VAL (FIXNUM_ZERO);
if (! CAN_PUSH_P (2 * (1 + 1 + CONTINUATION_SIZE)))
{
outf_error
- ("\nWarning: punted callback #%d. No room on stack!\n", callback_id);
+ ("\nWarning: punted callback #%ld. No room on stack!\n", callback_id);
outf_flush_error ();
SET_VAL (FIXNUM_ZERO);
return;
}
static SCM valid_callback_handler (void);
-static SCM valid_callback_id (int id);
+static SCM valid_callback_id (long id);
void
-callback_run_handler (int callback_id, SCM arglist)
+callback_run_handler (long callback_id, SCM arglist)
{
/* Used by callback kernels, inside the interpreter. Thus it MAY GC
abort.
}
static SCM
-valid_callback_id (int id)
+valid_callback_id (long id)
{
/* Validate the callback ID and convert to a fixnum. */
;; A symbol or list.
ctype)
+;; Breaking a word in two produces high and low fixnums. If they are
+;; two digits representing a larger number, then RADIX is their base.
+;; For a 32 bit word, (radix) is #x10000.
+;;
+;; This substitutes a constant when there is a compiler, per its
+;; target. Else this is a reference to %radix.
+(define-syntax radix
+ (er-macro-transformer
+ (lambda (form rename compare)
+ (declare (ignore rename compare))
+ (if (not (null? (cdr form)))
+ (syntax-error "No sub-forms allowed:" form))
+ (cond ((get-subsystem-version "LIAR/i386") #x10000)
+ ((get-subsystem-version "LIAR/x86-64") #x100000000)
+ (else
+ '%RADIX)))))
+
+;; This is only needed when the target machine's word size is unknown
+;; (e.g. when compiling to C, or when there is no compiler).
+(define %radix)
+
(set-record-type-unparser-method! rtd:alien
(standard-unparser-method
'alien
alien)
(define (alien/address-string alien)
- ;; Returns a string of length 8, e.g. "081adc60".
- (let ((high (%alien/high-bits alien)))
- (if (eq? high #f) "< null >"
- (let ((low (%alien/low-bits alien))
- (4hex (lambda (n)
- (string-pad-left (number->string n 16) 4 #\0))))
- (string-append (4hex high) (4hex low))))))
+ ;; Returns a string, e.g. "081adc60".
+ (let ((high (%alien/high-bits alien))
+ (low (%alien/low-bits alien))
+ (hex (lambda (n)
+ (string-pad-left (number->string n 16)
+ (if (fix:= (radix) #x10000) 4 8)
+ #\0))))
+ (string-append (hex high) (hex low))))
(define (make-alien #!optional ctype)
(let ((ctype (if (default-object? ctype) #f ctype)))
(declare (integrate-operator alien/address))
(define (alien/address alien)
- (+ (* (%alien/high-bits alien) #x10000)
+ (+ (* (%alien/high-bits alien) (radix))
(%alien/low-bits alien)))
(declare (integrate-operator copy-alien-address!))
;; This procedure returns ALIEN after modifying it to have an
;; address INCREMENT bytes away from its previous address. If CTYPE
;; is specified, the type slot of ALIEN is set.
- (let ((quotient.remainder (fix:divide increment #x10000)))
+ (let ((quotient.remainder (fix:divide increment (radix))))
(let ((new-high (fix:+ (%alien/high-bits alien)
(integer-divide-quotient quotient.remainder)))
(new-low (fix:+ (%alien/low-bits alien)
(if (fix:zero? new-high)
(error:bad-range-argument increment 'alien-byte-increment!)
(begin
- (set-%alien/low-bits! alien (fix:+ new-low #x10000))
+ (set-%alien/low-bits! alien (fix:+ new-low (radix)))
(set-%alien/high-bits! alien (fix:-1+ new-high)))))
- ((fix:>= new-low #x10000)
- (set-%alien/low-bits! alien (fix:- new-low #x10000))
+ ((fix:>= new-low (radix))
+ (set-%alien/low-bits! alien (fix:- new-low (radix)))
(set-%alien/high-bits! alien (fix:1+ new-high)))
(else
(set-%alien/low-bits! alien new-low)
(string-tail (%alien-function/name alienf) 4))
(define (%set-alien-function/address! alienf address)
- (let ((qr (integer-divide address #x10000)))
+ (let ((qr (integer-divide address (radix))))
(set-%alien-function/high-bits! alienf (integer-divide-quotient qr))
(set-%alien-function/low-bits! alienf (integer-divide-remainder qr))))
(reset-alien-functions!)
(reset-malloced-aliens!)
(reset-callbacks!)
+ (set! %radix (if (fix:fixnum? #x100000000) #x100000000 #x10000))
(set! trace? #f)
(set! calloutback-stack '()))