Skip to content

Newton API specs

hyuglim edited this page Jan 23, 2017 · 10 revisions

Methods

The following will go into the header file for Newton API. The caller of the API should call getPhysics whenever an unknown type is detected and fill in Physics field of NewtonIrNode with the returned value. The caller should also call checkSingleConstraint at appropriate times. The Report struct will contain the results of this call.

// COMPILE OR RUN TIME METHODS

Physics* getPhysics(char* physicsIdentifierString); This method returns a Physics struct given the name of that Physics type. What it does: NoisyState contains a list of Physics nodes that are identifiable by the name of that Physics node and a prime number. This method simply iterates through that list and returns the Physics node with physicsIdentifierString. For more information about the data structures, see noisy.h

Report* checkSingleConstraint(NewtonIrNode* subtreeRoot); Note that Report struct does not yet exist in the master branch. NewtonIrNode is structurally equivalent to NoisyIrNode, and as of 1/21/17, we use NoisyIrNode for both Noisy and Newton. subtreeRoot passed in is a representation of a host language program. Thus all that needs to be done is perform type checking on that subtree.

NewtonIrNode* getAST(); Returns the root NewtonIrNode

Dimension* getAllDimensions(); NoisyState contains a list of all Dimensions. Return the head of that list.

Dimension* getDimensionByName(char * dimensionName); NoisyState contains a list of all Dimensions. Return the element that contains dimensionName as the identifier.

Physics* getAllPhysics(); NoisyState contains a list of all Physicss. Return the head of that list.

Physics* getPhysicsByName(char * physicsName); NoisyState contains a list of all Physicss. Return the element that contains physicsName as the identifier.

The following are some of the data structures included in noisy.h `struct Physics { char * identifier; // name of the physics quantity. of type kNoisyConfigType_Tidentifier NoisyScope * scope; NoisySourceInfo * sourceInfo;

bool isVector;
Physics * vectorCounterpart; // non-NULL if a scalar AND counterpart defined in vectorScalarPairScope
Physics * scalarCounterpart; // non-NULl if a vector AND counterpart defined in vectorScalarPairScope

Dimension * numeratorDimensions;
int numberOfNumerators;
int numeratorPrimeProduct;

Dimension * denominatorDimensions;
int numberOfDenominators;
int denominatorPrimeProduct;

char * dimensionAlias;

Physics * definition;

Physics * next;

};`

`struct NoisyIrNode { NoisyIrNodeType type; Physics * physicsType;

/*
 *	Syntactic (AST) information.
 */
char *			tokenString;
NoisyToken * token;
NoisySourceInfo	*	sourceInfo;
NoisyIrNode *		irParent;
NoisyIrNode *		irLeftChild;
NoisyIrNode *		irRightChild;

NoisySymbol *		symbol;

/*
 * Used for evaluating dimensions in expressions
 */
Physics * physics;

/*
 * Used for returning integral list from noisyConfigParseIntegralList
 */
IntegralList * vectorIntegralList;
IntegralList * scalarIntegralList;

/*
 *	Used for coloring the IR tree, e.g., during Graphviz/dot generation
 */
NoisyIrNodeColor	nodeColor;

}; `

A Side Note

NewtonIrNode should have dimension, physics, values, type, source info, .. just reuse NoisyIrNode minus all the scope nodes.

Newton API as of now will support only the following:

  1. 4 basic arithmetic operations and exponents
  2. decimals and integers
  3. strings
  4. statements and expressions of scalars and dimensions

which means the following (from Noisy) are not supported

  1. channels and channel operations
  2. namegens
  3. matchseq, iter, and other control flow operations

For the Newton Standard AST, we will just reuse NoisyIrNode minus all the scope nodes NewtonIrNode should have Dimension, Physics, numeric values, SourceInfo, etc ...

Clone this wiki locally