diff --git a/C/arith0.c b/C/arith0.c index 3beb40cf0..3ce6122cb 100644 --- a/C/arith0.c +++ b/C/arith0.c @@ -18,8 +18,72 @@ static char SccsId[] = "%W% %G%"; #endif -/* - * This file implements arithmetic operations +/** + @file arith0.c + + @defgroup arithmetic_operators Arithmetic Functions + @ingroup arithmetic + + YAP implements several arithmetic functions. Arithmetic expressions + in YAP may use the following operators: + + - pi [ISO]

@anchor pi_0 + + An approximation to the value of pi, that is, the ratio of a circle's circumference to its diameter. + + - e

@anchor e_0 + + Euler's number, the base of the natural logarithms. + + - epsilon

@anchor epsilon_0 + + The difference between the float `1.0` and the next largest floating point number. + + - inf

@anchor inf_0 + + Infinity according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode. + + Note also that YAP supports `+inf` and `-inf` + + - nan (not a number)

@anchor nan_0 + + Not-a-number according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode. + + - random

@anchor random_0 + + A "random" floating point number between 0 and 1. + + - cputime

@anchor cputime_0 + + CPU time since YAP was invoked, in seconds. + + - heapused

@anchor heapused_0 + + Heap (data-base) space used, in bytes. + + - local

@anchor local_0 + + Local stack in use, in bytes + + - $b

@anchor b_0 + + current choicepoint + + - $env

@anchor env_0 + + Environment + + - $tr

@anchor tr_0 + + Trail in use + + - $free_stack

@anchor free_stack_0 + + Amount of free stack space, that is, free space between global and local stacks. + + - global

@anchor global_0 + + Global stack in use, in bytes. * */ @@ -89,7 +153,7 @@ eval0(Int fi) { } case op_nan: { -#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */ +#ifdef _MSC_VER /* Microsoft's Visual C++ Compiexp( _X_) [ISO]

@anchor exp_1 + + Natural exponential. + + - log( _X_) [ISO]

@anchor log_1 + + Natural logarithm. + + - log10( _X_)

@anchor log10_1 + + Decimal logarithm. + + - sqrt( _X_) [ISO]

@anchor sqrt_1 + + Square root. + + - sin( _X_) [ISO]

@anchor sin_1 + + Sine. + + - cos( _X_) [ISO]

@anchor cos_1 + + Cosine. + + - tan( _X_) [ISO]

@anchor tan_1 + + Tangent. + + - asin( _X_) [ISO]

@anchor asin_1 + + Arc sine. + + - acos( _X_) [ISO]

@anchor acos_1 + + Arc cosine. + + - atan( _X_) [ISO]

@anchor atan_1 + + Arc tangent. + + - sinh( _X_)

@anchor sinh_1 + + Hyperbolic sine. + + - cosh( _X_)

@anchor cosh_1 + + Hyperbolic cosine. + + - tanh( _X_)

@anchor tanh_1 + + Hyperbolic tangent. + + - asinh( _X_)

@anchor asinh_1 + + Hyperbolic arc sine. + + - acosh( _X_)

@anchor acosh_1 + + Hyperbolic arc cosine. + + - atanh( _X_)

@anchor atanh_1 + + Hyperbolic arc tangent. + + - lgamma( _X_)

@anchor lgamma_1 + + Logarithm of gamma function. + + - erf( _X_)

@anchor erf_1 + + Gaussian error function. + + - erfc( _X_)

@anchor erfc_1 + + Complementary gaussian error function. + + - random( _X_) [ISO]

@anchor random_1_op + + An integer random number between 0 and _X_. + + In `iso` language mode the argument must be a floating + point-number, the result is an integer and it the float is equidistant + it is rounded up, that is, to the least integer greater than _X_. + + - integer( _X_)

@anchor integer_1_op + + If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an + integer, the value of _X_. + + - float( _X_) [ISO]

@anchor float_1_op + + If _X_ evaluates to an integer, the corresponding float, else the float itself. + + - float_fractional_part( _X_) [ISO]

@anchor float_fractional_part_1 + + The fractional part of the floating point number _X_, or `0.0` if _X_ is an integer. In the `iso` language mode, _X_ must be an integer. + + - float_integer_part( _X_) [ISO]

@anchor float_integer_part_1 + + The float giving the integer part of the floating point number _X_, or _X_ if _X_ is an integer. In the `iso` language mode, _X_ must be an integer. + + - abs( _X_) [ISO]

@anchor abs_1 + + The absolute value of _X_. + + - ceiling( _X_) [ISO]

@anchor ceiling_1 + + The integer that is the smallest integral value not smaller than _X_. + + In `iso` language mode the argument must be a floating point-number and the result is an integer. + + - floor( _X_) [ISO]

@anchor floor_1 + + The integer that is the greatest integral value not greater than _X_. + + In `iso` language mode the argument must be a floating + point-number and the result is an integer. + + - round( _X_) [ISO]

@anchor round_1 + + The nearest integral value to _X_. If _X_ is equidistant to two integers, it will be rounded to the closest even integral value. + + In `iso` language mode the argument must be a floating point-number, the result is an integer and it the float is equidistant it is rounded up, that is, to the least integer greater than _X_. + + - sign( _X_) [ISO]

@anchor sign_1 + + Return 1 if the _X_ evaluates to a positive integer, 0 it if evaluates to 0, and -1 if it evaluates to a negative integer. If _X_ + evaluates to a floating-point number return 1.0 for a positive _X_, 0.0 for 0.0, and -1.0 otherwise. + + - truncate( _X_) [ISO]

@anchor truncate_1 + + The integral value between _X_ and 0 closest to _X_. + + - rational( _X_)

@anchor rational_1_op + + Convert the expression _X_ to a rational number or integer. The function returns the input on integers and rational numbers. For + floating point numbers, the returned rational number exactly represents + the float. As floats cannot exactly represent all decimal numbers the + results may be surprising. In the examples below, doubles can represent + `0.25` and the result is as expected, in contrast to the result of + `rational(0.1)`. The function `rationalize/1` gives a more + intuitive result. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog +?- A is rational(0.25). + +A is 1 rdiv 4 +?- A is rational(0.1). +A = 3602879701896397 rdiv 36028797018963968 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + - rationalize( _X_)

@anchor rationalize_1 + + Convert the expression _X_ to a rational number or integer. The function is + similar to [rational/1](@ref rational_1), but the result is only accurate within the + rounding error of floating point numbers, generally producing a much + smaller denominator. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog +?- A is rationalize(0.25). + +A = 1 rdiv 4 +?- A is rationalize(0.1). + +A = 1 rdiv 10 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + - \\ _X_ [ISO]

+ + Integer bitwise negation. + + - msb( _X_)

@anchor msb_1 + + The most significant bit of the non-negative integer _X_. + + - lsb( _X_)

@anchor lsb_1 + + The least significant bit of the non-negative integer _X_. + + - popcount( _X_)

@anchor popcount_1 + + The number of bits set to `1` in the binary representation of the non-negative integer _X_. + + - [ _X_]

+ + Evaluates to _X_ for expression _X_. Useful because character +strings in Prolog are lists of character codes. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog} +X is Y*10+C-"0" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +is the same as + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog} +X is Y*10+C-[48]. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +which would be evaluated as: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog} +X is Y*10+C-48. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +*/ #include "Yap.h" #include "Yatom.h" @@ -694,6 +896,7 @@ eval1(Int fi, Term t USES_REGS) { RERROR(); } } + /// end of switch RERROR(); } diff --git a/C/arith2.c b/C/arith2.c index 08d8d075d..c5d76b4bc 100644 --- a/C/arith2.c +++ b/C/arith2.c @@ -18,10 +18,111 @@ static char SccsId[] = "%W% %G%"; #endif -/* - * This file implements unary arithmetic operations in YAP - * - */ +/** + + @file arith2.c + + @addtogroup arithmetic_operators + +These are the binary numeric operators currently supported by YAP. + + - _X_+ _Y_ [ISO]

+ + Sum. + + - _X_- _Y_ [ISO]

+ + Difference. + + - _X_\* _Y_ [ISO]

+ + Product. + + - _X_/ _Y_ [ISO]

+ + Quotient. + + - _X_// _Y_ [ISO]

+ + Integer quotient. + + - _X_ mod _Y_ [ISO]

@anchor mod_2 + + Integer module operator, always positive. + + - _X_ rem _Y_ [ISO]

@anchor rem_2 + + Integer remainder, similar to `mod` but always has the same sign as `X`. + + - _X_ div _Y_ [ISO]

@anchor div_2 + + Integer division, as if defined by `( _X_ - _X_ mod _Y_)// _Y_`. + + - max( _X_, _Y_) [ISO]

@anchor max_2 + + The greater value of _X_ and _Y_. + + - min( _X_, _Y_) [ISO]

@anchor min_2 + + The lesser value of _X_ and _Y_. + + - _X_ ^ _Y_ [ISO]

+ + _X_ raised to the power of _Y_, (from the C-Prolog syntax). + + - exp( _X_, _Y_)

@anchor exp_2 + + _X_ raised to the power of _Y_, (from the Quintus Prolog syntax). + + - _X_ \*\* _Y_ [ISO]

+ + _X_ raised to the power of _Y_ (from ISO). + + - _X_ /\\ _Y_ [ISO]

+ + Integer bitwise conjunction. + + - _X_ \\/ _Y_ [ISO]

+ + Integer bitwise disjunction. + + - _X_ # _Y_

+ + Integer bitwise exclusive disjunction. + + - _X_ \>\< _Y_

+ + Integer bitwise exclusive disjunction. + + - xor( _X_ , _Y_) [ISO]

@anchor xor_2 + + Integer bitwise exclusive disjunction. + + - _X_ \<\< _Y_

+ + Integer bitwise left logical shift of _X_ by _Y_ places. + + - _X_ \>\> _Y_ [ISO]

+ + Integer bitwise right logical shift of _X_ by _Y_ places. + + - gcd( _X_, _Y_)

@anchor gcd_2 + + The greatest common divisor of the two integers _X_ and _Y_. + + - atan( _X_, _Y_)

@anchor atan_2 + + Four-quadrant arc tangent. Also available as `atan2/2`. + + - atan2( _X_, _Y_) [ISO]

@anchor atan2_2 + + Four-quadrant arc tangent. + + - _X_ rdiv _Y_ [ISO]

@anchor rdiv_2 + + Rational division. + +*/ #include "Yap.h" #include "Yatom.h" diff --git a/C/cdmgr.c b/C/cdmgr.c index 6d6288063..2754ff0af 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1998,7 +1998,6 @@ static void expand_consult( void ) LOCAL_ConsultLow = new_cl; } -/* p was already locked */ static int not_was_reconsulted(PredEntry *p, Term t, int mode) { @@ -6458,7 +6457,6 @@ p_nth_instance( USES_REGS1 ) } - void Yap_InitCdMgr(void) { diff --git a/C/cmppreds.c b/C/cmppreds.c index f48d87c44..0ead85144 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -14,6 +14,10 @@ * comments: comparing two prolog terms * * * *************************************************************************/ +/// @file cmppreds.c + + + #ifdef SCCS static char SccsId[] = "%W% %G%"; #endif @@ -647,6 +651,17 @@ a_cmp(Term t1, Term t2 USES_REGS) } } +/** + + @defgroup arithmetic_cmps Arithmetic Comparison Predicates + @ingroup arithmetic + + Comparison of Numeric Expressions. Both arguments must be valid ground expressions at time of call. + + @{ +*/ + + Int Yap_acmp(Term t1, Term t2 USES_REGS) { @@ -667,6 +682,15 @@ p_acomp( USES_REGS1 ) return out; } +/** + @class arith_eq_2 + @brief =:=/2: Equality of arithmetic expressions + + + _X_ =:= + _Y_ [ISO]

@anchor ar_eq_2 + + + The value of the expression _X_ is less than the value of expression _Y_. + */ static Int a_eq(Term t1, Term t2) { @@ -701,6 +725,15 @@ a_eq(Term t1, Term t2) return out == 0; } +/** + @class arith_dif_2 + @brief =\\=/2: Difference of arithmetic expressions + + + _X_ =\\= + _Y_ [ISO]

@anchor ar_dif_2 + + + The value of the expression _X_ is different from the value of expression _Y_. + */ static Int a_dif(Term t1, Term t2) { @@ -710,6 +743,16 @@ a_dif(Term t1, Term t2) return out != 0; } +/** + @class arith_gt_2 + @brief \>/2: Greater than arithmetic expressions + + + _X_ \> + _Y_ [ISO]

@anchor qQlg_2 + + + The value of the expression _X_ is less than or equal to the value + of expression _Y_. +*/ static Int a_gt(Term t1, Term t2) { /* A > B */ @@ -719,6 +762,16 @@ a_gt(Term t1, Term t2) return out > 0; } +/** + @class arith_ge_2 + @brief \>=/2: Greater than or equal to arithmetic expressions + + + _X_ \>= + _Y_ [ISO]

@anchor gGqQ_2 + + + The value of the expression _X_ is greater than or equal to the + value of expression _Y_. +*/ static Int a_ge(Term t1, Term t2) { /* A >= B */ @@ -728,6 +781,16 @@ a_ge(Term t1, Term t2) return out >= 0; } +/** + @class arith_lt_2 + @brief \+ _X_ \< + _Y_ [ISO]

@anchor sS_2 + + + The value of the expression _X_ is less than the value of expression + _Y_. +*/ static Int a_lt(Term t1, Term t2) { /* A < B */ @@ -737,6 +800,17 @@ a_lt(Term t1, Term t2) return out < 0; } +/** + * + @class arith_le_2 + @brief =\+ _X_ =\< + _Y_ [ISO]

@anchor qQsS_2 + + + The value of the expression _X_ is less than or equal to the value + of expression _Y_. +*/ static Int a_le(Term t1, Term t2) { /* A <= B */ @@ -746,6 +820,7 @@ a_le(Term t1, Term t2) return out <= 0; } +/// @} static Int a_noteq(Term t1, Term t2) diff --git a/C/eval.c b/C/eval.c index cb1a46143..25b5b24a1 100644 --- a/C/eval.c +++ b/C/eval.c @@ -18,10 +18,16 @@ static char SccsId[] = "%W% %G%"; #endif -/* - * This file implements arithmetic operations - * - */ +/** + @file eval.c + + @defgroup arithmetic_preds Arithmetic Predicates + @ingroup arithmetic + + @{ +*/ + + #include "Yap.h" #include "Yatom.h" #include "YapHeap.h" @@ -184,6 +190,23 @@ BEAM_is(void) #endif +/** + @class is_2 + @anchor is_2 + @brief evaluation of arithmetic expressions + + ? _X_:number is + _Y_:ground is det + + This predicate succeeds iff the result of evaluating the expression + _Y_ unifies with _X_. This is the predicate normally used to + perform evaluation of arithmetic expressions: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +X is 2+3*4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + succeeds with `X = 14`. + +*/ + static Int p_is( USES_REGS1 ) { /* X is Y */ @@ -204,6 +227,16 @@ p_is( USES_REGS1 ) return Yap_unify_constant(ARG1,out); } +/** + @class isnan_1 + @anchor isnan_1 + @brief True if _X_ is not a number + + isnan(? _X_:float) is det + + Interface to the IEE754 `isnan` test. +*/ + static Int p_isnan( USES_REGS1 ) { /* X is Y */ @@ -232,6 +265,17 @@ p_isnan( USES_REGS1 ) return isnan(FloatOfTerm(out)); } +/** + @class isinf_1 + @anchor isinf_1 + @brief True if _X_ is infinity + + isnan(? _X_:float) is det + + Interface to the IEE754 `isinf` test. +*/ + + static Int p_isinf( USES_REGS1 ) { /* X is Y */ @@ -260,6 +304,18 @@ p_isinf( USES_REGS1 ) return isinf(FloatOfTerm(out)); } +/** + @class logsum_3 + @anchor logsum_3 + @brief sum of two logarithms + + logsum(+ _Log1_, + _Log2_, - _Out_ ) is det + +True if _Log1_ is the logarithm of the positive number _A1_, + _Log2_ is the logarithm of the positive number _A2_, and + _Out_ is the logarithm of the sum of the numbers _A1_ and + _A2_. Useful in probability computation. +*/ static Int p_logsum( USES_REGS1 ) { /* X is Y */ @@ -391,6 +447,25 @@ static Int cont_between( USES_REGS1 ) } } +/** + @class between_3 + @anchor between_3 + @brief sequence of numbers + + between(+ _Low_:int, + _High_:int, ? _Value_:int) is nondet + + _Low_ and _High_ are integers, _High_ \>= _Low_. If + _Value_ is an integer, _Low_ =\< _Value_ + =\< _High_. When _Value_ is a variable it is successively + bound to all integers between _Low_ and _High_. If + _High_ is inf or infinite [between/3](@ref between_3) is true iff + _Value_ \>= _Low_, a feature that is particularly interesting + for generating integers from a certain value. + + @} + +*/ + static Int init_between( USES_REGS1 ) { diff --git a/C/iopreds.c b/C/iopreds.c index 305ace4a8..fdd148fe7 100755 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -553,6 +553,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd) } else { Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); rd->varnames = 0; + rd->singles = 0; return Yap_unify_constant( Yap_GetFromSlot( t0 PASS_REGS), MkAtomTerm (AtomEof)); } } @@ -636,7 +637,6 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd) return FALSE; } - if (rd->variables) { while (TRUE) { CELL *old_H = HR; @@ -680,8 +680,15 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd) TR = old_TR; } } - if (!Yap_unify(v, Yap_GetFromSlot( rd->singles PASS_REGS))) - return FALSE; + if (rd->singles == 1) { + if (IsPairTerm(v)) + rd->singles = Yap_InitSlot( v PASS_REGS); + else + rd->singles = FALSE; + } else if (rd->singles) { + if (!Yap_unify( rd->singles, Yap_GetFromSlot( v PASS_REGS ))) + return FALSE; + } } Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); return TRUE; @@ -871,6 +878,65 @@ p_float_format( USES_REGS1 ) return TRUE; } + +static Int +p_style_checker( USES_REGS1 ) +{ + Term t = Deref( ARG1 ); + LD_FROM_REGS + + if (IsVarTerm(t)) { + Term t = TermNil; + if ( debugstatus.styleCheck & LONGATOM_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomAtom), t ); + } + if ( debugstatus.styleCheck & SINGLETON_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomSingleton), t ); + } + if ( debugstatus.styleCheck & MULTITON_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomVarBranches), t ); + } + if ( debugstatus.styleCheck & DISCONTIGUOUS_STYLE) { + t = MkPairTerm( MkAtomTerm(AtomDiscontiguous), t ); + } + if ( debugstatus.styleCheck & NOEFFECT_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomNoEffect), t ); + } + if ( debugstatus.styleCheck & CHARSET_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomCharset), t ); + } + if ( debugstatus.styleCheck & MULTIPLE_CHECK) { + t = MkPairTerm( MkAtomTerm(AtomMultiple), t ); + } + } else { + while (IsPairTerm(t)) { + Term h = HeadOfTerm( t ); + t = TailOfTerm( t ); + + if (IsAtomTerm(h)) { + Atom at = AtomOfTerm( h ); + if (at == AtomAtom) debugstatus.styleCheck |= LONGATOM_CHECK; + else if (at == AtomSingleton) debugstatus.styleCheck |= SINGLETON_CHECK; + else if (at == AtomVarBranches) debugstatus.styleCheck |= MULTITON_CHECK; + else if (at == AtomDiscontiguous) debugstatus.styleCheck |= DISCONTIGUOUS_STYLE; + else if (at == AtomNoEffect) debugstatus.styleCheck |= NOEFFECT_CHECK; + else if (at == AtomCharset) debugstatus.styleCheck |= CHARSET_CHECK; + else if (at == AtomMultiple) debugstatus.styleCheck |= MULTIPLE_CHECK; + } else { + Atom at = AtomOfTerm( ArgOfTerm( 1, h ) ); + if (at == AtomAtom) debugstatus.styleCheck |= LONGATOM_CHECK; + else if (at == AtomSingleton) debugstatus.styleCheck &= ~SINGLETON_CHECK; + else if (at == AtomVarBranches) debugstatus.styleCheck &= ~MULTITON_CHECK; + else if (at == AtomDiscontiguous) debugstatus.styleCheck &= ~DISCONTIGUOUS_STYLE; + else if (at == AtomNoEffect) debugstatus.styleCheck &= ~NOEFFECT_CHECK; + else if (at == AtomMultiple) debugstatus.styleCheck &= ~MULTIPLE_CHECK; + } + } + } + return TRUE; +} + + void Yap_InitBackIO (void) { @@ -915,5 +981,5 @@ Yap_InitIOPreds(void) // Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag); #endif Yap_InitCPred ("$float_format", 1, p_float_format, SafePredFlag|SyncPredFlag); - + Yap_InitCPred ("$style_checker", 1, p_style_checker, SyncPredFlag); } diff --git a/C/modules.c b/C/modules.c index 7a441c7f8..27d16502e 100644 --- a/C/modules.c +++ b/C/modules.c @@ -120,8 +120,9 @@ LookupModule(Term a ) ModEntry *me; /* prolog module */ - if (a == 0) + if (a == 0) { return GetModuleEntry(AtomProlog); + } at = AtomOfTerm(a); me = GetModuleEntry(at); return me; diff --git a/C/tracer.c b/C/tracer.c index f0ff4ecf3..13dcf2eeb 100755 --- a/C/tracer.c +++ b/C/tracer.c @@ -146,7 +146,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args) // if (!worker_id) return; LOCK(Yap_heap_regs->low_level_trace_lock); sc = Yap_heap_regs; - //if (vsc_count == 54) jmp_deb(1); + if (vsc_count == 161862) jmp_deb(1); // Sfprintf(stderr,"B=%p ", B); #ifdef THREADS LOCAL_ThreadHandle.thread_inst_count++; diff --git a/H/eval.h b/H/eval.h index fad52dd3e..fff67560b 100644 --- a/H/eval.h +++ b/H/eval.h @@ -15,6 +15,85 @@ * * *************************************************************************/ +/** + + @defgroup arithmetic Arithmetic in YAP + + @tableofcontents + + YAP supports several different numeric types: +

+ +Arithmetic functions that require integer arguments accept, in addition +to integers, rational numbers with denominator `1' and floating point +numbers that can be accurately converted to integers. If the required +argument is a float the argument is converted to float. Note that +conversion of integers to floating point numbers may raise an overflow +exception. In all other cases, arguments are converted to the same type +using the order integer to rational number to floating point number. + +Evaluation generates the following _Call_ +exceptions: + + @exception "error(instantiation_error, Call )" if not ground + + @exception "type_error(evaluable( V ), Call)" if not evaluable term + @exception "type_error(integer( V ), Call)" if must be integer + @exception "type_error(float( V ), Call)" if must be float + + @exception "domain_error(out_of_range( V ), Call)" if argument invalid + @exception "domain_error(not_less_than_zero( V ), Call)" if argument must be positive or zero + + @exception "evaluation_error(undefined( V ), Call)" result is not defined (nan) + @exception "evaluation_error(overflow( V ), Call)" result is arithmetic overflow + +@secreflist +@refitem is_2 +@refitem isnan_1 +@endsecreflist + + + **/ + #include /* C library used to implement floating point functions */ diff --git a/H/iatoms.h b/H/iatoms.h index 6102b7d8a..8a4dcde66 100644 --- a/H/iatoms.h +++ b/H/iatoms.h @@ -50,6 +50,7 @@ AtomCharsio = Yap_LookupAtom("charsio"); AtomCharacter = Yap_LookupAtom("character"); AtomCharacterCode = Yap_LookupAtom("character_code"); + AtomCharset = Yap_LookupAtom("charset"); AtomCleanCall = Yap_FullLookupAtom("$clean_call"); AtomColomn = Yap_LookupAtom(":"); AtomCodeSpace = Yap_LookupAtom("code_space"); @@ -81,6 +82,7 @@ AtomDefault = Yap_LookupAtom("default"); AtomDevNull = Yap_LookupAtom("/dev/null"); AtomDiff = Yap_LookupAtom("\\="); + AtomDiscontiguous = Yap_LookupAtom("discontiguous"); AtomDollar = Yap_FullLookupAtom("$"); AtomDoLogUpdClause = Yap_FullLookupAtom("$do_log_upd_clause"); AtomDoLogUpdClause0 = Yap_FullLookupAtom("$do_log_upd_clause0"); @@ -183,6 +185,7 @@ AtomModify = Yap_LookupAtom("modify"); AtomMost = Yap_LookupAtom("most"); AtomMultiFile = Yap_FullLookupAtom("$mf"); + AtomMultiple = Yap_FullLookupAtom("multiple"); AtomMutable = Yap_LookupAtom("mutable"); AtomMutableVariable = Yap_FullLookupAtom("$mutable_variable"); AtomMyddasDB = Yap_FullLookupAtom("$myddas_db"); @@ -195,6 +198,7 @@ AtomNb = Yap_LookupAtom("nb"); AtomNbTerm = Yap_LookupAtom("nb_term"); AtomNew = Yap_LookupAtom("new"); + AtomNoEffect = Yap_LookupAtom("no_effect"); AtomNoMemory = Yap_LookupAtom("no_memory"); AtomNone = Yap_LookupAtom("none"); AtomNonEmptyList = Yap_LookupAtom("non_empty_list"); @@ -282,6 +286,7 @@ AtomSigUsr2 = Yap_LookupAtom("sig_usr2"); AtomSigVTAlarm = Yap_LookupAtom("sig_vtalarm"); AtomSigWakeUp = Yap_LookupAtom("sig_wake_up"); + AtomSingleton = Yap_LookupAtom("singleton"); AtomSlash = Yap_LookupAtom("/"); AtomSocket = Yap_LookupAtom("socket"); AtomSourceSink = Yap_LookupAtom("source_sink"); @@ -335,6 +340,7 @@ AtomUserOut = Yap_LookupAtom("user_output"); AtomVBar = Yap_LookupAtom("|"); AtomVar = Yap_FullLookupAtom("$VAR"); + AtomVarBranches = Yap_LookupAtom("var_branches"); AtomHiddenVar = Yap_FullLookupAtom("$V"); AtomVariable = Yap_LookupAtom("variable"); AtomVersionNumber = Yap_FullLookupAtom("$version_name"); diff --git a/H/pl-incl.h b/H/pl-incl.h index 2e7e36454..776ee643c 100755 --- a/H/pl-incl.h +++ b/H/pl-incl.h @@ -127,8 +127,6 @@ typedef int Char; /* char that can pass EOF */ #define source_char_no (LD->read_source.position.charno) #define source_byte_no (LD->read_source.position.byteno) -#define debugstatus (LD->_debugstatus) - #if SIZE_DOUBLE==SIZEOF_INT_P #define WORDS_PER_DOUBLE 1 #else @@ -306,10 +304,6 @@ typedef struct word culprit; /* for CVT_nocode/CVT_nochar */ } CVT_result; -#define MAXNEWLINES 5 /* maximum # of newlines in atom */ - -#define LONGATOM_CHECK 0x01 /* read/1: error on intptr_t atoms */ - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Operator types. NOTE: if you change OP_*, check operatorTypeToAtom()! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ @@ -454,6 +448,7 @@ extern int fileerrors; extern int ttymode; + #define CHARESCAPE_FEATURE 0x00001 /* handle \ in atoms */ #define GC_FEATURE 0x00002 /* do GC */ #define TRACE_GC_FEATURE 0x00004 /* verbose gc */ diff --git a/H/pl-shared.h b/H/pl-shared.h index 2b38bac18..0968992db 100755 --- a/H/pl-shared.h +++ b/H/pl-shared.h @@ -258,6 +258,22 @@ typedef struct initialise_handle * InitialiseHandle; extern unsigned int getUnknownModule(module_t m); +/* keep in sync with style_name/1 in boot/prims.pl */ + +#define LONGATOM_CHECK 0x0001 /* read/1: error on intptr_t atoms */ +#define SINGLETON_CHECK 0x0002 /* read/1: check singleton vars */ +#define MULTITON_CHECK 0x0004 /* read/1: check multiton vars */ +#define DISCONTIGUOUS_STYLE 0x0008 /* warn on discontiguous predicates */ +#define DYNAMIC_STYLE 0x0010 /* warn on assert/retract active */ +#define CHARSET_CHECK 0x0020 /* warn on unquoted characters */ +#define SEMSINGLETON_CHECK 0x0040 /* Semantic singleton checking */ +#define NOEFFECT_CHECK 0x0080 /* Check for meaningless statements */ +#define VARBRANCH_CHECK 0x0100 /* warn on unbalanced variables */ +#define MULTIPLE_CHECK 0x0100 /* warn on multiple file definitions for a predicate */ +#define MAXNEWLINES 5 /* maximum # of newlines in atom */ + +#define debugstatus (LD->_debugstatus) + #define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag) #define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag) #define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag) diff --git a/H/ratoms.h b/H/ratoms.h index 216126cc0..b6d236910 100644 --- a/H/ratoms.h +++ b/H/ratoms.h @@ -50,6 +50,7 @@ AtomCharsio = AtomAdjust(AtomCharsio); AtomCharacter = AtomAdjust(AtomCharacter); AtomCharacterCode = AtomAdjust(AtomCharacterCode); + AtomCharset = AtomAdjust(AtomCharset); AtomCleanCall = AtomAdjust(AtomCleanCall); AtomColomn = AtomAdjust(AtomColomn); AtomCodeSpace = AtomAdjust(AtomCodeSpace); @@ -81,6 +82,7 @@ AtomDefault = AtomAdjust(AtomDefault); AtomDevNull = AtomAdjust(AtomDevNull); AtomDiff = AtomAdjust(AtomDiff); + AtomDiscontiguous = AtomAdjust(AtomDiscontiguous); AtomDollar = AtomAdjust(AtomDollar); AtomDoLogUpdClause = AtomAdjust(AtomDoLogUpdClause); AtomDoLogUpdClause0 = AtomAdjust(AtomDoLogUpdClause0); @@ -183,6 +185,7 @@ AtomModify = AtomAdjust(AtomModify); AtomMost = AtomAdjust(AtomMost); AtomMultiFile = AtomAdjust(AtomMultiFile); + AtomMultiple = AtomAdjust(AtomMultiple); AtomMutable = AtomAdjust(AtomMutable); AtomMutableVariable = AtomAdjust(AtomMutableVariable); AtomMyddasDB = AtomAdjust(AtomMyddasDB); @@ -195,6 +198,7 @@ AtomNb = AtomAdjust(AtomNb); AtomNbTerm = AtomAdjust(AtomNbTerm); AtomNew = AtomAdjust(AtomNew); + AtomNoEffect = AtomAdjust(AtomNoEffect); AtomNoMemory = AtomAdjust(AtomNoMemory); AtomNone = AtomAdjust(AtomNone); AtomNonEmptyList = AtomAdjust(AtomNonEmptyList); @@ -282,6 +286,7 @@ AtomSigUsr2 = AtomAdjust(AtomSigUsr2); AtomSigVTAlarm = AtomAdjust(AtomSigVTAlarm); AtomSigWakeUp = AtomAdjust(AtomSigWakeUp); + AtomSingleton = AtomAdjust(AtomSingleton); AtomSlash = AtomAdjust(AtomSlash); AtomSocket = AtomAdjust(AtomSocket); AtomSourceSink = AtomAdjust(AtomSourceSink); @@ -335,6 +340,7 @@ AtomUserOut = AtomAdjust(AtomUserOut); AtomVBar = AtomAdjust(AtomVBar); AtomVar = AtomAdjust(AtomVar); + AtomVarBranches = AtomAdjust(AtomVarBranches); AtomHiddenVar = AtomAdjust(AtomHiddenVar); AtomVariable = AtomAdjust(AtomVariable); AtomVersionNumber = AtomAdjust(AtomVersionNumber); diff --git a/H/tatoms.h b/H/tatoms.h index 2c400fffd..7c7b3f06d 100644 --- a/H/tatoms.h +++ b/H/tatoms.h @@ -98,6 +98,8 @@ #define AtomCharacter Yap_heap_regs->AtomCharacter_ Atom AtomCharacterCode_; #define AtomCharacterCode Yap_heap_regs->AtomCharacterCode_ + Atom AtomCharset_; +#define AtomCharset Yap_heap_regs->AtomCharset_ Atom AtomCleanCall_; #define AtomCleanCall Yap_heap_regs->AtomCleanCall_ Atom AtomColomn_; @@ -160,6 +162,8 @@ #define AtomDevNull Yap_heap_regs->AtomDevNull_ Atom AtomDiff_; #define AtomDiff Yap_heap_regs->AtomDiff_ + Atom AtomDiscontiguous_; +#define AtomDiscontiguous Yap_heap_regs->AtomDiscontiguous_ Atom AtomDollar_; #define AtomDollar Yap_heap_regs->AtomDollar_ Atom AtomDoLogUpdClause_; @@ -364,6 +368,8 @@ #define AtomMost Yap_heap_regs->AtomMost_ Atom AtomMultiFile_; #define AtomMultiFile Yap_heap_regs->AtomMultiFile_ + Atom AtomMultiple_; +#define AtomMultiple Yap_heap_regs->AtomMultiple_ Atom AtomMutable_; #define AtomMutable Yap_heap_regs->AtomMutable_ Atom AtomMutableVariable_; @@ -388,6 +394,8 @@ #define AtomNbTerm Yap_heap_regs->AtomNbTerm_ Atom AtomNew_; #define AtomNew Yap_heap_regs->AtomNew_ + Atom AtomNoEffect_; +#define AtomNoEffect Yap_heap_regs->AtomNoEffect_ Atom AtomNoMemory_; #define AtomNoMemory Yap_heap_regs->AtomNoMemory_ Atom AtomNone_; @@ -562,6 +570,8 @@ #define AtomSigVTAlarm Yap_heap_regs->AtomSigVTAlarm_ Atom AtomSigWakeUp_; #define AtomSigWakeUp Yap_heap_regs->AtomSigWakeUp_ + Atom AtomSingleton_; +#define AtomSingleton Yap_heap_regs->AtomSingleton_ Atom AtomSlash_; #define AtomSlash Yap_heap_regs->AtomSlash_ Atom AtomSocket_; @@ -668,6 +678,8 @@ #define AtomVBar Yap_heap_regs->AtomVBar_ Atom AtomVar_; #define AtomVar Yap_heap_regs->AtomVar_ + Atom AtomVarBranches_; +#define AtomVarBranches Yap_heap_regs->AtomVarBranches_ Atom AtomHiddenVar_; #define AtomHiddenVar Yap_heap_regs->AtomHiddenVar_ Atom AtomVariable_; diff --git a/Makefile.in b/Makefile.in index fa838f274..ce93d8e7d 100755 --- a/Makefile.in +++ b/Makefile.in @@ -298,6 +298,7 @@ PLCONS_SOURCES = \ PL_SOURCES= \ pl/arith.yap \ + pl/arithpreds.yap \ pl/arrays.yap \ pl/attributes.yap \ pl/atoms.yap \ diff --git a/docs/builtins.tex b/docs/builtins.tex index b9b6d46b1..1ad112d5b 100644 --- a/docs/builtins.tex +++ b/docs/builtins.tex @@ -2,6 +2,8 @@ @node Built-ins, Library, Modules, Top +@chapter Built-In Predicates Library + @menu Built-ins, Debugging, Syntax, Top @@ -13,7 +15,7 @@ Built-ins, Debugging, Syntax, Top * Predicates on Characters:: Manipulating Characters * Comparing Terms:: Comparison of Terms * Arithmetic:: Arithmetic in YAP -* I/O:: Input/Output with YAP +* Input/Output:: Input/Output with YAP * Database:: Modifying Prolog's Database * Sets:: Finding All Possible Solutions * Grammars:: Grammar Rules @@ -30,7 +32,7 @@ Built-ins, Debugging, Syntax, Top @end menu @node Control, Undefined Procedures, , Top -@chapter Control Predicates +@section Control Predicates This chapter describes the predicates for controlling the execution of @@ -696,7 +698,7 @@ Translates a message-term into a string object. Primarily intended for SWI-Prolo @end table @node Testing Terms, Predicates on Atoms, Messages, Top -@chapter Predicates on terms +@section Predicates on terms @table @code @@ -1194,8 +1196,7 @@ the call. @item digit(@var{Weight}) @var{Char} is a digit with value - @var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X = - '6'}. Useful for parsing numbers. + @var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X = '6'}. Useful for parsing numbers. @item xdigit(@var{Weight}) @var{Char} is a hexa-decimal digit with value @var{Weight}. I.e. char_type(a, xdigit(X) yields X = '10'. Useful for parsing numbers. @@ -1412,9 +1413,21 @@ of length @var{S}. @end table -@node Arithmetic, I/O, Comparing Terms, Top +@node Arithmetic, Input/Output, Comparing Terms, Top @section Arithmetic +@ifplaintext +@copydoc arithmetic + +See @ref arithmetic_preds for the predicates that implement arithment + +See @ref arithmetic_cmps for the arithmetic comparisons supported in YAP + +See @ref arithmetic_operators for how to call arithmetic operations in YAP + +@end ifplaintext + +@texinfo YAP now supports several different numeric types: @table @code @@ -1440,7 +1453,8 @@ YAP now supports several different numeric types: numbers that are returned from is/2 are canonical, which means M is positive and N and M have no common divisors. Rational numbers are introduced in the computation using the rational/1, - rationalize/1 or the rdiv/2 (rational division) function. + rationalize/1 or the +rdiv/2 (rational division) function. @item float Floating point numbers are represented using the C-type double. On most today platforms these are 64-bit IEEE floating point numbers. @@ -1491,8 +1505,7 @@ Integer remainder, similar to @code{mod} but always has the same sign @code{X}. @item @var{X} div @var{Y} [ISO] -Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y}) -// @var{Y}}. +Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y})// @var{Y}}. @item exp(@var{X}) [ISO] Natural exponential. @@ -1767,6 +1780,7 @@ The primitive YAP predicates involving arithmetic expressions are: @table @code +@itemize @item @var{X} is +@var{Y} [2] @findex is/2 @syindex is/2 @@ -1780,6 +1794,7 @@ X is 2+3*4 @end example @noindent succeeds with @code{X = 14}. +@end itemize @item +@var{X} < +@var{Y} [ISO] @findex trace ; true ), assert_static( source( Inp, Lines, Line0 ) ), ( Line0 == end_of_file -> !, @@ -131,7 +130,9 @@ out( _S ) :- nb_setval( min, 0 ), fail. out( S ) :- - line( F, Pos, Line), + line( F, Pos, Line0), +%( Pos = 5770 -> trace ; true ), + jmp_blanks( Line0, Line), b_setval( line, F:Pos:Line ), process( Line , NewLine, F:Pos), offset( N ), @@ -141,8 +142,8 @@ out( S ) :- ; NewLine == "" -> -% nb_getval( old_line, OldLine ), -% OldLine \= "", + nb_getval( old_line, OldLine ), + OldLine \= "", format(string(SN), '~n', []) ; NewLine == force @@ -185,6 +186,9 @@ singleton_line(L) :- string_concat("@itemize",_R,L), !. singleton_line(L) :- string_concat("@enumerate",_R,L), !. singleton_line(L) :- string_concat("@table",_R,L), !. singleton_line(L) :- string_concat("@example",_R,L), !, assert( singletons ). +singleton_line(L) :- string_concat("@ifplaintext",_R,L), !, assert( singletons ). +singleton_line(L) :- string_concat("@pl_example",_R,L), !, assert( singletons ). +singleton_line(L) :- string_concat("@c_example",_R,L), !, assert( singletons ). singleton_line(L) :- string_concat("@simpleexample",_R,L), !, assert( singletons ). singleton_line(L) :- string_concat("@end",R,L), !, ( sub_string(R, _, _, _, "example") -> retract( singletons ) ; true ). @@ -200,16 +204,20 @@ process( Line , S, F:Pos ) :- ( first_word(Line, "@end", Rest) -> - first_word(Rest, Env1, _Rest2), ( - ( Env1 == "example" ; Env1 == "smallexample" ) + first_word(Rest, Env1, _Rest2), + sub_string( Env1, _, _, 0, "example" ) -> ( S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ; pop( skip, verbatim ), fail ) -% fail in other ends -% ; -% Env1 = "cartouche" + ; + first_word(Rest, Env1, _Rest2), + sub_string( Env1, _, _, 0, "plaintext" ) + -> + ( S = "" ; + pop( skip, verbatim ), fail + ) ) ; first_word(Line, "@cartouche", Rest) @@ -224,8 +232,12 @@ process( Line , "", _Pos ) :- first_word(Line, Word, Rest), Word == "@end", first_word(Rest, Word2, _Rest), - W2 = Word2, - pop( skip, W2 ). + ( W2 = Word2 + -> + pop( skip, W2 ) + ; + true + ). % command: flush and continue process( Command , NewLine , Pos) :- do_buffer(Command, NewLine, Pos ). @@ -254,36 +266,49 @@ command( Line, Word, Rest ) :- clause( process( Word, _, _, _, _ ), _), !. +process("@item", _Line, _Rest, NewLine , _FilePos) :- + speek( list, it(_Env, _Item, _Pos, Numb)), + Numb > 1, + NewLine = "". process("@item", Line, Rest, NewLine , FilePos) :- pop( list, it(Env, Item, Pos, Numb)), !, NNumb is Numb+1, run( Text, Rest ), - jmp_blanks( Rest, First ), - item_type(Item, Numb, Marker ), + jmp_blanks( Text, First ), + Pos1 is Pos, +% item_type(Item, Numb, Marker ), + Marker = "", ( - Env = "table", + Env = "@table", atom_string( A, Line ), pred( _Pred, Key, A, FilePos ) -> push( list, it(Env, Item, Pos, NNumb) ), ( % sendout the comand - format(string(NewLine), '~t~s ~*|~s @anchor ~a', [Marker, Pos, First, Key]), + format(string(NewLine), '~t~s ~*+
  • ~s @anchor ~a', [Marker, Pos1, First, Key]), push( indent, done ) ; NewLine = force ) ; - format(string(NewLine), '~t~s ~*|~s', [ Marker, Pos, First]), + format(string(NewLine), '~t~s ~*+
  • ~s', [ Marker, Pos, First]), push( list, it(Env, Item, Pos, NNumb) ), push( indent, done ) - ). + ). %, writeln(+FilePos:Line), listing(stack). +process("@end", _Line, _Rest, "
  • " , _Pos) :- + once( speek(list,it(_Env,_,_LL,_)) ). process("@end", _Line, Rest, NewLine , _Pos) :- speek(list,it(Env,_,_LL,_)), + ( Env = "@enumerate" -> + NewLine = "" + ; + NewLine = "" + ), sub_string( Env, 1, _, 0, Env1 ), sub_string( Rest, _, _, _, Env1), !, % check - pop( list, it(Env, _, _, _) ), - NewLine = "". +% writeln(_Pos:_Line), listing(stack), + pop( list, it(Env, _, _, _) ). process("@end", Line, _Rest, NewLine , _Pos) :- sub_string(Line, _, _, 0, "ifnottex"), !, % check NewLine = "\\endhtmlonly". @@ -304,7 +329,11 @@ process("@end", Line, _Rest, NewLine , _Pos) :- process("@author", _Line, Rest, NewLine , _Pos) :- !, jmp_blanks( Rest, Firs ), format( string( NewLine), '\\author ~s', [ Firs ] ). -process("@*", _Line, _Rest, ¨¨ , _Pos) :- !. +process("@*", _Line, _Rest, "" , _Pos). +process("@*", _Line, Rest, Line , _Pos) :- + !, + jmp_blanks( Rest, Firs ), + run( Line, Firs ). process("@c", _Line, Rest, NewLine , _Pos) :- !, gen_comment( Rest, NewLine ). process("@comment", _Line, Rest, NewLine , _Pos) :- !, @@ -320,7 +349,8 @@ process("@chapter", _Line, Rest, NewLine, _Pos ) :- !, run( Title, Firs ), nb_setval( level, 1 ), title_from_words(Firs, Id, _Pos), - format(string(NewLine), '@section ~s ~s', [Id,Title]). + title( '@chapter', _, TitleDox ), + format(string(NewLine), '~a ~s ~s', [TitleDox, Id,Title]). % ( format( string(NewLine), '~s', [Title] ) ; NewLine = "======" ). process("@cindex", _Line, _Rest, no , _Pos) :- !. process("@caindex", _Line, _Rest, no, _Pos ) :- !. @@ -329,6 +359,9 @@ process("@defindex", Line, _Rest, NewLine , _Pos) :- !, process("@direntry", Line, _Rest, NewLine, _Pos ) :- !, gen_comment( Line, NewLine ), push(skip, "direntry" ). +process("@texinfo", Line, _Rest, NewLine, _Pos ) :- !, + gen_comment( Line, NewLine ), + push(skip, "texinfo" ). process("@documentencoding", _Line, _Rest, "" , _Pos) :- !. % jmp_blanks( Rest, NewString ), % format( string( NewLine), '', [ NewString ] ). @@ -340,7 +373,16 @@ process("@enumerate", _Line, _Rest, NewLine , _Pos) :- process("@example", _Line, _Rest, "" , _Pos). process("@example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !, push( skip, verbatim). +process("@ifplaintext", _Line, _Rest, "" , _Pos) :- !, + push( skip, verbatim). +process("@pl_example", _Line, _Rest, "" , _Pos). +process("@pl_example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}" , _Pos) :- !, + push( skip, verbatim). +process("@c_example", _Line, _Rest, "" , _Pos). +process("@c_example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}" , _Pos) :- !, + push( skip, verbatim). process("@format", _Line, _Rest, "", _Pos ) :- !. +process("@alias", _Line, _Rest, "", _Pos ) :- !. process("@dircategory", _Line, _Rest, "", _Pos ) :- !. process("@smallexample", _Line, _Rest, "" , _Pos). process("@smallexample", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !, @@ -373,8 +415,9 @@ process("@section", _Line, Rest, NewLine, Pos ) :- !, run( NewTitle, Title ), nb_setval( level, 2 ), % format(string(NewLine), '# ~s #', [NewTitle]). + title( '@section', _, TitleDox ), title_from_words(NewTitle, Id, Pos), - format(string(NewLine), '@subsection ~s ~s', [Id,NewTitle]). + format(string(NewLine), '~a ~s ~s', [TitleDox,Id,NewTitle]). % format(string(NewLine), '# ~s #', [NewTitle]). process("@appendix", _Line, Rest, NewLine, _Pos ) :- !, jmp_blanks( Rest, Title ), @@ -384,8 +427,9 @@ process("@subsection", _Line, Rest, NewLine, _Pos ) :- !, jmp_blanks( Rest, Title ), run( NewTitle, Title ), nb_setval( level, 3 ), + title( '@subsection', _, TitleDox ), title_from_words(NewTitle, Id, _Pos), - format(string(NewLine), '@subsubsection ~s ~s', [Id,NewTitle]). + format(string(NewLine), '~a ~s ~s', [TitleDox,Id,NewTitle]). % format(string(NewLine), '## ~s ##', [NewTitle]). process("@unnumberedsubsubsec", _Line, Rest, NewLine, _Pos ) :- !, nb_setval( level, 4 ), @@ -394,8 +438,9 @@ process("@subsubsection", _Line, Rest, NewLine, _Pos ) :- !, nb_setval( level, 4 ), jmp_blanks( Rest, Title ), run( NewTitle, Title ), + title( '@subsubsection', _, TitleDox ), title_from_words(NewTitle, Id, _Pos), - format(string(NewLine), '@paragraph ~s ~s', [Id,NewTitle]). + format(string(NewLine), '~a ~s', [TitleDox,Id,NewTitle]). % format(string(NewLine), '### ~s ###', [NewTitle]). process("@set", _Line, Rest, NewLine , _Pos) :- !, first_word( Rest, V, SecC), @@ -416,16 +461,7 @@ process("@setchapternewpage", Line, _Rest, NewLine, _Pos ) :- !, gen_comment( Line, NewLine ). process("@setfilename", Line, _Rest, NewLine, _Pos ) :- !, gen_comment( Line, NewLine ). -process("@settitle", _Line, Rest, NewLine , _Pos) :- !, - jmp_blanks( Rest, Title ), - ( format(string(NewLine), '~s {#mainpage}', [Title]) ; NewLine = "=================="; NewLine = "" ; - NewLine = ""; - NewLine = "[TOC]"; - NewLine = ""; -NewLine = "@secreflist" ; - NewLine = ""; -NewLine = "@endsecreflist" -). +process("@settitle", _Line, _Rest, "" , _Pos) :- !. process("@subtitle", _Line, _Rest, "", _Pos ) :- !. process("@include", _Line, _Rest, "", _Pos ) :- !. process("@table", _Line, Rest, NewLine , _Pos) :- !, @@ -461,21 +497,25 @@ get_second( Rest, Title ) :- % clear the buffer first. % list( Env, Line, New, _Pos) :- - writeln(_Pos), first_word( Line, V, Rest), jmp_blanks( Rest, End ), ( - speek( list, it(_, _,Pos, _) ) -> - Pos1 is Pos + 6 + speek( list, it(_, _, _Pos, _) ) -> + Pos1 is 0 % Pos + 4 ; - Pos1 = 6 + Pos1 = 0 %4 ), push( list, it( Env, V, Pos1, 1 ) ), % b_getval( pos, _Pos ), % writeln(add:_Pos:Env:Pos1:End), % listing(stack), run( New, End). - +list( Env, _Line, NewLine, _Pos) :- + ( Env = "@enumerate" -> + NewLine = "
      " + ; + NewLine = "