Previous: Multiple return values in Pre-Scheme, Up: More Pre-Scheme packages
Pre-Scheme is a low-level language. It provides very low-level, direct
memory manipulation. `Addresses' index a flat store of sequences of
bytes. While Pre-Scheme `pointers' are statically checked for data
coherency, allow no arbitrary arithmetic, and in general are high-level
abstract data to some extent, addresses are much lower-level, have no
statically checked coherency — the values an address represents are
selected by what operation used to read or write from it —, permit
arbitrary address arithmetic, and are a much more concrete interface
into direct memory. The ps-memory structure exports these
direct memory manipulation primitives.
Allocate-memoryreserves a sequence of size bytes in the store and returns an address to the first byte in the sequence.Deallocate-memoryreleases the memory at address, which should have been the initial address of a contiguous byte sequence, asallocate-memorywould return, not an offset address from such an initial address.
Procedures for reading from & storing to memory.
Unsigned-byte-ref&unsigned-byte-set!access & store the first unsigned byte at address.Word-ref&word-set!access & store the first word — Pre-Scheme integer — beginning at address.Flonum-ref&flonum-set!access & store 64-bit floats beginning at address..Bug:
Flonum-ref&flonum-set!are unimplemented in the Pre-Scheme-as-Scheme layer (see Running Pre-Scheme as Scheme).
Disjoint type predicate for addresses.
Note:
Address?is available only at the top level, where code is evaluated at compile-time. Do not use this in any place where it may be called at run-time.
The null address. This is somewhat similar to the null pointer, except that it is an address.
Note: One acquires the null pointer by calling the procedure
null-pointer, whereas the constant value of the binding namednull-addressis the null address.
Null-address?returns true if address is the null address and false if not.
Address arithmetic operators.
Address+adds increment to address;address-subtracts decrement from address; andaddress-differencereturns the integer difference between addressa and addressb. For any addressp & addressq,(address+addressp(address-differenceaddressp addressq))is equal to addressq.
Address comparators.
Integers and addresses, although not the same type, may be converted to and from each other;
integer->address&address->integerperform this conversion. Note that Pre-Scheme pointers may not be converted to addresses or integers, and the converse is also true.
Copies count bytes starting at source-address to target-address. This is similar to C's
memcpy.
Compares the two sequences of count bytes starting at addresses addressa & addressb. It returns true if every byte is equal and false if not.
Char-pointer->stringreturns a string with size bytes from the contiguous sequence of bytes starting at address.Char-pointer->nul-terminated-stringdoes similarly, but it returns a string whose contents include every byte starting at address until, but not including, the first 0 byte, i.e. ASCII nul character, following address.
Read-blockattempts to read count bytes from port into memory starting at address.Write-blockattempts to write count bytes to port from the contiguous sequence in memory starting at address.Read-blockreturns three values: the number of bytes read, whether or not the read went to the end of the file, and the error status (see Pre-Scheme error handling).Write-blockreturns the error status.