FORM
4.1
|
#include "form3.h"
Go to the source code of this file.
Functions | |
WORD | Processor () |
WORD | TestSub (PHEAD WORD *term, WORD level) |
WORD | InFunction (PHEAD WORD *term, WORD *termout) |
WORD | InsertTerm (PHEAD WORD *term, WORD replac, WORD extractbuff, WORD *position, WORD *termout, WORD tepos) |
LONG | PasteFile (PHEAD WORD number, WORD *accum, POSITION *position, WORD **accfill, RENUMBER renumber, WORD *freeze, WORD nexpr) |
WORD * | PasteTerm (PHEAD WORD number, WORD *accum, WORD *position, WORD times, WORD divby) |
WORD | FiniTerm (PHEAD WORD *term, WORD *accum, WORD *termout, WORD number, WORD tepos) |
WORD | Generator (PHEAD WORD *term, WORD level) |
WORD | DoOnePow (PHEAD WORD *term, WORD power, WORD nexp, WORD *accum, WORD *aa, WORD level, WORD *freeze) |
WORD | Deferred (PHEAD WORD *term, WORD level) |
WORD | PrepPoly (PHEAD WORD *term) |
WORD | PolyFunMul (PHEAD WORD *term) |
Variables | |
WORD | printscratch [2] |
Contains the central terms processor routines. This is the core of the virtual machine. All other files are to help these routines.
Definition in file proces.c.
WORD Processor | ( | ) |
This is the central processor. It accepts a stream of Expressions which is accessed by calls to GetTerm. The expressions reside either in AR.infile or AR.hidefile The definitions of an expression are seen as an id-statement, so the primary Expressions should be written to the system of scratch files as single terms with an expression pointer. Each expression is terminated with a zero and the whole is terminated by two zeroes.
The routine DoExecute should determine whether results are to be printed, should revert the scratch I/O directions etc. In principle it is DoExecute that calls Processor.
Definition at line 64 of file proces.c.
References CbUf::Buffer, EndSort(), FlushOut(), Generator(), CbUf::lhs, LowerSortLevel(), NewSort(), PF_BroadcastRHS(), PF_InParallelProcessor(), PF_Processor(), CbUf::Pointer, PutOut(), CbUf::rhs, and StoreTerm().
WORD TestSub | ( | PHEAD WORD * | term, |
WORD | level | ||
) |
TestSub hunts for subexpression pointers. If one is found its power is given in AN.TeSuOut. and the returnvalue is 'expressionnumber'. If the expression number is negative it is an expression on disk.
In addition this routine tries to locate subexpression pointers in functions. It also notices that action must be taken with any of the special functions.
term | The term in which TestSub hunts for potential action |
level | The number of the 'level' in the compiler buffer. |
Other values that are returned are in AN.TeSuOut, AR.TePos, AT.TMbuff, AN.TeInFun, AN.Frozen, AT.TMaddr
The level in the compiler buffer is more or less the number of the statement in the module. Hence it refers to the element in the lhs array.
This routine is one of the most important routines in FORM.
Definition at line 655 of file proces.c.
References TaBlEs::bounds, TaBlEs::bufnum, CbUf::CanCommu, CompareSymbols(), EndSort(), Generator(), LowerSortLevel(), MiNmAx::maxi, MiNmAx::mini, TaBlEs::mm, NewSort(), TaBlEs::numind, TaBlEs::pattern, CbUf::Pointer, TaBlEs::prototype, CbUf::rhs, MiNmAx::size, TaBlEs::sparse, StoreTerm(), TaBlEs::strict, TaBlEs::tablepointers, and CbUf::Top.
Referenced by Generator().
WORD InFunction | ( | PHEAD WORD * | term, |
WORD * | termout | ||
) |
Makes the replacement of the subexpression with the number 'replac' in a function argument. Additional information is passed in some of the AR, AN, AT variables.
term | The input term |
termout | The output term |
Special attention should be given to nested functions!
Definition at line 1809 of file proces.c.
References Compare1(), CompareSymbols(), EndSort(), Generator(), LowerSortLevel(), NewSort(), StoreTerm(), and SymbolNormalize().
Referenced by Generator().
WORD InsertTerm | ( | PHEAD WORD * | term, |
WORD | replac, | ||
WORD | extractbuff, | ||
WORD * | position, | ||
WORD * | termout, | ||
WORD | tepos | ||
) |
Puts the terms 'term' and 'position' together into a single legal term in termout. replac is the number of the subexpression that should be replaced. It must be a positive term. When action is needed in the argument of a function all terms in that argument are dealt with recursively. The subexpression is sorted. Only one subexpression is done at a time this way.
term | the input term |
replac | number of the subexpression pointer to replace |
extractbuff | number of the compiler buffer replac refers to |
position | position from where to take the term in the compiler buffer |
termout | the output term |
tepos | offset in term where the subexpression is. |
Definition at line 2350 of file proces.c.
Referenced by Deferred(), Generator(), and PF_Deferred().
LONG PasteFile | ( | PHEAD WORD | number, |
WORD * | accum, | ||
POSITION * | position, | ||
WORD ** | accfill, | ||
RENUMBER | renumber, | ||
WORD * | freeze, | ||
WORD | nexpr | ||
) |
Gets a term from stored expression expr and puts it in the accumulator at position number. It returns the length of the term that came from file.
number | number of partial terms to skip in accum |
accum | the accumulator |
position | file position from where to get the stored term |
accfill | returns tail position in accum |
renumber | the renumber struct for the variables in the stored expression |
freeze | information about if we need only the contents of a bracket |
nexpr | the number of the stored expression |
Definition at line 2481 of file proces.c.
Referenced by Generator().
WORD* PasteTerm | ( | PHEAD WORD | number, |
WORD * | accum, | ||
WORD * | position, | ||
WORD | times, | ||
WORD | divby | ||
) |
Puts the term at position in the accumulator accum at position 'number+1'. if times > 0 the coefficient of this term is multiplied by times/divby.
number | The number of term fragments in accum that should be skipped |
accum | The accumulator of term fragments |
position | A position in (typically) a compiler buffer from where a (piece of a) term comes. |
times | Multiply the result by this |
divby | Divide the result by this. |
This routine is typically used when we have to replace a (sub)expression pointer by a power of a (sub)expression. This uses mostly a binomial expansion and the new term is the old term multiplied one by one by terms of the new expression. The factors times and divby keep track of the binomial coefficient. Once this is complete, the routine FiniTerm will make the contents of the accumulator into a proper term that still needs to be normalized.
Definition at line 2603 of file proces.c.
Referenced by Generator().
WORD FiniTerm | ( | PHEAD WORD * | term, |
WORD * | accum, | ||
WORD * | termout, | ||
WORD | number, | ||
WORD | tepos | ||
) |
Concatenates the contents of the accumulator into a single legal term, which replaces the subexpression pointer
term | the input term with the (sub)expression subterm |
accum | the accumulator with the term fragments |
termout | the location where the output should be written |
number | the number of term fragments in the accumulator |
tepos | the position of the subterm in term to be replaced |
Definition at line 2668 of file proces.c.
Referenced by DoOnePow(), and Generator().
WORD Generator | ( | PHEAD WORD * | term, |
WORD | level | ||
) |
The heart of the program. Here the expansion tree is set up in one giant recursion
term | the input term. may be overwritten |
level | the level in the compiler buffer (number of statement) |
The routine looks first whether there are unsubstituted (sub)expressions. If so, one of them gets inserted term by term and the new term is used in a renewed call to Generator. If there are no (sub)expressions, the term is normalized, the compiler level is raised (next statement) and the program looks what type of statement this is. If this is a special statement it is either treated on the spot or the appropriate routine is called. If it is a substitution, the pattern matcher is called (TestMatch) which tells whether there was a match. If so we need to call TestSub again to test for (sub)expressions. If we run out of levels, the term receives a final treatment for modulus calculus and/or brackets and is then sent off to the sorting routines.
Definition at line 2865 of file proces.c.
References Deferred(), DollarFactorize(), DoOnePow(), FiniTerm(), InFunction(), InsertTerm(), CbUf::lhs, VaRrEnUm::lo, PasteFile(), PasteTerm(), PF_Deferred(), PolyFunMul(), PrepPoly(), PutPreVar(), StoreTerm(), ReNuMbEr::symb, TestMatch(), and TestSub().
Referenced by Deferred(), DollarFactorize(), DoOnePow(), InFunction(), LocalConvertToPoly(), MakeDollarInteger(), MakeDollarMod(), PF_CollectModifiedDollars(), PF_Deferred(), PF_InParallelProcessor(), PF_Processor(), Processor(), TakeContent(), TestMatch(), TestSub(), and TheDefine().
WORD DoOnePow | ( | PHEAD WORD * | term, |
WORD | power, | ||
WORD | nexp, | ||
WORD * | accum, | ||
WORD * | aa, | ||
WORD | level, | ||
WORD * | freeze | ||
) |
Routine gets one power of an expression in the scratch system. If there are more powers needed there will be a recursion.
No attempt is made to use binomials because we have no information about commutating properties.
There is a searching for the contents of brackets if needed. This searching may be rather slow because of the single links.
term | is the term we are adding to. |
power | is the power of the expression that we need. |
nexp | is the number of the expression. |
accum | is the accumulator of terms. It accepts the termfragments that are made into a proper term in FiniTerm |
aa | points to the start of the entire accumulator. In *aa we store the number of term fragments that are in the accumulator. |
level | is the current depth in the tree of statements. It is needed to continue to the next operation/substitution with each generated term |
freeze | is the pointer to the bracket information that should be matched. |
Definition at line 4056 of file proces.c.
References FiniTerm(), Generator(), and FiLe::handle.
Referenced by Generator().
WORD Deferred | ( | PHEAD WORD * | term, |
WORD | level | ||
) |
Picks up the deferred brackets. These are the bracket contents of which we postpone the reading when we use the 'Keep Brackets' statement. These contents are multiplying the terms just before they are sent to the sorting system. Special attention goes to having it thread-safe We have to lock positioning the file and reading it in a thread specific buffer.
term | The term that must be multiplied by the contents of the current bracket |
level | The compiler level. This is needed because after multiplying term by term we call Generator again. |
Definition at line 4275 of file proces.c.
References Generator(), and InsertTerm().
Referenced by Generator().
WORD PrepPoly | ( | PHEAD WORD * | term | ) |
Routine checks whether the count of function AR.PolyFun is zero or one. If it is one and it has one scalarlike argument the coefficient of the term is pulled inside the argument. If the count is zero a new function is made with the coefficient as its only argument. The function should be placed at its proper position.
When this function is active it places the PolyFun as last object before the coefficient. This is needed because otherwise the compress algorithm has problems in MergePatches.
The bracket routine should also place the PolyFun at a comparable spot. The compression should then stop at the PolyFun. It doesn't really have to stop when writing the final result but this may be too complicated.
Definition at line 4402 of file proces.c.
Referenced by Generator().
WORD PolyFunMul | ( | PHEAD WORD * | term | ) |
Multiplies the arguments of multiple occurrences of the polyfun. In this routine we do the original PolyFun with one argument only. The PolyRatFun (PolyFunType = 2) is done in a dedicated routine in the file polynito.c The new result is written over the old result.
term | It contains the input term and later the output. |
Definition at line 4746 of file proces.c.
References EndSort(), LowerSortLevel(), NewSort(), and StoreTerm().
Referenced by Generator().