mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Moved Link to namespace math.expr
This commit is contained in:
parent
548708ffaa
commit
d1cc3a3f15
@ -1,16 +1,16 @@
|
||||
// TODO: comment link
|
||||
|
||||
function Link (scope, name, value) {
|
||||
math.expr.Link = function Link (scope, name, value) {
|
||||
this.scope = scope;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the links value
|
||||
* @returns {*} value
|
||||
*/
|
||||
Link.prototype.get = function () {
|
||||
math.expr.Link.prototype.get = function () {
|
||||
var value = this.value;
|
||||
if (!value) {
|
||||
// try to resolve again
|
||||
@ -22,7 +22,7 @@ Link.prototype.get = function () {
|
||||
}
|
||||
|
||||
// resolve a chain of links
|
||||
while (value instanceof Link) {
|
||||
while (value instanceof math.expr.Link) {
|
||||
value = value.get();
|
||||
}
|
||||
|
||||
@ -33,6 +33,6 @@ Link.prototype.get = function () {
|
||||
* Set the value for the link
|
||||
* @param {*} value
|
||||
*/
|
||||
Link.prototype.set = function (value) {
|
||||
math.expr.Link.prototype.set = function (value) {
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
@ -71,7 +71,7 @@ math.expr.Scope.prototype = {
|
||||
/**
|
||||
* create a symbol
|
||||
* @param {String} name
|
||||
* @return {Link} symbol
|
||||
* @return {math.expr.Link} symbol
|
||||
* @private
|
||||
*/
|
||||
createSymbol: function (name) {
|
||||
@ -81,7 +81,7 @@ math.expr.Scope.prototype = {
|
||||
var lastDef = this.findDef(name);
|
||||
|
||||
// create a new symbol
|
||||
symbol = new Link(this, name, lastDef);
|
||||
symbol = new math.expr.Link(this, name, lastDef);
|
||||
this.symbols[name] = symbol;
|
||||
|
||||
}
|
||||
@ -91,7 +91,7 @@ math.expr.Scope.prototype = {
|
||||
/**
|
||||
* create a link to a value.
|
||||
* @param {String} name
|
||||
* @return {Link} symbol
|
||||
* @return {math.expr.Link} symbol
|
||||
*/
|
||||
createLink: function (name) {
|
||||
var symbol = this.links[name];
|
||||
@ -107,7 +107,7 @@ math.expr.Scope.prototype = {
|
||||
* Returns the created symbol
|
||||
* @param {String} name
|
||||
* @param {*} [value]
|
||||
* @return {Link} symbol
|
||||
* @return {math.expr.Link} symbol
|
||||
*/
|
||||
createDef: function (name, value) {
|
||||
if (this.readonly) {
|
||||
@ -129,7 +129,7 @@ math.expr.Scope.prototype = {
|
||||
* Create a variable update definition
|
||||
* Returns the created symbol
|
||||
* @param {String} name
|
||||
* @return {Link} symbol
|
||||
* @return {math.expr.Link} symbol
|
||||
*/
|
||||
createUpdate: function (name) {
|
||||
if (this.readonly) {
|
||||
@ -148,11 +148,11 @@ math.expr.Scope.prototype = {
|
||||
* Create a constant
|
||||
* @param {String} name
|
||||
* @param {*} value
|
||||
* @return {Link} symbol
|
||||
* @return {math.expr.Link} symbol
|
||||
* @private
|
||||
*/
|
||||
createConstant: function (name, value) {
|
||||
var symbol = new Link(this, name, value);
|
||||
var symbol = new math.expr.Link(this, name, value);
|
||||
this.symbols[name] = symbol;
|
||||
this.defs[name] = symbol;
|
||||
return symbol;
|
||||
@ -163,7 +163,7 @@ math.expr.Scope.prototype = {
|
||||
* If the symbol is not found in this scope, it will be looked up in its parent
|
||||
* scope.
|
||||
* @param {String} name
|
||||
* @return {Link | undefined} symbol, or undefined when not found
|
||||
* @return {math.expr.Link | undefined} symbol, or undefined when not found
|
||||
*/
|
||||
findDef: function (name) {
|
||||
var symbol;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @param {String} name Symbol name
|
||||
* @param {Node[] | undefined} params Zero or more parameters
|
||||
* @param {Node} expr The expression defining the symbol
|
||||
* @param {Link} result placeholder for the result
|
||||
* @param {math.expr.Link} result placeholder for the result
|
||||
*/
|
||||
function Assignment(name, params, expr, result) {
|
||||
this.name = name;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* @param {String[]} variableNames Variable names
|
||||
* @param {function[]} variables Links to the variables in a scope
|
||||
* @param {Node} expr The function expression
|
||||
* @param {Link} result Link to store the result
|
||||
* @param {math.expr.Link} result Link to store the result
|
||||
*/
|
||||
function FunctionAssignment(name, variableNames, variables, expr, result) {
|
||||
this.name = name;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* A symbol can hold and evaluate a link to a value or function defined in a
|
||||
* scope.
|
||||
* @param {String} [name]
|
||||
* @param {Link} link
|
||||
* @param {math.expr.Link} link
|
||||
* @extends {Node}
|
||||
*/
|
||||
function Symbol(name, link) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user