Permalink
Browse files

Perlito5 - js - new structure p5ArrayOfAlias

  • Loading branch information...
1 parent b93e775 commit b50d8dc7008920a8bdac63199e42cb113ec060b3 @fglock committed Oct 12, 2012
Showing with 159 additions and 1 deletion.
  1. +79 −0 html/perlito5.js
  2. +1 −1 perlito5.pl
  3. +79 −0 src5/lib/Perlito5/Javascript2/Array.pm
View
@@ -990,6 +990,85 @@ p5untie_array = function(v) {
};
+function p5ArrayOfAlias(o) {
+
+ // this is the structure that represents @_
+ // _array = [ ref, index,
+ // ref, index,
+ // ...
+ // ]
+
+ // TODO - autovivify array cells
+
+ this._array_ = o;
+
+ this.p5aget = function (i) {
+ if (i < 0) { i = this.length + i };
+ return this._array_[i+i][this._array_[i+i]+1];
+ }
+ this.p5aset = function (i, v) {
+ if (i < 0) { i = this.length + i };
+ this._array_[i+i][this._array_[i+i]+1] = v;
+ return this._array_[i+i][this._array_[i+i]+1]
+ }
+ this.p5incr = function (i) {
+ if (i < 0) { i = this.length + i };
+ this._array_[i+i][this._array_[i+i]+1] = p5incr(this._array_[i+i][this._array_[i+i]+1]);
+ return this._array_[i+i][this._array_[i+i]+1];
+ }
+ this.p5postincr = function (i) {
+ if (i < 0) { i = this.length + i };
+ var v = this._array_[i+i][this._array_[i+i]+1];
+ this._array_[i+i][this._array_[i+i]+1] = p5incr(this._array_[i+i][this._array_[i+i]+1]);
+ return v;
+ }
+ this.p5decr = function (i) {
+ if (i < 0) { i = this.length + i };
+ this._array_[i+i][this._array_[i+i]+1] = p5decr(this._array_[i+i][this._array_[i+i]+1]);
+ return this._array_[i+i][this._array_[i+i]+1];
+ }
+ this.p5postdecr = function (i) {
+ if (i < 0) { i = this.length + i };
+ var v = this._array_[i+i][this._array_[i+i]+1];
+ this._array_[i+i][this._array_[i+i]+1] = p5decr(this._array_[i+i][this._array_[i+i]+1]);
+ return v;
+ }
+ this.p5aget_array = function (i) {
+ if (i < 0) { i = this.length + i };
+ if (this._array_[i+i][this._array_[i+i]+1] == null) {
+ this._array_[i+i][this._array_[i+i]+1] = new p5ArrayRef([])
+ }
+ return this._array_[i+i][this._array_[i+i]+1]
+ }
+ this.p5aget_hash = function (i) {
+ if (i < 0) { i = this.length + i };
+ if (this._array_[i+i][this._array_[i+i]+1] == null) {
+ this._array_[i+i][this._array_[i+i]+1] = new p5HashRef({})
+ }
+ return this._array_[i+i][this._array_[i+i]+1]
+ }
+ this.p5unshift = function (args) {
+ for(var i = args.length-1; i >= 0; i--) {
+ this.unshift(0);
+ this.unshift([args[i]]);
+ }
+ return this._array_.length / 2;
+ }
+ this.p5push = function (args) {
+ for(var i = 0; i < args.length; i++) {
+ this.push([args[i]]);
+ this.push(0);
+ }
+ return this._array_.length / 2;
+ }
+
+ // TODO - shift()
+
+ // TODO - pop()
+
+}
+
+
//
//
// lib/Perlito5/Javascript2/CORE.js
Oops, something went wrong.

0 comments on commit b50d8dc

Please sign in to comment.