-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemory.min.js
More file actions
1 lines (1 loc) · 1.21 KB
/
memory.min.js
File metadata and controls
1 lines (1 loc) · 1.21 KB
1
var memoryJS={name:"A memoryJS base global scoped object"};class Pointer{constructor(e="0",t=!1){var n=e,r=t;this.isLocal=function(){return r},this.value=function(){return n}}pointedTo(e){return this.isLocal()?e.valueOf(this.value()):memoryJS.publicMemoryObj.valueOf(this.value())}changeValue(e,t){return this.isLocal()?t.changeValue(this.value(),e):memoryJS.publicMemoryObj.changeValue(this.value(),e),0}free(e){return this.isLocal()?e.free(this.value()):memoryJS.publicMemoryObj.free(),null}set point(e){if(this.isLocal())throw new Error("Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead");this.changeValue(e)}get point(){if(this.isLocal())throw new Error("Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead");return this.pointedTo()}}class Memory{constructor(e=!1){var t=0,n=[];this.newobj=function(r){return n.push(r),t+=1,e?new Pointer((t-1).toString(36)):new Pointer((t-1).toString(36),!0)},this.valueOf=function(e="0"){return n[parseInt(e,36)]},this.changeValue=function(e,t){return n[parseInt(e,36)]=t,0},this.free=function(e="0"){return n[parseInt(e,36)]=null,0},this.nullptr=this.newobj(null)}}memoryJS.publicMemoryObj=new Memory(!0);