public bool SetVariable(ILiteral variable) { // Mark the variable as used _usedVariables.Add(_indexForVariable[variable]); // Create a new reference IReferenceLiteral newReference; // Add to the current structure if (_lastArgument != null) { // The last argument is the reference newReference = _lastArgument; _lastArgument = _lastArgument.NextArgument; } else { newReference = new SimpleReference(); } // Store in the variable _addressForName[variable].SetTo(newReference); return(true); }
public ArgumentReference(IReferenceLiteral value, ArgumentReference nextArgument) { if (value == null) value = this; Term = null; Reference = value; NextArgument = nextArgument; }
public ArgumentReference(IReferenceLiteral value, ArgumentReference nextArgument) { if (value == null) { value = this; } Term = null; Reference = value; NextArgument = nextArgument; }
public bool SetValue(ILiteral variable) { // Read the variable var variableValue = _addressForName[variable]; // Store to the current structure if (_lastArgument != null) { _lastArgument.SetTo(variableValue); _lastArgument = _lastArgument.NextArgument; } return(true); }
public bool GetStructure(ILiteral termName, int termLength, ILiteral variable) { // This variable becomes used _usedVariables.Add(_indexForVariable[variable]); // Get the dereferenced address of the variable var heapValue = _addressForName[variable].Dereference(); // Action depends on what's at that address if (heapValue.IsVariable()) { // Variable is an unbound ref cell: bind it to a new value that we create ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var newStructure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; _structurePtr = firstArgument; Bind(heapValue, newStructure); _writeMode = true; } else if (!heapValue.IsReference()) { if (Equals(heapValue.Term, termName)) { // Set the structure pointer, and use read mode _structurePtr = heapValue.Reference; _writeMode = false; } else { // Structure doesn't match; fail return(false); } } else { // Fail return(false); } return(true); }
public bool UnifyValue(ILiteral variable) { if (!_writeMode) { if (!Unify(_addressForName[variable], _structurePtr)) { return(false); } } else { _lastArgument.SetTo(_addressForName[variable]); _lastArgument = _lastArgument.NextArgument; } _structurePtr = _structurePtr.NextArgument; return(true); }
public bool PutVariable(ILiteral variable1, ILiteral variable2) { _usedVariables.Add(_indexForVariable[variable1]); _usedVariables.Add(_indexForVariable[variable2]); var newValue = new SimpleReference(); // Store in the variables _addressForName[variable1].SetTo(newValue); _addressForName[variable2].SetTo(newValue); // Store to the current structure if (_lastArgument != null) { _lastArgument.SetTo(newValue); _lastArgument = _lastArgument.NextArgument; } return(true); }
public bool UnifyVariable(ILiteral variable) { // This variable becomes used _usedVariables.Add(_indexForVariable[variable]); if (!_writeMode) { // Just read the value of the variable _addressForName[variable].SetTo(_structurePtr); } else { // Write the value of the variable _addressForName[variable].SetTo(_lastArgument); _lastArgument = _lastArgument.NextArgument; } _structurePtr = _structurePtr.NextArgument; return(true); }
public bool PutStructure(ILiteral termName, int termLength, ILiteral variable) { // Mark this variable as used _usedVariables.Add(_indexForVariable[variable]); // Create the structure ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var structure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; // Store in the variable _addressForName[variable].SetTo(structure); return(true); }
public bool UnifyVariable(ILiteral variable) { // This variable becomes used _usedVariables.Add(_indexForVariable[variable]); if (!_writeMode) { // Just read the value of the variable _addressForName[variable].SetTo(_structurePtr); } else { // Write the value of the variable _addressForName[variable].SetTo(_lastArgument); _lastArgument = _lastArgument.NextArgument; } _structurePtr = _structurePtr.NextArgument; return true; }
public bool UnifyValue(ILiteral variable) { if (!_writeMode) { if (!Unify(_addressForName[variable], _structurePtr)) { return false; } } else { _lastArgument.SetTo(_addressForName[variable]); _lastArgument = _lastArgument.NextArgument; } _structurePtr = _structurePtr.NextArgument; return true; }
public bool SetVariable(ILiteral variable) { // Mark the variable as used _usedVariables.Add(_indexForVariable[variable]); // Create a new reference IReferenceLiteral newReference; // Add to the current structure if (_lastArgument != null) { // The last argument is the reference newReference = _lastArgument; _lastArgument = _lastArgument.NextArgument; } else { newReference = new SimpleReference(); } // Store in the variable _addressForName[variable].SetTo(newReference); return true; }
public bool SetValue(ILiteral variable) { // Read the variable var variableValue = _addressForName[variable]; // Store to the current structure if (_lastArgument != null) { _lastArgument.SetTo(variableValue); _lastArgument = _lastArgument.NextArgument; } return true; }
public bool PutVariable(ILiteral variable1, ILiteral variable2) { _usedVariables.Add(_indexForVariable[variable1]); _usedVariables.Add(_indexForVariable[variable2]); var newValue = new SimpleReference(); // Store in the variables _addressForName[variable1].SetTo(newValue); _addressForName[variable2].SetTo(newValue); // Store to the current structure if (_lastArgument != null) { _lastArgument.SetTo(newValue); _lastArgument = _lastArgument.NextArgument; } return true; }
public bool PutStructure(ILiteral termName, int termLength, ILiteral variable) { // Mark this variable as used _usedVariables.Add(_indexForVariable[variable]); // Create the structure ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var structure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; // Store in the variable _addressForName[variable].SetTo(structure); return true; }
/// <summary> /// Either begins unifying against an existing structure (if the variable is bound) or /// begins writing a new structure to an unbound variable. /// </summary> private bool GetStructure(int literal, int variable, int termLength) { var termName = _literals[literal]; // Get the dereferenced address of the variable var heapValue = _registers[variable].Dereference(); // Action depends on what's at that address if (heapValue.IsVariable()) { // Variable is an unbound ref cell: bind it to a new value that we create ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var newStructure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; _structurePtr = firstArgument; Bind(heapValue, newStructure); _writeMode = true; } else if (!heapValue.IsReference()) { if (Equals(heapValue.Term, termName)) { // Set the structure pointer, and use read mode _structurePtr = heapValue.Reference; _writeMode = false; } else { // Structure doesn't match; fail return false; } } else { // Fail return false; } return true; }
/// <summary> /// Generates a new empty structure of a particular length on the heap and stores a reference /// to it in a variable /// </summary> private void PutStructure(int termLiteral, int variable, int termLength) { var termName = _literals[termLiteral]; // Create the structure ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var structure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; // Store in the variable _registers[variable].SetTo(structure); }
public bool GetStructure(ILiteral termName, int termLength, ILiteral variable) { // This variable becomes used _usedVariables.Add(_indexForVariable[variable]); // Get the dereferenced address of the variable var heapValue = _addressForName[variable].Dereference(); // Action depends on what's at that address if (heapValue.IsVariable()) { // Variable is an unbound ref cell: bind it to a new value that we create ArgumentReference firstArgument = null; for (int argNum = 0; argNum < termLength; ++argNum) { var newArgument = new ArgumentReference(null, firstArgument); firstArgument = newArgument; } var newStructure = new SimpleReference(termName, firstArgument); _lastArgument = firstArgument; _structurePtr = firstArgument; Bind(heapValue, newStructure); _writeMode = true; } else if (!heapValue.IsReference()) { if (Equals(heapValue.Term, termName)) { // Set the structure pointer, and use read mode _structurePtr = heapValue.Reference; _writeMode = false; } else { // Structure doesn't match; fail return false; } } else { // Fail return false; } return true; }