2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
2004-05-14 17:33:47 +01:00
|
|
|
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
|
2001-04-09 20:54:03 +01:00
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: stdpreds.c *
|
|
|
|
* comments: General-purpose C implemented system predicates *
|
|
|
|
* *
|
2008-07-24 17:02:04 +01:00
|
|
|
* Last rev: $Date: 2008-07-24 16:02:00 $,$Author: vsc $ *
|
2004-05-13 21:54:58 +01:00
|
|
|
* $Log: not supported by cvs2svn $
|
2008-07-24 17:02:04 +01:00
|
|
|
* Revision 1.131 2008/06/12 10:55:52 vsc
|
|
|
|
* fix syntax error messages
|
|
|
|
*
|
2008-06-12 11:55:52 +01:00
|
|
|
* Revision 1.130 2008/04/06 11:53:02 vsc
|
|
|
|
* fix some restore bugs
|
|
|
|
*
|
2008-04-06 12:53:02 +01:00
|
|
|
* Revision 1.129 2008/03/15 12:19:33 vsc
|
|
|
|
* fix flags
|
|
|
|
*
|
2008-03-15 12:19:33 +00:00
|
|
|
* Revision 1.128 2008/02/15 12:41:33 vsc
|
|
|
|
* more fixes to modules
|
|
|
|
*
|
2008-02-15 12:41:33 +00:00
|
|
|
* Revision 1.127 2008/02/13 10:15:35 vsc
|
|
|
|
* fix some bugs from yesterday plus improve support for modules in
|
|
|
|
* operators.
|
|
|
|
*
|
2008-02-13 10:15:36 +00:00
|
|
|
* Revision 1.126 2008/02/07 23:09:13 vsc
|
|
|
|
* don't break ISO standard in current_predicate/1.
|
|
|
|
* Include Nicos flag.
|
|
|
|
*
|
2008-02-07 23:09:13 +00:00
|
|
|
* Revision 1.125 2008/01/23 17:57:53 vsc
|
|
|
|
* valgrind it!
|
|
|
|
* enable atom garbage collection.
|
|
|
|
*
|
2008-01-23 17:57:56 +00:00
|
|
|
* Revision 1.124 2007/11/26 23:43:08 vsc
|
|
|
|
* fixes to support threads and assert correctly, even if inefficiently.
|
|
|
|
*
|
2007-11-26 23:43:10 +00:00
|
|
|
* Revision 1.123 2007/11/06 17:02:12 vsc
|
|
|
|
* compile ground terms away.
|
|
|
|
*
|
2007-11-06 17:02:13 +00:00
|
|
|
* Revision 1.122 2007/10/18 08:24:16 vsc
|
|
|
|
* fix global variables
|
|
|
|
*
|
2007-10-18 09:24:16 +01:00
|
|
|
* Revision 1.121 2007/10/10 09:44:24 vsc
|
|
|
|
* some more fixes to make YAP swi compatible
|
|
|
|
* fix absolute_file_name (again)
|
|
|
|
* fix setarg
|
|
|
|
*
|
2007-10-10 10:44:28 +01:00
|
|
|
* Revision 1.120 2007/10/08 23:02:15 vsc
|
|
|
|
* minor fixes
|
|
|
|
*
|
2007-10-09 00:02:16 +01:00
|
|
|
* Revision 1.119 2007/04/18 23:01:16 vsc
|
|
|
|
* fix deadlock when trying to create a module with the same name as a
|
|
|
|
* predicate (for now, just don't lock modules). obs Paulo Moura.
|
|
|
|
*
|
2007-04-19 00:01:16 +01:00
|
|
|
* Revision 1.118 2007/02/26 10:41:40 vsc
|
|
|
|
* fix prolog_flags for chr.
|
|
|
|
*
|
2007-02-26 10:41:40 +00:00
|
|
|
* Revision 1.117 2007/01/28 14:26:37 vsc
|
|
|
|
* WIN32 support
|
|
|
|
*
|
2007-01-28 14:26:37 +00:00
|
|
|
* Revision 1.116 2006/12/13 16:10:23 vsc
|
|
|
|
* several debugger and CLP(BN) improvements.
|
|
|
|
*
|
2006-12-13 16:10:26 +00:00
|
|
|
* Revision 1.115 2006/11/28 13:46:41 vsc
|
|
|
|
* fix wide_char support for name/2.
|
|
|
|
*
|
2006-11-28 13:46:41 +00:00
|
|
|
* Revision 1.114 2006/11/27 17:42:03 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
2006-11-27 17:42:03 +00:00
|
|
|
* Revision 1.113 2006/11/16 14:26:00 vsc
|
|
|
|
* fix handling of infinity in name/2 and friends.
|
|
|
|
*
|
2006-11-16 14:26:00 +00:00
|
|
|
* Revision 1.112 2006/11/08 01:56:47 vsc
|
|
|
|
* fix argument order in db statistics.
|
|
|
|
*
|
2006-11-08 01:56:47 +00:00
|
|
|
* Revision 1.111 2006/11/06 18:35:04 vsc
|
|
|
|
* 1estranha
|
|
|
|
*
|
2006-11-06 18:35:05 +00:00
|
|
|
* Revision 1.110 2006/10/10 14:08:17 vsc
|
|
|
|
* small fixes on threaded implementation.
|
|
|
|
*
|
2006-10-10 15:08:17 +01:00
|
|
|
* Revision 1.109 2006/09/15 19:32:47 vsc
|
|
|
|
* ichanges for QSAR
|
|
|
|
*
|
2006-09-15 20:32:47 +01:00
|
|
|
* Revision 1.108 2006/09/01 20:14:42 vsc
|
|
|
|
* more fixes for global data-structures.
|
|
|
|
* statistics on atom space.
|
|
|
|
*
|
2006-09-01 21:14:42 +01:00
|
|
|
* Revision 1.107 2006/08/22 16:12:46 vsc
|
|
|
|
* global variables
|
|
|
|
*
|
2006-08-22 17:12:46 +01:00
|
|
|
* Revision 1.106 2006/08/07 18:51:44 vsc
|
|
|
|
* fix garbage collector not to try to garbage collect when we ask for large
|
|
|
|
* chunks of stack in a single go.
|
|
|
|
*
|
2006-08-07 19:51:44 +01:00
|
|
|
* Revision 1.105 2006/06/05 19:36:00 vsc
|
|
|
|
* hacks
|
|
|
|
*
|
2006-06-05 20:36:00 +01:00
|
|
|
* Revision 1.104 2006/05/19 14:31:32 vsc
|
|
|
|
* get rid of IntArrays and FloatArray code.
|
|
|
|
* include holes when calculating memory usage.
|
|
|
|
*
|
2006-05-19 15:31:32 +01:00
|
|
|
* Revision 1.103 2006/05/18 16:33:05 vsc
|
|
|
|
* fix info reported by memory manager under DL_MALLOC and SYSTEM_MALLOC
|
|
|
|
*
|
2006-05-18 17:33:05 +01:00
|
|
|
* Revision 1.102 2006/04/28 17:53:44 vsc
|
|
|
|
* fix the expand_consult patch
|
|
|
|
*
|
2006-04-28 18:53:44 +01:00
|
|
|
* Revision 1.101 2006/04/28 13:23:23 vsc
|
|
|
|
* fix number of overflow bugs affecting threaded version
|
|
|
|
* make current_op faster.
|
|
|
|
*
|
2006-04-28 14:23:23 +01:00
|
|
|
* Revision 1.100 2006/02/05 02:26:35 tiagosoares
|
|
|
|
* MYDDAS: Top Level Functionality
|
|
|
|
*
|
2006-02-05 02:26:35 +00:00
|
|
|
* Revision 1.99 2006/02/05 02:17:54 tiagosoares
|
|
|
|
* MYDDAS: Top Level Functionality
|
|
|
|
*
|
2006-02-05 02:19:15 +00:00
|
|
|
* Revision 1.98 2005/12/17 03:25:39 vsc
|
|
|
|
* major changes to support online event-based profiling
|
|
|
|
* improve error discovery and restart on scanner.
|
|
|
|
*
|
2005-12-17 03:25:39 +00:00
|
|
|
* Revision 1.97 2005/11/22 11:25:59 tiagosoares
|
|
|
|
* support for the MyDDAS interface library
|
|
|
|
*
|
2005-11-22 11:25:59 +00:00
|
|
|
* Revision 1.96 2005/10/28 17:38:49 vsc
|
|
|
|
* sveral updates
|
|
|
|
*
|
2005-10-28 18:38:50 +01:00
|
|
|
* Revision 1.95 2005/10/21 16:09:02 vsc
|
|
|
|
* SWI compatible module only operators
|
|
|
|
*
|
2005-10-21 17:09:03 +01:00
|
|
|
* Revision 1.94 2005/09/08 22:06:45 rslopes
|
|
|
|
* BEAM for YAP update...
|
|
|
|
*
|
2005-09-08 23:06:45 +01:00
|
|
|
* Revision 1.93 2005/08/04 15:45:53 ricroc
|
|
|
|
* TABLING NEW: support to limit the table space size
|
|
|
|
*
|
2005-08-04 16:45:56 +01:00
|
|
|
* Revision 1.92 2005/07/20 13:54:27 rslopes
|
|
|
|
* solved warning: cast from pointer to integer of different size
|
|
|
|
*
|
2005-07-20 14:54:42 +01:00
|
|
|
* Revision 1.91 2005/07/06 19:33:54 ricroc
|
|
|
|
* TABLING: answers for completed calls can now be obtained by loading (new option) or executing (default) them from the trie data structure.
|
|
|
|
*
|
2005-07-06 20:34:12 +01:00
|
|
|
* Revision 1.90 2005/07/06 15:10:14 vsc
|
|
|
|
* improvements to compiler: merged instructions and fixes for ->
|
|
|
|
*
|
2005-07-06 16:10:18 +01:00
|
|
|
* Revision 1.89 2005/05/26 18:01:11 rslopes
|
|
|
|
* *** empty log message ***
|
|
|
|
*
|
2005-05-26 19:03:08 +01:00
|
|
|
* Revision 1.88 2005/04/27 20:09:25 vsc
|
|
|
|
* indexing code could get confused with suspension points
|
|
|
|
* some further improvements on oveflow handling
|
|
|
|
* fix paths in Java makefile
|
|
|
|
* changs to support gibbs sampling in CLP(BN)
|
|
|
|
*
|
2005-04-27 21:09:26 +01:00
|
|
|
* Revision 1.87 2005/04/07 17:48:55 ricroc
|
|
|
|
* Adding tabling support for mixed strategy evaluation (batched and local scheduling)
|
|
|
|
* UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and -DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the Makefile or --enable-tabling in configure.
|
|
|
|
* NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all tabled predicates to MODE (batched, local or default).
|
|
|
|
* NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of predicate PRED to MODE (batched or local).
|
|
|
|
*
|
2005-04-07 18:56:58 +01:00
|
|
|
* Revision 1.86 2005/03/13 06:26:11 vsc
|
|
|
|
* fix excessive pruning in meta-calls
|
|
|
|
* fix Term->int breakage in compiler
|
|
|
|
* improve JPL (at least it does something now for amd64).
|
|
|
|
*
|
2005-03-13 06:26:13 +00:00
|
|
|
* Revision 1.85 2005/03/02 19:48:02 vsc
|
|
|
|
* Fix some possible errors in name/2 and friends, and cleanup code a bit
|
|
|
|
* YAP_Error changed.
|
|
|
|
*
|
2005-03-02 19:48:03 +00:00
|
|
|
* Revision 1.84 2005/03/02 18:35:46 vsc
|
|
|
|
* try to make initialisation process more robust
|
|
|
|
* try to make name more robust (in case Lookup new atom fails)
|
|
|
|
*
|
2005-03-02 18:35:49 +00:00
|
|
|
* Revision 1.83 2005/03/01 22:25:09 vsc
|
|
|
|
* fix pruning bug
|
|
|
|
* make DL_MALLOC less enthusiastic about walking through buckets.
|
|
|
|
*
|
2005-03-01 22:25:09 +00:00
|
|
|
* Revision 1.82 2005/02/21 16:50:04 vsc
|
|
|
|
* amd64 fixes
|
|
|
|
* library fixes
|
|
|
|
*
|
2005-02-21 16:50:21 +00:00
|
|
|
* Revision 1.81 2005/02/08 04:05:35 vsc
|
|
|
|
* fix mess with add clause
|
|
|
|
* improves on sigsegv handling
|
|
|
|
*
|
2005-02-08 04:05:39 +00:00
|
|
|
* Revision 1.80 2005/01/05 05:32:37 vsc
|
|
|
|
* Ricardo's latest version of profiler.
|
|
|
|
*
|
2005-01-05 05:32:37 +00:00
|
|
|
* Revision 1.79 2004/12/28 22:20:36 vsc
|
|
|
|
* some extra bug fixes for trail overflows: some cannot be recovered that easily,
|
|
|
|
* some can.
|
|
|
|
*
|
2004-12-28 22:20:37 +00:00
|
|
|
* Revision 1.78 2004/12/08 04:45:03 vsc
|
|
|
|
* polish changes to undefp
|
|
|
|
* get rid of a few warnings
|
|
|
|
*
|
2004-12-08 04:45:04 +00:00
|
|
|
* Revision 1.77 2004/12/05 05:07:26 vsc
|
|
|
|
* name/2 should accept [] as a valid list (string)
|
|
|
|
*
|
2004-12-05 05:07:26 +00:00
|
|
|
* Revision 1.76 2004/12/05 05:01:25 vsc
|
|
|
|
* try to reduce overheads when running with goal expansion enabled.
|
|
|
|
* CLPBN fixes
|
|
|
|
* Handle overflows when allocating big clauses properly.
|
|
|
|
*
|
2004-12-05 05:01:45 +00:00
|
|
|
* Revision 1.75 2004/12/02 06:06:46 vsc
|
|
|
|
* fix threads so that they at least start
|
|
|
|
* allow error handling to work with threads
|
|
|
|
* replace heap_base by Yap_heap_base, according to Yap's convention for globals.
|
|
|
|
*
|
2004-12-02 06:06:47 +00:00
|
|
|
* Revision 1.74 2004/11/19 22:08:43 vsc
|
|
|
|
* replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate.
|
|
|
|
*
|
2004-11-19 22:08:43 +00:00
|
|
|
* Revision 1.73 2004/11/19 17:14:14 vsc
|
|
|
|
* a few fixes for 64 bit compiling.
|
|
|
|
*
|
2004-11-19 17:14:15 +00:00
|
|
|
* Revision 1.72 2004/11/18 22:32:37 vsc
|
|
|
|
* fix situation where we might assume nonextsing double initialisation of C predicates (use
|
|
|
|
* Hidden Pred Flag).
|
|
|
|
* $host_type was double initialised.
|
|
|
|
*
|
2004-11-18 22:32:40 +00:00
|
|
|
* Revision 1.71 2004/07/23 21:08:44 vsc
|
|
|
|
* windows fixes
|
|
|
|
*
|
2004-07-23 22:08:45 +01:00
|
|
|
* Revision 1.70 2004/06/29 19:04:42 vsc
|
|
|
|
* fix multithreaded version
|
|
|
|
* include new version of Ricardo's profiler
|
|
|
|
* new predicat atomic_concat
|
|
|
|
* allow multithreaded-debugging
|
|
|
|
* small fixes
|
|
|
|
*
|
2004-06-29 20:04:46 +01:00
|
|
|
* Revision 1.69 2004/06/16 14:12:53 vsc
|
|
|
|
* miscellaneous fixes
|
|
|
|
*
|
2004-06-16 15:12:53 +01:00
|
|
|
* Revision 1.68 2004/05/14 17:11:30 vsc
|
|
|
|
* support BigNums in interface
|
|
|
|
*
|
2004-05-14 18:11:32 +01:00
|
|
|
* Revision 1.67 2004/05/14 16:33:45 vsc
|
|
|
|
* add Yap_ReadBuffer
|
|
|
|
*
|
2004-05-14 17:33:47 +01:00
|
|
|
* Revision 1.66 2004/05/13 20:54:58 vsc
|
|
|
|
* debugger fixes
|
|
|
|
* make sure we always go back to current module, even during initizlization.
|
|
|
|
*
|
2004-05-13 21:54:58 +01:00
|
|
|
* Revision 1.65 2004/04/27 15:14:36 vsc
|
|
|
|
* fix halt/0 and halt/1
|
|
|
|
* *
|
2004-04-27 16:14:38 +01:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
#endif
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
#define HAS_CACHE_REGS 1
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
|
|
|
* This file includes the definition of a miscellania of standard predicates
|
|
|
|
* for yap refering to: Consulting, Executing a C predicate from call,
|
|
|
|
* Comparisons (both general and numeric), Structure manipulation, Direct
|
|
|
|
* access to atoms and predicates, Basic support for the debugger
|
|
|
|
*
|
|
|
|
* It also includes a table where all C-predicates are initializated
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "Yatom.h"
|
2009-10-23 14:22:17 +01:00
|
|
|
#include "YapHeap.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "eval.h"
|
|
|
|
#include "yapio.h"
|
2010-04-16 02:08:06 +01:00
|
|
|
#ifdef TABLING
|
|
|
|
#include "tab.macros.h"
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2006-05-18 17:33:05 +01:00
|
|
|
#if HAVE_MALLOC_H
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2006-11-27 17:42:03 +00:00
|
|
|
#include <wchar.h>
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_setval, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_value, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_values, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef undefined
|
|
|
|
STD_PROTO(static CODEADDR *FindAtom, (CODEADDR, int *));
|
|
|
|
#endif /* undefined */
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_opdec, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
STD_PROTO(static Term get_num, (char *));
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_name, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_atom_chars, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_atom_codes, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_atom_length, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_atom_split, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_number_chars, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_number_codes, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_univ, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_abort, ( USES_REGS1 ));
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(Int p_halt, ( USES_REGS1 ));
|
2005-09-08 23:06:45 +01:00
|
|
|
#else
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_halt, ( USES_REGS1 ));
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int init_current_atom, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int cont_current_atom, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int init_current_predicate, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int cont_current_predicate, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int init_current_predicate_for_atom, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int cont_current_predicate_for_atom, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static OpEntry *NextOp, (OpEntry * CACHE_TYPE));
|
|
|
|
STD_PROTO(static Int init_current_op, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int cont_current_op, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int init_current_atom_op, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int cont_current_atom_op, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_debug, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_flags, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
STD_PROTO(static int AlreadyHidden, (char *));
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_hide, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_hidden, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_unhide, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
STD_PROTO(static Int TrailMax, (void));
|
|
|
|
STD_PROTO(static Int GlobalMax, (void));
|
|
|
|
STD_PROTO(static Int LocalMax, (void));
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(static Int p_statistics_heap_max, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_statistics_global_max, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_statistics_local_max, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_statistics_heap_info, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_statistics_stacks_info, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_statistics_trail_info, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Term mk_argc_list, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_argv, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_cputime, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_systime, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_runtime, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_walltime, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_access_yap_flags, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(static Int p_set_yap_flags, ( USES_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
2011-03-07 16:02:55 +00:00
|
|
|
STD_PROTO(Int use_eam, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int eager_split, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int force_wait, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int commit, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int skip_while_var, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int wait_while_var, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int show_time, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int start_eam, ( USES_REGS1 ));
|
|
|
|
STD_PROTO(Int cont_eam, ( USES_REGS1 ));
|
2005-09-08 23:06:45 +01:00
|
|
|
|
|
|
|
extern int EAM;
|
|
|
|
extern int eam_am(PredEntry*);
|
|
|
|
extern int showTime(void);
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int start_eam( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (eam_am((PredEntry *) 0x1)) return (TRUE);
|
|
|
|
else { cut_fail(); return (FALSE); }
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int cont_eam( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (eam_am((PredEntry *) 0x2)) return (TRUE);
|
|
|
|
else { cut_fail(); return (FALSE); }
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int use_eam( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) EAM=0;
|
2008-12-23 01:53:52 +00:00
|
|
|
else { Yap_PutValue(AtomCArith,0); EAM=1; }
|
2005-09-08 23:06:45 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int commit( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
|
|
|
printf("Nao deveria ter sido chamado commit do stdpreds\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int skip_while_var( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
|
|
|
printf("Nao deveria ter sido chamado skip_while_var do stdpreds\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int wait_while_var( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
|
|
|
printf("Nao deveria ter sido chamado wait_while_var do stdpreds\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int force_wait( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
|
|
|
printf("Nao deveria ter sido chamado force_wait do stdpreds\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int eager_split( USES_REGS1 ) {
|
2005-09-08 23:06:45 +01:00
|
|
|
if (EAM) {
|
|
|
|
printf("Nao deveria ter sido chamado eager_split do stdpreds\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
Int show_time( USES_REGS1 ) /* MORE PRECISION */
|
2005-09-08 23:06:45 +01:00
|
|
|
{
|
|
|
|
return (showTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* BEAM */
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_setval( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$set_value'(+Atom,+Atomic) */
|
|
|
|
Term t1 = Deref(ARG1), t2 = Deref(ARG2);
|
|
|
|
if (!IsVarTerm(t1) && IsAtomTerm(t1) &&
|
|
|
|
(!IsVarTerm(t2) && (IsAtomTerm(t2) || IsNumTerm(t2)))) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomOfTerm(t1), t2);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_value( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$get_value'(+Atom,?Val) */
|
|
|
|
Term t1 = Deref(ARG1);
|
2002-09-13 22:30:06 +01:00
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"get_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"get_value/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2002-09-13 22:30:06 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG2, Yap_GetValue(AtomOfTerm(t1))));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_values( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$values'(Atom,Old,New) */
|
|
|
|
Term t1 = Deref(ARG1), t3 = Deref(ARG3);
|
|
|
|
|
2002-09-13 22:30:06 +01:00
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"set_value/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
2002-09-13 22:30:06 +01:00
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"set_value/2");
|
2002-09-13 22:30:06 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
if (!Yap_unify_constant(ARG2, Yap_GetValue(AtomOfTerm(t1))))
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
if (!IsVarTerm(t3)) {
|
|
|
|
if (IsAtomTerm(t3) || IsNumTerm(t3)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(AtomOfTerm(t1), t3);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
inline static void
|
2011-03-07 16:02:55 +00:00
|
|
|
do_signal(yap_signals sig USES_REGS)
|
2004-01-23 02:23:51 +00:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
if (!LOCAL_InterruptsDisabled)
|
2009-05-20 07:53:14 +01:00
|
|
|
CreepFlag = Unsigned(LCL0);
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ActiveSignals |= sig;
|
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2004-01-23 02:23:51 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
inline static void
|
2011-03-07 16:02:55 +00:00
|
|
|
undo_signal(yap_signals sig USES_REGS)
|
2005-10-28 18:38:50 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
if (LOCAL_ActiveSignals == sig) {
|
2005-10-28 18:38:50 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ActiveSignals &= ~sig;
|
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_creep( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
at = AtomCreep;
|
2002-11-18 18:18:05 +00:00
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
2001-10-30 16:42:05 +00:00
|
|
|
CreepCode = pred;
|
2011-03-07 16:02:55 +00:00
|
|
|
do_signal(YAP_CREEP_SIGNAL PASS_REGS);
|
2003-08-27 14:37:10 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-02-08 04:05:39 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_signal_creep( USES_REGS1 )
|
2005-02-08 04:05:39 +00:00
|
|
|
{
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
at = AtomCreep;
|
2005-02-08 04:05:39 +00:00
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
|
|
|
CreepCode = pred;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
LOCAL_ActiveSignals |= YAP_CREEP_SIGNAL;
|
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2008-08-30 02:39:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_disable_creep( USES_REGS1 )
|
2008-08-30 02:39:36 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) {
|
|
|
|
LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
if (!LOCAL_ActiveSignals)
|
2008-08-30 02:39:36 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2011-05-04 10:11:41 +01:00
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2008-08-30 02:39:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2008-08-30 02:39:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* never fails */
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_disable_docreep( USES_REGS1 )
|
2008-08-30 02:39:36 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
if (LOCAL_ActiveSignals & YAP_CREEP_SIGNAL) {
|
|
|
|
LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
if (!LOCAL_ActiveSignals)
|
2008-08-30 02:39:36 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
2011-05-04 10:11:41 +01:00
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2008-08-30 02:39:36 +01:00
|
|
|
} else {
|
2011-05-04 10:11:41 +01:00
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2008-08-30 02:39:36 +01:00
|
|
|
}
|
2005-02-08 04:05:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_stop_creep( USES_REGS1 )
|
2003-08-27 14:37:10 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCK(LOCAL_SignalLock);
|
|
|
|
LOCAL_ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
|
|
|
if (!LOCAL_ActiveSignals) {
|
2004-05-13 21:54:58 +01:00
|
|
|
CreepFlag = CalculateStackGap();
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
UNLOCK(LOCAL_SignalLock);
|
2003-08-27 14:37:10 +01:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
void
|
|
|
|
Yap_signal(yap_signals sig)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
do_signal(sig PASS_REGS);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
void
|
|
|
|
Yap_undo_signal(yap_signals sig)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
undo_signal(sig PASS_REGS);
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef undefined
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns where some particular piece of code is, it may take its time but
|
|
|
|
* then you only need it while creeping, so why bother ?
|
|
|
|
*/
|
|
|
|
static CODEADDR *
|
|
|
|
FindAtom(codeToFind, arity)
|
|
|
|
CODEADDR codeToFind;
|
|
|
|
unsigned int *arityp;
|
|
|
|
{
|
|
|
|
Atom a;
|
|
|
|
int i;
|
|
|
|
|
2003-10-28 01:16:03 +00:00
|
|
|
for (i = 0; i < AtomHashTableSize; ++i) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(HashChain[i].AeRWLock);
|
|
|
|
a = HashChain[i].Entry;
|
|
|
|
READ_UNLOCK(HashChain[i].AeRWLock);
|
|
|
|
while (a != NIL) {
|
|
|
|
register PredEntry *pp;
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
READ_LOCK(ae->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
pp = RepPredProp(RepAtom(a)->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (!EndOfPAEntr(pp) && ((pp->KindOfPE & 0x8000)
|
|
|
|
|| (pp->CodeOfPred != codeToFind)))
|
|
|
|
pp = RepPredProp(pp->NextOfPE);
|
|
|
|
if (pp != NIL) {
|
|
|
|
CODEADDR *out;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(90,pp);
|
2001-04-09 20:54:03 +01:00
|
|
|
out = &(pp->CodeOfPred)
|
|
|
|
*arityp = pp->ArityOfPE;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
a = RepAtom(a)->NextOfAE;
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
for (i = 0; i < WideAtomHashTableSize; ++i) {
|
|
|
|
READ_LOCK(HashChain[i].AeRWLock);
|
|
|
|
a = HashChain[i].Entry;
|
|
|
|
READ_UNLOCK(HashChain[i].AeRWLock);
|
|
|
|
while (a != NIL) {
|
|
|
|
register PredEntry *pp;
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
READ_LOCK(ae->ARWLock);
|
|
|
|
pp = RepPredProp(RepAtom(a)->PropsOfAE);
|
|
|
|
while (!EndOfPAEntr(pp) && ((pp->KindOfPE & 0x8000)
|
|
|
|
|| (pp->CodeOfPred != codeToFind)))
|
|
|
|
pp = RepPredProp(pp->NextOfPE);
|
|
|
|
if (pp != NIL) {
|
|
|
|
CODEADDR *out;
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(91,pp);
|
2006-11-27 17:42:03 +00:00
|
|
|
out = &(pp->CodeOfPred)
|
|
|
|
*arityp = pp->ArityOfPE;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pp->PELock);
|
2006-11-27 17:42:03 +00:00
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
a = RepAtom(a)->NextOfAE;
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
*arityp = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called when you want to creep a C-predicate or a predicate written
|
|
|
|
* in assembly
|
|
|
|
*/
|
|
|
|
CELL
|
|
|
|
FindWhatCreep(toCreep)
|
|
|
|
CELL toCreep;
|
|
|
|
{
|
|
|
|
unsigned int arity;
|
|
|
|
Atom at;
|
|
|
|
CODEADDR *place;
|
|
|
|
|
|
|
|
if (toCreep > 64) { /* written in C */
|
|
|
|
int i;
|
|
|
|
place = FindAtom((CODEADDR) toCreep, &arity);
|
|
|
|
*--ASP = Unsigned(P);
|
|
|
|
*--ASP = N = arity;
|
|
|
|
for (i = 1; i <= arity; ++i)
|
|
|
|
*--ASP = X[i];
|
|
|
|
/* P = CellPtr(CCREEPCODE); */
|
|
|
|
return (Unsigned(place));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* undefined */
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_opdec( USES_REGS1 )
|
2002-09-09 18:40:12 +01:00
|
|
|
{ /* '$opdec'(p,type,atom) */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* we know the arguments are integer, atom, atom */
|
|
|
|
Term p = Deref(ARG1), t = Deref(ARG2), at = Deref(ARG3);
|
2005-10-21 17:09:03 +01:00
|
|
|
Term tmod = Deref(ARG4);
|
|
|
|
if (tmod == TermProlog) {
|
|
|
|
tmod = PROLOG_MODULE;
|
|
|
|
}
|
|
|
|
return Yap_OpDec((int) IntOfTerm(p), RepAtom(AtomOfTerm(t))->StrOfAE,
|
|
|
|
AtomOfTerm(at), tmod);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NO_STRTOD
|
|
|
|
|
|
|
|
#if HAVE_CTYPE_H
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
double
|
|
|
|
strtod(s, pe)
|
|
|
|
char *s, **pe;
|
|
|
|
{
|
|
|
|
double r = atof(s);
|
|
|
|
*pe = s;
|
|
|
|
while (*s == ' ')
|
|
|
|
++s;
|
|
|
|
if (*s == '+' || *s == '-')
|
|
|
|
++s;
|
|
|
|
if (!isdigit(*s))
|
|
|
|
return (r);
|
|
|
|
while (isdigit(*s))
|
|
|
|
++s;
|
|
|
|
if (*s == '.')
|
|
|
|
++s;
|
|
|
|
while (isdigit(*s))
|
|
|
|
++s;
|
|
|
|
if (*s == 'e' || *s == 'E')
|
|
|
|
++s;
|
|
|
|
if (*s == '+' || *s == '-')
|
|
|
|
++s;
|
|
|
|
while (isdigit(*s))
|
|
|
|
++s;
|
|
|
|
*pe = s;
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-11-16 14:26:00 +00:00
|
|
|
#ifndef INFINITY
|
|
|
|
#define INFINITY (1.0/0.0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NAN
|
|
|
|
#define NAN (0.0/0.0)
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Term
|
|
|
|
get_num(char *t)
|
|
|
|
{
|
|
|
|
Term out;
|
2011-02-15 13:54:19 +00:00
|
|
|
IOSTREAM *smem = Sopenmem(&t, NULL, "r");
|
|
|
|
out = Yap_scan_num(smem);
|
|
|
|
Sclose(smem);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* not ever iso */
|
|
|
|
if (out == TermNil && yap_flags[LANGUAGE_MODE_FLAG] != 1) {
|
|
|
|
int sign = 1;
|
|
|
|
if (t[0] == '+') {
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
if (t[0] == '-') {
|
|
|
|
t++;
|
|
|
|
sign = -1;
|
|
|
|
}
|
|
|
|
if(strcmp(t,"inf") == 0) {
|
|
|
|
if (sign > 0) {
|
2006-11-16 14:26:00 +00:00
|
|
|
return MkFloatTerm(INFINITY);
|
|
|
|
} else {
|
|
|
|
return MkFloatTerm(-INFINITY);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(strcmp(t,"nan") == 0) {
|
|
|
|
if (sign > 0) {
|
2006-11-16 14:26:00 +00:00
|
|
|
return MkFloatTerm(NAN);
|
|
|
|
} else {
|
|
|
|
return MkFloatTerm(-NAN);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-15 13:54:19 +00:00
|
|
|
/*
|
2001-04-09 20:54:03 +01:00
|
|
|
if (cur_char_ptr[0] == '\0')
|
|
|
|
else
|
|
|
|
return(TermNil);
|
2011-02-15 13:54:19 +00:00
|
|
|
*/
|
|
|
|
return(out);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2004-03-02 16:44:58 +00:00
|
|
|
static UInt
|
2011-03-07 16:02:55 +00:00
|
|
|
runtime( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_cputime()-Yap_total_gc_time()-Yap_total_stack_shift_time());
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* $runtime(-SinceInterval,-SinceStart) */
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_runtime( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int now, interval,
|
|
|
|
gc_time,
|
|
|
|
ss_time;
|
2008-01-23 17:57:56 +00:00
|
|
|
Term tnow, tinterval;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_cputime_interval(&now, &interval);
|
|
|
|
gc_time = Yap_total_gc_time();
|
2008-01-23 17:57:56 +00:00
|
|
|
now -= gc_time;
|
2002-11-18 18:18:05 +00:00
|
|
|
ss_time = Yap_total_stack_shift_time();
|
2008-01-23 17:57:56 +00:00
|
|
|
now -= ss_time;
|
2011-05-04 10:11:41 +01:00
|
|
|
interval -= (gc_time-LOCAL_LastGcTime)+(ss_time-LOCAL_LastSSTime);
|
|
|
|
LOCAL_LastGcTime = gc_time;
|
|
|
|
LOCAL_LastSSTime = ss_time;
|
2008-01-23 17:57:56 +00:00
|
|
|
tnow = MkIntegerTerm(now);
|
|
|
|
tinterval = MkIntegerTerm(interval);
|
|
|
|
return( Yap_unify_constant(ARG1, tnow) &&
|
|
|
|
Yap_unify_constant(ARG2, tinterval) );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* $cputime(-SinceInterval,-SinceStart) */
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_cputime( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int now, interval;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_cputime_interval(&now, &interval);
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:56:40 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_systime( USES_REGS1 )
|
2009-02-09 21:56:40 +00:00
|
|
|
{
|
|
|
|
Int now, interval;
|
|
|
|
Yap_systime_interval(&now, &interval);
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_walltime( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int now, interval;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_walltime_interval(&now, &interval);
|
|
|
|
return( Yap_unify_constant(ARG1, MkIntegerTerm(now)) &&
|
|
|
|
Yap_unify_constant(ARG2, MkIntegerTerm(interval)) );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_char_code( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int t0 = Deref(ARG1);
|
|
|
|
if (IsVarTerm(t0)) {
|
|
|
|
Term t1 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t0,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsIntegerTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t1,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else {
|
|
|
|
Int code = IntegerOfTerm(t1);
|
|
|
|
Term tout;
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
if (code < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,t1,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-12-13 16:10:26 +00:00
|
|
|
if (code > MAX_ISO_LATIN1) {
|
|
|
|
wchar_t wcodes[2];
|
|
|
|
|
|
|
|
wcodes[0] = code;
|
|
|
|
wcodes[1] = '\0';
|
|
|
|
tout = MkAtomTerm(Yap_LookupWideAtom(wcodes));
|
|
|
|
} else {
|
|
|
|
char codes[2];
|
|
|
|
|
|
|
|
codes[0] = code;
|
|
|
|
codes[1] = '\0';
|
|
|
|
tout = MkAtomTerm(Yap_LookupAtom(codes));
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG1,tout);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else if (!IsAtomTerm(t0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,t0,"char_code/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else {
|
2006-12-13 16:10:26 +00:00
|
|
|
Atom at = AtomOfTerm(t0);
|
|
|
|
Term tf;
|
|
|
|
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *c = RepAtom(at)->WStrOfAE;
|
|
|
|
|
|
|
|
if (c[1] != '\0') {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,t0,"char_code/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
tf = MkIntegerTerm(c[0]);
|
|
|
|
} else {
|
|
|
|
char *c = RepAtom(at)->StrOfAE;
|
|
|
|
|
|
|
|
if (c[1] != '\0') {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,t0,"char_code/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
tf = MkIntTerm((unsigned char)(c[0]));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-12-13 16:10:26 +00:00
|
|
|
return Yap_unify(ARG2,tf);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-27 17:42:03 +00:00
|
|
|
static wchar_t *
|
2011-03-07 16:02:55 +00:00
|
|
|
ch_to_wide(char *base, char *charp USES_REGS)
|
2006-11-27 17:42:03 +00:00
|
|
|
{
|
|
|
|
int n = charp-base, i;
|
|
|
|
wchar_t *nb = (wchar_t *)base;
|
|
|
|
|
|
|
|
if ((nb+n) + 1024 > (wchar_t *)AuxSp) {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
|
|
|
|
LOCAL_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
2006-11-27 17:42:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i=n; i > 0; i--) {
|
2010-07-21 11:11:19 +01:00
|
|
|
nb[i-1] = (unsigned char)base[i-1];
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
|
|
|
return nb+n;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_name( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* name(?Atomic,?String) */
|
2004-02-05 16:57:02 +00:00
|
|
|
char *String, *s; /* alloc temp space on trail */
|
2005-04-27 21:09:26 +01:00
|
|
|
Term t = Deref(ARG2), NewT, AtomNameT = Deref(ARG1);
|
2006-11-27 17:42:03 +00:00
|
|
|
wchar_t *ws = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-04-27 21:09:26 +01:00
|
|
|
restart_aux:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsVarTerm(AtomNameT)) {
|
2006-11-27 17:42:03 +00:00
|
|
|
if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) {
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,
|
|
|
|
"name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsAtomTerm(AtomNameT)) {
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom at = AtomOfTerm(AtomNameT);
|
|
|
|
if (IsWideAtom(at)) {
|
2008-07-24 17:02:04 +01:00
|
|
|
NewT = Yap_WideStringToList((wchar_t *)(RepAtom(at)->StrOfAE));
|
2006-11-27 17:42:03 +00:00
|
|
|
return Yap_unify(NewT, ARG2);
|
|
|
|
} else
|
|
|
|
String = RepAtom(at)->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsIntTerm(AtomNameT)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(AtomNameT));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsFloatTerm(AtomNameT)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
sprintf(String, "%f", FloatOfTerm(AtomNameT));
|
|
|
|
} else if (IsLongIntTerm(AtomNameT)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
2004-02-05 16:57:02 +00:00
|
|
|
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(AtomNameT));
|
2005-03-02 19:48:03 +00:00
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(AtomNameT)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
2010-05-28 15:29:20 +01:00
|
|
|
if (!Yap_gmp_to_string(AtomNameT, String, ((char *)AuxSp-String)-1024, 10 ))
|
2005-04-27 21:09:26 +01:00
|
|
|
goto expand_auxsp;
|
2005-03-02 19:48:03 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
return Yap_unify(NewT, ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
s = String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String == ((AtomEntry *)NULL)->StrOfAE ||
|
|
|
|
String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsVarTerm(t) && t == MkAtomTerm(AtomNil)) {
|
2008-12-23 01:53:52 +00:00
|
|
|
return Yap_unify_constant(ARG1, MkAtomTerm(AtomEmptyAtom));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
while (!IsVarTerm(t) && IsPairTerm(t)) {
|
|
|
|
Term Head;
|
|
|
|
Int i;
|
2005-04-27 21:09:26 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"name/2");
|
2005-03-01 22:25:09 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (!IsIntegerTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,Head,"name/2");
|
2005-03-01 22:25:09 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
i = IntegerOfTerm(Head);
|
2006-11-28 13:46:41 +00:00
|
|
|
if (i < 0) {
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,Head,"name/2");
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (ws) {
|
|
|
|
if (ws > (wchar_t *)AuxSp-1024) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = i;
|
|
|
|
} else {
|
2006-11-28 13:46:41 +00:00
|
|
|
if (i > MAX_ISO_LATIN1) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ws = ch_to_wide(String, s PASS_REGS);
|
2006-11-28 13:46:41 +00:00
|
|
|
*ws++ = i;
|
|
|
|
} else {
|
|
|
|
if (s > (char *)AuxSp-1024) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*s++ = i;
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (ws) {
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
*ws = '\0';
|
|
|
|
while ((at = Yap_LookupWideAtom((wchar_t *)String)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG2, "generating atom from string in name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* safest to restart, we don't know what happened to String */
|
|
|
|
t = Deref(ARG2);
|
|
|
|
AtomNameT = Deref(ARG1);
|
|
|
|
goto restart_aux;
|
|
|
|
}
|
|
|
|
NewT = MkAtomTerm(at);
|
|
|
|
return Yap_unify_constant(ARG1, NewT);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
*s = '\0';
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"name/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(t) && AtomOfTerm(t) == AtomNil) {
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2005-03-02 18:35:49 +00:00
|
|
|
Atom at;
|
|
|
|
while ((at = Yap_LookupAtom(String)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG2, "generating atom from string in name/2");
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
2005-04-27 21:09:26 +01:00
|
|
|
/* safest to restart, we don't know what happened to String */
|
|
|
|
t = Deref(ARG2);
|
|
|
|
AtomNameT = Deref(ARG1);
|
|
|
|
goto restart_aux;
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
|
|
|
NewT = MkAtomTerm(at);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-01 22:25:09 +00:00
|
|
|
return Yap_unify_constant(ARG1, NewT);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"name/2");
|
2005-03-01 22:25:09 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-04-27 21:09:26 +01:00
|
|
|
|
|
|
|
/* error handling */
|
|
|
|
expand_auxsp:
|
2009-05-23 00:35:24 +01:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
AtomNameT = Deref(ARG1);
|
|
|
|
t = Deref(ARG2);
|
|
|
|
goto restart_aux;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2011-06-13 01:43:03 +01:00
|
|
|
static Int
|
|
|
|
p_string_to_atom( USES_REGS1 )
|
|
|
|
{ /* name(?Atomic,?String) */
|
|
|
|
char *String; /* alloc temp space on trail */
|
|
|
|
Term t = Deref(ARG1), NewT, AtomNameT = Deref(ARG2);
|
|
|
|
|
|
|
|
restart_aux:
|
|
|
|
if (!IsVarTerm(t)) {
|
|
|
|
Atom at;
|
|
|
|
do {
|
|
|
|
if (Yap_IsWideStringTerm(t)) {
|
|
|
|
at = Yap_LookupWideAtom(Yap_BlobWideStringOfTerm(t));
|
|
|
|
} else if (Yap_IsStringTerm(t)) {
|
|
|
|
at = Yap_LookupAtom(Yap_BlobStringOfTerm(t));
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
return Yap_unify(t, ARG2);
|
|
|
|
} else if (IsIntTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t));
|
|
|
|
at = Yap_LookupAtom(String);
|
|
|
|
} else if (IsFloatTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t));
|
|
|
|
at = Yap_LookupAtom(String);
|
|
|
|
} else if (IsLongIntTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t));
|
|
|
|
at = Yap_LookupAtom(String);
|
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(t)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (!Yap_gmp_to_string(t, String, ((char *)AuxSp-String)-1024, 10 ))
|
|
|
|
goto expand_auxsp;
|
|
|
|
at = Yap_LookupAtom(String);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (at != NIL)
|
|
|
|
break;
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG2, "generating atom from string in string_to_atom/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t = Deref(ARG1);
|
|
|
|
} while(TRUE);
|
|
|
|
return Yap_unify_constant(ARG2, MkAtomTerm(at));
|
|
|
|
}
|
2011-06-14 08:59:17 +01:00
|
|
|
if (IsVarTerm(AtomNameT)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "string_to_atom/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
else if (IsAtomTerm(AtomNameT)) {
|
|
|
|
Atom at = AtomOfTerm(AtomNameT);
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *s = RepAtom(at)->WStrOfAE;
|
|
|
|
NewT = Yap_MkBlobWideStringTerm(s, wcslen(s));
|
|
|
|
return Yap_unify(NewT, ARG1);
|
|
|
|
} else
|
|
|
|
String = RepAtom(at)->StrOfAE;
|
|
|
|
} else if (IsIntTerm(AtomNameT)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(AtomNameT));
|
|
|
|
} else if (IsFloatTerm(AtomNameT)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(AtomNameT));
|
|
|
|
} else if (IsLongIntTerm(AtomNameT)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(AtomNameT));
|
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(AtomNameT)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (!Yap_gmp_to_string(AtomNameT, String, ((char *)AuxSp-String)-1024, 10 ))
|
|
|
|
goto expand_auxsp;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
NewT = Yap_MkBlobStringTerm(String, strlen(String));
|
|
|
|
return Yap_unify(NewT, ARG1);
|
|
|
|
|
|
|
|
/* error handling */
|
|
|
|
expand_auxsp:
|
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in string_to_atom/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
AtomNameT = Deref(ARG1);
|
|
|
|
t = Deref(ARG2);
|
|
|
|
goto restart_aux;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_string_to_list( USES_REGS1 )
|
|
|
|
{ /* name(?Atomic,?String) */
|
|
|
|
char *String; /* alloc temp space on trail */
|
|
|
|
Term t = Deref(ARG1), NewT, NameT = Deref(ARG2);
|
|
|
|
|
|
|
|
restart_aux:
|
|
|
|
if (!IsVarTerm(t)) {
|
|
|
|
Term StringT;
|
|
|
|
|
|
|
|
if (Yap_IsWideStringTerm(t)) {
|
|
|
|
StringT = Yap_WideStringToList(Yap_BlobWideStringOfTerm(t));
|
|
|
|
} else if (Yap_IsStringTerm(t)) {
|
|
|
|
StringT = Yap_StringToList(Yap_BlobStringOfTerm(t));
|
|
|
|
} else if (IsAtomTerm(t)) {
|
|
|
|
Atom at = AtomOfTerm(t);
|
|
|
|
if (IsWideAtom(at))
|
|
|
|
StringT = Yap_WideStringToList(RepAtom(at)->WStrOfAE);
|
|
|
|
else
|
|
|
|
StringT = Yap_StringToList(RepAtom(at)->StrOfAE);
|
|
|
|
} else if (IsIntTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t));
|
|
|
|
StringT = Yap_StringToList(String);
|
|
|
|
} else if (IsFloatTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t));
|
|
|
|
StringT = Yap_StringToList(String);
|
|
|
|
} else if (IsLongIntTerm(t)) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t));
|
|
|
|
StringT = Yap_StringToList(String);
|
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(t)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (!Yap_gmp_to_string(t, String, ((char *)AuxSp-String)-1024, 10 ))
|
|
|
|
goto expand_auxsp;
|
|
|
|
StringT = Yap_StringToList(String);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC,NameT,"string_to_list/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return Yap_unify_constant(ARG2, StringT);
|
|
|
|
}
|
|
|
|
if (!IsVarTerm(NameT)) {
|
|
|
|
if (IsAtomTerm(NameT)) {
|
|
|
|
Atom at = AtomOfTerm(NameT);
|
2011-06-13 01:43:03 +01:00
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *s = RepAtom(at)->WStrOfAE;
|
|
|
|
NewT = Yap_MkBlobWideStringTerm(s, wcslen(s));
|
|
|
|
return Yap_unify(NewT, ARG1);
|
|
|
|
} else
|
|
|
|
String = RepAtom(at)->StrOfAE;
|
2011-06-14 08:59:17 +01:00
|
|
|
} else if (IsIntTerm(NameT)) {
|
2011-06-13 01:43:03 +01:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
2011-06-14 08:59:17 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(NameT));
|
|
|
|
} else if (IsFloatTerm(NameT)) {
|
2011-06-13 01:43:03 +01:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
2011-06-14 08:59:17 +01:00
|
|
|
sprintf(String, "%f", FloatOfTerm(NameT));
|
|
|
|
} else if (IsLongIntTerm(NameT)) {
|
2011-06-13 01:43:03 +01:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
|
2011-06-14 08:59:17 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(NameT));
|
2011-06-13 01:43:03 +01:00
|
|
|
#if USE_GMP
|
2011-06-14 08:59:17 +01:00
|
|
|
} else if (IsBigIntTerm(NameT)) {
|
2011-06-13 01:43:03 +01:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2011-06-14 08:59:17 +01:00
|
|
|
if (!Yap_gmp_to_string(NameT, String, ((char *)AuxSp-String)-1024, 10 ))
|
2011-06-13 01:43:03 +01:00
|
|
|
goto expand_auxsp;
|
|
|
|
#endif
|
2011-06-14 08:59:17 +01:00
|
|
|
} else {
|
|
|
|
wchar_t *WString = (wchar_t *)Yap_PreAllocCodeSpace();
|
|
|
|
wchar_t *ws = WString;
|
|
|
|
while (IsPairTerm(NameT)) {
|
|
|
|
Term Head = HeadOfTerm(NameT);
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
if (IsVarTerm(Head)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"string_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(Head)) {
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,Head,"string_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
i = IntegerOfTerm(Head);
|
|
|
|
if (i < 0) {
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,Head,"string_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (ws > (wchar_t *)AuxSp-1024) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = i;
|
|
|
|
NameT = TailOfTerm(NameT);
|
|
|
|
}
|
|
|
|
if (IsVarTerm(NameT)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,ARG2,"string_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (NameT != TermNil) {
|
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"string_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*ws++ = '\0';
|
|
|
|
NewT = Yap_MkBlobWideStringTerm(WString, wcslen(WString));
|
2011-06-13 01:43:03 +01:00
|
|
|
return Yap_unify(NewT, ARG1);
|
2011-06-14 08:59:17 +01:00
|
|
|
/* **** */
|
2011-06-13 01:43:03 +01:00
|
|
|
}
|
2011-06-14 08:59:17 +01:00
|
|
|
NewT = Yap_MkBlobStringTerm(String, sizeof(String));
|
|
|
|
return Yap_unify(NewT, ARG1);
|
2011-06-13 01:43:03 +01:00
|
|
|
}
|
2011-06-14 08:59:17 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "string_to_list/2");
|
2011-06-13 01:43:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
/* error handling */
|
|
|
|
expand_auxsp:
|
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
2011-06-14 08:59:17 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in string_to_list/2");
|
2011-06-13 01:43:03 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-06-14 08:59:17 +01:00
|
|
|
NameT = Deref(ARG1);
|
2011-06-13 01:43:03 +01:00
|
|
|
t = Deref(ARG2);
|
|
|
|
goto restart_aux;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_chars( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t1 = Deref(ARG1);
|
2005-04-27 21:09:26 +01:00
|
|
|
char *String;
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2005-04-27 21:09:26 +01:00
|
|
|
restart_aux:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
Term NewT;
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom at;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
at = AtomOfTerm(t1);
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
2008-07-24 17:02:04 +01:00
|
|
|
NewT = Yap_WideStringToList((wchar_t *)RepAtom(at)->StrOfAE);
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
2008-07-24 17:02:04 +01:00
|
|
|
NewT = Yap_WideStringToListOfAtoms((wchar_t *)RepAtom(AtomOfTerm(t1))->StrOfAE);
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2006-11-27 17:42:03 +00:00
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
NewT = Yap_StringToList(RepAtom(at)->StrOfAE);
|
|
|
|
} else {
|
|
|
|
NewT = Yap_StringToListOfAtoms(RepAtom(AtomOfTerm(t1))->StrOfAE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
return Yap_unify(NewT, ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* ARG1 unbound */
|
2005-04-27 21:09:26 +01:00
|
|
|
Term t = Deref(ARG2);
|
|
|
|
char *s;
|
2006-11-27 17:42:03 +00:00
|
|
|
wchar_t *ws = NULL;
|
2005-03-02 19:48:03 +00:00
|
|
|
Atom at;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-04-27 21:09:26 +01:00
|
|
|
String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
s = String;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (t == TermNil) {
|
2008-12-23 01:53:52 +00:00
|
|
|
return (Yap_unify_constant(t1, MkAtomTerm(AtomEmptyAtom)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsPairTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
while (t != TermNil) {
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2006-11-27 17:42:03 +00:00
|
|
|
} else if (!IsIntegerTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
i = IntegerOfTerm(Head);
|
|
|
|
if (i < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (i > MAX_ISO_LATIN1 && !ws) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ws = ch_to_wide(String, s PASS_REGS);
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
|
|
|
if (ws) {
|
|
|
|
if (ws > (wchar_t *)AuxSp-1024) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = i;
|
|
|
|
} else {
|
|
|
|
if (s+1024 > (char *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*s++ = i;
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* ISO Prolog Mode */
|
2010-03-25 09:59:39 +00:00
|
|
|
int has_atoms = yap_flags[STRICT_ISO_FLAG];
|
|
|
|
int has_ints = FALSE;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
while (t != TermNil) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Term Head;
|
|
|
|
char *is;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2010-03-25 09:59:39 +00:00
|
|
|
} else if (IsAtomTerm(Head) && !has_ints) {
|
|
|
|
at = AtomOfTerm(Head);
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *wis = (wchar_t *)RepAtom(at)->StrOfAE;
|
|
|
|
if (wis[1] != '\0') {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"atom_chars/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!ws) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ws = ch_to_wide(String, s PASS_REGS);
|
2010-03-25 09:59:39 +00:00
|
|
|
}
|
|
|
|
if (ws+1024 == (wchar_t *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = wis[0];
|
|
|
|
} else {
|
|
|
|
is = RepAtom(at)->StrOfAE;
|
|
|
|
if (is[1] != '\0') {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"atom_chars/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (ws) {
|
|
|
|
if (ws+1024 == (wchar_t *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = is[0];
|
|
|
|
} else {
|
|
|
|
if (s+1024 == (char *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*s++ = is[0];
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
} else if (IsIntegerTerm(Head) && !has_atoms) {
|
|
|
|
Int i = IntegerOfTerm(Head);
|
|
|
|
if (i < 0) {
|
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_codes/2");
|
2006-11-27 17:42:03 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
if (i > MAX_ISO_LATIN1 && !ws) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ws = ch_to_wide(String, s PASS_REGS);
|
2010-03-25 09:59:39 +00:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (ws) {
|
2010-03-25 09:59:39 +00:00
|
|
|
if (ws+1024 > (wchar_t *)AuxSp) {
|
2006-11-27 17:42:03 +00:00
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
*ws++ = i;
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
2010-03-25 09:59:39 +00:00
|
|
|
if (s+1024 > (char *)AuxSp) {
|
2006-11-27 17:42:03 +00:00
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
*s++ = i;
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"atom_chars/2");
|
|
|
|
return(FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2010-03-26 16:16:05 +00:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_chars/2");
|
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_chars/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (ws) {
|
|
|
|
*ws++ = '\0';
|
|
|
|
while ((at = Yap_LookupWideAtom((wchar_t *)String)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*s++ = '\0';
|
|
|
|
while ((at = Yap_LookupAtom(String)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Yap_unify_constant(ARG1, MkAtomTerm(at));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-04-27 21:09:26 +01:00
|
|
|
/* error handling */
|
|
|
|
expand_auxsp:
|
2009-05-23 00:35:24 +01:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in atom_chars/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
goto restart_aux;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-04-17 22:07:41 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_concat( USES_REGS1 )
|
2001-04-17 22:07:41 +01:00
|
|
|
{
|
2006-11-27 17:42:03 +00:00
|
|
|
Term t1;
|
|
|
|
int wide_mode = FALSE;
|
2001-04-17 22:07:41 +01:00
|
|
|
|
|
|
|
restart:
|
2006-11-27 17:42:03 +00:00
|
|
|
t1 = Deref(ARG1);
|
2001-04-17 22:07:41 +01:00
|
|
|
/* we need to have a list */
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
2001-04-17 22:07:41 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (wide_mode) {
|
|
|
|
wchar_t *cptr = (wchar_t *)(((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE), *cpt0;
|
|
|
|
wchar_t *top = (wchar_t *)AuxSp;
|
2012-04-23 17:26:49 +01:00
|
|
|
unsigned char *atom_str;
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom ahead;
|
2012-04-23 17:26:49 +01:00
|
|
|
UInt sz;
|
2006-11-27 17:42:03 +00:00
|
|
|
|
|
|
|
cpt0 = cptr;
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
if (IsVarTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "atom_concat/2");
|
2001-04-17 22:07:41 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
ahead = AtomOfTerm(thead);
|
|
|
|
if (IsWideAtom(ahead)) {
|
|
|
|
/* check for overflows */
|
2012-04-23 17:26:49 +01:00
|
|
|
sz = wcslen(RepAtom(ahead)->WStrOfAE);
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
2012-04-23 17:26:49 +01:00
|
|
|
atom_str = (unsigned char *)RepAtom(ahead)->StrOfAE;
|
|
|
|
sz = strlen((char *)atom_str);
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2012-04-23 17:26:49 +01:00
|
|
|
if (cptr+sz > top+1024) {
|
|
|
|
cptr = (wchar_t *)Yap_ExpandPreAllocCodeSpace(sz+1024,NULL, TRUE);
|
|
|
|
if (cptr+sz > (wchar_t *)AuxSp+1024) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in atom_concat/2");
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-04-23 17:26:49 +01:00
|
|
|
top = (wchar_t *)AuxSp;
|
2006-11-27 17:42:03 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
if (IsWideAtom(ahead)) {
|
2012-04-23 17:26:49 +01:00
|
|
|
memcpy((void *)cptr, RepAtom(ahead)->WStrOfAE, sz*sizeof(wchar_t));
|
2006-11-27 17:42:03 +00:00
|
|
|
cptr += sz;
|
|
|
|
} else {
|
2012-04-23 17:26:49 +01:00
|
|
|
UInt i;
|
|
|
|
|
2006-11-27 17:42:03 +00:00
|
|
|
for (i=0; i < sz; i++) {
|
|
|
|
*cptr++ = *atom_str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-17 22:07:41 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (t1 == TermNil) {
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
cptr[0] = '\0';
|
|
|
|
while ((at = Yap_LookupWideAtom(cpt0)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
2006-11-27 17:42:03 +00:00
|
|
|
return Yap_unify(ARG2, MkAtomTerm(at));
|
2001-04-17 22:07:41 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
|
|
|
char *cptr = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE, *cpt0;
|
|
|
|
char *top = (char *)AuxSp;
|
2012-04-23 17:26:49 +01:00
|
|
|
unsigned char *atom_str;
|
|
|
|
UInt sz;
|
2006-11-27 17:42:03 +00:00
|
|
|
|
|
|
|
cpt0 = cptr;
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
if (IsVarTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsWideAtom(AtomOfTerm(thead)) && !wide_mode) {
|
|
|
|
wide_mode = TRUE;
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
goto restart;
|
|
|
|
}
|
2012-04-23 17:26:49 +01:00
|
|
|
atom_str = (unsigned char *)RepAtom(AtomOfTerm(thead))->StrOfAE;
|
2006-11-27 17:42:03 +00:00
|
|
|
/* check for overflows */
|
2012-04-23 17:26:49 +01:00
|
|
|
sz = strlen((char *)atom_str);
|
2006-11-27 17:42:03 +00:00
|
|
|
if (cptr+sz >= top-1024) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
memcpy((void *)cptr, (void *)atom_str, sz);
|
|
|
|
cptr += sz;
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (t1 == TermNil) {
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
cptr[0] = '\0';
|
|
|
|
while ((at = Yap_LookupAtom(cpt0)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
return Yap_unify(ARG2, MkAtomTerm(at));
|
|
|
|
}
|
2001-04-17 22:07:41 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG1, "atom_concat/2");
|
2005-04-27 21:09:26 +01:00
|
|
|
return FALSE;
|
2001-04-17 22:07:41 +01:00
|
|
|
}
|
|
|
|
|
2004-06-16 15:12:53 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atomic_concat( USES_REGS1 )
|
2004-06-16 15:12:53 +01:00
|
|
|
{
|
2006-11-27 17:42:03 +00:00
|
|
|
Term t1;
|
|
|
|
int wide_mode = FALSE;
|
|
|
|
char *base;
|
2004-06-16 15:12:53 +01:00
|
|
|
|
|
|
|
restart:
|
2006-11-27 17:42:03 +00:00
|
|
|
base = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
|
|
|
while (base+1024 > (char *)AuxSp) {
|
2009-05-23 00:35:24 +01:00
|
|
|
base = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
2006-11-27 17:42:03 +00:00
|
|
|
if (base + 1024 > (char *)AuxSp) {
|
2005-04-27 21:09:26 +01:00
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in atomic_concat/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
t1 = Deref(ARG1);
|
2004-06-16 15:12:53 +01:00
|
|
|
/* we need to have a list */
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (wide_mode) {
|
|
|
|
wchar_t *wcptr = (wchar_t *)base, *wcpt0;
|
|
|
|
wchar_t *wtop = (wchar_t *)AuxSp;
|
|
|
|
|
|
|
|
wcpt0 = wcptr;
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
if (IsVarTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!IsAtomicTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC, ARG1, "atom_concat/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(thead)) {
|
|
|
|
Atom at = AtomOfTerm(thead);
|
|
|
|
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *watom_str = (wchar_t *)RepAtom(AtomOfTerm(thead))->StrOfAE;
|
|
|
|
UInt sz = wcslen(watom_str);
|
|
|
|
|
|
|
|
if (wcptr+sz >= wtop-1024) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
memcpy((void *)wcptr, (void *)watom_str, sz*sizeof(wchar_t));
|
|
|
|
wcptr += sz;
|
|
|
|
} else {
|
2012-04-23 17:26:49 +01:00
|
|
|
unsigned char *atom_str = (unsigned char *)RepAtom(AtomOfTerm(thead))->StrOfAE;
|
2006-11-27 17:42:03 +00:00
|
|
|
/* check for overflows */
|
2012-04-23 17:26:49 +01:00
|
|
|
UInt sz = strlen((char *)atom_str);
|
2006-11-27 17:42:03 +00:00
|
|
|
if (wcptr+sz >= wtop-1024) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
while ((*wcptr++ = *atom_str++));
|
|
|
|
wcptr--;
|
|
|
|
}
|
|
|
|
} else if (IsIntegerTerm(thead)) {
|
|
|
|
UInt sz, i;
|
|
|
|
char *cptr = (char *)wcptr;
|
|
|
|
|
|
|
|
#if HAVE_SNPRINTF
|
2010-05-06 15:00:44 +01:00
|
|
|
sz = snprintf(cptr, (wtop-wcptr)-1024,Int_FORMAT, IntegerOfTerm(thead));
|
2006-11-27 17:42:03 +00:00
|
|
|
#else
|
2010-05-06 15:00:44 +01:00
|
|
|
sz = sprintf(cptr,Int_FORMAT, IntegerOfTerm(thead));
|
2006-11-27 17:42:03 +00:00
|
|
|
#endif
|
|
|
|
for (i=sz; i>0; i--) {
|
|
|
|
wcptr[i-1] = cptr[i-1];
|
|
|
|
}
|
|
|
|
wcptr += sz;
|
|
|
|
} else if (IsFloatTerm(thead)) {
|
|
|
|
char *cptr = (char *)wcptr;
|
|
|
|
UInt i, sz;
|
|
|
|
|
|
|
|
#if HAVE_SNPRINTF
|
|
|
|
sz = snprintf(cptr,(wtop-wcptr)-1024,"%g", FloatOfTerm(thead));
|
|
|
|
#else
|
|
|
|
sz = sprintf(cptr,"%g", FloatOfTerm(thead));
|
|
|
|
#endif
|
|
|
|
for (i=sz; i>0; i--) {
|
|
|
|
wcptr[i-1] = cptr[i-1];
|
|
|
|
}
|
|
|
|
wcptr += sz;
|
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(thead)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
size_t sz, i;
|
2006-11-27 17:42:03 +00:00
|
|
|
char *tmp = (char *)wcptr;
|
|
|
|
|
2010-05-28 15:29:20 +01:00
|
|
|
sz = Yap_gmp_to_size(thead, 10);
|
|
|
|
if (!Yap_gmp_to_string(thead, tmp, (wtop-wcptr)-1024, 10 )) {
|
2006-11-27 17:42:03 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
for (i=sz; i>0; i--) {
|
|
|
|
wcptr[i-1] = tmp[i-1];
|
|
|
|
}
|
|
|
|
wcptr += sz;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (t1 == TermNil) {
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
wcptr[0] = '\0';
|
|
|
|
while ((at = Yap_LookupWideAtom(wcpt0)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-06-16 15:12:53 +01:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
2006-11-27 17:42:03 +00:00
|
|
|
return Yap_unify(ARG2, MkAtomTerm(at));
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
|
|
|
char *top = (char *)AuxSp;
|
|
|
|
char *cpt0 = base;
|
|
|
|
char *cptr = base;
|
|
|
|
|
|
|
|
while (IsPairTerm(t1)) {
|
|
|
|
Term thead = HeadOfTerm(t1);
|
|
|
|
if (IsVarTerm(thead)) {
|
2004-06-16 15:12:53 +01:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
2006-11-27 17:42:03 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomicTerm(thead)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_ATOMIC, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsAtomTerm(thead)) {
|
2012-04-23 17:26:49 +01:00
|
|
|
unsigned char *atom_str;
|
2006-11-27 17:42:03 +00:00
|
|
|
UInt sz;
|
|
|
|
|
|
|
|
if (IsWideAtom(AtomOfTerm(thead))) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
wide_mode = TRUE;
|
|
|
|
goto restart;
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
2012-04-23 17:26:49 +01:00
|
|
|
atom_str = (unsigned char *)RepAtom(AtomOfTerm(thead))->StrOfAE;
|
2006-11-27 17:42:03 +00:00
|
|
|
/* check for overflows */
|
2012-04-23 17:26:49 +01:00
|
|
|
sz = strlen((char *)atom_str);
|
2006-11-27 17:42:03 +00:00
|
|
|
if (cptr+sz >= top-1024) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
memcpy((void *)cptr, (void *)atom_str, sz);
|
|
|
|
cptr += sz;
|
|
|
|
} else if (IsIntegerTerm(thead)) {
|
2004-06-29 20:04:46 +01:00
|
|
|
#if HAVE_SNPRINTF
|
2010-05-06 15:00:44 +01:00
|
|
|
snprintf(cptr, (top-cptr)-1024,Int_FORMAT, IntegerOfTerm(thead));
|
2004-06-29 20:04:46 +01:00
|
|
|
#else
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(cptr, Int_FORMAT, IntegerOfTerm(thead));
|
2004-06-29 20:04:46 +01:00
|
|
|
#endif
|
2006-11-27 17:42:03 +00:00
|
|
|
while (*cptr && cptr < top-1024) cptr++;
|
|
|
|
} else if (IsFloatTerm(thead)) {
|
2004-06-29 20:04:46 +01:00
|
|
|
#if HAVE_SNPRINTF
|
2006-11-27 17:42:03 +00:00
|
|
|
snprintf(cptr,(top-cptr)-1024,"%g", FloatOfTerm(thead));
|
2004-06-29 20:04:46 +01:00
|
|
|
#else
|
2006-11-27 17:42:03 +00:00
|
|
|
sprintf(cptr,"%g", FloatOfTerm(thead));
|
2004-06-29 20:04:46 +01:00
|
|
|
#endif
|
2006-11-27 17:42:03 +00:00
|
|
|
while (*cptr && cptr < top-1024) cptr++;
|
2004-06-29 20:04:46 +01:00
|
|
|
#if USE_GMP
|
2006-11-27 17:42:03 +00:00
|
|
|
} else if (IsBigIntTerm(thead)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
if (!Yap_gmp_to_string(thead, cptr, (top-cptr)-1024, 10 )) {
|
|
|
|
size_t sz = Yap_gmp_to_size(thead, 10);
|
2006-11-27 17:42:03 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
if (!Yap_growheap(FALSE, sz+1024, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
goto restart;
|
2004-06-29 20:04:46 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
while (*cptr) cptr++;
|
2004-06-29 20:04:46 +01:00
|
|
|
#endif
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
|
|
|
t1 = TailOfTerm(t1);
|
|
|
|
if (IsVarTerm(t1)) {
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (t1 == TermNil) {
|
|
|
|
Atom at;
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2006-11-27 17:42:03 +00:00
|
|
|
cptr[0] = '\0';
|
|
|
|
while ((at = Yap_LookupAtom(cpt0)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-11-27 17:42:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
return Yap_unify(ARG2, MkAtomTerm(at));
|
2005-03-02 19:48:03 +00:00
|
|
|
}
|
2004-06-16 15:12:53 +01:00
|
|
|
}
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)cpt0);
|
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG1, "atom_concat/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_codes( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t1 = Deref(ARG1);
|
2005-04-27 21:09:26 +01:00
|
|
|
char *String;
|
|
|
|
|
|
|
|
restart_pred:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
Term NewT;
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom at;
|
|
|
|
|
2011-03-11 23:21:23 +00:00
|
|
|
if (Yap_IsStringTerm(t1)) {
|
|
|
|
if (Yap_IsWideStringTerm(t1)) {
|
|
|
|
NewT = Yap_WideStringToList(Yap_BlobWideStringOfTerm(t1));
|
|
|
|
} else {
|
|
|
|
NewT = Yap_StringToList(Yap_BlobStringOfTerm(t1));
|
|
|
|
}
|
|
|
|
} else if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2006-11-27 17:42:03 +00:00
|
|
|
} else {
|
2011-03-11 23:21:23 +00:00
|
|
|
at = AtomOfTerm(t1);
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
NewT = Yap_WideStringToList((wchar_t *)RepAtom(at)->StrOfAE);
|
|
|
|
} else {
|
|
|
|
NewT = Yap_StringToList(RepAtom(at)->StrOfAE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(NewT, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* ARG1 unbound */
|
2005-04-27 21:09:26 +01:00
|
|
|
Term t = Deref(ARG2);
|
|
|
|
char *s;
|
2006-11-27 17:42:03 +00:00
|
|
|
wchar_t *ws = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-04-27 21:09:26 +01:00
|
|
|
String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
s = String;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (t == TermNil) {
|
2008-12-23 01:53:52 +00:00
|
|
|
return (Yap_unify_constant(t1, MkAtomTerm(AtomEmptyAtom)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsPairTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
while (t != TermNil) {
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2010-03-25 09:59:39 +00:00
|
|
|
} else if (!IsIntegerTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
i = IntegerOfTerm(Head);
|
2006-11-27 17:42:03 +00:00
|
|
|
if (i < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (i > MAX_ISO_LATIN1 && !ws) {
|
2011-03-07 16:02:55 +00:00
|
|
|
ws = ch_to_wide(String, s PASS_REGS);
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
|
|
|
if (ws) {
|
|
|
|
if (ws+1024 > (wchar_t *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*ws++ = i;
|
|
|
|
} else {
|
|
|
|
if (s+1024 > (char *)AuxSp) {
|
|
|
|
goto expand_auxsp;
|
|
|
|
}
|
|
|
|
*s++ = i;
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "atom_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (ws) {
|
|
|
|
*ws++ = '\0';
|
|
|
|
return Yap_unify_constant(ARG1, MkAtomTerm(Yap_LookupWideAtom((wchar_t *)String)));
|
|
|
|
} else {
|
|
|
|
*s++ = '\0';
|
|
|
|
return Yap_unify_constant(ARG1, MkAtomTerm(Yap_LookupAtom(String)));
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-04-27 21:09:26 +01:00
|
|
|
/* error handling */
|
|
|
|
expand_auxsp:
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
2009-05-23 00:35:24 +01:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in atom_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
}
|
|
|
|
goto restart_pred;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_length( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term t2 = Deref(ARG2);
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom at;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-03-14 20:53:48 +00:00
|
|
|
restart_aux:
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-03-14 20:53:48 +00:00
|
|
|
if (Yap_IsStringTerm(t1)) {
|
|
|
|
size_t len;
|
|
|
|
if (Yap_IsWideStringTerm(t1)) {
|
|
|
|
len = wcslen(Yap_BlobWideStringOfTerm(t1));
|
|
|
|
} else {
|
|
|
|
len = strlen(Yap_BlobStringOfTerm(t1));
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG2, MkIntegerTerm(len));
|
|
|
|
} else if (!IsAtomTerm(t1)) {
|
|
|
|
if (!yap_flags[STRICT_ISO_FLAG]) {
|
|
|
|
char *String;
|
|
|
|
|
|
|
|
if (IsIntegerTerm(t1)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
sprintf(String, Int_FORMAT, IntegerOfTerm(t1));
|
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + 1024 > (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(t1)) {
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 ))
|
|
|
|
goto expand_auxsp;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_length/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG2, MkIntegerTerm(strlen(String)));
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "atom_length/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
at = AtomOfTerm(t1);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsVarTerm(t2)) {
|
2006-11-27 17:42:03 +00:00
|
|
|
size_t len;
|
|
|
|
if (!IsIntegerTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if ((len = IntegerOfTerm(t2)) < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
return wcslen((wchar_t *)RepAtom(at)->StrOfAE) == len;
|
|
|
|
} else {
|
|
|
|
return(strlen(RepAtom(at)->StrOfAE) == len);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2006-11-27 17:42:03 +00:00
|
|
|
Term tj;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
len = wcslen((wchar_t *)RepAtom(at)->StrOfAE);
|
|
|
|
} else {
|
|
|
|
len = strlen(RepAtom(at)->StrOfAE);
|
|
|
|
}
|
|
|
|
tj = MkIntegerTerm(len);
|
2005-03-02 19:48:03 +00:00
|
|
|
return Yap_unify_constant(t2,tj);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2011-03-14 20:53:48 +00:00
|
|
|
expand_auxsp:
|
|
|
|
{
|
|
|
|
char *String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in name/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
goto restart_aux;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-27 17:42:03 +00:00
|
|
|
static int
|
|
|
|
is_wide(wchar_t *s)
|
|
|
|
{
|
|
|
|
wchar_t ch;
|
|
|
|
|
|
|
|
while ((ch = *s++)) {
|
|
|
|
if (ch > MAX_ISO_LATIN1)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* split an atom into two sub-atoms */
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_split( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term t2 = Deref(ARG2);
|
2006-11-27 17:42:03 +00:00
|
|
|
size_t len;
|
2001-04-09 20:54:03 +01:00
|
|
|
int i;
|
|
|
|
Term to1, to2;
|
2006-11-27 17:42:03 +00:00
|
|
|
Atom at;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t1, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsVarTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if ((len = IntOfTerm(t2)) < 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "$atom_split/4");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
at = AtomOfTerm(t1);
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *ws, *ws1 = (wchar_t *)H;
|
|
|
|
char *s1 = (char *)H;
|
|
|
|
size_t wlen;
|
|
|
|
|
|
|
|
ws = (wchar_t *)RepAtom(at)->StrOfAE;
|
|
|
|
wlen = wcslen(ws);
|
|
|
|
if (len > wlen) return FALSE;
|
|
|
|
if (s1+len > (char *)LCL0-1024)
|
2004-11-19 22:08:43 +00:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR,t1,"$atom_split/4");
|
2006-11-27 17:42:03 +00:00
|
|
|
for (i = 0; i< len; i++) {
|
|
|
|
if (ws[i] > MAX_ISO_LATIN1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s1[i] = ws[i];
|
|
|
|
}
|
|
|
|
if (ws1[i] > MAX_ISO_LATIN1) {
|
|
|
|
/* first sequence is wide */
|
|
|
|
if (ws1+len > (wchar_t *)ASP-1024)
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR,t1,"$atom_split/4");
|
|
|
|
ws = (wchar_t *)RepAtom(at)->StrOfAE;
|
|
|
|
for (i = 0; i< len; i++) {
|
|
|
|
ws1[i] = ws[i];
|
|
|
|
}
|
|
|
|
ws1[len] = '\0';
|
|
|
|
to1 = MkAtomTerm(Yap_LookupWideAtom(ws1));
|
|
|
|
/* we don't know if the rest of the string is wide or not */
|
|
|
|
if (is_wide(ws+len)) {
|
|
|
|
to2 = MkAtomTerm(Yap_LookupWideAtom(ws+len));
|
|
|
|
} else {
|
|
|
|
char *s2 = (char *)H;
|
|
|
|
if (s2+(wlen-len) > (char *)ASP-1024)
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR,t1,"$atom_split/4");
|
|
|
|
ws += len;
|
|
|
|
while ((*s2++ = *ws++));
|
|
|
|
to2 = MkAtomTerm(Yap_LookupAtom((char *)H));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s1[len] = '\0';
|
|
|
|
to1 = MkAtomTerm(Yap_LookupAtom(s1));
|
|
|
|
/* second atom must be wide, if first wasn't */
|
|
|
|
to2 = MkAtomTerm(Yap_LookupWideAtom(ws+len));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *s, *s1 = (char *)H;
|
|
|
|
|
|
|
|
s = RepAtom(at)->StrOfAE;
|
|
|
|
if (len > (Int)strlen(s)) return(FALSE);
|
|
|
|
if (s1+len > (char *)ASP-1024)
|
|
|
|
Yap_Error(OUT_OF_STACK_ERROR,t1,"$atom_split/4");
|
|
|
|
for (i = 0; i< len; i++) {
|
|
|
|
s1[i] = s[i];
|
|
|
|
}
|
|
|
|
s1[len] = '\0';
|
|
|
|
to1 = MkAtomTerm(Yap_LookupAtom(s1));
|
|
|
|
to2 = MkAtomTerm(Yap_LookupAtom(s+len));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify_constant(ARG3,to1) && Yap_unify_constant(ARG4,to2));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-10-08 06:00:36 +01:00
|
|
|
static Term
|
2008-06-12 11:55:52 +01:00
|
|
|
gen_syntax_error(Atom InpAtom, char *s)
|
2002-10-08 06:00:36 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2008-11-26 09:56:18 +00:00
|
|
|
Term ts[7], ti[2];
|
2002-10-08 06:00:36 +01:00
|
|
|
ti[0] = ARG1;
|
|
|
|
ti[1] = ARG2;
|
2002-11-18 18:18:05 +00:00
|
|
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(s),2),2,ti);
|
2002-10-08 06:00:36 +01:00
|
|
|
ts[1] = ts[4] = ts[5] = MkIntTerm(0);
|
2008-12-23 01:53:52 +00:00
|
|
|
ts[2] = MkAtomTerm(AtomExpectedNumber);
|
2002-10-08 06:00:36 +01:00
|
|
|
ts[3] = TermNil;
|
2008-06-12 11:55:52 +01:00
|
|
|
ts[6] = MkAtomTerm(InpAtom);
|
2008-12-24 09:04:44 +00:00
|
|
|
return(Yap_MkApplTerm(FunctorSyntaxError,7,ts));
|
2002-10-08 06:00:36 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_number_chars( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
Term NewT;
|
2004-02-05 16:57:02 +00:00
|
|
|
register char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-04-27 21:09:26 +01:00
|
|
|
restart_aux:
|
2004-02-05 16:57:02 +00:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String+1024 > (char *)AuxSp) {
|
2009-05-23 00:35:24 +01:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in number_chars/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-10-29 10:28:25 +01:00
|
|
|
if (IsNonVarTerm(t1) && !Yap_IsGroundTerm(t)) {
|
2001-11-19 23:19:23 +00:00
|
|
|
Term NewT;
|
|
|
|
if (!IsNumTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
return(FALSE);
|
|
|
|
} else if (IsIntTerm(t1)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t1));
|
2001-11-19 23:19:23 +00:00
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
} else if (IsBigIntTerm(t1)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
if (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 )) {
|
|
|
|
size_t sz = Yap_gmp_to_size(t1, 10);
|
|
|
|
Yap_ReleasePreAllocCodeSpace((ADDR)String);
|
|
|
|
if (!Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, LOCAL_ErrorMessage);
|
2010-05-28 15:29:20 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto restart_aux;
|
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
} else {
|
|
|
|
NewT = Yap_StringToListOfAtoms(String);
|
|
|
|
}
|
|
|
|
return Yap_unify(NewT, ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t1, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-10-08 06:00:36 +01:00
|
|
|
if (!IsPairTerm(t) && t != TermNil) {
|
2010-10-29 10:28:25 +01:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
s = String;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
|
|
|
|
while (t != TermNil) {
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2010-03-25 09:59:39 +00:00
|
|
|
} else if (!IsIntegerTerm(Head)) {
|
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
if (i < 0 || i > 255) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2005-04-27 21:09:26 +01:00
|
|
|
if (s+1024 > (char *)AuxSp) {
|
|
|
|
int offs = (s-String);
|
2009-05-23 00:35:24 +01:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + (offs+1024) > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in number_chars/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto restart_aux;
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
*s++ = i;
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST,t,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* ISO code */
|
2010-03-25 09:59:39 +00:00
|
|
|
int has_atoms = yap_flags[STRICT_ISO_FLAG];
|
|
|
|
int has_ints = FALSE;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
while (t != TermNil) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Term Head;
|
|
|
|
char *is;
|
|
|
|
Int ch;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2010-03-25 09:59:39 +00:00
|
|
|
} else if (IsAtomTerm(Head) && !has_ints) {
|
|
|
|
has_atoms = TRUE;
|
|
|
|
is = RepAtom(AtomOfTerm(Head))->StrOfAE;
|
2010-10-29 10:28:25 +01:00
|
|
|
if (is[0] == '\0')
|
|
|
|
goto next_in_loop;
|
2010-03-25 09:59:39 +00:00
|
|
|
if (is[1] != '\0') {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"number_chars/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ch = is[0];
|
|
|
|
} else if (IsIntTerm(Head) && !has_atoms) {
|
|
|
|
has_ints = TRUE;
|
|
|
|
ch = IntOfTerm(Head);
|
|
|
|
if (ch < 0 || ch > 255) {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"number_chars/2");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_CHARACTER,Head,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
*H++ = t;
|
2009-05-23 00:35:24 +01:00
|
|
|
nString = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2004-02-05 16:57:02 +00:00
|
|
|
t = *--H;
|
|
|
|
s = nString+(s-String);
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2010-03-25 09:59:39 +00:00
|
|
|
*s++ = ch;
|
2010-10-29 10:28:25 +01:00
|
|
|
next_in_loop:
|
2001-04-09 20:54:03 +01:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2010-03-25 09:59:39 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2010-10-29 10:28:25 +01:00
|
|
|
Yap_Error(TYPE_ERROR_LIST,ARG2,"number_chars/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*s++ = '\0';
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2008-06-12 11:55:52 +01:00
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_chars"), "while scanning %s", String);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_number_atom( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
Term NewT;
|
2005-04-27 21:09:26 +01:00
|
|
|
char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
s = String = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE;
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String+1024 > (char *)AuxSp) {
|
2009-05-23 00:35:24 +01:00
|
|
|
s = String = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in number_atom/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsNonVarTerm(t1)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
Atom at;
|
|
|
|
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsIntTerm(t1)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t1));
|
2001-11-19 23:19:23 +00:00
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t1));
|
2005-03-02 19:48:03 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
} else if (IsBigIntTerm(t1)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
while (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 )) {
|
|
|
|
size_t sz = Yap_gmp_to_size(t1, 10);
|
|
|
|
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, LOCAL_ErrorMessage);
|
2010-05-28 15:29:20 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_atom/2");
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
while ((at = Yap_LookupAtom(String)) == NIL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
return Yap_unify(MkAtomTerm(at), ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "number_chars/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (!IsAtomTerm(t)) {
|
2010-10-29 10:28:25 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t, "number_atom/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
|
|
|
if ((NewT = get_num(s)) == TermNil) {
|
2008-06-12 11:55:52 +01:00
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_atom"), "while scanning %s", s);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_number_codes( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-05 16:57:02 +00:00
|
|
|
char *String; /* alloc temp space on Trail */
|
2001-11-19 23:19:23 +00:00
|
|
|
register Term t = Deref(ARG2), t1 = Deref(ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
Term NewT;
|
2004-02-05 16:57:02 +00:00
|
|
|
register char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
String = Yap_PreAllocCodeSpace();
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String+1024 > (char *)AuxSp) {
|
2009-05-23 00:35:24 +01:00
|
|
|
s = String = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2005-04-27 21:09:26 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in number_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-10-29 10:28:25 +01:00
|
|
|
if (IsNonVarTerm(t1) && !Yap_IsGroundTerm(t)) {
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsIntTerm(t1)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (IsFloatTerm(t1)) {
|
|
|
|
sprintf(String, "%f", FloatOfTerm(t1));
|
|
|
|
} else if (IsLongIntTerm(t1)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t1));
|
2001-04-09 20:54:03 +01:00
|
|
|
#if USE_GMP
|
2001-11-19 23:19:23 +00:00
|
|
|
} else if (IsBigIntTerm(t1)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
while (!Yap_gmp_to_string(t1, String, ((char *)AuxSp-String)-1024, 10 )) {
|
|
|
|
size_t sz = Yap_gmp_to_size(t1, 10);
|
|
|
|
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, t1, LOCAL_ErrorMessage);
|
2010-05-28 15:29:20 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2001-11-19 23:19:23 +00:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t1, "number_codes/2");
|
2005-03-02 19:48:03 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 19:48:03 +00:00
|
|
|
NewT = Yap_StringToList(String);
|
|
|
|
return Yap_unify(NewT, ARG2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2001-11-19 23:19:23 +00:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t, "number_codes/2");
|
2001-11-19 23:19:23 +00:00
|
|
|
}
|
2002-10-08 06:00:36 +01:00
|
|
|
if (!IsPairTerm(t) && t != TermNil) {
|
2010-10-29 10:28:25 +01:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
s = String; /* alloc temp space on Trail */
|
2001-04-09 20:54:03 +01:00
|
|
|
while (t != TermNil) {
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2004-02-05 16:57:02 +00:00
|
|
|
if (s+1 == (char *)AuxSp) {
|
|
|
|
char *nString;
|
|
|
|
|
|
|
|
*H++ = t;
|
2009-05-23 00:35:24 +01:00
|
|
|
nString = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2004-02-05 16:57:02 +00:00
|
|
|
t = *--H;
|
|
|
|
s = nString+(s-String);
|
|
|
|
String = nString;
|
2002-10-22 05:00:11 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
*s++ = i;
|
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2010-10-29 10:28:25 +01:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "number_codes/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*s++ = '\0';
|
|
|
|
if ((NewT = get_num(String)) == TermNil) {
|
2008-06-12 11:55:52 +01:00
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_codes"), "while scanning %s", String);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(ARG1, NewT));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-10-09 00:02:16 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_atom_number( USES_REGS1 )
|
2007-10-09 00:02:16 +01:00
|
|
|
{
|
|
|
|
Term t = Deref(ARG1), t2 = Deref(ARG2);
|
|
|
|
Term NewT;
|
|
|
|
|
|
|
|
if (IsVarTerm(t)) {
|
|
|
|
char *String; /* alloc temp space on Trail */
|
2012-02-17 11:31:46 +00:00
|
|
|
|
2007-10-09 00:02:16 +01:00
|
|
|
if (IsVarTerm(t2)) {
|
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "atom_number/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String+1024 > (char *)AuxSp) {
|
2012-02-17 11:31:46 +00:00
|
|
|
String = Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE);
|
2007-10-09 00:02:16 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in number_codes/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IsIntTerm(t2)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, IntOfTerm(t2));
|
2007-10-09 00:02:16 +01:00
|
|
|
} else if (IsFloatTerm(t2)) {
|
|
|
|
sprintf(String, "%g", FloatOfTerm(t2));
|
|
|
|
} else if (IsLongIntTerm(t2)) {
|
2010-05-06 15:00:44 +01:00
|
|
|
sprintf(String, Int_FORMAT, LongIntOfTerm(t2));
|
2007-10-09 00:02:16 +01:00
|
|
|
#if USE_GMP
|
|
|
|
} else if (IsBigIntTerm(t2)) {
|
2010-05-28 15:29:20 +01:00
|
|
|
while (!Yap_gmp_to_string(t2, String, ((char *)AuxSp-String)-1024, 10 )) {
|
|
|
|
size_t sz = Yap_gmp_to_size(t2, 10);
|
|
|
|
if (!(String = Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, t2, LOCAL_ErrorMessage);
|
2010-05-28 15:29:20 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-10-09 00:02:16 +01:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Yap_Error(TYPE_ERROR_NUMBER, t2, "atom_number/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
NewT = MkAtomTerm(Yap_LookupAtom(String));
|
|
|
|
return Yap_unify(NewT, ARG1);
|
|
|
|
} else {
|
|
|
|
Atom at;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (!IsAtomTerm(t)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t, "atom_number/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
at = AtomOfTerm(t);
|
|
|
|
if (IsWideAtom(at)) {
|
2008-06-12 11:55:52 +01:00
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error(at, "number_codes"), "while scanning %S", RepAtom(at)->WStrOfAE);
|
2007-10-09 00:02:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
s = RepAtom(at)->StrOfAE; /* alloc temp space on Trail */
|
|
|
|
if ((NewT = get_num(s)) == TermNil) {
|
2008-06-12 11:55:52 +01:00
|
|
|
Yap_Error(SYNTAX_ERROR, gen_syntax_error(at, "atom_number"), "while scanning %s", s);
|
2007-10-09 00:02:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG2, NewT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_univ( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* A =.. L */
|
|
|
|
unsigned int arity;
|
|
|
|
register Term tin;
|
|
|
|
Term twork, t2;
|
|
|
|
Atom at;
|
|
|
|
|
|
|
|
tin = Deref(ARG1);
|
|
|
|
t2 = Deref(ARG2);
|
|
|
|
if (IsVarTerm(tin)) {
|
|
|
|
/* we need to have a list */
|
|
|
|
Term *Ar;
|
|
|
|
if (IsVarTerm(t2)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsPairTerm(t2)) {
|
|
|
|
if (t2 == TermNil)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_NON_EMPTY_LIST, t2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
twork = HeadOfTerm(t2);
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (IsNumTerm(twork)) {
|
|
|
|
Term tt = TailOfTerm(t2);
|
|
|
|
if (IsVarTerm(tt) || tt != MkAtomTerm(AtomNil)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG1, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (!IsAtomTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
at = AtomOfTerm(twork);
|
|
|
|
twork = TailOfTerm(t2);
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(twork)) {
|
|
|
|
if (twork != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify_constant(ARG1, MkAtomTerm(at)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
build_compound:
|
2001-04-09 20:54:03 +01:00
|
|
|
/* build the term directly on the heap */
|
|
|
|
Ar = H;
|
|
|
|
H++;
|
|
|
|
|
|
|
|
while (!IsVarTerm(twork) && IsPairTerm(twork)) {
|
|
|
|
*H++ = HeadOfTerm(twork);
|
2002-05-07 22:19:52 +01:00
|
|
|
if (H > ASP - 1024) {
|
|
|
|
/* restore space */
|
|
|
|
H = Ar;
|
2008-08-28 04:43:00 +01:00
|
|
|
if (!Yap_gcl((ASP-H)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2006-08-07 19:51:44 +01:00
|
|
|
return FALSE;
|
2002-10-10 06:58:49 +01:00
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
twork = TailOfTerm(Deref(ARG2));
|
|
|
|
goto build_compound;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
twork = TailOfTerm(twork);
|
|
|
|
}
|
|
|
|
if (IsVarTerm(twork)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, twork, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (twork != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, ARG2, "(=..)/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
#ifdef SFUNC
|
|
|
|
DOES_NOT_WORK();
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
SFEntry *pe = (SFEntry *) Yap_GetAProp(at, SFProperty);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe)
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = MkSFTerm(Yap_MkFunctor(at, SFArity),
|
2001-04-09 20:54:03 +01:00
|
|
|
arity, CellPtr(TR), pe->NilValue);
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = Yap_MkApplTerm(Yap_MkFunctor(at, arity),
|
2001-04-09 20:54:03 +01:00
|
|
|
arity, CellPtr(TR));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
arity = H-Ar-1;
|
|
|
|
if (at == AtomDot && arity == 2) {
|
|
|
|
Ar[0] = Ar[1];
|
|
|
|
Ar[1] = Ar[2];
|
|
|
|
H --;
|
|
|
|
twork = AbsPair(Ar);
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
*Ar = (CELL)(Yap_MkFunctor(at, arity));
|
2001-04-09 20:54:03 +01:00
|
|
|
twork = AbsAppl(Ar);
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(ARG1, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (IsAtomicTerm(tin)) {
|
|
|
|
twork = MkPairTerm(tin, MkAtomTerm(AtomNil));
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(twork, ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (IsRefTerm(tin))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsApplTerm(tin)) {
|
|
|
|
Functor fun = FunctorOfTerm(tin);
|
|
|
|
arity = ArityOfFunctor(fun);
|
|
|
|
at = NameOfFunctor(fun);
|
|
|
|
#ifdef SFUNC
|
|
|
|
if (arity == SFArity) {
|
|
|
|
CELL *p = CellPtr(TR);
|
|
|
|
CELL *q = ArgsOfSFTerm(tin);
|
|
|
|
int argno = 1;
|
|
|
|
while (*q) {
|
|
|
|
while (*q > argno++)
|
|
|
|
*p++ = MkVarTerm();
|
|
|
|
++q;
|
|
|
|
*p++ = Deref(*q++);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
|
2002-10-29 04:19:09 +00:00
|
|
|
while (IsIntTerm(twork)) {
|
2008-08-28 04:43:00 +01:00
|
|
|
if (!Yap_gc(2, ENV, gc_P(P,CP))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2002-10-29 04:19:09 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = Yap_ArrayToList(CellPtr(TR), argno - 1);
|
2002-10-29 04:19:09 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
#endif
|
2002-05-07 22:19:52 +01:00
|
|
|
{
|
2002-10-29 04:19:09 +00:00
|
|
|
while (H+arity*2 > ASP-1024) {
|
2008-08-28 04:43:00 +01:00
|
|
|
if (!Yap_gcl((arity*2)*sizeof(CELL), 2, ENV, gc_P(P,CP))) {
|
2011-05-23 16:19:47 +01:00
|
|
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, LOCAL_ErrorMessage);
|
2002-10-10 06:58:49 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-05-07 22:19:52 +01:00
|
|
|
tin = Deref(ARG1);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = Yap_ArrayToList(RepAppl(tin) + 1, arity);
|
2002-05-07 22:19:52 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
/* We found a list */
|
|
|
|
at = AtomDot;
|
2002-11-18 18:18:05 +00:00
|
|
|
twork = Yap_ArrayToList(RepPair(tin), 2);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
twork = MkPairTerm(MkAtomTerm(at), twork);
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_unify(ARG2, twork));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-10-09 00:02:16 +01:00
|
|
|
/* $sub_atom_extract(A,Bef,Size,After,SubAt).*/
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_sub_atom_extract( USES_REGS1 )
|
2007-10-09 00:02:16 +01:00
|
|
|
{
|
|
|
|
Atom at = AtomOfTerm(Deref(ARG1)), nat;
|
|
|
|
Int start = IntegerOfTerm(Deref(ARG2));
|
|
|
|
Int len = IntegerOfTerm(Deref(ARG3));
|
|
|
|
Int leftover;
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,ARG2,"sub_atom/5");
|
|
|
|
if (len < 0)
|
|
|
|
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,ARG3,"sub_atom/5");
|
|
|
|
start:
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *s = RepAtom(at)->WStrOfAE;
|
|
|
|
int max = wcslen(s);
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
leftover = max-(start+len);
|
|
|
|
if (leftover < 0)
|
|
|
|
return FALSE;
|
|
|
|
for (i=0;i<len;i++) {
|
|
|
|
if ((s+start)[i] > 255) break;
|
|
|
|
}
|
|
|
|
if (i == len) {
|
|
|
|
char *String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + (len+1024) >= (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
for (i=0;i<len;i++) {
|
|
|
|
String[i] = (s+start)[i];
|
|
|
|
}
|
|
|
|
String[len] = '\0';
|
|
|
|
nat = Yap_LookupAtom(String);
|
|
|
|
} else {
|
|
|
|
wchar_t *String = (wchar_t *)Yap_PreAllocCodeSpace();
|
|
|
|
if (String + (len+1024) >= (wchar_t *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
wcsncpy(String, s+start, len);
|
|
|
|
String[len] = '\0';
|
|
|
|
nat = Yap_LookupWideAtom(String);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *s = RepAtom(at)->StrOfAE, *String;
|
|
|
|
int max = strlen(s);
|
|
|
|
|
|
|
|
leftover = max-(start+len);
|
|
|
|
if (leftover < 0)
|
|
|
|
return FALSE;
|
|
|
|
String = Yap_PreAllocCodeSpace();
|
|
|
|
if (String + (len+1024) >= (char *)AuxSp)
|
|
|
|
goto expand_auxsp;
|
|
|
|
strncpy(String, s+start, len);
|
|
|
|
String[len] = '\0';
|
|
|
|
nat = Yap_LookupAtom(String);
|
|
|
|
}
|
|
|
|
return Yap_unify(ARG5,MkAtomTerm(nat)) &&
|
|
|
|
Yap_unify(ARG4,MkIntegerTerm(leftover));
|
|
|
|
|
|
|
|
expand_auxsp:
|
|
|
|
{
|
2009-05-23 00:35:24 +01:00
|
|
|
char *String = Yap_ExpandPreAllocCodeSpace(len, NULL, TRUE);
|
2007-10-09 00:02:16 +01:00
|
|
|
if (String + 1024 > (char *)AuxSp) {
|
|
|
|
/* crash in flames */
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in sub_atom/5");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
2009-06-22 21:35:40 +01:00
|
|
|
/* $sub_atom_extract(A,Bef,Size,After,SubAt).*/
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_sub_atom_fetch( USES_REGS1 )
|
2009-06-22 21:35:40 +01:00
|
|
|
{
|
2010-01-17 00:04:17 +00:00
|
|
|
Atom at = AtomOfTerm(EXTRA_CBACK_ARG(5,1));
|
|
|
|
Atom subatom = AtomOfTerm(EXTRA_CBACK_ARG(5,2));
|
|
|
|
Int offset = IntegerOfTerm(EXTRA_CBACK_ARG(5,3));
|
2010-01-18 14:27:56 +00:00
|
|
|
Int sb = IntegerOfTerm(EXTRA_CBACK_ARG(5,4));
|
|
|
|
Int sz = IntegerOfTerm(EXTRA_CBACK_ARG(5,5));
|
2009-06-22 21:35:40 +01:00
|
|
|
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *s = RepAtom(at)->WStrOfAE;
|
|
|
|
wchar_t *ins, *where;
|
2010-01-18 14:27:56 +00:00
|
|
|
Int start, after;
|
2010-01-17 00:04:17 +00:00
|
|
|
Int res;
|
2009-06-22 21:35:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!IsWideAtom(subatom)) {
|
|
|
|
/* first convert to wchar_t */
|
|
|
|
char *inschars = RepAtom(subatom)->StrOfAE;
|
|
|
|
Int i;
|
|
|
|
|
2010-01-17 00:04:17 +00:00
|
|
|
if (offset+sz > sb)
|
|
|
|
cut_fail();
|
2009-06-22 21:35:40 +01:00
|
|
|
ins = (wchar_t *)Yap_PreAllocCodeSpace();
|
|
|
|
while ((ins = (wchar_t *)Yap_PreAllocCodeSpace()) + (sz+1) > (wchar_t *)AuxSp) {
|
|
|
|
if (!Yap_ExpandPreAllocCodeSpace(sizeof(wchar_t)*(sz+1), NULL, TRUE)) {
|
|
|
|
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG5, "allocating temp space in sub_atom/2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0;i<=sz;i++)
|
|
|
|
ins[i] = inschars[i];
|
|
|
|
} else {
|
|
|
|
ins = RepAtom(subatom)->WStrOfAE;
|
|
|
|
}
|
|
|
|
if (!(where = wcsstr(s+offset, ins))) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
2010-01-18 14:27:56 +00:00
|
|
|
if (!Yap_unify(EXTRA_CBACK_ARG(5,5), ARG3)) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
start = where-s;
|
|
|
|
after = sb-(start+sz);
|
|
|
|
res = (Yap_unify(MkIntegerTerm(start), ARG2) &&
|
|
|
|
Yap_unify(MkIntegerTerm(after), ARG4));
|
2010-01-18 14:27:56 +00:00
|
|
|
if (!res) {
|
|
|
|
if (!after) {
|
|
|
|
cut_fail();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,3) = MkIntegerTerm(start+1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!after) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_succeed();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,3) = MkIntegerTerm(start+1);
|
|
|
|
return TRUE;
|
2009-06-22 21:35:40 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *s = RepAtom(at)->StrOfAE;
|
|
|
|
char *ins, *where;
|
2010-01-18 14:27:56 +00:00
|
|
|
Int start, after;
|
2010-01-17 00:04:17 +00:00
|
|
|
Int res;
|
2009-06-22 21:35:40 +01:00
|
|
|
|
|
|
|
ins = subatom->StrOfAE;
|
2010-01-17 00:04:17 +00:00
|
|
|
if (offset+sz > sb) {
|
|
|
|
cut_fail();
|
|
|
|
}
|
2009-06-22 21:35:40 +01:00
|
|
|
if (!(where = strstr(s+offset, ins))) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
2010-01-18 14:27:56 +00:00
|
|
|
if (!Yap_unify(EXTRA_CBACK_ARG(5,5), ARG3)) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
start = where-s;
|
|
|
|
after = sb-(start+sz);
|
|
|
|
res = (Yap_unify(MkIntegerTerm(start), ARG2) &&
|
|
|
|
Yap_unify(MkIntegerTerm(after), ARG4));
|
2010-01-18 14:27:56 +00:00
|
|
|
if (!res) {
|
|
|
|
if (!after) {
|
|
|
|
cut_fail();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,3) = MkIntegerTerm(start+1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!after) {
|
2010-01-17 00:04:17 +00:00
|
|
|
cut_succeed();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,3) = MkIntegerTerm(start+1);
|
|
|
|
return TRUE;
|
2009-06-22 21:35:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-17 00:04:17 +00:00
|
|
|
/* $sub_atom_extract(A,Bef,Size,After,SubAt).*/
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_sub_atom_fetch( USES_REGS1 )
|
2010-01-17 00:04:17 +00:00
|
|
|
{
|
2010-01-18 14:27:56 +00:00
|
|
|
Term tat1, tat2;
|
|
|
|
Atom at1, at2;
|
|
|
|
|
|
|
|
EXTRA_CBACK_ARG(5,1) = tat1 = Deref(ARG1);
|
|
|
|
EXTRA_CBACK_ARG(5,2) = tat2 = Deref(ARG5);
|
2010-01-17 00:04:17 +00:00
|
|
|
EXTRA_CBACK_ARG(5,3) = MkIntegerTerm(0);
|
2010-01-18 14:27:56 +00:00
|
|
|
at1 = AtomOfTerm(tat1);
|
|
|
|
at2 = AtomOfTerm(tat2);
|
|
|
|
if (IsWideAtom(at1)) {
|
|
|
|
EXTRA_CBACK_ARG(5,4) = MkIntegerTerm(wcslen(at1->WStrOfAE));
|
|
|
|
if (IsWideAtom(at2)) {
|
|
|
|
EXTRA_CBACK_ARG(5,5) = MkIntegerTerm(wcslen(at2->WStrOfAE));
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,5) = MkIntegerTerm(strlen(at2->StrOfAE));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,4) = MkIntegerTerm(strlen(at1->StrOfAE));
|
|
|
|
if (IsWideAtom(at2)) {
|
|
|
|
cut_fail();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(5,5) = MkIntegerTerm(strlen(at2->StrOfAE));
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
return cont_sub_atom_fetch( PASS_REGS1 );
|
2010-01-17 00:04:17 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 00:02:16 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_abort( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* abort */
|
|
|
|
/* make sure we won't go creeping around */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PURE_ABORT, TermNil, "");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
extern void exit_eam(char *s);
|
|
|
|
|
|
|
|
Int
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2005-09-08 23:06:45 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
p_halt( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* halt */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
Int out;
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
if (EAM) exit_eam("\n\n[ Prolog execution halted ]\n");
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"halt/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntegerTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER,t,"halt/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
out = IntegerOfTerm(t);
|
2004-04-27 16:14:38 +01:00
|
|
|
Yap_exit(out);
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_atom( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Atom catom;
|
|
|
|
Int i = IntOfTerm(EXTRA_CBACK_ARG(1,2));
|
|
|
|
AtomEntry *ap; /* nasty hack for gcc on hpux */
|
|
|
|
|
|
|
|
/* protect current hash table line */
|
|
|
|
if (IsAtomTerm(EXTRA_CBACK_ARG(1,1)))
|
|
|
|
catom = AtomOfTerm(EXTRA_CBACK_ARG(1,1));
|
|
|
|
else
|
|
|
|
catom = NIL;
|
|
|
|
if (catom == NIL){
|
|
|
|
i++;
|
|
|
|
/* move away from current hash table line */
|
2003-10-28 01:16:03 +00:00
|
|
|
while (i < AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
catom = HashChain[i].Entry;
|
2004-02-19 19:24:46 +00:00
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (catom != NIL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2003-10-28 01:16:03 +00:00
|
|
|
if (i == AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ap = RepAtom(catom);
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) {
|
2004-02-19 19:24:46 +00:00
|
|
|
READ_LOCK(ap->ARWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (ap->NextOfAE == NIL) {
|
2004-02-19 19:24:46 +00:00
|
|
|
READ_UNLOCK(ap->ARWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
i++;
|
2003-10-28 01:16:03 +00:00
|
|
|
while (i < AtomHashTableSize) {
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
|
|
|
catom = HashChain[i].Entry;
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
if (catom != NIL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2003-10-28 01:16:03 +00:00
|
|
|
if (i == AtomHashTableSize) {
|
2004-02-19 19:24:46 +00:00
|
|
|
cut_fail();
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(catom);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(ap->NextOfAE);
|
|
|
|
READ_UNLOCK(ap->ARWLock);
|
|
|
|
}
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(i);
|
2004-02-19 19:24:46 +00:00
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2004-02-19 19:24:46 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_atom( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* current_atom(?Atom) */
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
if (IsAtomTerm(t1))
|
|
|
|
cut_succeed();
|
|
|
|
else
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
READ_LOCK(HashChain[0].AERWLock);
|
|
|
|
if (HashChain[0].Entry != NIL) {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(HashChain[0].Entry);
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkIntTerm(0);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(HashChain[0].AERWLock);
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(0);
|
2011-03-07 16:02:55 +00:00
|
|
|
return (cont_current_atom( PASS_REGS1 ));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2006-11-27 17:42:03 +00:00
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_wide_atom( USES_REGS1 )
|
2006-11-27 17:42:03 +00:00
|
|
|
{
|
|
|
|
Atom catom;
|
|
|
|
Int i = IntOfTerm(EXTRA_CBACK_ARG(1,2));
|
|
|
|
AtomEntry *ap; /* nasty hack for gcc on hpux */
|
|
|
|
|
|
|
|
/* protect current hash table line */
|
|
|
|
if (IsAtomTerm(EXTRA_CBACK_ARG(1,1)))
|
|
|
|
catom = AtomOfTerm(EXTRA_CBACK_ARG(1,1));
|
|
|
|
else
|
|
|
|
catom = NIL;
|
|
|
|
if (catom == NIL){
|
|
|
|
i++;
|
|
|
|
/* move away from current hash table line */
|
|
|
|
while (i < WideAtomHashTableSize) {
|
|
|
|
READ_LOCK(WideHashChain[i].AERWLock);
|
|
|
|
catom = WideHashChain[i].Entry;
|
|
|
|
READ_UNLOCK(WideHashChain[i].AERWLock);
|
|
|
|
if (catom != NIL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i == WideAtomHashTableSize) {
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ap = RepAtom(catom);
|
|
|
|
if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) {
|
|
|
|
READ_LOCK(ap->ARWLock);
|
|
|
|
if (ap->NextOfAE == NIL) {
|
|
|
|
READ_UNLOCK(ap->ARWLock);
|
|
|
|
i++;
|
|
|
|
while (i < WideAtomHashTableSize) {
|
|
|
|
READ_LOCK(WideHashChain[i].AERWLock);
|
|
|
|
catom = WideHashChain[i].Entry;
|
|
|
|
READ_UNLOCK(WideHashChain[i].AERWLock);
|
|
|
|
if (catom != NIL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i == WideAtomHashTableSize) {
|
|
|
|
cut_fail();
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(catom);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(ap->NextOfAE);
|
|
|
|
READ_UNLOCK(ap->ARWLock);
|
|
|
|
}
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(i);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_wide_atom( USES_REGS1 )
|
2006-11-27 17:42:03 +00:00
|
|
|
{ /* current_atom(?Atom) */
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
if (!IsVarTerm(t1)) {
|
|
|
|
if (IsAtomTerm(t1))
|
|
|
|
cut_succeed();
|
|
|
|
else
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
READ_LOCK(WideHashChain[0].AERWLock);
|
|
|
|
if (WideHashChain[0].Entry != NIL) {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkAtomTerm(WideHashChain[0].Entry);
|
|
|
|
} else {
|
|
|
|
EXTRA_CBACK_ARG(1,1) = MkIntTerm(0);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(WideHashChain[0].AERWLock);
|
|
|
|
EXTRA_CBACK_ARG(1,2) = MkIntTerm(0);
|
2011-03-07 16:02:55 +00:00
|
|
|
return (cont_current_wide_atom( PASS_REGS1 ));
|
2006-11-27 17:42:03 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_predicate( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2001-11-15 00:01:43 +00:00
|
|
|
PredEntry *pp = (PredEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(3,1));
|
2001-10-03 14:39:16 +01:00
|
|
|
UInt Arity;
|
2003-10-28 01:16:03 +00:00
|
|
|
Term name;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-08-14 17:00:54 +01:00
|
|
|
while (pp != NULL) {
|
2007-04-19 00:01:16 +01:00
|
|
|
if (pp->PredFlags & HiddenPredFlag) {
|
2002-08-14 17:00:54 +01:00
|
|
|
pp = pp->NextPredOfModule;
|
2007-04-19 00:01:16 +01:00
|
|
|
} else
|
2002-08-14 17:00:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2001-10-03 14:39:16 +01:00
|
|
|
if (pp == NULL)
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_fail();
|
2001-11-15 00:01:43 +00:00
|
|
|
EXTRA_CBACK_ARG(3,1) = (CELL)MkIntegerTerm((Int)(pp->NextPredOfModule));
|
2002-09-17 17:37:48 +01:00
|
|
|
if (pp->FunctorOfPred == FunctorModule)
|
2008-04-06 12:53:02 +01:00
|
|
|
return FALSE;
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pp->ModuleOfPred != IDB_MODULE) {
|
2003-10-28 01:16:03 +00:00
|
|
|
Arity = pp->ArityOfPE;
|
|
|
|
if (Arity)
|
|
|
|
name = MkAtomTerm(NameOfFunctor(pp->FunctorOfPred));
|
|
|
|
else
|
|
|
|
name = MkAtomTerm((Atom)pp->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
if (pp->PredFlags & NumberDBPredFlag) {
|
|
|
|
name = MkIntegerTerm(pp->src.IndxId);
|
|
|
|
Arity = 0;
|
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
|
|
|
name = MkAtomTerm((Atom)pp->FunctorOfPred);
|
|
|
|
Arity = 0;
|
|
|
|
} else {
|
|
|
|
Functor f = pp->FunctorOfPred;
|
|
|
|
name = MkAtomTerm(NameOfFunctor(f));
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 12:53:02 +01:00
|
|
|
return
|
|
|
|
Yap_unify(ARG2,name) &&
|
|
|
|
Yap_unify(ARG3, MkIntegerTerm((Int)Arity));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_predicate( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2001-11-15 00:01:43 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsAtomTerm(t1)) cut_fail();
|
2004-02-12 17:09:17 +00:00
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)Yap_ModulePred(t1));
|
2011-03-07 16:02:55 +00:00
|
|
|
return cont_current_predicate( PASS_REGS1 );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-09-02 18:33:00 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_predicate_for_atom( USES_REGS1 )
|
2002-09-02 18:33:00 +01:00
|
|
|
{
|
|
|
|
Prop pf = (Prop)IntegerOfTerm(EXTRA_CBACK_ARG(3,1));
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2002-09-02 18:33:00 +01:00
|
|
|
|
|
|
|
while (pf != NIL) {
|
|
|
|
FunctorEntry *pp = RepFunctorProp(pf);
|
|
|
|
if (IsFunctorProperty(pp->KindOfPE)) {
|
|
|
|
Prop p0 = pp->PropsOfFE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *p = RepPredProp(p0);
|
|
|
|
if (p->ModuleOfPred == mod ||
|
|
|
|
p->ModuleOfPred == 0) {
|
|
|
|
/* we found the predicate */
|
2008-04-06 12:53:02 +01:00
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
|
|
|
|
return
|
|
|
|
Yap_unify(ARG3,Yap_MkNewApplTerm(p->FunctorOfPred,p->ArityOfPE));
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
|
|
|
p0 = p->NextOfPE;
|
|
|
|
}
|
|
|
|
} else if (pp->KindOfPE == PEProp) {
|
|
|
|
PredEntry *pe = RepPredProp(pf);
|
|
|
|
if (pe->ModuleOfPred == mod ||
|
|
|
|
pe->ModuleOfPred == 0) {
|
|
|
|
/* we found the predicate */
|
2008-04-06 12:53:02 +01:00
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
|
|
|
|
return Yap_unify(ARG3,MkAtomTerm((Atom)(pe->FunctorOfPred)));
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pf = pp->NextOfPE;
|
|
|
|
}
|
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_predicate_for_atom( USES_REGS1 )
|
2002-09-02 18:33:00 +01:00
|
|
|
{
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1) || !IsAtomTerm(t1)) cut_fail();
|
|
|
|
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)RepAtom(AtomOfTerm(t1))->PropsOfAE);
|
2011-03-07 16:02:55 +00:00
|
|
|
return (cont_current_predicate_for_atom( PASS_REGS1 ));
|
2002-09-02 18:33:00 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static OpEntry *
|
2011-03-07 16:02:55 +00:00
|
|
|
NextOp(OpEntry *pp USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2009-11-27 16:09:48 +00:00
|
|
|
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty &&
|
|
|
|
(pp->OpModule != PROLOG_MODULE || pp->OpModule != CurrentModule))
|
2001-04-09 20:54:03 +01:00
|
|
|
pp = RepOpProp(pp->NextOfPE);
|
|
|
|
return (pp);
|
|
|
|
}
|
|
|
|
|
2009-11-27 16:09:48 +00:00
|
|
|
int
|
|
|
|
Yap_IsOp(Atom at)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
2009-11-27 16:09:48 +00:00
|
|
|
return (!EndOfPAEntr(op));
|
|
|
|
}
|
|
|
|
|
2010-02-26 14:14:10 +00:00
|
|
|
int
|
|
|
|
Yap_IsOpMaxPrio(Atom at)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
|
|
|
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
2010-02-26 14:14:10 +00:00
|
|
|
int max;
|
|
|
|
|
|
|
|
if (EndOfPAEntr(op))
|
|
|
|
return 0;
|
|
|
|
max = (op->Prefix & 0xfff);
|
|
|
|
if ((op->Infix & 0xfff) > max)
|
|
|
|
max = op->Infix & 0xfff;
|
|
|
|
if ((op->Posfix & 0xfff) > max)
|
|
|
|
max = op->Posfix & 0xfff;
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2009-11-25 00:38:47 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
unify_op(OpEntry *op USES_REGS)
|
2009-11-25 00:38:47 +00:00
|
|
|
{
|
|
|
|
Term tmod = op->OpModule;
|
|
|
|
|
|
|
|
if (tmod == PROLOG_MODULE)
|
|
|
|
tmod = TermProlog;
|
|
|
|
return
|
|
|
|
Yap_unify_constant(ARG2,tmod) &&
|
|
|
|
Yap_unify_constant(ARG3,MkIntegerTerm(op->Prefix)) &&
|
|
|
|
Yap_unify_constant(ARG4,MkIntegerTerm(op->Infix)) &&
|
|
|
|
Yap_unify_constant(ARG5,MkIntegerTerm(op->Posfix));
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_op( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2009-11-25 00:38:47 +00:00
|
|
|
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5,1)), *next;
|
|
|
|
|
|
|
|
READ_LOCK(op->OpRWLock);
|
|
|
|
next = op->OpNext;
|
|
|
|
if (Yap_unify_constant(ARG1,MkAtomTerm(op->OpName)) &&
|
2011-03-07 16:02:55 +00:00
|
|
|
unify_op(op PASS_REGS)) {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((CELL)next);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_succeed();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((CELL)next);
|
|
|
|
return FALSE;
|
2006-04-28 14:23:23 +01:00
|
|
|
} else {
|
|
|
|
cut_fail();
|
|
|
|
}
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_op( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* current_op(-Precedence,-Type,-Atom) */
|
2009-11-25 00:38:47 +00:00
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((CELL)OpList);
|
2011-03-07 16:02:55 +00:00
|
|
|
return cont_current_op( PASS_REGS1 );
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
cont_current_atom_op( USES_REGS1 )
|
2009-11-25 00:38:47 +00:00
|
|
|
{
|
|
|
|
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5,1)), *next;
|
|
|
|
|
|
|
|
READ_LOCK(op->OpRWLock);
|
2011-03-07 16:02:55 +00:00
|
|
|
next = NextOp(RepOpProp(op->NextOfPE) PASS_REGS);
|
|
|
|
if (unify_op(op PASS_REGS)) {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((CELL)next);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cut_succeed();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2006-04-28 14:23:23 +01:00
|
|
|
} else {
|
2009-12-17 18:11:02 +00:00
|
|
|
READ_UNLOCK(op->OpRWLock);
|
2009-11-25 00:38:47 +00:00
|
|
|
if (next) {
|
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((CELL)next);
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
2006-04-28 14:23:23 +01:00
|
|
|
cut_fail();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
init_current_atom_op( USES_REGS1 )
|
2009-11-25 00:38:47 +00:00
|
|
|
{ /* current_op(-Precedence,-Type,-Atom) */
|
|
|
|
Term t = Deref(ARG1);
|
|
|
|
AtomEntry *ae;
|
|
|
|
OpEntry *ope;
|
|
|
|
|
|
|
|
if (IsVarTerm(t) || !IsAtomTerm(t)) {
|
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t,"current_op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
cut_fail();
|
2009-11-25 00:38:47 +00:00
|
|
|
}
|
|
|
|
ae = RepAtom(AtomOfTerm(t));
|
2011-03-07 16:02:55 +00:00
|
|
|
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) {
|
2009-11-25 00:38:47 +00:00
|
|
|
cut_fail();
|
|
|
|
}
|
|
|
|
EXTRA_CBACK_ARG(5,1) = (CELL) MkIntegerTerm((Int)ope);
|
2011-03-07 16:02:55 +00:00
|
|
|
return cont_current_atom_op( PASS_REGS1 );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_debug( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* $debug(+Flag) */
|
|
|
|
int i = IntOfTerm(Deref(ARG1));
|
|
|
|
|
|
|
|
if (i >= 'a' && i <= 'z')
|
2011-05-25 16:40:36 +01:00
|
|
|
GLOBAL_Option[i - 96] = !GLOBAL_Option[i - 96];
|
2001-04-09 20:54:03 +01:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_flags( USES_REGS1 )
|
2001-11-15 00:01:43 +00:00
|
|
|
{ /* $flags(+Functor,+Mod,?OldFlags,?NewFlags) */
|
2001-04-09 20:54:03 +01:00
|
|
|
PredEntry *pe;
|
|
|
|
Int newFl;
|
|
|
|
Term t1 = Deref(ARG1);
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = Deref(ARG2);
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
2001-11-15 00:01:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
if (IsAtomTerm(t1)) {
|
2007-11-06 17:02:13 +00:00
|
|
|
while ((pe = RepPredProp(PredPropByAtom(AtomOfTerm(t1), mod)))== NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
} else if (IsApplTerm(t1)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Functor funt = FunctorOfTerm(t1);
|
2007-11-06 17:02:13 +00:00
|
|
|
while ((pe = RepPredProp(PredPropByFunc(funt, mod)))== NULL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, ARG1, "while generating new predicate");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t1 = Deref(ARG1);
|
|
|
|
mod = Deref(ARG2);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} else
|
|
|
|
return (FALSE);
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return (FALSE);
|
2010-07-25 11:22:16 +01:00
|
|
|
PELOCK(92,pe);
|
2003-12-04 18:13:04 +00:00
|
|
|
if (!Yap_unify_constant(ARG3, MkIntegerTerm(pe->PredFlags))) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-11-15 00:01:43 +00:00
|
|
|
ARG4 = Deref(ARG4);
|
|
|
|
if (IsVarTerm(ARG4)) {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (TRUE);
|
2003-12-04 18:13:04 +00:00
|
|
|
} else if (!IsIntegerTerm(ARG4)) {
|
2008-12-04 23:33:32 +00:00
|
|
|
Term te = Yap_Eval(ARG4);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-12-04 23:33:32 +00:00
|
|
|
if (IsIntegerTerm(te)) {
|
|
|
|
newFl = IntegerOfTerm(te);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, ARG4, "flags");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
} else
|
2003-12-04 18:13:04 +00:00
|
|
|
newFl = IntegerOfTerm(ARG4);
|
|
|
|
pe->PredFlags = (CELL)newFl;
|
2007-11-26 23:43:10 +00:00
|
|
|
UNLOCK(pe->PELock);
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
AlreadyHidden(char *name)
|
|
|
|
{
|
|
|
|
AtomEntry *chain;
|
|
|
|
|
|
|
|
READ_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, name) != 0)
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_hide( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* hide(+Atom) */
|
|
|
|
Atom atomToInclude;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"hide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"hide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
atomToInclude = AtomOfTerm(t1);
|
|
|
|
if (AlreadyHidden(RepAtom(atomToInclude)->StrOfAE)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,t1,"an atom of name %s was already hidden",
|
2001-04-09 20:54:03 +01:00
|
|
|
RepAtom(atomToInclude)->StrOfAE);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleaseAtom(atomToInclude);
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
WRITE_LOCK(RepAtom(atomToInclude)->ARWLock);
|
|
|
|
RepAtom(atomToInclude)->NextOfAE = INVISIBLECHAIN.Entry;
|
|
|
|
WRITE_UNLOCK(RepAtom(atomToInclude)->ARWLock);
|
|
|
|
INVISIBLECHAIN.Entry = atomToInclude;
|
|
|
|
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_hidden( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* '$hidden'(+F) */
|
|
|
|
Atom at;
|
|
|
|
AtomEntry *chain;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsAtomTerm(t1))
|
|
|
|
at = AtomOfTerm(t1);
|
|
|
|
else if (IsApplTerm(t1))
|
|
|
|
at = NameOfFunctor(FunctorOfTerm(t1));
|
|
|
|
else
|
|
|
|
return (FALSE);
|
|
|
|
READ_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
while (!EndOfPAEntr(chain) && AbsAtom(chain) != at)
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
2001-10-30 22:13:18 +00:00
|
|
|
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_unhide( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* unhide(+Atom) */
|
|
|
|
AtomEntry *atom, *old, *chain;
|
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
|
|
|
|
if (IsVarTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t1,"unhide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsAtomTerm(t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM,t1,"unhide/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
atom = RepAtom(AtomOfTerm(t1));
|
|
|
|
WRITE_LOCK(atom->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
if (atom->PropsOfAE != NIL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,t1,"cannot unhide an atom in use");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
old = NIL;
|
|
|
|
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, atom->StrOfAE) != 0) {
|
|
|
|
old = chain;
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
|
|
|
}
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
return (FALSE);
|
2001-10-30 16:42:05 +00:00
|
|
|
atom->PropsOfAE = chain->PropsOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (old == NIL)
|
|
|
|
INVISIBLECHAIN.Entry = chain->NextOfAE;
|
|
|
|
else
|
|
|
|
old->NextOfAE = chain->NextOfAE;
|
|
|
|
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
WRITE_UNLOCK(atom->ARWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_show_statistics(void)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2006-05-18 17:33:05 +01:00
|
|
|
unsigned long int heap_space_taken;
|
|
|
|
double frag;
|
|
|
|
|
|
|
|
#if USE_SYSTEM_MALLOC && HAVE_MALLINFO
|
|
|
|
struct mallinfo mi = mallinfo();
|
|
|
|
|
2006-05-19 15:31:32 +01:00
|
|
|
heap_space_taken = (mi.arena+mi.hblkhd)-Yap_HoleSize;
|
2006-05-18 17:33:05 +01:00
|
|
|
#else
|
|
|
|
heap_space_taken =
|
2006-05-19 15:31:32 +01:00
|
|
|
(unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase))-Yap_HoleSize;
|
2006-05-18 17:33:05 +01:00
|
|
|
#endif
|
|
|
|
frag = (100.0*(heap_space_taken-HeapUsed))/heap_space_taken;
|
2002-11-11 17:38:10 +00:00
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr, "Code Space: %ld (%ld bytes needed, %ld bytes used, fragmentation %.3f%%).\n",
|
2002-11-18 18:18:05 +00:00
|
|
|
(unsigned long int)(Unsigned (H0) - Unsigned (Yap_HeapBase)),
|
|
|
|
(unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)),
|
2002-11-11 17:38:10 +00:00
|
|
|
(unsigned long int)(HeapUsed),
|
|
|
|
frag);
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr, "Stack Space: %ld (%ld for Global, %ld for local).\n",
|
2002-11-11 17:38:10 +00:00
|
|
|
(unsigned long int)(sizeof(CELL)*(LCL0-H0)),
|
|
|
|
(unsigned long int)(sizeof(CELL)*(H-H0)),
|
|
|
|
(unsigned long int)(sizeof(CELL)*(LCL0-ASP)));
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr, "Trail Space: %ld (%ld used).\n",
|
2011-05-23 16:19:47 +01:00
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(LOCAL_TrailTop)-Unsigned(LOCAL_TrailBase))),
|
|
|
|
(unsigned long int)(sizeof(tr_fr_ptr)*(Unsigned(TR)-Unsigned(LOCAL_TrailBase))));
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr, "Runtime: %lds.\n", (unsigned long int)(runtime ( PASS_REGS1 )));
|
|
|
|
fprintf(GLOBAL_stderr, "Cputime: %lds.\n", (unsigned long int)(Yap_cputime ()));
|
|
|
|
fprintf(GLOBAL_stderr, "Walltime: %lds.\n", (unsigned long int)(Yap_walltime ()));
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_heap_max( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tmax = MkIntegerTerm(HeapMax);
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The results of the next routines are not to be trusted too */
|
|
|
|
/* much. Basically, any stack shifting will seriously confuse the */
|
|
|
|
/* results */
|
|
|
|
|
|
|
|
static Int TrailTide = -1, LocalTide = -1, GlobalTide = -1;
|
|
|
|
|
|
|
|
/* maximum Trail usage */
|
|
|
|
static Int
|
|
|
|
TrailMax(void)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
2011-05-23 16:19:47 +01:00
|
|
|
Int TrWidth = Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (TrailTide != TrWidth) {
|
|
|
|
pt = (CELL *)TR;
|
2011-05-23 16:19:47 +01:00
|
|
|
while (pt+2 < (CELL *)LOCAL_TrailTop) {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pt[0] == 0 &&
|
|
|
|
pt[1] == 0 &&
|
|
|
|
pt[2] == 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
pt++;
|
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (pt+2 < (CELL *)LOCAL_TrailTop)
|
|
|
|
i = Unsigned(pt) - Unsigned(LOCAL_TrailBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
|
|
|
i = TrWidth;
|
|
|
|
} else
|
|
|
|
return(TrWidth);
|
|
|
|
if (TrailTide > i)
|
|
|
|
i = TrailTide;
|
|
|
|
else
|
|
|
|
TrailTide = i;
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_trail_max( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tmax = MkIntegerTerm(TrailMax());
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maximum Global usage */
|
|
|
|
static Int
|
|
|
|
GlobalMax(void)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (GlobalTide != StkWidth) {
|
|
|
|
pt = H;
|
|
|
|
while (pt+2 < ASP) {
|
|
|
|
if (pt[0] == 0 &&
|
|
|
|
pt[1] == 0 &&
|
|
|
|
pt[2] == 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
pt++;
|
|
|
|
}
|
|
|
|
if (pt+2 < ASP)
|
|
|
|
i = Unsigned(pt) - Unsigned(H0);
|
|
|
|
else
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
} else
|
|
|
|
return(StkWidth);
|
|
|
|
if (GlobalTide > i)
|
|
|
|
i = GlobalTide;
|
|
|
|
else
|
|
|
|
GlobalTide = i;
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_global_max( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tmax = MkIntegerTerm(GlobalMax());
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
LocalMax(void)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
Int i;
|
|
|
|
Int StkWidth = Unsigned(LCL0) - Unsigned(H0);
|
|
|
|
CELL *pt;
|
|
|
|
|
|
|
|
if (LocalTide != StkWidth) {
|
|
|
|
pt = LCL0;
|
|
|
|
while (pt-3 > H) {
|
|
|
|
if (pt[-1] == 0 &&
|
|
|
|
pt[-2] == 0 &&
|
|
|
|
pt[-3] == 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
--pt;
|
|
|
|
}
|
|
|
|
if (pt-3 > H)
|
|
|
|
i = Unsigned(LCL0) - Unsigned(pt);
|
|
|
|
else
|
|
|
|
/* so that both Local and Global have reached maximum width */
|
|
|
|
GlobalTide = LocalTide = i = StkWidth;
|
|
|
|
} else
|
|
|
|
return(StkWidth);
|
|
|
|
if (LocalTide > i)
|
|
|
|
i = LocalTide;
|
|
|
|
else
|
|
|
|
LocalTide = i;
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_local_max( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tmax = MkIntegerTerm(LocalMax());
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_heap_info( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tusage = MkIntegerTerm(HeapUsed);
|
|
|
|
|
2006-05-18 17:33:05 +01:00
|
|
|
#if USE_SYSTEM_MALLOC && HAVE_MALLINFO
|
|
|
|
struct mallinfo mi = mallinfo();
|
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
UInt sstack = Yap_HoleSize+(LOCAL_TrailTop-LOCAL_GlobalBase);
|
2010-04-10 21:18:35 +01:00
|
|
|
UInt mmax = (mi.arena+mi.hblkhd);
|
|
|
|
Term tmax = MkIntegerTerm(mmax-sstack);
|
|
|
|
tusage = MkIntegerTerm(mmax-(mi.fordblks+sstack));
|
2006-05-18 17:33:05 +01:00
|
|
|
#else
|
2011-05-23 16:19:47 +01:00
|
|
|
Term tmax = MkIntegerTerm((LOCAL_GlobalBase - Yap_HeapBase)-Yap_HoleSize);
|
2006-05-18 17:33:05 +01:00
|
|
|
#endif
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_stacks_info( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tmax = MkIntegerTerm(Unsigned(LCL0) - Unsigned(H0));
|
|
|
|
Term tgusage = MkIntegerTerm(Unsigned(H) - Unsigned(H0));
|
|
|
|
Term tlusage = MkIntegerTerm(Unsigned(LCL0) - Unsigned(ASP));
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tgusage,ARG2) && Yap_unify(tlusage,ARG3));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-06 18:35:05 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_trail_info( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-23 16:19:47 +01:00
|
|
|
Term tmax = MkIntegerTerm(Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase));
|
|
|
|
Term tusage = MkIntegerTerm(Unsigned(TR) - Unsigned(LOCAL_TrailBase));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2));
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-01 21:14:42 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_atom_info( USES_REGS1 )
|
2006-09-01 21:14:42 +01:00
|
|
|
{
|
|
|
|
UInt count = 0, spaceused = 0, i;
|
|
|
|
|
|
|
|
for (i =0; i < AtomHashTableSize; i++) {
|
|
|
|
Atom catom;
|
|
|
|
|
2006-10-10 15:08:17 +01:00
|
|
|
READ_LOCK(HashChain[i].AERWLock);
|
2006-09-01 21:14:42 +01:00
|
|
|
catom = HashChain[i].Entry;
|
|
|
|
if (catom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(catom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(HashChain[i].AERWLock);
|
|
|
|
while (catom != NIL) {
|
|
|
|
Atom ncatom;
|
|
|
|
count++;
|
|
|
|
spaceused += sizeof(AtomEntry)+strlen(RepAtom(catom)->StrOfAE);
|
|
|
|
ncatom = RepAtom(catom)->NextOfAE;
|
|
|
|
if (ncatom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(ncatom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(RepAtom(ncatom)->ARWLock);
|
|
|
|
catom = ncatom;
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
for (i =0; i < WideAtomHashTableSize; i++) {
|
|
|
|
Atom catom;
|
|
|
|
|
|
|
|
READ_LOCK(WideHashChain[i].AERWLock);
|
|
|
|
catom = WideHashChain[i].Entry;
|
|
|
|
if (catom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(catom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(WideHashChain[i].AERWLock);
|
|
|
|
while (catom != NIL) {
|
|
|
|
Atom ncatom;
|
|
|
|
count++;
|
|
|
|
spaceused += sizeof(AtomEntry)+wcslen((wchar_t *)( RepAtom(catom)->StrOfAE));
|
|
|
|
ncatom = RepAtom(catom)->NextOfAE;
|
|
|
|
if (ncatom != NIL) {
|
|
|
|
READ_LOCK(RepAtom(ncatom)->ARWLock);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(RepAtom(ncatom)->ARWLock);
|
|
|
|
catom = ncatom;
|
|
|
|
}
|
|
|
|
}
|
2006-09-01 21:14:42 +01:00
|
|
|
return Yap_unify(ARG1, MkIntegerTerm(count)) &&
|
|
|
|
Yap_unify(ARG2, MkIntegerTerm(spaceused));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-06 18:35:05 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_db_size( USES_REGS1 )
|
2006-11-06 18:35:05 +00:00
|
|
|
{
|
|
|
|
Term t = MkIntegerTerm(Yap_ClauseSpace);
|
|
|
|
Term tit = MkIntegerTerm(Yap_IndexSpace_Tree);
|
|
|
|
Term tis = MkIntegerTerm(Yap_IndexSpace_SW);
|
|
|
|
Term tie = MkIntegerTerm(Yap_IndexSpace_EXT);
|
|
|
|
|
|
|
|
return
|
|
|
|
Yap_unify(t, ARG1) &&
|
|
|
|
Yap_unify(tit, ARG2) &&
|
|
|
|
Yap_unify(tis, ARG3) &&
|
|
|
|
Yap_unify(tie, ARG4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_statistics_lu_db_size( USES_REGS1 )
|
2006-11-06 18:35:05 +00:00
|
|
|
{
|
|
|
|
Term t = MkIntegerTerm(Yap_LUClauseSpace);
|
|
|
|
Term tit = MkIntegerTerm(Yap_LUIndexSpace_Tree);
|
|
|
|
Term tic = MkIntegerTerm(Yap_LUIndexSpace_CP);
|
|
|
|
Term tix = MkIntegerTerm(Yap_LUIndexSpace_EXT);
|
|
|
|
Term tis = MkIntegerTerm(Yap_LUIndexSpace_SW);
|
|
|
|
|
|
|
|
return
|
|
|
|
Yap_unify(t, ARG1) &&
|
|
|
|
Yap_unify(tit, ARG2) &&
|
|
|
|
Yap_unify(tic, ARG3) &&
|
2006-11-08 01:56:47 +00:00
|
|
|
Yap_unify(tis, ARG4) &&
|
|
|
|
Yap_unify(tix, ARG5);
|
2006-11-06 18:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
mk_argc_list( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i =0;
|
|
|
|
Term t = TermNil;
|
2011-05-25 16:40:36 +01:00
|
|
|
while (i < GLOBAL_argc) {
|
|
|
|
char *arg = GLOBAL_argv[i];
|
2001-05-28 20:54:53 +01:00
|
|
|
/* check for -L -- */
|
|
|
|
if (arg[0] == '-' && arg[1] == 'L') {
|
|
|
|
arg += 2;
|
|
|
|
while (*arg != '\0' && (*arg == ' ' || *arg == '\t'))
|
|
|
|
arg++;
|
|
|
|
if (*arg == '-' && arg[1] == '-' && arg[2] == '\0') {
|
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
2011-05-25 16:40:36 +01:00
|
|
|
for (j = GLOBAL_argc-1; j > i+1; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
|
2001-05-28 20:54:53 +01:00
|
|
|
}
|
2008-10-17 12:37:39 +01:00
|
|
|
return t;
|
2011-05-25 16:40:36 +01:00
|
|
|
} else if (GLOBAL_argv[i+1] && GLOBAL_argv[i+1][0] == '-' && GLOBAL_argv[i+1][1] == '-' && GLOBAL_argv[i+1][2] == '\0') {
|
2008-10-17 12:37:39 +01:00
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
2011-05-25 16:40:36 +01:00
|
|
|
for (j = GLOBAL_argc-1; j > i+2; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
|
2008-10-17 12:37:39 +01:00
|
|
|
}
|
|
|
|
return t;
|
2001-05-28 20:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0') {
|
|
|
|
/* we found the separator */
|
|
|
|
int j;
|
2011-05-25 16:40:36 +01:00
|
|
|
for (j = GLOBAL_argc-1; j > i; --j) {
|
|
|
|
t = MkPairTerm(MkAtomTerm(Yap_LookupAtom(GLOBAL_argv[j])),t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(t);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_argv( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
Term t = mk_argc_list( PASS_REGS1 );
|
2009-12-10 01:16:29 +00:00
|
|
|
return Yap_unify(t, ARG1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_executable( USES_REGS1 )
|
2009-12-10 01:16:29 +00:00
|
|
|
{
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
Yap_TrueFileName (GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
2011-05-23 16:19:47 +01:00
|
|
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),ARG1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_access_yap_flags( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tflag = Deref(ARG1);
|
|
|
|
Int flag;
|
2005-08-04 16:45:56 +01:00
|
|
|
Term tout = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
if (IsVarTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tflag, "access_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "access_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
flag = IntOfTerm(tflag);
|
|
|
|
if (flag < 0 || flag > NUMBER_OF_YAP_FLAGS) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2005-07-06 20:34:12 +01:00
|
|
|
#ifdef TABLING
|
|
|
|
if (flag == TABLING_MODE_FLAG) {
|
2010-04-16 02:08:06 +01:00
|
|
|
tout = TermNil;
|
|
|
|
if (IsMode_LocalTrie(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLocalTrie), tout);
|
|
|
|
else if (IsMode_GlobalTrie(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomGlobalTrie), tout);
|
|
|
|
if (IsMode_ExecAnswers(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomExecAnswers), tout);
|
|
|
|
else if (IsMode_LoadAnswers(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLoadAnswers), tout);
|
|
|
|
if (IsMode_Batched(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomBatched), tout);
|
|
|
|
else if (IsMode_Local(yap_flags[flag]))
|
|
|
|
tout = MkPairTerm(MkAtomTerm(AtomLocal), tout);
|
2005-07-06 20:34:12 +01:00
|
|
|
} else
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
tout = MkIntegerTerm(yap_flags[flag]);
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG2, tout));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_has_yap_or( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#ifdef YAPOR
|
|
|
|
return(TRUE);
|
|
|
|
#else
|
|
|
|
return(FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-08 23:06:45 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_has_eam( USES_REGS1 )
|
2005-09-08 23:06:45 +01:00
|
|
|
{
|
|
|
|
#ifdef BEAM
|
|
|
|
return(TRUE);
|
|
|
|
#else
|
|
|
|
return(FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-06-22 18:53:36 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_set_yap_flags( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term tflag = Deref(ARG1);
|
|
|
|
Term tvalue = Deref(ARG2);
|
|
|
|
Int flag, value;
|
|
|
|
|
|
|
|
if (IsVarTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tflag, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(tflag)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tflag, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
flag = IntOfTerm(tflag);
|
|
|
|
if (IsVarTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, tvalue, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!IsIntTerm(tvalue)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, tvalue, "set_yap_flags/2");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
value = IntOfTerm(tvalue);
|
|
|
|
/* checking should have been performed */
|
|
|
|
switch(flag) {
|
|
|
|
case CHAR_CONVERSION_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[CHAR_CONVERSION_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case YAP_DOUBLE_QUOTES_FLAG:
|
|
|
|
if (value < 0 || value > 2)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case YAP_TO_CHARS_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[YAP_TO_CHARS_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case LANGUAGE_MODE_FLAG:
|
|
|
|
if (value < 0 || value > 2)
|
|
|
|
return(FALSE);
|
|
|
|
if (value == 1) {
|
2008-12-24 09:04:44 +00:00
|
|
|
Yap_heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(FunctorMetaCall,0));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2008-12-24 09:04:44 +00:00
|
|
|
Yap_heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(FunctorMetaCall,0));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
yap_flags[LANGUAGE_MODE_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case STRICT_ISO_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[STRICT_ISO_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case SOURCE_MODE_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[SOURCE_MODE_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case CHARACTER_ESCAPE_FLAG:
|
2001-04-17 22:07:41 +01:00
|
|
|
if (value != ISO_CHARACTER_ESCAPES
|
|
|
|
&& value != CPROLOG_CHARACTER_ESCAPES
|
|
|
|
&& value != SICSTUS_CHARACTER_ESCAPES)
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
yap_flags[CHARACTER_ESCAPE_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case WRITE_QUOTED_STRING_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = value;
|
|
|
|
break;
|
|
|
|
case ALLOW_ASSERTING_STATIC_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = value;
|
|
|
|
break;
|
2002-12-10 14:36:22 +00:00
|
|
|
case STACK_DUMP_ON_ERROR_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[STACK_DUMP_ON_ERROR_FLAG] = value;
|
|
|
|
break;
|
2007-02-26 10:41:40 +00:00
|
|
|
case GENERATE_DEBUG_INFO_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[GENERATE_DEBUG_INFO_FLAG] = value;
|
|
|
|
break;
|
2003-06-06 12:54:02 +01:00
|
|
|
case INDEXING_MODE_FLAG:
|
|
|
|
if (value < INDEX_MODE_OFF || value > INDEX_MODE_MAX)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[INDEXING_MODE_FLAG] = value;
|
|
|
|
break;
|
2005-04-07 18:56:58 +01:00
|
|
|
#ifdef TABLING
|
2005-07-06 20:34:12 +01:00
|
|
|
case TABLING_MODE_FLAG:
|
|
|
|
if (value == 0) { /* default */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2005-07-06 20:34:12 +01:00
|
|
|
while(tab_ent) {
|
2010-04-16 02:08:06 +01:00
|
|
|
TabEnt_mode(tab_ent) = TabEnt_flags(tab_ent);
|
2005-07-06 20:34:12 +01:00
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
yap_flags[TABLING_MODE_FLAG] = 0;
|
|
|
|
} else if (value == 1) { /* batched */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2005-07-06 20:34:12 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_Batched(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_Batched(yap_flags[TABLING_MODE_FLAG]);
|
|
|
|
} else if (value == 2) { /* local */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2005-07-06 20:34:12 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_Local(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_Local(yap_flags[TABLING_MODE_FLAG]);
|
|
|
|
} else if (value == 3) { /* exec_answers */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2005-07-06 20:34:12 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_ExecAnswers(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_ExecAnswers(yap_flags[TABLING_MODE_FLAG]);
|
|
|
|
} else if (value == 4) { /* load_answers */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2005-07-06 20:34:12 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_LoadAnswers(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_LoadAnswers(yap_flags[TABLING_MODE_FLAG]);
|
2010-04-16 02:08:06 +01:00
|
|
|
} else if (value == 5) { /* local_trie */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2010-04-16 02:08:06 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_LocalTrie(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_LocalTrie(yap_flags[TABLING_MODE_FLAG]);
|
|
|
|
} else if (value == 6) { /* global_trie */
|
2011-05-10 11:47:18 +01:00
|
|
|
tab_ent_ptr tab_ent = GLOBAL_root_tab_ent;
|
2010-04-16 02:08:06 +01:00
|
|
|
while(tab_ent) {
|
|
|
|
SetMode_GlobalTrie(TabEnt_mode(tab_ent));
|
|
|
|
tab_ent = TabEnt_next(tab_ent);
|
|
|
|
}
|
|
|
|
SetMode_GlobalTrie(yap_flags[TABLING_MODE_FLAG]);
|
2005-07-06 20:34:12 +01:00
|
|
|
}
|
2005-04-07 18:56:58 +01:00
|
|
|
break;
|
2005-07-06 20:34:12 +01:00
|
|
|
#endif /* TABLING */
|
2008-02-07 23:09:13 +00:00
|
|
|
case VARS_CAN_HAVE_QUOTE_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return(FALSE);
|
|
|
|
yap_flags[VARS_CAN_HAVE_QUOTE_FLAG] = value;
|
|
|
|
break;
|
2008-03-15 12:19:33 +00:00
|
|
|
case QUIET_MODE_FLAG:
|
|
|
|
if (value != 0 && value != 1)
|
2010-04-14 23:47:01 +01:00
|
|
|
return FALSE;
|
|
|
|
yap_flags[QUIET_MODE_FLAG] = value;
|
2008-03-15 12:19:33 +00:00
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
default:
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_system_mode( USES_REGS1 )
|
2006-12-13 16:10:26 +00:00
|
|
|
{
|
|
|
|
Int i = IntegerOfTerm(Deref(ARG1));
|
|
|
|
if (i == 0)
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode &= ~SystemMode;
|
2006-12-13 16:10:26 +00:00
|
|
|
else
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode |= SystemMode;
|
2006-12-13 16:10:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-01 17:27:42 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_lock_system( USES_REGS1 )
|
2003-12-01 17:27:42 +00:00
|
|
|
{
|
2011-05-10 10:06:51 +01:00
|
|
|
LOCK(GLOBAL_BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_unlock_system( USES_REGS1 )
|
2003-12-01 17:27:42 +00:00
|
|
|
{
|
2011-05-10 10:06:51 +01:00
|
|
|
UNLOCK(GLOBAL_BGL);
|
2003-12-01 17:27:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-12-08 04:45:04 +00:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_enterundefp( USES_REGS1 )
|
2004-12-08 04:45:04 +00:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_DoingUndefp) {
|
2004-12-08 04:45:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_DoingUndefp = TRUE;
|
2004-12-08 04:45:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_exitundefp( USES_REGS1 )
|
2004-12-08 04:45:04 +00:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_DoingUndefp) {
|
|
|
|
LOCAL_DoingUndefp = FALSE;
|
2004-12-08 04:45:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern void DumpActiveGoals(void);
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_dump_active_goals( USES_REGS1 ) {
|
2001-04-09 20:54:03 +01:00
|
|
|
DumpActiveGoals();
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-04 03:25:41 +00:00
|
|
|
#ifdef INES
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_euc_dist( USES_REGS1 ) {
|
2002-03-04 03:25:41 +00:00
|
|
|
Term t1 = Deref(ARG1);
|
|
|
|
Term t2 = Deref(ARG2);
|
|
|
|
double d1 = (double)(IntegerOfTerm(ArgOfTerm(1,t1))-IntegerOfTerm(ArgOfTerm(1,t2)));
|
|
|
|
double d2 = (double)(IntegerOfTerm(ArgOfTerm(2,t1))-IntegerOfTerm(ArgOfTerm(2,t2)));
|
|
|
|
double d3 = (double)(IntegerOfTerm(ArgOfTerm(3,t1))-IntegerOfTerm(ArgOfTerm(3,t2)));
|
|
|
|
Int result = (Int)sqrt(d1*d1+d2*d2+d3*d3);
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_unify(ARG3,MkIntegerTerm(result)));
|
2002-03-04 03:25:41 +00:00
|
|
|
}
|
2002-03-08 06:32:11 +00:00
|
|
|
|
|
|
|
volatile int loop_counter = 0;
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_loop( USES_REGS1 ) {
|
2002-03-08 06:32:11 +00:00
|
|
|
while (loop_counter == 0);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
2002-03-04 03:25:41 +00:00
|
|
|
#endif
|
|
|
|
|
2006-06-05 20:36:00 +01:00
|
|
|
#if QSAR
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_in_range( USES_REGS1 ) {
|
2006-06-05 20:36:00 +01:00
|
|
|
Term t;
|
|
|
|
double i,j;
|
|
|
|
double d1;
|
|
|
|
double d2;
|
|
|
|
double d3;
|
|
|
|
|
|
|
|
t = Deref(ARG1);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(ARG4);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d1 = i-j;
|
|
|
|
t = Deref(ARG2);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(ARG5);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d2 = i-j;
|
|
|
|
t = Deref(ARG3);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(ARG6);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d3 = i-j;
|
|
|
|
t = Deref(ARG7);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(ARG8);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
|
|
|
|
return fabs(sqrt(d1*d1 + d2*d2 + d3*d3)-i) <= j;
|
|
|
|
|
2006-09-15 20:32:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_in_range2( USES_REGS1 ) {
|
2006-09-15 20:32:47 +01:00
|
|
|
CELL *p1, *p2;
|
|
|
|
Term t;
|
|
|
|
double i,j;
|
|
|
|
double d1;
|
|
|
|
double d2;
|
|
|
|
double d3;
|
|
|
|
UInt arity;
|
|
|
|
p1 = RepAppl(Deref(ARG1));
|
|
|
|
arity = ArityOfFunctor((Functor)*p1);
|
|
|
|
p1 += arity-2;
|
|
|
|
p2 = RepAppl(Deref(ARG2))+(arity-2);;
|
|
|
|
|
|
|
|
t = Deref(p1[0]);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(p2[0]);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d1 = i-j;
|
|
|
|
t = Deref(p1[1]);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(p2[1]);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d2 = i-j;
|
|
|
|
t = Deref(p1[2]);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(p2[2]);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
d3 = i-j;
|
|
|
|
t = Deref(ARG3);
|
|
|
|
if (IsFloatTerm(t)) i = FloatOfTerm(t); else i = IntegerOfTerm(t);
|
|
|
|
t = Deref(ARG4);
|
|
|
|
if (IsFloatTerm(t)) j = FloatOfTerm(t); else j = IntegerOfTerm(t);
|
|
|
|
|
|
|
|
return fabs(sqrt(d1*d1 + d2*d2 + d3*d3)-i) <= j;
|
|
|
|
|
2006-06-05 20:36:00 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-10-28 18:38:50 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_max_tagged_integer( USES_REGS1 ) {
|
2010-05-11 00:18:12 +01:00
|
|
|
return Yap_unify(ARG1, MkIntTerm(MAX_ABS_INT-((CELL)1)));
|
2005-10-28 18:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_min_tagged_integer( USES_REGS1 ) {
|
2005-10-28 18:38:50 +01:00
|
|
|
return Yap_unify(ARG1, MkIntTerm(-MAX_ABS_INT));
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitBackCPreds(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPredBack("$current_atom", 1, 2, init_current_atom, cont_current_atom,
|
2004-11-18 22:32:40 +00:00
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2006-11-27 17:42:03 +00:00
|
|
|
Yap_InitCPredBack("$current_wide_atom", 1, 2, init_current_wide_atom,
|
|
|
|
cont_current_wide_atom,
|
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPredBack("$current_predicate", 3, 1, init_current_predicate, cont_current_predicate,
|
2004-11-18 22:32:40 +00:00
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPredBack("$current_predicate_for_atom", 3, 1, init_current_predicate_for_atom, cont_current_predicate_for_atom,
|
2004-11-18 22:32:40 +00:00
|
|
|
SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2009-11-25 00:38:47 +00:00
|
|
|
Yap_InitCPredBack("$current_op", 5, 1, init_current_op, cont_current_op,
|
|
|
|
SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPredBack("$current_atom_op", 5, 1, init_current_atom_op, cont_current_atom_op,
|
2001-04-09 20:54:03 +01:00
|
|
|
SafePredFlag|SyncPredFlag);
|
2010-01-18 14:27:56 +00:00
|
|
|
Yap_InitCPredBack("$sub_atom_fetch", 5, 5, init_sub_atom_fetch, cont_sub_atom_fetch, HiddenPredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
Yap_InitCPredBack("eam", 1, 0, start_eam, cont_eam,
|
|
|
|
SafePredFlag);
|
|
|
|
#endif
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitBackIO();
|
|
|
|
Yap_InitBackDB();
|
|
|
|
Yap_InitUserBacks();
|
2005-11-22 11:25:59 +00:00
|
|
|
#if defined MYDDAS_MYSQL && defined CUT_C
|
|
|
|
Yap_InitBackMYDDAS_MySQLPreds();
|
|
|
|
#endif
|
|
|
|
#if defined MYDDAS_ODBC && defined CUT_C
|
|
|
|
Yap_InitBackMYDDAS_ODBCPreds();
|
|
|
|
#endif
|
|
|
|
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
|
|
|
|
Yap_InitBackMYDDAS_SharedPreds();
|
|
|
|
#endif
|
2011-02-10 21:14:38 +00:00
|
|
|
{
|
|
|
|
extern void initIO(void);
|
|
|
|
initIO();
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*Proc)(void);
|
|
|
|
|
|
|
|
Proc E_Modules[]= {/* init_fc,*/ (Proc) 0 };
|
|
|
|
|
2010-01-15 01:03:34 +00:00
|
|
|
#ifndef YAPOR
|
2011-06-21 15:19:07 +01:00
|
|
|
static Int p_parallel_mode( USES_REGS1 ) {
|
2010-01-15 01:03:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-06-21 15:19:07 +01:00
|
|
|
|
|
|
|
static Int p_yapor_workers( USES_REGS1 ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif /* YAPOR */
|
2010-01-15 01:03:34 +00:00
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPreds(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
/* numerical comparison */
|
2003-08-27 14:37:10 +01:00
|
|
|
Yap_InitCPred("set_value", 2, p_setval, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("get_value", 2, p_value, TestPredFlag|SafePredFlag|SyncPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$values", 3, p_values, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* general purpose */
|
2005-10-21 17:09:03 +01:00
|
|
|
Yap_InitCPred("$opdec", 4, p_opdec, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_InitCPred("name", 2, p_name, 0);
|
2011-06-13 01:43:03 +01:00
|
|
|
Yap_InitCPred("string_to_atom", 2, p_string_to_atom, 0);
|
2011-06-14 08:59:17 +01:00
|
|
|
Yap_InitCPred("string_to_list", 2, p_string_to_list, 0);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("char_code", 2, p_char_code, SafePredFlag);
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_InitCPred("atom_chars", 2, p_atom_chars, 0);
|
|
|
|
Yap_InitCPred("atom_codes", 2, p_atom_codes, 0);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("atom_length", 2, p_atom_length, SafePredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$atom_split", 4, p_atom_split, SafePredFlag|HiddenPredFlag);
|
2007-10-09 00:02:16 +01:00
|
|
|
Yap_InitCPred("$sub_atom_extract", 5, p_sub_atom_extract, HiddenPredFlag);
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_InitCPred("number_chars", 2, p_number_chars, 0);
|
|
|
|
Yap_InitCPred("number_atom", 2, p_number_atom, 0);
|
|
|
|
Yap_InitCPred("number_codes", 2, p_number_codes, 0);
|
2007-10-09 00:02:16 +01:00
|
|
|
Yap_InitCPred("atom_number", 2, p_atom_number, 0);
|
2005-04-27 21:09:26 +01:00
|
|
|
Yap_InitCPred("atom_concat", 2, p_atom_concat, 0);
|
|
|
|
Yap_InitCPred("atomic_concat", 2, p_atomic_concat, 0);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("=..", 2, p_univ, 0);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$statistics_trail_max", 1, p_statistics_trail_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_heap_max", 1, p_statistics_heap_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_global_max", 1, p_statistics_global_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_local_max", 1, p_statistics_local_max, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_heap_info", 2, p_statistics_heap_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_stacks_info", 3, p_statistics_stacks_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_trail_info", 2, p_statistics_trail_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2006-09-01 21:14:42 +01:00
|
|
|
Yap_InitCPred("$statistics_atom_info", 2, p_statistics_atom_info, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_InitCPred("$statistics_db_size", 4, p_statistics_db_size, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$statistics_lu_db_size", 5, p_statistics_lu_db_size, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$argv", 1, p_argv, SafePredFlag|HiddenPredFlag);
|
2009-12-10 01:16:29 +00:00
|
|
|
Yap_InitCPred("$executable", 1, p_executable, SafePredFlag|HiddenPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$runtime", 2, p_runtime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$cputime", 2, p_cputime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2009-02-09 21:56:40 +00:00
|
|
|
Yap_InitCPred("$systime", 2, p_systime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$walltime", 2, p_walltime, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$access_yap_flags", 2, p_access_yap_flags, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$set_yap_flags", 2, p_set_yap_flags, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2006-12-13 16:10:26 +00:00
|
|
|
Yap_InitCPred("$p_system_mode", 1, p_system_mode, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("abort", 0, p_abort, SyncPredFlag);
|
2005-10-28 18:38:50 +01:00
|
|
|
Yap_InitCPred("$max_tagged_integer", 1, p_max_tagged_integer, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$min_tagged_integer", 1, p_min_tagged_integer, SafePredFlag|HiddenPredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
Yap_InitCPred("@", 0, eager_split, SafePredFlag);
|
|
|
|
Yap_InitCPred(":", 0, force_wait, SafePredFlag);
|
|
|
|
Yap_InitCPred("/", 0, commit, SafePredFlag);
|
|
|
|
Yap_InitCPred("skip_while_var",1,skip_while_var,SafePredFlag);
|
|
|
|
Yap_InitCPred("wait_while_var",1,wait_while_var,SafePredFlag);
|
|
|
|
Yap_InitCPred("eamtime", 0, show_time, SafePredFlag);
|
|
|
|
Yap_InitCPred("eam", 0, use_eam, SafePredFlag);
|
|
|
|
#endif
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$halt", 1, p_halt, SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$lock_system", 0, p_lock_system, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$unlock_system", 0, p_unlock_system, SafePredFlag|HiddenPredFlag);
|
2004-12-08 04:45:04 +00:00
|
|
|
Yap_InitCPred("$enter_undefp", 0, p_enterundefp, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$exit_undefp", 0, p_exitundefp, SafePredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* basic predicates for the prolog machine tracer */
|
|
|
|
/* they are defined in analyst.c */
|
|
|
|
/* Basic predicates for the debugger */
|
2008-08-30 02:39:36 +01:00
|
|
|
Yap_InitCPred("$creep", 0, p_creep, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$signal_creep", 0, p_signal_creep, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$disable_creep", 0, p_disable_creep, SafePredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$disable_docreep", 0, p_disable_docreep, SafePredFlag|HiddenPredFlag);
|
2005-02-08 04:05:39 +00:00
|
|
|
Yap_InitCPred("$do_not_creep", 0, p_stop_creep, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$debug", 1, p_debug, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
/* Accessing and changing the flags for a predicate */
|
2007-11-06 17:02:13 +00:00
|
|
|
Yap_InitCPred("$flags", 4, p_flags, SyncPredFlag|HiddenPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* hiding and unhiding some predicates */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("hide", 1, p_hide, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("unhide", 1, p_unhide, SafePredFlag|SyncPredFlag);
|
2004-11-18 22:32:40 +00:00
|
|
|
Yap_InitCPred("$hidden", 1, p_hidden, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$has_yap_or", 0, p_has_yap_or, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2005-09-08 23:06:45 +01:00
|
|
|
Yap_InitCPred("$has_eam", 0, p_has_eam, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
2001-05-28 20:54:53 +01:00
|
|
|
#ifndef YAPOR
|
2011-06-21 15:19:07 +01:00
|
|
|
Yap_InitCPred("parallel_mode", 1, p_parallel_mode, SafePredFlag|SyncPredFlag);
|
|
|
|
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
|
|
|
#endif /* YAPOR */
|
2002-03-04 03:25:41 +00:00
|
|
|
#ifdef INES
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("euc_dist", 3, p_euc_dist, SafePredFlag);
|
|
|
|
Yap_InitCPred("loop", 0, p_loop, SafePredFlag);
|
2002-03-04 03:25:41 +00:00
|
|
|
#endif
|
2006-06-05 20:36:00 +01:00
|
|
|
#if QSAR
|
2006-09-15 20:32:47 +01:00
|
|
|
Yap_InitCPred("in_range", 8, p_in_range, TestPredFlag|SafePredFlag);
|
|
|
|
Yap_InitCPred("in_range", 4, p_in_range2, TestPredFlag|SafePredFlag);
|
2006-06-05 20:36:00 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("dump_active_goals", 0, p_dump_active_goals, SafePredFlag|SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitArrayPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitBBPreds();
|
|
|
|
Yap_InitBigNums();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitCdMgr();
|
|
|
|
Yap_InitCmpPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCoroutPreds();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitDBPreds();
|
|
|
|
Yap_InitExecFs();
|
|
|
|
Yap_InitGlobals();
|
|
|
|
Yap_InitInlines();
|
|
|
|
Yap_InitIOPreds();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitLoadForeign();
|
2004-02-06 02:26:23 +00:00
|
|
|
Yap_InitModulesC();
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_InitSavePreds();
|
|
|
|
Yap_InitSysPreds();
|
|
|
|
Yap_InitUnify();
|
2011-08-03 08:23:00 +01:00
|
|
|
Yap_InitQLY();
|
2011-08-24 04:11:54 +01:00
|
|
|
Yap_InitQLYR();
|
2005-11-22 11:25:59 +00:00
|
|
|
#if defined CUT_C && defined MYDDAS_MYSQL
|
|
|
|
Yap_InitMYDDAS_MySQLPreds();
|
|
|
|
#endif
|
|
|
|
#if defined CUT_C && defined MYDDAS_ODBC
|
|
|
|
Yap_InitMYDDAS_ODBCPreds();
|
|
|
|
#endif
|
|
|
|
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
|
|
|
|
Yap_InitMYDDAS_SharedPreds();
|
|
|
|
#endif
|
2006-02-05 02:19:15 +00:00
|
|
|
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE
|
|
|
|
Yap_InitMYDDAS_TopLevelPreds();
|
2005-11-22 11:25:59 +00:00
|
|
|
#endif
|
2009-02-20 11:42:48 +00:00
|
|
|
Yap_udi_init();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitUserCPreds();
|
|
|
|
Yap_InitUtilCPreds();
|
|
|
|
Yap_InitSortPreds();
|
|
|
|
Yap_InitMaVarCPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEPTH_LIMIT
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitItDeepenPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#ifdef ANALYST
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAnalystPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitLowLevelTrace();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitEval();
|
|
|
|
Yap_InitGrowPreds();
|
2005-12-17 03:25:39 +00:00
|
|
|
Yap_InitLowProf();
|
2001-04-09 20:54:03 +01:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_optyap_preds();
|
2003-11-07 16:31:08 +00:00
|
|
|
#endif /* YAPOR || TABLING */
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_InitThreadPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
void (*(*(p))) (void) = E_Modules;
|
|
|
|
while (*p)
|
|
|
|
(*(*p++)) ();
|
|
|
|
}
|
|
|
|
#if CAMACHO
|
|
|
|
{
|
|
|
|
extern void InitForeignPreds(void);
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitForeignPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
2002-09-25 05:29:01 +01:00
|
|
|
#if APRIL
|
2002-09-24 20:01:29 +01:00
|
|
|
{
|
|
|
|
extern void init_ol(void), init_time(void);
|
|
|
|
|
|
|
|
init_ol();
|
|
|
|
init_time();
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-28 18:53:44 +01:00
|
|
|
#if SUPPORT_CONDOR
|
|
|
|
init_sys();
|
|
|
|
init_random();
|
|
|
|
// init_tries();
|
|
|
|
init_regexp();
|
|
|
|
#endif
|
2007-10-10 10:44:28 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2007-10-10 10:44:28 +01:00
|
|
|
Term cm = CurrentModule;
|
|
|
|
CurrentModule = SWI_MODULE;
|
2007-10-18 09:24:16 +01:00
|
|
|
Yap_swi_install();
|
2007-10-10 10:44:28 +01:00
|
|
|
CurrentModule = cm;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|