Module: c-ffi-implementation Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define macro pointer-ref-method-definer { define pointer-ref-method ?function-name:name ?pointer-type:name ?raw-type:name ?boxed-class:name ?getter:name ?boxer:name ?unboxer:name end } => { define inline-only function ?function-name (c-pointer :: , #key byte-index :: = 0, scaled-index :: = 0) => (value :: ?boxed-class) ?boxer(?getter(primitive-unwrap-c-pointer(c-pointer), integer-as-raw(scaled-index), integer-as-raw(byte-index))) end function ?function-name; define inline-only function ?function-name ## "-setter" (new-value :: ?boxed-class, c-pointer :: , #key byte-index :: = 0, scaled-index :: = 0) => (res :: ?boxed-class) ?getter ## "-setter" (?unboxer(new-value), primitive-unwrap-c-pointer(c-pointer), integer-as-raw(scaled-index), integer-as-raw(byte-index)); new-value end function ?function-name ## "-setter"; } end macro; define pointer-ref-method C-signed-char-at raw-c-signed-char primitive-c-signed-char-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-unsigned-char-at raw-c-unsigned-char primitive-c-unsigned-char-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-signed-short-at raw-c-signed-short primitive-c-signed-short-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-unsigned-short-at raw-c-unsigned-short primitive-c-unsigned-short-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-signed-long-at raw-c-signed-long primitive-c-signed-long-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-unsigned-long-at raw-c-unsigned-long primitive-c-unsigned-long-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-signed-int-at raw-c-signed-int primitive-c-signed-int-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-unsigned-int-at raw-c-unsigned-int primitive-c-unsigned-int-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define constant c-long-at = c-signed-long-at; define constant c-long-at-setter = c-signed-long-at-setter; define constant c-short-at = c-signed-short-at; define constant c-short-at-setter = c-signed-short-at-setter; define constant c-char-at = c-signed-char-at; define constant c-char-at-setter = c-signed-char-at-setter; define constant c-int-at = c-signed-int-at; define constant c-int-at-setter = c-signed-int-at-setter; /* define pointer-ref-method C-signed-long-long-at raw-c-signed-long-long primitive-c-signed-long-long-at primitive-wrap-machine-word primitive-unwrap-machine-word end; define pointer-ref-method C-unsigned-long-long-at raw-c-unsigned-long-long primitive-c-unsigned-long-long-at primitive-wrap-machine-word primitive-unwrap-machine-word end; */ define pointer-ref-method C-float-at raw-single-float primitive-c-float-at primitive-raw-as-single-float primitive-single-float-as-raw end; define pointer-ref-method C-double-at raw-double-float primitive-c-double-at primitive-raw-as-double-float primitive-double-float-as-raw end; /* define pointer-ref-method C-long-double-at raw-extended-float primitive-c-long-double-at primitive-raw-as-extended-float primitive-extended-float-as-raw end; */ define inline function C-pointer-at (class :: subclass(), pointer :: , #key byte-index :: = 0, scaled-index :: = 0) => (value :: ); make(class, address: primitive-wrap-machine-word (primitive-cast-pointer-as-raw (primitive-c-pointer-at (primitive-unwrap-c-pointer(pointer), integer-as-raw(scaled-index), integer-as-raw(byte-index))))) end function; define inline function C-pointer-at-setter (new-value :: , pointer :: , #key byte-index :: = 0, scaled-index :: = 0) => (new-value :: ); primitive-c-pointer-at(primitive-unwrap-c-pointer(pointer), integer-as-raw(scaled-index), integer-as-raw(byte-index)) := primitive-unwrap-c-pointer(new-value); new-value end function; /* // might be useful someday define function pointer-add (result-class :: , object :: , byte-offset :: ) => (new-pointer :: ); // make(result-class, address: pointer-address(object) + byte-offset); end; */