Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!pyrnj!mirror!ima!haddock!karl From: karl@haddock.UUCP (Karl Heuer) Newsgroups: comp.lang.forth Subject: Re: Unix system calls from Forth Message-ID: <182@haddock.UUCP> Date: Wed, 3-Dec-86 22:55:47 EST Article-I.D.: haddock.182 Posted: Wed Dec 3 22:55:47 1986 Date-Received: Thu, 4-Dec-86 03:06:36 EST References: <12234@watnot.UUCP> Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer) Distribution: net Organization: Interactive Systems, Boston Lines: 27 In article <12234@watnot.UUCP> ccplumb@watnot.UUCP (Colin Plumb) writes: >I'm working on a 32-bit Forth for a VAX under BSD 4.2 Unix. >I'm trying to figure out how to implement the system call interface. Well, I've already done it on SysV, and I think the same idea should work on BSD. On success, the return values (0, 1, or 2 of them) and a success indicator are placed on the stack; on failure, only the failure indicator. (I used 1 for ok vs. 0 for error, but 0 for ok would've made it easier to test.) The error code can be retrieved via "errno" (which is not a variable because I didn't think it needed to be user-writable); I didn't leave it on the stack because most of the time it isn't needed. For consistency, even calls that never fail (e.g. getpid) have the flag on top. (I also defined a word which drops the top of stack and bombs with an appropriate message if it was a failure.) I used a leading "$" (so "$dup" is a system call, while "dup" is a Forth word), or "$_" for the "real" system call if the C interface twiddles it (so $_getpid returns two values, while $getpid and $getppid select the one of interest). I didn't do this with $pipe and $wait; they just return two values (too bad C can't do that! Returning a struct by value doesn't count). I used one defining word which takes three arguments (number of arguments, number of results, and chmk number), and had one chunk of common code in assembly language. The asm code was the only part I needed to rewrite when I ported my TIL to a 3b2. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint