From 6d507ff49fad0b54177521dc2bf057f457f26d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 22 Jul 2015 19:19:35 -0500 Subject: [PATCH] BEW CONSTANTS. --- C/init.c | 11 ++++--- H/blobs.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ H/dglobals.h | 3 ++ H/dhstruct.h | 7 +++-- H/dlocals.h | 8 ++++-- H/hglobals.h | 3 ++ H/hlocals.h | 4 ++- H/hstruct.h | 7 +++-- H/iatoms.h | 7 +++-- H/iglobals.h | 3 ++ H/ihstruct.h | 7 +++-- H/ilocals.h | 4 ++- H/ratoms.h | 7 +++-- H/rglobals.h | 3 ++ H/rhstruct.h | 7 +++-- H/rlocals.h | 2 ++ H/tatoms.h | 10 +++++-- 17 files changed, 148 insertions(+), 26 deletions(-) create mode 100644 H/blobs.h diff --git a/C/init.c b/C/init.c index 007cb8e41..f89e80fdc 100755 --- a/C/init.c +++ b/C/init.c @@ -1071,16 +1071,19 @@ InitLogDBErasedMarker(void) static void InitSWIAtoms(void) { - /* extern atom_t ATOM_; + /* extern atom_t ATOM_;FUNV int j=0; MaxAtomTranslations = 2*N_SWI_ATOMS ; SWI_Atoms = (Atom *)malloc(sizeof(Atom)*MaxAtomTranslations); SWI_Functors = (Functor *)malloc(sizeof(Functor)*2*N_SWI_ATOMS); -#include "iswiatoms.h" +#include "i + + + atoms.h" Yap_InitSWIHash(); ATOM_ = PL_new_atom(""); - */ + */ } static void @@ -1263,7 +1266,7 @@ InitHandles(int wid) { REMOTE_CurSlot(wid) = 1; REMOTE_NSlots(wid) = initial_slots; - handles = malloc(initial_slots * sizeof(CELL)); + handles = calloc(initial_slots , sizeof(CELL)); if(handles == NULL) { Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__); diff --git a/H/blobs.h b/H/blobs.h new file mode 100644 index 000000000..cae04601e --- /dev/null +++ b/H/blobs.h @@ -0,0 +1,81 @@ +// +// blobs.h +// yap +// +// Created by VITOR SANTOS COSTA on 09/05/15. +// Copyright (c) 2015 VITOR SANTOS COSTA. All rights reserved. +// + +// based on the SWI Blob implementation, an extension of atoms for SWI-Prolog + +#ifndef BLOBS_H +#define BLOBS_H + +#ifndef X_API +#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(PL_KERNEL) +#define X_API __declspec(dllexport) +#else +#define X_API +#endif +#endif + +/******************************* + * BLOBS * + *******************************/ + +#define YAP_BLOB_MAGIC_B 0x75293a00 /* Magic to validate a blob-type */ +#define PL_BLOB_VERSION (YAP_BLOB_MAGIC_B|PL_BLOB_VERSION) + +#define PL_BLOB_UNIQUE 0x01 /* Blob content is unique */ +#define PL_BLOB_TEXT 0x02 /* blob contains text */ +#define PL_BLOB_NOCOPY 0x04 /* do not copy the data */ +#define PL_BLOB_WCHAR 0x08 /* wide character string */ + +typedef struct YAP_blob_t +{ uintptr_t magic; /* YAP_BLOB_MAGIC */ + uintptr_t flags; /* YAP_BLOB_* */ + char * name; /* name of the type */ + int (*release)(Atom a); + int (*compare)(Atom a, Atom b); +#ifdef SIO_MAGIC + int (*write)(FILE *s, Atom a, int flags); +#else + int (*write)(void *s, Atom a, int flags); +#endif + void (*acquire)(Atom a); +#ifdef SIO_MAGIC + int (*save)(Atom a, FILE *s); + Atom (*load)(FILE *s); +#else + int (*save)(Atom a, void*); + Atom (*load)(void *s); +#endif + /* private */ + void * reserved[10]; /* for future extension */ + int registered; /* Already registered? */ + int rank; /* Rank for ordering atoms */ + struct YAP_blob_t * next; /* next in registered type-chain */ + Atom atom_name; /* Name as atom */ +} blob_type_t; + +int Yap_write_blob(AtomEntry *ref, FILE *stream); +char * Yap_blob_to_string(AtomEntry *ref, const char *s, size_t sz); +X_API bool YAP_is_blob(YAP_Term t, blob_type_t **type); +X_API bool YAP_unify_blob(YAP_Term *t, void *blob, size_t len, + blob_type_t *type); +X_API bool YAP_put_blob(YAP_Term *t, void *blob, size_t len, + blob_type_t *type); +X_API bool YAP_get_blob(YAP_Term t, void **blob, size_t *len, + blob_type_t **type); + +X_API void* YAP_blob_data(Atom a, + size_t *len, + struct YAP_blob_t **type); + +X_API void YAP_register_blob_type(blob_type_t *type); +X_API blob_type_t* YAP_find_blob_type(const char* name); +//YAP_blob_type_t* YAP_find_blob_type(Atom at); +X_API bool YAP_unregister_blob_type(blob_type_t *type); + + +#endif diff --git a/H/dglobals.h b/H/dglobals.h index a844461f7..e8a55d98d 100644 --- a/H/dglobals.h +++ b/H/dglobals.h @@ -71,6 +71,9 @@ #endif /* THREADS */ #define GLOBAL_Stream Yap_global->Stream_ +#if defined(THREADS) +#define GLOBAL_StreamDescLock Yap_global->StreamDescLock_ +#endif #define GLOBAL_argv Yap_global->argv_ #define GLOBAL_argc Yap_global->argc_ diff --git a/H/dhstruct.h b/H/dhstruct.h index 4410732d0..70c6f36ed 100644 --- a/H/dhstruct.h +++ b/H/dhstruct.h @@ -1,6 +1,6 @@ - - /* This file, dhstruct.h, was generated automatically by "yap -L misc/buildheap" - please do not update, update misc/HEAPFIELDS instead */ + + /* This file, dhstruct.h , was generated automatically by "yap -L misc/buildheap" + please do not update, update misc/HEAPFIELDS instead */ @@ -179,6 +179,7 @@ #endif #define PredGoalExpansion Yap_heap_regs->pred_goal_expansion #define PredMetaCall Yap_heap_regs->pred_meta_call +#define PredTraceMetaCall Yap_heap_regs->pred_trace_meta_call #define PredDollarCatch Yap_heap_regs->pred_dollar_catch #define PredRecordedWithKey Yap_heap_regs->pred_recorded_with_key #define PredLogUpdClause Yap_heap_regs->pred_log_upd_clause diff --git a/H/dlocals.h b/H/dlocals.h index 5d6855527..f4927ebfc 100644 --- a/H/dlocals.h +++ b/H/dlocals.h @@ -153,8 +153,12 @@ #define REMOTE_UncaughtThrow(wid) REMOTE(wid)->UncaughtThrow_ #define LOCAL_DoingUndefp LOCAL->DoingUndefp_ #define REMOTE_DoingUndefp(wid) REMOTE(wid)->DoingUndefp_ -#define LOCAL_StartLine LOCAL->StartLine_ -#define REMOTE_StartLine(wid) REMOTE(wid)->StartLine_ +#define LOCAL_StartCharCount LOCAL->StartCharCount_ +#define REMOTE_StartCharCount(wid) REMOTE(wid)->StartCharCount_ +#define LOCAL_StartLineCount LOCAL->StartLineCount_ +#define REMOTE_StartLineCount(wid) REMOTE(wid)->StartLineCount_ +#define LOCAL_StartLinePos LOCAL->StartLinePos_ +#define REMOTE_StartLinePos(wid) REMOTE(wid)->StartLinePos_ #define LOCAL_ScratchPad LOCAL->ScratchPad_ #define REMOTE_ScratchPad(wid) REMOTE(wid)->ScratchPad_ #ifdef COROUTINING diff --git a/H/hglobals.h b/H/hglobals.h index ea51a139c..64e71529c 100644 --- a/H/hglobals.h +++ b/H/hglobals.h @@ -71,6 +71,9 @@ typedef struct global_data { #endif /* THREADS */ struct stream_desc* Stream_; +#if defined(THREADS) + lockvar StreamDescLock_; +#endif char** argv_; int argc_; diff --git a/H/hlocals.h b/H/hlocals.h index ebe95e865..65b1faacd 100644 --- a/H/hlocals.h +++ b/H/hlocals.h @@ -85,7 +85,9 @@ typedef struct worker_local { yamop* ProfEnd_; int UncaughtThrow_; int DoingUndefp_; - Int StartLine_; + Int StartCharCount_; + Int StartLineCount_; + Int StartLinePos_; scratch_block ScratchPad_; #ifdef COROUTINING Term WokenGoals_; diff --git a/H/hstruct.h b/H/hstruct.h index 7aec0b933..3208a7155 100755 --- a/H/hstruct.h +++ b/H/hstruct.h @@ -1,6 +1,6 @@ - - /* This file, hstruct.h, was generated automatically by "yap -L misc/buildheap" - please do not update, update misc/HEAPFIELDS instead */ + + /* This file, hstruct.h , was generated automatically by "yap -L misc/buildheap" + please do not update, update misc/HEAPFIELDS instead */ @@ -179,6 +179,7 @@ #endif struct pred_entry *pred_goal_expansion; struct pred_entry *pred_meta_call; + struct pred_entry *pred_trace_meta_call; struct pred_entry *pred_dollar_catch; struct pred_entry *pred_recorded_with_key; struct pred_entry *pred_log_upd_clause; diff --git a/H/iatoms.h b/H/iatoms.h index 701d2a24f..118b10771 100644 --- a/H/iatoms.h +++ b/H/iatoms.h @@ -1,5 +1,5 @@ - - /* This file, iatoms.h, was generated automatically by "yap -L misc/buildatoms" + + /* This file, iatoms.h , was generated automatically by "yap -L misc/buildatoms" please do not update, update misc/ATOMS instead */ Atom3Dots = Yap_LookupAtom("..."); @@ -81,6 +81,7 @@ AtomDBTerm = Yap_LookupAtom("db_term"); AtomDBref = Yap_FullLookupAtom("$dbref"); AtomDInteger = Yap_FullLookupAtom("$integer"); + AtomDebugMeta = Yap_FullLookupAtom("$debug_meta"); AtomDebuggerInput = Yap_LookupAtom("debugger_input"); AtomDec10 = Yap_LookupAtom("dec10"); AtomDefault = Yap_LookupAtom("default"); @@ -354,6 +355,7 @@ AtomTimeoutError = Yap_LookupAtom("timeout_error"); AtomTopLevelGoal = Yap_FullLookupAtom("$top_level_goal"); AtomTopThreadGoal = Yap_FullLookupAtom("$top_thread_goal"); + AtomTraceMetaCall = Yap_FullLookupAtom("$trace_meta_call"); AtomTrail = Yap_LookupAtom("trail"); AtomTrue = Yap_LookupAtom("true"); AtomTty = Yap_LookupAtom("tty"); @@ -504,6 +506,7 @@ FunctorThreadRun = Yap_MkFunctor(AtomTopThreadGoal,2); FunctorThrow = Yap_MkFunctor(AtomThrow,1); FunctorTimeoutError = Yap_MkFunctor(AtomTimeoutError,2); + FunctorTraceMetaCall = Yap_MkFunctor(AtomTraceMetaCall,3); FunctorTypeError = Yap_MkFunctor(AtomTypeError,2); FunctorUMinus = Yap_MkFunctor(AtomMinus,1); FunctorUPlus = Yap_MkFunctor(AtomPlus,1); diff --git a/H/iglobals.h b/H/iglobals.h index 2c39c3e9f..31d2064b5 100644 --- a/H/iglobals.h +++ b/H/iglobals.h @@ -71,6 +71,9 @@ static void InitGlobal(void) { #endif /* THREADS */ +#if defined(THREADS) + INIT_LOCK(GLOBAL_StreamDescLock); +#endif diff --git a/H/ihstruct.h b/H/ihstruct.h index 758a3880d..dece3ec2d 100644 --- a/H/ihstruct.h +++ b/H/ihstruct.h @@ -1,6 +1,6 @@ - - /* This file, ihstruct.h, was generated automatically by "yap -L misc/buildheap" - please do not update, update misc/HEAPFIELDS instead */ + + /* This file, ihstruct.h , was generated automatically by "yap -L misc/buildheap" + please do not update, update misc/HEAPFIELDS instead */ @@ -179,6 +179,7 @@ #endif PredGoalExpansion = RepPredProp(PredPropByFunc(FunctorGoalExpansion,USER_MODULE)); PredMetaCall = RepPredProp(PredPropByFunc(FunctorMetaCall,PROLOG_MODULE)); + PredTraceMetaCall = RepPredProp(PredPropByFunc(FunctorTraceMetaCall,PROLOG_MODULE)); PredDollarCatch = RepPredProp(PredPropByFunc(FunctorCatch,PROLOG_MODULE)); PredRecordedWithKey = RepPredProp(PredPropByFunc(FunctorRecordedWithKey,PROLOG_MODULE)); PredLogUpdClause = RepPredProp(PredPropByFunc(FunctorDoLogUpdClause,PROLOG_MODULE)); diff --git a/H/ilocals.h b/H/ilocals.h index 6a3c3c7f7..3c96e4fdc 100755 --- a/H/ilocals.h +++ b/H/ilocals.h @@ -85,7 +85,9 @@ static void InitWorker(int wid) { REMOTE_ProfEnd(wid) = NULL; REMOTE_UncaughtThrow(wid) = FALSE; REMOTE_DoingUndefp(wid) = FALSE; - REMOTE_StartLine(wid) = 0L; + REMOTE_StartCharCount(wid) = 0L; + REMOTE_StartLineCount(wid) = 0L; + REMOTE_StartLinePos(wid) = 0L; InitScratchPad(wid); #ifdef COROUTINING REMOTE_WokenGoals(wid) = 0L; diff --git a/H/ratoms.h b/H/ratoms.h index d7a239996..7683c43ec 100644 --- a/H/ratoms.h +++ b/H/ratoms.h @@ -1,5 +1,5 @@ - - /* This file, ratoms.h, was generated automatically by "yap -L misc/buildatoms" + + /* This file, ratoms.h , was generated automatically by "yap -L misc/buildatoms" please do not update, update misc/ATOMS instead */ Atom3Dots = AtomAdjust(Atom3Dots); @@ -81,6 +81,7 @@ AtomDBTerm = AtomAdjust(AtomDBTerm); AtomDBref = AtomAdjust(AtomDBref); AtomDInteger = AtomAdjust(AtomDInteger); + AtomDebugMeta = AtomAdjust(AtomDebugMeta); AtomDebuggerInput = AtomAdjust(AtomDebuggerInput); AtomDec10 = AtomAdjust(AtomDec10); AtomDefault = AtomAdjust(AtomDefault); @@ -354,6 +355,7 @@ AtomTimeoutError = AtomAdjust(AtomTimeoutError); AtomTopLevelGoal = AtomAdjust(AtomTopLevelGoal); AtomTopThreadGoal = AtomAdjust(AtomTopThreadGoal); + AtomTraceMetaCall = AtomAdjust(AtomTraceMetaCall); AtomTrail = AtomAdjust(AtomTrail); AtomTrue = AtomAdjust(AtomTrue); AtomTty = AtomAdjust(AtomTty); @@ -504,6 +506,7 @@ FunctorThreadRun = FuncAdjust(FunctorThreadRun); FunctorThrow = FuncAdjust(FunctorThrow); FunctorTimeoutError = FuncAdjust(FunctorTimeoutError); + FunctorTraceMetaCall = FuncAdjust(FunctorTraceMetaCall); FunctorTypeError = FuncAdjust(FunctorTypeError); FunctorUMinus = FuncAdjust(FunctorUMinus); FunctorUPlus = FuncAdjust(FunctorUPlus); diff --git a/H/rglobals.h b/H/rglobals.h index 55789b3c9..f1f613f2b 100644 --- a/H/rglobals.h +++ b/H/rglobals.h @@ -71,6 +71,9 @@ static void RestoreGlobal(void) { #endif /* THREADS */ +#if defined(THREADS) + REINIT_LOCK(GLOBAL_StreamDescLock); +#endif diff --git a/H/rhstruct.h b/H/rhstruct.h index 064efb018..0731297ef 100644 --- a/H/rhstruct.h +++ b/H/rhstruct.h @@ -1,6 +1,6 @@ - - /* This file, rhstruct.h, was generated automatically by "yap -L misc/buildheap" - please do not update, update misc/HEAPFIELDS instead */ + + /* This file, rhstruct.h , was generated automatically by "yap -L misc/buildheap" + please do not update, update misc/HEAPFIELDS instead */ @@ -179,6 +179,7 @@ #endif PredGoalExpansion = PtoPredAdjust(PredGoalExpansion); PredMetaCall = PtoPredAdjust(PredMetaCall); + PredTraceMetaCall = PtoPredAdjust(PredTraceMetaCall); PredDollarCatch = PtoPredAdjust(PredDollarCatch); PredRecordedWithKey = PtoPredAdjust(PredRecordedWithKey); PredLogUpdClause = PtoPredAdjust(PredLogUpdClause); diff --git a/H/rlocals.h b/H/rlocals.h index a56db1b19..87d79f84a 100644 --- a/H/rlocals.h +++ b/H/rlocals.h @@ -87,6 +87,8 @@ static void RestoreWorker(int wid USES_REGS) { + + #ifdef COROUTINING REMOTE_WokenGoals(wid) = TermToGlobalAdjust(REMOTE_WokenGoals(wid)); REMOTE_AttsMutableList(wid) = TermToGlobalAdjust(REMOTE_AttsMutableList(wid)); diff --git a/H/tatoms.h b/H/tatoms.h index 121d93034..a52a6d357 100644 --- a/H/tatoms.h +++ b/H/tatoms.h @@ -1,5 +1,5 @@ - - /* This file, tatoms.h, was generated automatically by "yap -L misc/buildatoms" + + /* This file, tatoms.h , was generated automatically by "yap -L misc/buildatoms" please do not update, update misc/ATOMS instead */ Atom Atom3Dots_; @@ -160,6 +160,8 @@ #define AtomDBref Yap_heap_regs->AtomDBref_ Atom AtomDInteger_; #define AtomDInteger Yap_heap_regs->AtomDInteger_ + Atom AtomDebugMeta_; +#define AtomDebugMeta Yap_heap_regs->AtomDebugMeta_ Atom AtomDebuggerInput_; #define AtomDebuggerInput Yap_heap_regs->AtomDebuggerInput_ Atom AtomDec10_; @@ -706,6 +708,8 @@ #define AtomTopLevelGoal Yap_heap_regs->AtomTopLevelGoal_ Atom AtomTopThreadGoal_; #define AtomTopThreadGoal Yap_heap_regs->AtomTopThreadGoal_ + Atom AtomTraceMetaCall_; +#define AtomTraceMetaCall Yap_heap_regs->AtomTraceMetaCall_ Atom AtomTrail_; #define AtomTrail Yap_heap_regs->AtomTrail_ Atom AtomTrue_; @@ -1006,6 +1010,8 @@ #define FunctorThrow Yap_heap_regs->FunctorThrow_ Functor FunctorTimeoutError_; #define FunctorTimeoutError Yap_heap_regs->FunctorTimeoutError_ + Functor FunctorTraceMetaCall_; +#define FunctorTraceMetaCall Yap_heap_regs->FunctorTraceMetaCall_ Functor FunctorTypeError_; #define FunctorTypeError Yap_heap_regs->FunctorTypeError_ Functor FunctorUMinus_;