--- gforth/prim 2007/06/30 20:50:48 1.215 +++ gforth/prim 2010/05/02 16:21:32 1.249 @@ -1,12 +1,12 @@ \ Gforth primitives -\ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006 Free Software Foundation, Inc. +\ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. \ This file is part of Gforth. \ Gforth is free software; you can redistribute it and/or \ modify it under the terms of the GNU General Public License -\ as published by the Free Software Foundation; either version 2 +\ as published by the Free Software Foundation, either version 3 \ of the License, or (at your option) any later version. \ This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ \ GNU General Public License for more details. \ You should have received a copy of the GNU General Public License -\ along with this program; if not, write to the Free Software -\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. +\ along with this program. If not, see http://www.gnu.org/licenses/. \ WARNING: This file is processed by m4. Make sure your identifiers @@ -109,9 +108,9 @@ \E store-optimization on \E ' noop tail-nextp2 ! \ now INST_TAIL just stores, but does not jump \E -\E include-skipped-insts on \ static superinsts include cells for components -\E \ useful for dynamic programming and -\E \ superinsts across entry points +\E `include-skipped-insts' on \ static superinsts include cells for components +\E \ useful for dynamic programming and +\E \ superinsts across entry points \ \ @@ -203,6 +202,14 @@ INST_TAIL; goto *next_code; #endif /* defined(NO_IP) */ +(dovalue) ( -- w ) gforth-internal paren_doval +""run-time routine for constants"" +w = *(Cell *)PFA(CFA); +#ifdef NO_IP +INST_TAIL; +goto *next_code; +#endif /* defined(NO_IP) */ + (dodoes) ( -- a_body R:a_retaddr ) gforth-internal paren_dodoes ""run-time routine for @code{does>}-defined words"" #ifdef NO_IP @@ -222,9 +229,28 @@ fprintf(stderr, "dodoes to %x, push %x\n SET_IP(DOES_CODE1(CFA)); #endif /* !defined(NO_IP) */ -(does-handler) ( -- ) gforth-internal paren_does_handler -""just a slot to have an encoding for the DOESJUMP, -which is no longer used anyway (!! eliminate this)"" +(doabicode) ( ... -- ...) gforth-internal paren_doabicode +""run-time routine for @code{ABI-code} definitions"" +abifunc *f = (abifunc *)PFA(CFA); +Float *fp_mem = fp; +sp = (*f)(sp, &fp_mem); +fp = fp_mem; +#ifdef NO_IP +INST_TAIL; +goto *next_code; +#endif /* defined(NO_IP) */ + +(do;abicode) ( ... -- ... ) gforth-internal paren_do_semicolon_abi_code +""run-time routine for @code{;abi-code}-defined words"" +Float *fp_mem = fp; +Address body = (Address)PFA(CFA); +semiabifunc *f = (semiabifunc *)DOES_CODE1(CFA); +sp = (*f)(sp, &fp_mem, body); +fp = fp_mem; +#ifdef NO_IP +INST_TAIL; +goto *next_code; +#endif /* defined(NO_IP) */ \F [endif] @@ -695,7 +721,7 @@ c2 = toupper(c1); : dup [char] a - [ char z char a - 1 + ] Literal u< bl and - ; -capscompare ( c_addr1 u1 c_addr2 u2 -- n ) string +capscompare ( c_addr1 u1 c_addr2 u2 -- n ) gforth ""Compare two strings lexicographically. If they are equal, @i{n} is 0; if the first string is smaller, @i{n} is -1; if the first string is larger, @i{n} is 1. Currently this is based on the machine's character @@ -1655,7 +1681,11 @@ ucols=cols; wcwidth ( u -- n ) gforth ""The number of fixed-width characters per unicode character u"" +#ifdef HAVE_WCWIDTH n = wcwidth(u); +#else +n = 1; +#endif flush-icache ( c_addr u -- ) gforth flush_icache ""Make sure that the instruction cache of the processor (if there is @@ -1667,7 +1697,7 @@ supported on your machine (take a look a your machine has a separate instruction cache. In such cases, @code{flush-icache} does nothing instead of flushing the instruction cache."" -FLUSH_ICACHE(c_addr,u); +FLUSH_ICACHE((caddr_t)c_addr,u); (bye) ( n -- ) gforth paren_bye SUPER_END; @@ -1687,6 +1717,7 @@ c_addr2 = (Char *)getenv(cstr(c_addr1,u1 u2 = (c_addr2 == NULL ? 0 : strlen((char *)c_addr2)); open-pipe ( c_addr u wfam -- wfileid wior ) gforth open_pipe +fflush(stdout); wfileid=(Cell)popen(cstr(c_addr,u,1),pfileattr[wfam]); /* ~ expansion of 1st arg? */ wior = IOR(wfileid==0); /* !! the man page says that errno is not set reliably */ @@ -1770,11 +1801,21 @@ access the stack itself. The stack point variables @code{gforth_SP} and @code{gforth_FP}."" /* This is a first attempt at support for calls to C. This may change in the future */ +IF_fpTOS(fp[0]=fpTOS); gforth_FP=fp; gforth_SP=sp; +gforth_RP=rp; +gforth_LP=lp; +#ifdef HAS_LINKBACK ((void (*)())w)(); +#else +((void (*)(void *))w)(gforth_pointers); +#endif sp=gforth_SP; fp=gforth_FP; +rp=gforth_RP; +lp=gforth_LP; +IF_fpTOS(fpTOS=fp[0]); \+ \+file @@ -1783,19 +1824,10 @@ close-file ( wfileid -- wior ) file clo wior = IOR(fclose((FILE *)wfileid)==EOF); open-file ( c_addr u wfam -- wfileid wior ) file open_file -wfileid = (Cell)fopen(tilde_cstr(c_addr, u, 1), fileattr[wfam]); -wior = IOR(wfileid == 0); +wfileid = opencreate_file(tilde_cstr(c_addr,u,1), wfam, 0, &wior); create-file ( c_addr u wfam -- wfileid wior ) file create_file -Cell fd; -fd = open(tilde_cstr(c_addr, u, 1), O_CREAT|O_TRUNC|ufileattr[wfam], 0666); -if (fd != -1) { - wfileid = (Cell)fdopen(fd, fileattr[wfam]); - wior = IOR(wfileid == 0); -} else { - wfileid = 0; - wior = IOR(1); -} +wfileid = opencreate_file(tilde_cstr(c_addr,u,1), wfam, O_CREAT|O_TRUNC, &wior); delete-file ( c_addr u -- wior ) file delete_file wior = IOR(unlink(tilde_cstr(c_addr, u, 1))==-1); @@ -1823,13 +1855,15 @@ wior = IOR(ftruncate(fileno((FILE *)wfil read-file ( c_addr u1 wfileid -- u2 wior ) file read_file /* !! fread does not guarantee enough */ u2 = fread(c_addr, sizeof(Char), u1, (FILE *)wfileid); +if (u2>0) + gf_regetc((FILE *)wfileid); wior = FILEIO(u2