12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import { Location } from "../../memory/location";
- import { Type } from '../../typeSystem/type';
- export class StoreObject {
- private _type: Type;
- private _loc_address: number;
- private _readOnly: boolean;
- private _id : String | null;
- /**
- *
- * @param {Type} type
- * @param {Number} loc_address
- * @param {Boolean} readOnly
- */
- constructor (type: Type, loc_address: number, readOnly = false) {
- this._loc_address = loc_address;
- this._type = type;
- this._readOnly = readOnly;
- this._id = null;
- }
- setID (id: String | null) {
- this._id = id;
- Location.updateAddress(this._loc_address, this.value, true);
- }
- get id () {
- return this._id;
- }
- get inStore () {
- return this.id !== null;
- }
- get type () {
- return this._type;
- }
- /**
- * Returns the actual value stored at the loccation address present in this object.
- * The returned value is compatible with @prop{StoreObject.type}
- */
- get value () {
- const address = Location.find(this._loc_address);
- if (address != null) {
- return address.value
- } else {
- throw new Error("!!!Critical Error: variable "+this.id+" does not have a valid address. Loc-Address "+ this.locAddress);
- }
- }
-
- get number () {
- throw new Error("DOT NOT USE THIS PROPERTY!");
- }
- get readOnly () {
- return this._readOnly;
- }
- set readOnly (value) {
- this._readOnly = value;
- }
- isCompatible (another: StoreObject) {
- return this.type.isCompatible(another.type);
- }
- destroy () {
- return Location.deallocate(this._loc_address);
- }
- copy () {
- const clone = new StoreObject(this.type, Location.allocate(this.value), this.readOnly);
- return clone;
- }
- get locAddress () {
- return this._loc_address;
- }
- }
|