simplify text code by just using UF8 and allocating in trail

This commit is contained in:
Vitor Santos Costa 2016-08-15 14:54:46 -05:00
parent cc1a44c7a7
commit eb54e3e052
5 changed files with 988 additions and 1736 deletions

View File

@ -1306,7 +1306,6 @@ X_API Term YAP_NBufferToString(const char *s, size_t len) {
inp.val.c0 = s;
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_CODES | YAP_STRING_NCHARS | YAP_STRING_TRUNC;
out.sz = len;
out.max = len;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
@ -1344,7 +1343,6 @@ X_API Term YAP_NWideBufferToString(const wchar_t *s, size_t len) {
inp.val.w0 = s;
inp.type = YAP_STRING_WCHARS;
out.type = YAP_STRING_CODES | YAP_STRING_NCHARS | YAP_STRING_TRUNC;
out.sz = len;
out.max = len;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
@ -1427,7 +1425,6 @@ X_API Term YAP_NBufferToAtomList(const char *s, size_t len) {
inp.val.c0 = s;
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_ATOMS | YAP_STRING_NCHARS | YAP_STRING_TRUNC;
out.sz = len;
out.max = len;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
@ -1465,7 +1462,6 @@ X_API Term YAP_NWideBufferToAtomList(const wchar_t *s, size_t len) {
inp.val.w0 = s;
inp.type = YAP_STRING_WCHARS;
out.type = YAP_STRING_ATOMS | YAP_STRING_NCHARS | YAP_STRING_TRUNC;
out.sz = len;
out.max = len;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
@ -1487,7 +1483,6 @@ X_API Term YAP_NWideBufferToAtomDiffList(const wchar_t *s, Term t0,
inp.type = YAP_STRING_WCHARS;
out.type =
YAP_STRING_ATOMS | YAP_STRING_NCHARS | YAP_STRING_TRUNC | YAP_STRING_DIFF;
out.sz = len;
out.max = len;
out.dif = t0;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
@ -1528,7 +1523,6 @@ X_API Term YAP_NBufferToDiffList(const char *s, Term t0, size_t len) {
inp.type = YAP_STRING_CHARS;
out.type =
YAP_STRING_CODES | YAP_STRING_NCHARS | YAP_STRING_TRUNC | YAP_STRING_DIFF;
out.sz = len;
out.max = len;
out.dif = t0;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
@ -1569,7 +1563,6 @@ X_API Term YAP_NWideBufferToDiffList(const wchar_t *s, Term t0, size_t len) {
inp.type = YAP_STRING_WCHARS;
out.type =
YAP_STRING_CODES | YAP_STRING_NCHARS | YAP_STRING_TRUNC | YAP_STRING_DIFF;
out.sz = len;
out.max = len;
out.dif = t0;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))

View File

@ -744,65 +744,9 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, Term cmod USE
break;
case String_tok: /* build list on the heap */
{
Volatile char *p = (char *)LOCAL_tokptr->TokInfo;
// we may be operating under a syntax error
yap_error_number oerr = LOCAL_Error_TYPE;
LOCAL_Error_TYPE = YAP_NO_ERROR;
t = Yap_CharsToTDQ(p, cmod, enc PASS_REGS);
if (!t) {
syntax_msg("line %d: could not convert \"%s\"",LOCAL_tokptr->TokPos, (char *)LOCAL_tokptr->TokInfo);
FAIL;
}
LOCAL_Error_TYPE = oerr;
NextToken;
} break;
case WString_tok: /* build list on the heap */
{
Volatile wchar_t *p = (wchar_t *)LOCAL_tokptr->TokInfo;
// we may be operating under a syntax error
yap_error_number oerr = LOCAL_Error_TYPE;
LOCAL_Error_TYPE = YAP_NO_ERROR;
t = Yap_WCharsToTDQ(p, cmod PASS_REGS);
if (!t) {
syntax_msg("line %d: could not convert \'%S\'",LOCAL_tokptr->TokPos, (wchar_t *)LOCAL_tokptr->TokInfo);
FAIL;
}
LOCAL_Error_TYPE = oerr;
NextToken;
} break;
case BQString_tok: /* build list on the heap */
{
Volatile char *p = (char *)LOCAL_tokptr->TokInfo;
// we may be operating under a syntax error
yap_error_number oerr = LOCAL_Error_TYPE;
LOCAL_Error_TYPE = YAP_NO_ERROR;
t = Yap_CharsToTBQ(p, cmod, LOCAL_encoding PASS_REGS);
if (!t) {
syntax_msg("line %d: could not convert \'%s\"",LOCAL_tokptr->TokPos, (char *)LOCAL_tokptr->TokInfo);
FAIL;
}
LOCAL_Error_TYPE = oerr;
NextToken;
} break;
case WBQString_tok: /* build list on the heap */
{
Volatile wchar_t *p = (wchar_t *)LOCAL_tokptr->TokInfo;
t = Yap_WCharsToTBQ(p, cmod PASS_REGS);
// we may be operating under a syntax error
yap_error_number oerr = LOCAL_Error_TYPE;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!t) {
syntax_msg("line %d: could not convert \"%S\"",LOCAL_tokptr->TokPos, (wchar_t *)LOCAL_tokptr->TokInfo);
FAIL;
}
LOCAL_Error_TYPE = oerr;
NextToken;
} break;
t = LOCAL_tokptr->TokInfo;
NextToken;
break;
case Var_tok:
varinfo = (VarEntry *)(LOCAL_tokptr->TokInfo);

View File

@ -575,7 +575,7 @@ static TokEntry *AuxSpaceError__(TokEntry *p, TokEntry *l,
/* huge atom or variable, we are in trouble */
LOCAL_ErrorMessage = (char *)msg;
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK;
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
Yap_ReleasePreAllocCodeSpace((COBEADDR)TokImage);
if (p) {
p->Tok = eot_tok;
p->TokInfo = TermOutOfAuxspaceError;
@ -584,12 +584,13 @@ static TokEntry *AuxSpaceError__(TokEntry *p, TokEntry *l,
return l;
}
static void InitScannerMemory(void) {
static void * InitScannerMemory(void) {
CACHE_REGS
LOCAL_ErrorMessage = NULL;
LOCAL_Error_Size = 0;
LOCAL_ScannerStack = (char *)TR;
LOCAL_ScannerExtraBlocks = NULL;
LOCAL_ScannerStack = (char *)TR;
return (char *)TR;
}
static char *AllocScannerMemory(unsigned int size) {
@ -1624,6 +1625,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
LOCAL_ErrorMessage = "layout character \n inside quotes";
break;
}
if (ch == quote) {
ch = getchrq(inp_stream);
if (ch != quote)
@ -1661,55 +1663,49 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
} else {
*charp = '\0';
}
if (quote == '"' || quote == '`') {
if (wcharp) {
mp = AllocScannerMemory(sizeof(wchar_t) * (len + 1));
} else {
mp = AllocScannerMemory(len + 1);
}
if (mp == NULL) {
LOCAL_ErrorMessage =
"not enough heap space to read in string or quoted atom";
if (quote == '"' ) {
if (wcharp) {
t->TokInfo = Yap_WCharsToTDQ((wchar_t *)TokImage,
CurrentModule
PASS_REGS);
} else {
t->TokInfo = Yap_CharsToTDQ(TokImage, CurrentModule, LOCAL_encoding
PASS_REGS);
}
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = String_tok);
} else if (quote == '`') {
if (wcharp) {
t->TokInfo = Yap_WCharsToTBQ((wchar_t *)TokImage,
CurrentModule PASS_REGS);
} else {
t->TokInfo = Yap_CharsToTBQ(TokImage, CurrentModule,
LOCAL_encoding
PASS_REGS);
}
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = String_tok);
} else {
if (wcharp) {
t->TokInfo = Unsigned(Yap_LookupWideAtom((wchar_t *)TokImage));
} else {
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
}
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = eot_tok);
t->TokInfo = TermOutOfHeapError;
return l;
}
if (wcharp) {
wcscpy((wchar_t *)mp, (wchar_t *)TokImage);
} else {
strcpy(mp, TokImage);
}
t->TokInfo = Unsigned(mp);
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
if (quote == '"') {
if (wcharp) {
t->Tok = Ord(kind = WString_tok);
} else {
t->Tok = Ord(kind = String_tok);
}
} else {
if (wcharp) {
t->Tok = Ord(kind = WBQString_tok);
} else {
t->Tok = Ord(kind = BQString_tok);
}
}
} else {
if (wcharp) {
t->TokInfo = Unsigned(Yap_LookupWideAtom((wchar_t *)TokImage));
} else {
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
}
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = Name_tok);
if (ch == '(')
solo_flag = false;
t->Tok = Ord(kind = Name_tok);
if (ch == '(')
solo_flag = false;
}
break;
break;
case BS:
if (ch == '\0') {
@ -2046,9 +2042,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->TokInfo = TermEof;
}
#if DEBUG
if (GLOBAL_Option[2])
fprintf(stderr, "[Token %d %s]", Ord(kind),
Yap_tokRep(t, inp_stream->encoding));
if (GLOBAL_Option[2]) {
static int n;
if (n == 975) jmp_deb(2);
fprintf(stderr, "[Token %d %s %d]", Ord(kind),
Yap_tokRep(t, inp_stream->encoding),n++);
}
#endif
if (LOCAL_ErrorMessage) {
/* insert an error token to inform the system of what happened */
@ -2069,10 +2068,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return (l);
}
int vsc_count;
void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable,
VarEntry *anonvartable) {
CACHE_REGS
struct scanner_extra_alloc *ptr = LOCAL_ScannerExtraBlocks;
struct scanner_extra_alloc *ptr = LOCAL_ScannerExtraBlocks;
while (ptr) {
struct scanner_extra_alloc *next = ptr->next;
free(ptr);
@ -2085,6 +2086,7 @@ void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable,
free(LOCAL_CommentsBuff);
LOCAL_CommentsBuff = NULL;
}
LOCAL_ScannerStack = NULL;
LOCAL_CommentsBuffLim = 0;
}

2444
C/text.c

File diff suppressed because it is too large Load Diff

View File

@ -175,8 +175,13 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) {
utf8proc_ssize_t l = utf8proc_iterate(pt, -1, &b);
if (b == 0)
return rc;
pt += l;
rc += l;
else if (b > 0) {
pt += l;
rc += l;
} else {
pt++;
}
}
return rc;
}
@ -298,7 +303,8 @@ typedef enum {
YAP_STRING_WITH_BUFFER = 0x40000, // output on existing buffer
YAP_STRING_MALLOC = 0x80000, // output on malloced buffer
YAP_STRING_UPCASE = 0x100000, // output on malloced buffer
YAP_STRING_DOWNCASE = 0x200000 // output on malloced buffer
YAP_STRING_DOWNCASE = 0x200000, // output on malloced buffer
YAP_STRING_IN_TMP = 0x200000 // temporary space has been allocated
} enum_seq_type_t;
typedef UInt seq_type_t;
@ -325,7 +331,6 @@ typedef struct text_cvt {
seq_type_t type;
seq_val_t val;
Term mod; // optional
size_t sz; // fixed sz, or -1
Term dif; // diff-list, usually TermNil
size_t max; // max_size
encoding_t enc;
@ -385,14 +390,14 @@ static inline seq_type_t mod_to_bqtype(Term mod USES_REGS) {
// the routines
extern void *Yap_readText(void *buf, seq_tv_t *inp, encoding_t *enc,
int *minimal, size_t *lengp USES_REGS);
extern bool write_Text(void *inp, seq_tv_t *out, encoding_t enc, int minimal,
extern unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp
USES_REGS);
extern bool write_Text(unsigned char *inp, seq_tv_t *out,
size_t leng USES_REGS);
extern bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS);
extern void *Yap_Concat_Text(int n, seq_tv_t inp[], seq_tv_t *out USES_REGS);
extern void *Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
encoding_t encv[], seq_tv_t outv[] USES_REGS);
extern bool Yap_Concat_Text(int n, seq_tv_t inp[], seq_tv_t *out USES_REGS);
extern bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
seq_tv_t outv[] USES_REGS);
// user friendly interface
@ -675,7 +680,6 @@ static inline Atom Yap_CharsToAtom(const char *s, encoding_t enc USES_REGS) {
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.enc = enc;
inp.type = YAP_STRING_CHARS;
out.val.uc = NULL;
@ -690,7 +694,6 @@ static inline Term Yap_CharsToListOfAtoms(const char *s,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.enc = enc;
inp.type = YAP_STRING_CHARS;
out.val.uc = NULL;
@ -705,7 +708,6 @@ static inline Term Yap_CharsToListOfCodes(const char *s,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.enc = enc;
inp.type = YAP_STRING_CHARS;
out.val.uc = NULL;
@ -719,7 +721,6 @@ static inline Term Yap_UTF8ToListOfCodes(const char *s USES_REGS) {
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.type = YAP_STRING_CHARS;
inp.enc = ENC_ISO_UTF8;
out.type = YAP_STRING_CODES;
@ -732,7 +733,6 @@ static inline Atom Yap_UTF8ToAtom(const unsigned char *s USES_REGS) {
seq_tv_t inp, out;
inp.val.uc0 = s;
inp.sz = 0;
inp.type = YAP_STRING_CHARS;
inp.enc = ENC_ISO_UTF8;
out.type = YAP_STRING_ATOM;
@ -747,7 +747,6 @@ static inline Term Yap_CharsToDiffListOfCodes(const char *s, Term tail,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.enc = enc;
inp.type = YAP_STRING_CHARS;
out.val.uc = NULL;
@ -763,7 +762,6 @@ static inline Term Yap_UTF8ToDiffListOfCodes(const char *s,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.type = YAP_STRING_CHARS;
inp.enc = ENC_ISO_UTF8;
out.type = YAP_STRING_DIFF | YAP_STRING_CODES;
@ -779,7 +777,6 @@ static inline Term Yap_WCharsToDiffListOfCodes(const wchar_t *s,
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = 0;
inp.type = YAP_STRING_WCHARS;
out.type = YAP_STRING_DIFF | YAP_STRING_CODES;
out.val.uc = NULL;
@ -794,7 +791,6 @@ static inline Term Yap_CharsToString(const char *s, encoding_t enc USES_REGS) {
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.enc = enc;
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_STRING;
@ -808,7 +804,6 @@ static inline char *Yap_AtomToUTF8Text(Atom at, const char *s USES_REGS) {
seq_tv_t inp, out;
inp.val.a = at;
inp.sz = 0;
inp.type = YAP_STRING_ATOM;
out.type = YAP_STRING_CHARS;
out.val.uc = NULL;
@ -829,7 +824,6 @@ static inline Term Yap_CharsToTDQ(const char *s, Term mod,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.type = YAP_STRING_CHARS;
inp.mod = mod;
inp.enc = enc;
@ -847,7 +841,6 @@ static inline Term Yap_CharsToTBQ(const char *s, Term mod,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = 0;
inp.type = YAP_STRING_CHARS;
inp.mod = mod;
inp.enc = enc;
@ -944,7 +937,7 @@ static inline Term Yap_ListToAtomic(Term t0 USES_REGS) {
inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | YAP_STRING_TERM;
out.val.uc = NULL;
out.type = YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
YAP_STRING_BIG | YAP_STRING_TERM;
YAP_STRING_BIG ;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
return out.val.t;
@ -1028,7 +1021,6 @@ static inline Atom Yap_NCharsToAtom(const char *s, size_t len,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = len;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
inp.enc = enc;
out.type = YAP_STRING_ATOM;
@ -1058,7 +1050,6 @@ static inline Term Yap_NCharsToListOfCodes(const char *s, size_t len,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = len;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
inp.enc = enc;
out.type = YAP_STRING_CODES;
@ -1073,7 +1064,6 @@ static inline Term Yap_NCharsToString(const char *s, size_t len,
seq_tv_t inp, out;
inp.val.c0 = s;
inp.sz = len;
inp.enc = enc;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
out.type = YAP_STRING_STRING;
@ -1089,7 +1079,6 @@ static inline Term Yap_NCharsToTDQ(const char *s, size_t len, encoding_t enc,
inp.val.c0 = s;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
inp.sz = len;
inp.enc = enc;
inp.mod = mod;
out.type = mod_to_type(mod PASS_REGS);
@ -1107,9 +1096,9 @@ static inline Term Yap_NCharsToTBQ(const char *s, size_t len, encoding_t enc,
inp.val.c0 = s;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
inp.sz = len;
inp.enc = enc;
inp.mod = mod;
out.type = mod_to_bqtype(mod PASS_REGS);
out.max = len;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
@ -1167,7 +1156,6 @@ static inline Atom Yap_NWCharsToAtom(const wchar_t *s, size_t len USES_REGS) {
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = len;
inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
out.type = YAP_STRING_ATOM;
out.max = len;
@ -1181,7 +1169,6 @@ static inline Term Yap_NWCharsToListOfAtoms(const wchar_t *s,
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = len;
inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
out.type = YAP_STRING_ATOMS;
out.max = len;
@ -1195,7 +1182,6 @@ static inline Term Yap_NWCharsToListOfCodes(const wchar_t *s,
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = len;
inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
out.type = YAP_STRING_CODES;
out.val.uc = NULL;
@ -1209,7 +1195,6 @@ static inline Term Yap_NWCharsToString(const wchar_t *s, size_t len USES_REGS) {
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = len;
inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
out.val.uc = NULL;
out.type = YAP_STRING_STRING;
@ -1221,7 +1206,6 @@ static inline Term Yap_NWCharsToString(const wchar_t *s, size_t len USES_REGS) {
static inline Atom Yap_StringToAtom(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING;
out.val.uc = NULL;
@ -1233,7 +1217,6 @@ static inline Atom Yap_StringToAtom(Term t0 USES_REGS) {
static inline Atom Yap_StringSWIToAtom(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |
@ -1247,11 +1230,10 @@ static inline Atom Yap_StringSWIToAtom(Term t0 USES_REGS) {
static inline size_t Yap_StringToAtomic(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING;
out.type = YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
YAP_STRING_BIG | YAP_STRING_TERM;
YAP_STRING_BIG ;
out.val.uc = NULL;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
@ -1260,7 +1242,6 @@ static inline size_t Yap_StringToAtomic(Term t0 USES_REGS) {
static inline size_t Yap_StringToLength(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING;
out.type = YAP_STRING_LENGTH;
@ -1272,7 +1253,6 @@ static inline size_t Yap_StringToLength(Term t0 USES_REGS) {
static inline size_t Yap_StringToListOfAtoms(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING;
out.type = YAP_STRING_ATOMS;
@ -1284,7 +1264,6 @@ static inline size_t Yap_StringToListOfAtoms(Term t0 USES_REGS) {
static inline size_t Yap_StringSWIToListOfAtoms(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.sz = 0;
inp.val.t = t0;
inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |
@ -1299,7 +1278,6 @@ static inline size_t Yap_StringSWIToListOfAtoms(Term t0 USES_REGS) {
static inline size_t Yap_StringToListOfCodes(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t0;
inp.sz = 0;
inp.type = YAP_STRING_STRING;
out.type = YAP_STRING_CODES;
out.val.uc = NULL;
@ -1324,7 +1302,6 @@ static inline size_t Yap_StringSWIToListOfCodes(Term t0 USES_REGS) {
static inline Term Yap_StringToNumber(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t0;
inp.sz = 0;
inp.type = YAP_STRING_STRING;
out.type =
YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
@ -1384,8 +1361,7 @@ static inline Term Yap_UTF8ToString(const char *s USES_REGS) {
static inline Term Yap_WCharsToListOfCodes(const wchar_t *s USES_REGS) {
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = 0;
inp.type = YAP_STRING_WCHARS;
inp.type = YAP_STRING_WCHARS;
out.val.uc = NULL;
out.type = YAP_STRING_CODES;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
@ -1398,7 +1374,7 @@ static inline Term Yap_WCharsToTDQ(wchar_t *s, Term mod USES_REGS) {
inp.val.w0 = s;
inp.type = YAP_STRING_WCHARS;
inp.sz = 0;
inp.mod = mod;
out.type = mod_to_type(mod PASS_REGS);
out.val.uc = NULL;
@ -1414,7 +1390,6 @@ static inline Term Yap_WCharsToTBQ(wchar_t *s, Term mod USES_REGS) {
inp.val.w = s;
inp.type = YAP_STRING_WCHARS;
inp.sz = 0;
inp.mod = mod;
out.type = mod_to_bqtype(mod PASS_REGS);
out.val.uc = NULL;
@ -1428,7 +1403,6 @@ static inline Term Yap_WCharsToTBQ(wchar_t *s, Term mod USES_REGS) {
static inline Term Yap_WCharsToString(const wchar_t *s USES_REGS) {
seq_tv_t inp, out;
inp.val.w0 = s;
inp.sz = 0;
inp.type = YAP_STRING_WCHARS;
out.type = YAP_STRING_STRING;
out.val.uc = NULL;
@ -1441,10 +1415,8 @@ static inline Atom Yap_ConcatAtoms(Term t1, Term t2 USES_REGS) {
seq_tv_t inpv[2], out;
inpv[0].val.t = t1;
inpv[0].type = YAP_STRING_ATOM;
inpv[0].sz = 0;
inpv[1].val.t = t2;
inpv[1].type = YAP_STRING_ATOM;
inpv[1].sz = 0;
out.type = YAP_STRING_ATOM;
out.val.uc = NULL;
if (!Yap_Concat_Text(2, inpv, &out PASS_REGS))
@ -1457,11 +1429,9 @@ static inline Atom Yap_ConcatAtomics(Term t1, Term t2 USES_REGS) {
inpv[0].val.t = t1;
inpv[0].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
inpv[0].sz = 0;
inpv[1].val.t = t2;
inpv[1].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
inpv[1].sz = 0;
out.type = YAP_STRING_ATOM;
out.val.uc = NULL;
if (!Yap_Concat_Text(2, inpv, &out PASS_REGS))
@ -1473,10 +1443,8 @@ static inline Term Yap_ConcatStrings(Term t1, Term t2 USES_REGS) {
seq_tv_t inpv[2], out;
inpv[0].val.t = t1;
inpv[0].type = YAP_STRING_STRING;
inpv[0].sz = 0;
inpv[1].val.t = t2;
inpv[1].type = YAP_STRING_STRING;
inpv[1].sz = 0;
out.type = YAP_STRING_STRING;
if (!Yap_Concat_Text(2, inpv, &out PASS_REGS))
@ -1492,12 +1460,9 @@ static inline Atom Yap_SpliceAtom(Term t1, Atom ats[], size_t cut,
cuts[1] = max;
inp.type = YAP_STRING_ATOM;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_ATOM;
outv[0].sz = 0;
outv[1].type = YAP_STRING_ATOM;
outv[1].sz = 0;
if (!Yap_Splice_Text(2, cuts, &inp, (encoding_t *)NULL, outv PASS_REGS))
if (!Yap_Splice_Text(2, cuts, &inp, outv PASS_REGS))
return (Atom)NULL;
ats[0] = outv[0].val.a;
ats[1] = outv[1].val.a;
@ -1508,14 +1473,11 @@ static inline Atom Yap_SubtractHeadAtom(Term t1, Term th USES_REGS) {
seq_tv_t outv[2], inp;
inp.type = YAP_STRING_ATOM;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_ATOM;
outv[0].val.t = th;
outv[0].sz = 0;
outv[1].type = YAP_STRING_ATOM;
outv[1].val.t = 0;
outv[1].sz = 0;
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp, (encoding_t *)NULL,
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp,
outv PASS_REGS))
return (Atom)NULL;
return outv[1].val.a;
@ -1525,13 +1487,11 @@ static inline Atom Yap_SubtractTailAtom(Term t1, Term th USES_REGS) {
seq_tv_t outv[2], inp;
inp.type = YAP_STRING_ATOM;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_ATOM;
outv[0].val.t = 0;
outv[0].sz = 0;
outv[1].type = YAP_STRING_ATOM;
outv[1].val.t = th;
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp, (encoding_t *)NULL,
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp,
outv PASS_REGS))
return (Atom)NULL;
return outv[0].val.a;
@ -1543,13 +1503,11 @@ static inline Term Yap_SpliceString(Term t1, Term ts[], size_t cut,
size_t cuts[2];
inp.type = YAP_STRING_STRING;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_STRING;
outv[1].type = YAP_STRING_STRING;
outv[1].sz = 0;
cuts[0] = cut;
cuts[1] = max;
if (!Yap_Splice_Text(2, cuts, &inp, (encoding_t *)NULL, outv PASS_REGS))
if (!Yap_Splice_Text(2, cuts, &inp, outv PASS_REGS))
return 0L;
ts[0] = outv[0].val.t;
ts[1] = outv[1].val.t;
@ -1560,14 +1518,11 @@ static inline Term Yap_SubtractHeadString(Term t1, Term th USES_REGS) {
seq_tv_t outv[2], inp;
inp.type = YAP_STRING_STRING;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_STRING;
outv[0].val.t = th;
outv[0].sz = 0;
outv[1].type = YAP_STRING_STRING;
outv[1].val.t = 0;
outv[1].sz = 0;
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp, (encoding_t *)NULL,
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp,
outv PASS_REGS))
return 0L;
return outv[1].val.t;
@ -1577,13 +1532,11 @@ static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) {
seq_tv_t outv[2], inp;
inp.type = YAP_STRING_STRING;
inp.val.t = t1;
inp.sz = 0;
outv[0].type = YAP_STRING_STRING;
outv[0].val.t = 0;
outv[0].sz = 0;
outv[1].type = YAP_STRING_STRING;
outv[1].val.t = th;
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp, (encoding_t *)NULL,
if (!Yap_Splice_Text(2, (size_t *)NULL, &inp,
outv PASS_REGS))
return 0L;
return outv[0].val.t;