FORM 4.3
Functions | Variables
proces.c File Reference
#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 par)
 
WORD PolyFunMul (PHEAD WORD *term)
 

Variables

WORD printscratch [2]
 

Detailed Description

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.

Function Documentation

◆ Processor()

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.

Returns
if everything OK: 0. Otherwise error. The preprocessor may continue with compilation though. Really fatal errors should return on the spot by calling Terminate.

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, poly_factorize_expression(), poly_unfactorize_expression(), PutOut(), CbUf::rhs, and StoreTerm().

◆ TestSub()

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.

Parameters
termThe term in which TestSub hunts for potential action
levelThe number of the 'level' in the compiler buffer.
Returns
The number of the (sub)expression that was encountered.

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 681 of file proces.c.

References AddRHS(), TaBlEs::bounds, TaBlEs::bufnum, CbUf::CanCommu, CompareSymbols(), DoubleCbuffer(), EndSort(), Generator(), LowerSortLevel(), MiNmAx::maxi, MiNmAx::mini, TaBlEs::mm, NewSort(), TaBlEs::numind, TaBlEs::pattern, CbUf::Pointer, PrepPoly(), TaBlEs::prototype, CbUf::rhs, MiNmAx::size, TaBlEs::sparse, StoreTerm(), TaBlEs::strict, TaBlEs::tablepointers, TestSub(), and CbUf::Top.

Referenced by Generator(), and TestSub().

◆ InFunction()

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.

Parameters
termThe input term
termoutThe output term
Returns
0: everything is fine, Negative: fatal, Positive: error.

Special attention should be given to nested functions!

Definition at line 2033 of file proces.c.

References Compare1(), CompareSymbols(), EndSort(), Generator(), LowerSortLevel(), NewSort(), StoreTerm(), and SymbolNormalize().

Referenced by Generator().

◆ InsertTerm()

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.

Parameters
termthe input term
replacnumber of the subexpression pointer to replace
extractbuffnumber of the compiler buffer replac refers to
positionposition from where to take the term in the compiler buffer
termoutthe output term
teposoffset in term where the subexpression is.
Returns
Normal conventions (OK = 0).

Definition at line 2579 of file proces.c.

Referenced by Deferred(), Generator(), and PF_Deferred().

◆ PasteFile()

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.

Parameters
numbernumber of partial terms to skip in accum
accumthe accumulator
positionfile position from where to get the stored term
accfillreturns tail position in accum
renumberthe renumber struct for the variables in the stored expression
freezeinformation about if we need only the contents of a bracket
nexprthe number of the stored expression
Returns
Normal conventions (OK = 0).

Definition at line 2715 of file proces.c.

Referenced by Generator().

◆ PasteTerm()

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.

Parameters
numberThe number of term fragments in accum that should be skipped
accumThe accumulator of term fragments
positionA position in (typically) a compiler buffer from where a (piece of a) term comes.
timesMultiply the result by this
divbyDivide 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 2837 of file proces.c.

Referenced by Generator().

◆ FiniTerm()

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

Parameters
termthe input term with the (sub)expression subterm
accumthe accumulator with the term fragments
termoutthe location where the output should be written
numberthe number of term fragments in the accumulator
teposthe position of the subterm in term to be replaced

Definition at line 2902 of file proces.c.

Referenced by DoOnePow(), and Generator().

◆ Generator()

WORD Generator ( PHEAD WORD * term,
WORD level )

The heart of the program. Here the expansion tree is set up in one giant recursion

Parameters
termthe input term. may be overwritten
levelthe level in the compiler buffer (number of statement)
Returns
Normal conventions (OK = 0).

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 3101 of file proces.c.

References Deferred(), DoOnePow(), FiniTerm(), Generator(), InFunction(), InsertTerm(), CbUf::lhs, VaRrEnUm::lo, PasteFile(), PasteTerm(), PF_Deferred(), CbUf::Pointer, PolyFunMul(), PrepPoly(), PutPreVar(), CbUf::rhs, StoreTerm(), ReNuMbEr::symb, TestMatch(), and TestSub().

Referenced by Deferred(), DoOnePow(), generate_expression(), Generator(), InFunction(), MakeDollarInteger(), MakeDollarMod(), PF_CollectModifiedDollars(), PF_Deferred(), PF_Processor(), poly_factorize_expression(), poly_unfactorize_expression(), Processor(), TestMatch(), and TestSub().

◆ DoOnePow()

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.

Parameters
termis the term we are adding to.
poweris the power of the expression that we need.
nexpis the number of the expression.
accumis the accumulator of terms. It accepts the termfragments that are made into a proper term in FiniTerm
aapoints to the start of the entire accumulator. In *aa we store the number of term fragments that are in the accumulator.
levelis the current depth in the tree of statements. It is needed to continue to the next operation/substitution with each generated term
freezeis the pointer to the bracket information that should be matched.

Definition at line 4395 of file proces.c.

References DoOnePow(), FiniTerm(), Generator(), and FiLe::handle.

Referenced by DoOnePow(), and Generator().

◆ Deferred()

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.

Parameters
termThe term that must be multiplied by the contents of the current bracket
levelThe compiler level. This is needed because after multiplying term by term we call Generator again.

Definition at line 4616 of file proces.c.

References Generator(), and InsertTerm().

Referenced by Generator().

◆ PrepPoly()

WORD PrepPoly ( PHEAD WORD * term,
WORD par )

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.

The parameter par tells whether we are at groundlevel or inside a function or dollar variable.

Definition at line 4744 of file proces.c.

References poly_ratfun_normalize().

Referenced by Generator(), and TestSub().

◆ PolyFunMul()

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 polywrap.cc The new result is written over the old result.

Parameters
termIt contains the input term and later the output.
Returns
Normal conventions (OK = 0).

Definition at line 5132 of file proces.c.

References EndSort(), LowerSortLevel(), NewSort(), poly_ratfun_normalize(), and StoreTerm().

Referenced by Generator().

Variable Documentation

◆ printscratch

WORD printscratch[2]

Definition at line 39 of file proces.c.