/* _fcompat.h */

#ifndef _FCOMPATH
#define _FCOMPATH

/*	Copyright (C) 2002 Free Software Foundation, Inc.
 *
 * This file is part of GUILE
 *
 * GUILE 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, or (at your option)
 * any later version.
 *
 * GUILE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA
 *
 * As a special exception, the Free Software Foundation gives permission
 * for additional uses of the text contained in its release of GUILE.
 *
 * The exception is that, if you link the GUILE library with other files
 * to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the GUILE library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the
 * Free Software Foundation under the name GUILE.  If you copy
 * code from other Free Software Foundation releases into a copy of
 * GUILE, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for GUILE, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.  */

/* Some "forward compatibility" definitions.  This can be viewed as the
   beginnings of the "1.4-HEAD compatibility header" mentioned in the TODO.
   (We start w/ something small and eventually make it comprehensive.)  Code
   that relies on auto variables lives in the related _fcompat.c.

   This file is only used by *.c in this directory and is not installed.  */

/* numbers */

#include "libguile/numbers.h"

#define zzl(t,a,b,c)  ((t)(scm_num2long      (a, (char *) SCM_ARG ## b, c)))
#define zzll(t,a,b,c) ((t)(scm_num2long_long (a, (char *) SCM_ARG ## b, c)))

#define scm_num2int(n,pos,who)    (zzl (int, n, pos, who))
#define scm_num2uint(n,pos,who)   (zzl (unsigned int, n, pos, who))
#define scm_num2short(n,pos,who)  (zzl (short, n, pos, who))
#define scm_num2ushort(n,pos,who) (zzl (unsigned short, n, pos, who))

#define scm_num2ulong_long(n,pos,who) (zzll (unsigned long long, n, pos, who))

#define scm_int2num(n)    (scm_long2num ((long) n))
#define scm_uint2num(n)   (scm_long2num ((long) n))
#define scm_short2num(n)  (scm_long2num ((long) n))
#define scm_ushort2num(n) (scm_long2num ((long) n))

#define scm_ulong_long2num(n) (scm_long_long2num ((long long) n))

/* strings */

#include "libguile/strings.h"

#define SCM_STRING_LENGTH(s) (SCM_ROLENGTH (s))
#define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
                                         pos_start, start, c_start,\
                                         pos_end, end, c_end) \
  do {\
    SCM_VALIDATE_ROSTRING_COPY (pos_str, str, c_str);\
    SCM_VALIDATE_INUM_DEF_COPY (pos_start, start, 0, c_start);\
    SCM_VALIDATE_INUM_DEF_COPY (pos_end, end, SCM_STRING_LENGTH (str), c_end);\
    SCM_ASSERT_RANGE (pos_start, start,\
                      0 <= c_start \
                      && (size_t) c_start <= SCM_STRING_LENGTH (str));\
    SCM_ASSERT_RANGE (pos_end, end,\
		      c_start <= c_end \
                      && (size_t) c_end <= SCM_STRING_LENGTH (str));\
  } while (0)

#define scm_allocate_string(len)  (scm_makstr (len, 0))
#define scm_mem2string(src,len)   (scm_makfromstr (src, len, 0))

#define SCM_STRING_CHARS(s)  (SCM_ROCHARS(s))
#define SCM_STRING_UCHARS(s) (SCM_ROUCHARS(s))

/* symbols */

#define scm_mem2symbol(s,len)   (SCM_CAR (scm_intern (s, len)))
#define scm_str2symbol(s)       (SCM_CAR (scm_intern (s, strlen (s))))

/* list_N / call_N */

#define scm_list_1(e0)    (SCM_LIST1 (e0))
#define scm_list_2(e0,e1) (SCM_LIST2 (e0, e1))

#define scm_call_1(proc,arg1)      (scm_apply (proc, arg1, scm_listofnull))
#define scm_call_2(proc,arg1,arg2) (scm_apply (proc, arg1, scm_cons (arg2, scm_listofnull)))

/* module system */

#include "libguile/variable.h"

#define scm_c_resolve_module(frag)              \
 (scm_resolve_module                            \
   (scm_read (scm_open_input_string             \
     (scm_makfrom0str ("(" ## frag ## ")")))))

#define scm_c_module_lookup(module,str)                 \
 (scm_module_ref (module, scm_str2symbol (str)))

/* FIXME: This scm_c_module_lookup differs in semantics from the one provided
   in HEAD; it returns the value of the variable specified by {module, name}
   instead of the variable object itself.  The only known usage (srfi-13.c)
   requires passing scm_c_module_lookup return value to SCM_VARIABLE_REF in
   order to get at the variable value, so we make the parallel change in
   semantics for SCM_VARIABLE_REF (immediately below); it is now the identity
   function.

   Ambiguity in the name "scm_c_module_lookup" and its singular usage in all
   of Guile (SRFI and otherwise) is what gives us license to do this arguably
   horrible re-interpretation.

   However horrible, this still pales in comparison to the ironic need for a
   "forward compatibility header" in the first place, highlighting the lack of
   backward compatibility support by HEAD which stems (as always) from those
   programmers who don't care about the past, instead preferring to repeat
   stupidities and propagate NIH thinking, all the while ignoring the actual
   usage of their creations (see "scatalogical" and "lame").  Maybe this is
   due to the cognac, but probably the cognac only exascerbates extant ego
   problems and cannot be blamed for what amounts to failure by people to take
   proper responsibility for their own growth, the predictable result being
   infantile WOMBAT behavior that makes work for the rest of us.

   And this is the worst kind of "work" because it really is a lot of effort
   just to stay the "same", which according to standard thermodynamics is no
   work at all!  It is pure entropy, a form of twisted warfare waged against
   fellow programmers that is truly shameful in both its prevalance and in its
   sharp contrast to the whole idea of programming (which is to reduce the
   rate of entropy as much as possible).  All this is to say, the proprietary
   mindset manifests openly even in free software programmers, to the sad sad
   detriment of civilized society.  Hackers beware!  */
#define SCM_VARIABLE_REF(cell) (cell)

/* gc */

#include "libguile/gc.h"

#define scm_gc_malloc(size,what)   (scm_must_malloc (size, what))

#define scm_remember_upto_here_1(obj)   (scm_remember(&(obj)))

/* values */

extern SCM scm_values (SCM);

#endif /* !_FCOMPATH */

/* _fcompat.h ends here */
