--- gforth/prim 2006/04/02 09:18:56 1.192 +++ gforth/prim 2006/10/21 22:13:48 1.197 @@ -809,12 +809,21 @@ n = n1*n2; / ( n1 n2 -- n ) core slash n = n1/n2; -if(FLOORED_DIV && ((n1^n2) < 0) && (n1%n2 != 0)) n--; +if (CHECK_DIVISION && (n2 == 0)) + throw(-10); +if (CHECK_DIVISION && n2 == -1 && n1 == CELL_MIN) + throw(-11); +if (FLOORED_DIV && ((n1^n2) < 0) && (n1%n2 != 0)) + n--; : /mod nip ; mod ( n1 n2 -- n ) core n = n1%n2; +if (CHECK_DIVISION && (n2 == 0)) + throw(-10); +if (CHECK_DIVISION && n2 == -1 && n1 == CELL_MIN) + throw(-11); if(FLOORED_DIV && ((n1^n2) < 0) && n!=0) n += n2; : /mod drop ; @@ -822,6 +831,10 @@ if(FLOORED_DIV && ((n1^n2) < 0) && n!=0) /mod ( n1 n2 -- n3 n4 ) core slash_mod n4 = n1/n2; n3 = n1%n2; /* !! is this correct? look into C standard! */ +if (CHECK_DIVISION && (n2 == 0)) + throw(-10); +if (CHECK_DIVISION && n2 == -1 && n1 == CELL_MIN) + throw(-11); if (FLOORED_DIV && ((n1^n2) < 0) && n3!=0) { n4--; n3+=n2; @@ -1647,7 +1660,11 @@ n=1; \g hostos key-file ( wfileid -- c ) gforth paren_key_file -""Read one character @i{c} from @i{wfileid}. "" +""Read one character @i{c} from @i{wfileid}. This word disables +buffering for @i{wfileid}. If you want to read characters from a +terminal in non-canonical (raw) mode, you have to put the terminal in +non-canonical mode yourself (using the C interface); the exception is +@code{stdin}: Gforth automatically puts it into non-canonical mode."" #ifdef HAS_FILE fflush(stdout); c = key((FILE*)wfileid); @@ -1657,7 +1674,9 @@ c = key(stdin); key?-file ( wfileid -- f ) gforth key_q_file ""@i{f} is true if at least one character can be read from @i{wfileid} -without blocking."" +without blocking. If you also want to use @code{read-file} or +@code{read-line} on the file, you have to call @code{key?-file} or +@code{key-file} first (these two words disable buffering)."" #ifdef HAS_FILE fflush(stdout); f = key_query((FILE*)wfileid); @@ -1668,12 +1687,15 @@ f = key_query(stdin); \+os stdin ( -- wfileid ) gforth +""The standard input file of the Gforth process."" wfileid = (Cell)stdin; stdout ( -- wfileid ) gforth +""The standard output file of the Gforth process."" wfileid = (Cell)stdout; stderr ( -- wfileid ) gforth +""The standard error output file of the Gforth process."" wfileid = (Cell)stderr; form ( -- urows ucols ) gforth @@ -2689,7 +2711,7 @@ w = ffi_prep_closure((ffi_closure *)a_cl ffi-2@ ( a_addr -- d ) gforth ffi_2fetch #ifdef BUGGY_LONG_LONG -DLO_IS(d, (Cell*)(*a_addr)); +DLO_IS(d, *(Cell*)(*a_addr)); DHI_IS(d, 0); #else d = *(DCell*)(a_addr); @@ -2705,14 +2727,25 @@ ffi-2! ( d a_addr -- ) gforth ffi_2store ffi-arg-int ( -- w ) gforth ffi_arg_int w = *(int *)(*gforth_clist++); +ffi-arg-long ( -- w ) gforth ffi_arg_long +w = *(long *)(*gforth_clist++); + ffi-arg-longlong ( -- d ) gforth ffi_arg_longlong #ifdef BUGGY_LONG_LONG -DLO_IS(d, (Cell*)(*gforth_clist++)); -DHI_IS(d, 0); +DLO_IS(d, *(Cell*)(*gforth_clist++)); +DHI_IS(d, -(*(Cell*)(*gforth_clist++)<0)); #else d = *(DCell*)(*gforth_clist++); #endif +ffi-arg-dlong ( -- d ) gforth ffi_arg_dlong +#ifdef BUGGY_LONG_LONG +DLO_IS(d, *(Cell*)(*gforth_clist++)); +DHI_IS(d, -(*(Cell*)(*gforth_clist++)<0)); +#else +d = *(Cell*)(*gforth_clist++); +#endif + ffi-arg-ptr ( -- c_addr ) gforth ffi_arg_ptr c_addr = *(Char **)(*gforth_clist++); @@ -2737,6 +2770,18 @@ ffi-ret-longlong ( d -- ) gforth ffi_ret #endif return 0; +ffi-ret-dlong ( d -- ) gforth ffi_ret_dlong +#ifdef BUGGY_LONG_LONG +*(Cell*)(gforth_ritem) = DLO(d); +#else +*(Cell*)(gforth_ritem) = d; +#endif +return 0; + +ffi-ret-long ( n -- ) gforth ffi_ret_long +*(Cell*)(gforth_ritem) = n; +return 0; + ffi-ret-ptr ( c_addr -- ) gforth ffi_ret_ptr *(Char **)(gforth_ritem) = c_addr; return 0;