Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Perlito5 - js - add UNTIE

  • Loading branch information...
commit 1ec6ea07cc3eec308810941d34dfcb7085355a8b 1 parent 9536f4a
@fglock authored
View
11 README-perlito5-js
@@ -27,8 +27,6 @@
- Tie array.
-- String increment.
-
* Perlito5-in-Javascript differences from "perl"
@@ -76,6 +74,8 @@
- tie() is partially implemented.
+- String increment partially implemented - array and hash lookups; not in scalars.
+
* Perlito5 compiler globals
@@ -123,14 +123,17 @@ subroutine call
- "this" is not used.
Hash
-- native {}
+- native {} with perl5-specific getters and setters
Array
-- native []
+- native [] with perl5-specific getters and setters
Scalar
- native value
+Tied containers
+- javascript object with perl5-specific getters and setters
+
HashRef
- native {} wrapped in a "HashRef" object
View
63 html/perlito5.js
@@ -348,12 +348,14 @@ p5tie_array = function(v, List__) {
Object.defineProperty( v, "p5aget", {
enumerable : false,
+ configurable : true,
value : function (i) {
return p5call(res, 'FETCH', [i]);
}
});
Object.defineProperty( v, "p5aset", {
enumerable : false,
+ configurable : true,
value : function (i, value) {
p5call(res, 'STORE', [i, value]);
return value;
@@ -361,6 +363,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5incr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5incr(p5call(res, 'FETCH', [i]));
p5call(res, 'STORE', [i, value]);
@@ -369,6 +372,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5postincr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
p5call(res, 'STORE', [i, p5incr(value)]);
@@ -377,6 +381,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5decr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5decr(p5call(res, 'FETCH', [i]));
p5call(res, 'STORE', [i, value]);
@@ -385,6 +390,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5postdecr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
p5call(res, 'STORE', [i, p5decr(value)]);
@@ -394,6 +400,7 @@ p5tie_array = function(v, List__) {
Object.defineProperty( v, "p5aget_array", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
if (value == null) {
@@ -405,6 +412,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5aget_hash", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
if (value == null) {
@@ -414,10 +422,36 @@ p5tie_array = function(v, List__) {
return value;
}
});
+ Object.defineProperty( v, "p5untie", {
+ enumerable : false,
+ configurable : true,
+ value : function (i) {
+ return p5call(res, 'UNTIE', []);
+ }
+ });
return res;
};
+p5untie_array = function(v) {
+ if (v.hasOwnProperty('p5untie')) {
+ var res = v.p5untie(); // call UNTIE
+ delete v.p5aget;
+ delete v.p5aset;
+ delete v.p5incr;
+ delete v.p5postincr;
+ delete v.p5decr;
+ delete v.p5postdecr;
+ delete v.p5aget_array;
+ delete v.p5aget_hash;
+ delete v.p5untie;
+ return res;
+ }
+ else {
+ return null;
+ }
+};
+
//-------- Hash
Object.defineProperty( Object.prototype, "p5hget", {
@@ -3801,6 +3835,35 @@ var p5100 = p5pkg['main'];
};
};
return (p5context([('p5tie_' + p5str(v_meth) + '(' + p5str(p5call(v_v, "emit_javascript2", [v_level], 0)) + ', ' + p5str(p5pkg["Perlito5::Javascript2"].to_list([(new p5ArrayRef(List_arguments))], 0)) + ')')], p5want));
+ }, 'untie', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
+ var v_level = null;
+ (v_level = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
+ var v_wantarray = null;
+ (v_wantarray = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
+ var List_arguments = [];
+ (List_arguments = p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_));
+ var v_v = null;
+ (v_v = (p5pkg["Perlito5::AST::Apply"].shift([List_arguments])));
+ var v_meth = null;
+ if ( (p5bool(p5call(v_v, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_v, "sigil", [], 0)) == '%')) ) {
+ (v_meth = ('hash'));
+ }
+ else {
+ if ( (p5bool(p5call(v_v, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_v, "sigil", [], 0)) == '@')) ) {
+ (v_meth = ('array'));
+ }
+ else {
+ if ( (p5bool(p5call(v_v, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_v, "sigil", [], 0)) == '$')) ) {
+ (v_meth = ('scalar'));
+ }
+ else {
+ p5pkg["Perlito5::AST::Apply"].die([p5list_to_a('tie ' + String.fromCharCode(39), p5pkg["Perlito5::AST::Apply"].ref([v_v], 1), String.fromCharCode(39) + ' not implemented')], null);
+ };
+ };
+ };
+ return (p5context([('p5untie_' + p5str(v_meth) + '(' + p5str(p5call(v_v, "emit_javascript2", [v_level], 0)) + ')')], p5want));
}, 'map', function (List__, p5want) {
var v_self = null;
(v_self = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
View
26 perlito5.pl
@@ -8849,6 +8849,30 @@ package Perlito5::AST::Apply;
}
};
return (('p5tie_' . $meth . '(' . $v->emit_javascript2($level) . ', ' . Perlito5::Javascript2::to_list(\@arguments) . ')'))
+}, 'untie', sub {
+ ((my $self) = shift());
+ ((my $level) = shift());
+ ((my $wantarray) = shift());
+ ((my @arguments) = @{$self->{'arguments'}});
+ ((my $v) = shift(@arguments));
+ (my $meth);
+ if (($v->isa('Perlito5::AST::Var') && ($v->sigil() eq '%'))) {
+ ($meth = 'hash')
+ }
+ else {
+ if (($v->isa('Perlito5::AST::Var') && ($v->sigil() eq '@'))) {
+ ($meth = 'array')
+ }
+ else {
+ if (($v->isa('Perlito5::AST::Var') && ($v->sigil() eq '$'))) {
+ ($meth = 'scalar')
+ }
+ else {
+ die('tie ' . chr(39), ref($v), chr(39) . ' not implemented')
+ }
+ }
+ };
+ return (('p5untie_' . $meth . '(' . $v->emit_javascript2($level) . ')'))
}, 'map', sub {
((my $self) = shift());
((my $level) = shift());
@@ -9176,7 +9200,7 @@ package main;
undef();
package Perlito5::Javascript2::Runtime;
sub Perlito5::Javascript2::Runtime::emit_javascript2 {
- return ((('//' . chr(10) . '// lib/Perlito5/Javascript2/Runtime.js' . chr(10) . '//' . chr(10) . '// Runtime for "Perlito" Perl5-in-Javascript2' . chr(10) . '//' . chr(10) . '// AUTHORS' . chr(10) . '//' . chr(10) . '// Flavio Soibelmann Glock fglock@gmail.com' . chr(10) . '//' . chr(10) . '// COPYRIGHT' . chr(10) . '//' . chr(10) . '// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.' . chr(10) . '//' . chr(10) . '// This program is free software; you can redistribute it and/or modify it' . chr(10) . '// under the same terms as Perl itself.' . chr(10) . '//' . chr(10) . '// See http://www.perl.com/perl/misc/Artistic.html' . chr(10) . chr(10) . 'var isNode = typeof require != "undefined";' . chr(10) . chr(10) . 'if (typeof p5pkg !== "object") {' . chr(10) . ' p5pkg = {};' . chr(10) . ' p5LOCAL = [];' . chr(10) . chr(10) . ' var universal = function () {};' . chr(10) . ' p5pkg.UNIVERSAL = new universal();' . chr(10) . ' p5pkg.UNIVERSAL._ref_ = "UNIVERSAL";' . chr(10) . ' p5pkg.UNIVERSAL.isa = function (List__) {' . chr(10) . ' // TODO - use @ISA' . chr(10) . ' return List__[0]._class_._ref_ == List__[1]' . chr(10) . ' };' . chr(10) . ' p5pkg.UNIVERSAL.can = function (List__) {' . chr(10) . ' var o = List__[0];' . chr(10) . ' var s = List__[1];' . chr(10) . ' if ( s.indexOf("::") == -1 ) {' . chr(10) . ' return p5method_lookup(s, o._class_._ref__, {})' . chr(10) . ' }' . chr(10) . ' var c = s.split("::");' . chr(10) . ' s = c.pop(); ' . chr(10) . ' return p5method_lookup(s, c.join("::"), {});' . chr(10) . ' };' . chr(10) . ' p5pkg.UNIVERSAL.DOES = p5pkg.UNIVERSAL.can;' . chr(10) . chr(10) . ' var core = function () {};' . chr(10) . ' p5pkg["CORE"] = new core();' . chr(10) . ' p5pkg["CORE"]._ref_ = "CORE";' . chr(10) . chr(10) . ' var core_global = function () {};' . chr(10) . ' core_global.prototype = p5pkg.CORE;' . chr(10) . ' p5pkg["CORE::GLOBAL"] = new core_global();' . chr(10) . ' p5pkg["CORE::GLOBAL"]._ref_ = "CORE::GLOBAL";' . chr(10) . chr(10) . ' p5_error = function (type, v) {' . chr(10) . ' this.type = type;' . chr(10) . ' this.v = v;' . chr(10) . ' this.toString = function(){' . chr(10) . ' if (this.type == ' . chr(39) . 'break' . chr(39) . ') {' . chr(10) . ' return ' . chr(39) . 'Can' . chr(92) . chr(39) . 't "break" outside a given block' . chr(39) . chr(10) . ' }' . chr(10) . ' if (this.type == ' . chr(39) . 'next' . chr(39) . ' || this.type == ' . chr(39) . 'last' . chr(39) . ' || this.type == ' . chr(39) . 'redo' . chr(39) . ') {' . chr(10) . ' if (this.v == "") { return ' . chr(39) . 'Can' . chr(92) . chr(39) . 't "' . chr(39) . ' + this.type + ' . chr(39) . '" outside a loop block' . chr(39) . ' }' . chr(10) . ' return ' . chr(39) . 'Label not found for "' . chr(39) . ' + this.type + ' . chr(39) . ' ' . chr(39) . ' + this.v + ' . chr(39) . '"' . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' return this.v;' . chr(10) . ' };' . chr(10) . ' };' . chr(10) . ' p5_error.prototype = Error.prototype;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5make_package(pkg_name) {' . chr(10) . ' if (!p5pkg.hasOwnProperty(pkg_name)) {' . chr(10) . ' var tmp = function () {};' . chr(10) . ' tmp.prototype = p5pkg["CORE::GLOBAL"];' . chr(10) . ' p5pkg[pkg_name] = new tmp();' . chr(10) . ' p5pkg[pkg_name]._ref_ = pkg_name;' . chr(10) . ' p5pkg[pkg_name]._class_ = p5pkg[pkg_name]; // XXX memory leak' . chr(10) . chr(10) . ' // TODO - add the other package global variables' . chr(10) . ' p5pkg[pkg_name]["List_ISA"] = [];' . chr(10) . ' p5pkg[pkg_name]["v_a"] = null;' . chr(10) . ' p5pkg[pkg_name]["v_b"] = null;' . chr(10) . ' p5pkg[pkg_name]["v__"] = null;' . chr(10) . ' p5pkg[pkg_name]["v_AUTOLOAD"] = null;' . chr(10) . ' }' . chr(10) . ' return p5pkg[pkg_name];' . chr(10) . '}' . chr(10) . chr(10) . 'function p5code_lookup_by_name(package_name, sub_name) {' . chr(10) . ' // sub_name can have an optional namespace' . chr(10) . ' var parts = sub_name.split(/::/);' . chr(10) . ' if (parts.length > 1) {' . chr(10) . ' sub_name = parts.pop();' . chr(10) . ' package_name = parts.join("::");' . chr(10) . ' }' . chr(10) . ' if (p5pkg.hasOwnProperty(package_name)) {' . chr(10) . ' var c = p5pkg[package_name];' . chr(10) . ' if ( c.hasOwnProperty(sub_name) ) {' . chr(10) . ' return c[sub_name]' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return null;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5get_class_for_method(method, class_name, seen) {' . chr(10) . ' // default mro' . chr(10) . ' // TODO - cache the methods that were already looked up' . chr(10) . ' if ( p5pkg[class_name].hasOwnProperty(method) ) {' . chr(10) . ' return class_name' . chr(10) . ' }' . chr(10) . ' var isa = p5pkg[class_name].List_ISA;' . chr(10) . ' for (var i = 0; i < isa.length; i++) {' . chr(10) . ' if (!seen[isa[i]]) {' . chr(10) . ' var m = p5get_class_for_method(method, isa[i]);' . chr(10) . ' if (m) {' . chr(10) . ' return m ' . chr(10) . ' }' . chr(10) . ' seen[isa[i]]++;' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '}' . chr(10) . chr(10) . 'function p5method_lookup(method, class_name, seen) {' . chr(10) . ' var c = p5get_class_for_method(method, class_name, seen);' . chr(10) . ' if (c) {' . chr(10) . ' return p5pkg[c][method]' . chr(10) . ' }' . chr(10) . ' if ( p5pkg.UNIVERSAL.hasOwnProperty(method) ) {' . chr(10) . ' return p5pkg.UNIVERSAL[method]' . chr(10) . ' }' . chr(10) . '}' . chr(10) . chr(10) . 'function p5call(invocant, method, list) {' . chr(10) . ' list.unshift(invocant);' . chr(10) . chr(10) . ' if (typeof invocant === "string") {' . chr(10) . ' invocant = p5make_package(invocant);' . chr(10) . ' }' . chr(10) . chr(10) . ' if ( invocant.hasOwnProperty("_class_") ) {' . chr(10) . chr(10) . ' if ( invocant._class_.hasOwnProperty(method) ) {' . chr(10) . ' return invocant._class_[method](list)' . chr(10) . ' }' . chr(10) . ' var m = p5method_lookup(method, invocant._class_._ref_, {});' . chr(10) . ' if (m) {' . chr(10) . ' return m(list)' . chr(10) . ' }' . chr(10) . chr(10) . ' // method can have an optional namespace' . chr(10) . ' var pkg_name = method.split(/::/);' . chr(10) . ' if (pkg_name.length > 1) {' . chr(10) . ' var name = pkg_name.pop();' . chr(10) . ' pkg_name = pkg_name.join("::");' . chr(10) . ' m = p5method_lookup(name, pkg_name, {});' . chr(10) . ' if (m) {' . chr(10) . ' return m(list)' . chr(10) . ' }' . chr(10) . ' p5pkg.CORE.die(["method not found: ", name, " in class ", pkg_name]);' . chr(10) . ' }' . chr(10) . chr(10) . ' pkg_name = p5get_class_for_method(' . chr(39) . 'AUTOLOAD' . chr(39) . ', invocant._class_._ref_, {}) || p5get_class_for_method(' . chr(39) . 'AUTOLOAD' . chr(39) . ', "UNIVERSAL", {});' . chr(10) . ' if (pkg_name) {' . chr(10) . ' p5pkg[pkg_name]["v_AUTOLOAD"] = invocant._class_._ref_ + "::" + method;' . chr(10) . ' return p5pkg[pkg_name]["AUTOLOAD"](list);' . chr(10) . ' }' . chr(10) . chr(10) . ' p5pkg.CORE.die(["method not found: ", method, " in class ", invocant._class_._ref_]);' . chr(10) . chr(10) . ' }' . chr(10) . chr(10) . ' p5pkg.CORE.die(["Can' . chr(39) . 't call method ", method, " on unblessed reference"]);' . chr(10) . chr(10) . '}' . chr(10) . chr(10) . 'p5make_package("main");' . chr(10) . 'p5pkg["main"]["v_@"] = []; // $@' . chr(10) . 'p5pkg["main"]["v_|"] = 0; // $|' . chr(10) . 'p5pkg["main"]["List_#"] = []; // @#' . chr(10) . 'p5pkg["main"]["v_^O"] = isNode ? "node.js" : "javascript2";' . chr(10) . 'p5pkg["main"]["List_INC"] = [];' . chr(10) . 'p5pkg["main"]["Hash_INC"] = {};' . chr(10) . 'p5pkg["main"]["List_ARGV"] = [];' . chr(10) . 'p5pkg["main"]["Hash_ENV"] = {};' . chr(10) . 'if (isNode) {' . chr(10) . ' p5pkg["main"]["List_ARGV"] = process.argv.splice(2);' . chr(10) . chr(10) . ' p5pkg["main"]["Hash_ENV"] = {};' . chr(10) . ' for (e in process.env) p5pkg["main"]["Hash_ENV"][e] = process.env[e];' . chr(10) . chr(10) . ' p5pkg["main"]["v_$"] = process.pid;' . chr(10) . '} else if (typeof arguments === "object") {' . chr(10) . ' p5pkg["main"]["List_ARGV"] = arguments;' . chr(10) . '}' . chr(10) . chr(10) . 'p5make_package("Perlito5");' . chr(10) . 'p5make_package("Perlito5::IO");' . chr(10) . 'p5make_package("Perlito5::Runtime");' . chr(10) . 'p5make_package("Perlito5::Grammar");' . chr(10) . chr(10) . 'function p5make_sub(pkg_name, sub_name, func) {' . chr(10) . ' p5pkg[pkg_name][sub_name] = func;' . chr(10) . '}' . chr(10) . chr(10) . 'var sigils = { ' . chr(39) . '@' . chr(39) . ' : ' . chr(39) . 'List_' . chr(39) . ', ' . chr(39) . '%' . chr(39) . ' : ' . chr(39) . 'Hash_' . chr(39) . ', ' . chr(39) . '$' . chr(39) . ' : ' . chr(39) . 'v_' . chr(39) . ' };' . chr(10) . chr(10) . 'function p5set_local(namespace, name, sigil) {' . chr(10) . ' var vname = sigils[sigil] + name;' . chr(10) . ' p5LOCAL.push([namespace, vname, namespace[vname]]);' . chr(10) . chr(10) . ' if (sigil == ' . chr(39) . '$' . chr(39) . ') {' . chr(10) . ' namespace[vname] = null;' . chr(10) . ' }' . chr(10) . ' else if (sigil == ' . chr(39) . '@' . chr(39) . ') {' . chr(10) . ' namespace[vname] = new p5Array([]);' . chr(10) . ' }' . chr(10) . ' else if (sigil == ' . chr(39) . '%' . chr(39) . ') {' . chr(10) . ' namespace[vname] = new p5Hash({});' . chr(10) . ' }' . chr(10) . ' return namespace[vname];' . chr(10) . '}' . chr(10) . chr(10) . 'function p5cleanup_local(idx, value) {' . chr(10) . ' while (p5LOCAL.length > idx) {' . chr(10) . ' l = p5LOCAL.pop();' . chr(10) . ' l[0][l[1]] = l[2];' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5HashRef(o) {' . chr(10) . ' this._hash_ = o;' . chr(10) . ' this._ref_ = "HASH";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5ArrayRef(o) {' . chr(10) . ' this._array_ = o;' . chr(10) . ' this._ref_ = "ARRAY";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5ScalarRef(o) {' . chr(10) . ' this._scalar_ = o;' . chr(10) . ' this._ref_ = "SCALAR";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5GlobRef(o) {' . chr(10) . ' this._scalar_ = o;' . chr(10) . ' this._ref_ = "GLOB";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . chr(10) . '//-------- Array ' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' return this[i] ' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5aset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i, v) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = v;' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' if (this[i] == null) { this[i] = new p5ArrayRef([]) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' if (this[i] == null) { this[i] = new p5HashRef({}) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'p5tie_array = function(v, List__) {' . chr(10) . ' var pkg_name = p5str(List__.shift());' . chr(10) . chr(10) . ' var res = p5call(pkg_name, ' . chr(39) . 'TIEARRAY' . chr(39) . ', List__, null);' . chr(10) . ' ' . chr(10) . ' // TODO' . chr(10) . ' ' . chr(10) . ' // A class implementing an ordinary array should have the following methods:' . chr(10) . ' // TIEARRAY pkg_name, LIST' . chr(10) . ' // FETCH this, key' . chr(10) . ' // STORE this, key, value' . chr(10) . ' // FETCHSIZE this' . chr(10) . ' // STORESIZE this, count' . chr(10) . ' // CLEAR this' . chr(10) . ' // PUSH this, LIST' . chr(10) . ' // POP this' . chr(10) . ' // SHIFT this' . chr(10) . ' // UNSHIFT this, LIST' . chr(10) . ' // SPLICE this, offset, length, LIST' . chr(10) . ' // EXTEND this, count' . chr(10) . ' // DESTROY this' . chr(10) . ' // UNTIE this' . chr(10) . ' ' . chr(10) . ' Object.defineProperty( v, "p5aget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' return p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5aset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i, value) {' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5incr(p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]));' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, p5incr(value)]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5decr(p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]));' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, p5decr(value)]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' ' . chr(10) . ' Object.defineProperty( v, "p5aget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' if (value == null) {' . chr(10) . ' value = new p5ArrayRef([]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5aget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' if (value == null) {' . chr(10) . ' value = new p5HashRef({});' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . '//-------- Hash ' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) { return this[i] }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5hset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i, v) { this[i] = v; return this[i] }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (this[i] == null) { this[i] = new p5ArrayRef([]) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (this[i] == null) { this[i] = new p5HashRef({}) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . '//-------' . chr(10) . chr(10) . chr(10) . 'if (isNode) {' . chr(10) . ' var fs = require("fs");' . chr(10) . ' p5make_sub("Perlito5::IO", "slurp", function(List__) {' . chr(10) . ' return fs.readFileSync(List__[0],"utf8");' . chr(10) . ' });' . chr(10) . '} else {' . chr(10) . ' p5make_sub("Perlito5::IO", "slurp", function(List__) {' . chr(10) . ' var filename = List__[0];' . chr(10) . ' if (typeof readFile == "function") {' . chr(10) . ' return readFile(filename);' . chr(10) . ' }' . chr(10) . ' if (typeof read == "function") {' . chr(10) . ' // v8' . chr(10) . ' return read(filename);' . chr(10) . ' }' . chr(10) . ' p5pkg.CORE.die(["Perlito5::IO::slurp() not implemented"]);' . chr(10) . ' });' . chr(10) . '}' . chr(10) . chr(10) . 'p5context = function(List__, p5want) {' . chr(10) . ' if (p5want) {' . chr(10) . ' return p5list_to_a.apply(null, List__);' . chr(10) . ' }' . chr(10) . ' // scalar: return the last value' . chr(10) . ' var o = List__;' . chr(10) . ' while (o instanceof Array) {' . chr(10) . ' o = o.length' . chr(10) . ' ? o[o.length-1]' . chr(10) . ' : null;' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '}' . chr(10) . chr(10) . 'p5list_to_a = function() {' . chr(10) . ' var res = [];' . chr(10) . ' for (i = 0; i < arguments.length; i++) {' . chr(10) . ' var o = arguments[i];' . chr(10) . ' if ( o == null' . chr(10) . ' || o._class_ // perl5 blessed reference' . chr(10) . ' || o._ref_ // perl5 un-blessed reference' . chr(10) . ' )' . chr(10) . ' {' . chr(10) . ' res.push(o);' . chr(10) . ' }' . chr(10) . ' else if (o instanceof Array) {' . chr(10) . ' // perl5 array' . chr(10) . ' for (j = 0; j < o.length; j++) {' . chr(10) . ' res.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' else if (typeof o === "object") {' . chr(10) . ' // perl5 hash' . chr(10) . ' for(var j in o) {' . chr(10) . ' if (o.hasOwnProperty(j)) {' . chr(10) . ' res.push(j);' . chr(10) . ' res.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' else {' . chr(10) . ' // non-ref' . chr(10) . ' res.push(o);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . 'p5a_to_h = function(a) {' . chr(10) . ' var res = {};' . chr(10) . ' for (i = 0; i < a.length; i+=2) {' . chr(10) . ' res[p5str(a[i])] = a[i+1];' . chr(10) . ' }' . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . 'p5idx = function(a, i) {' . chr(10) . ' return i >= 0 ? i : a.length + i' . chr(10) . '};' . chr(10) . chr(10) . 'p5str = function(o) {' . chr(10) . ' if (o == null) {' . chr(10) . ' return "";' . chr(10) . ' }' . chr(10) . ' if (typeof o === "object" && (o instanceof Array)) {' . chr(10) . ' return CORE.join(["", o]);' . chr(10) . ' }' . chr(10) . ' // if (typeof o.string === "function") {' . chr(10) . ' // return o.string();' . chr(10) . ' // }' . chr(10) . ' if (typeof o == "number" && Math.abs(o) < 0.0001 && o != 0) {' . chr(10) . ' return o.toExponential().replace(/e-(' . chr(92) . 'd)$/,"e-0$1");' . chr(10) . ' }' . chr(10) . ' if (typeof o === "boolean") {' . chr(10) . ' return o ? "1" : "";' . chr(10) . ' }' . chr(10) . ' if (typeof o !== "string") {' . chr(10) . ' return "" + o;' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '};' . chr(10) . chr(10) . 'p5num = function(o) {' . chr(10) . ' if (o == null) {' . chr(10) . ' return 0;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "object" && (o instanceof Array)) {' . chr(10) . ' return o.length;' . chr(10) . ' }' . chr(10) . ' // if (typeof o.num === "function") {' . chr(10) . ' // return o.num();' . chr(10) . ' // }' . chr(10) . ' if (typeof o !== "number") {' . chr(10) . ' return parseFloat(p5str(o));' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '};' . chr(10) . chr(10) . 'p5bool = function(o) {' . chr(10) . ' if (o) {' . chr(10) . ' if (typeof o === "boolean") {' . chr(10) . ' return o;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "string") {' . chr(10) . ' return o != "" && o != "0";' . chr(10) . ' }' . chr(10) . ' // if (typeof o.bool === "function") {' . chr(10) . ' // return o.bool();' . chr(10) . ' // }' . chr(10) . ' if (typeof o.length === "number") {' . chr(10) . ' return o.length;' . chr(10) . ' }' . chr(10) . ' if (o instanceof Error) {' . chr(10) . ' return true;' . chr(10) . ' }' . chr(10) . ' for (var i in o) {' . chr(10) . ' return true;' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return false;' . chr(10) . '};' . chr(10) . chr(10) . 'p5incr = function(o) {' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o + 1;' . chr(10) . ' }' . chr(10) . ' return p5str_inc(p5str(o));' . chr(10) . '};' . chr(10) . chr(10) . 'p5decr = function(o) {' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o - 1;' . chr(10) . ' }' . chr(10) . ' return p5num(o) - 1;' . chr(10) . '};' . chr(10) . chr(10) . 'p5and = function(a, fb) {' . chr(10) . ' if (p5bool(a)) {' . chr(10) . ' return fb();' . chr(10) . ' }' . chr(10) . ' return a;' . chr(10) . '};' . chr(10) . chr(10) . 'p5or = function(a, fb) {' . chr(10) . ' if (p5bool(a)) {' . chr(10) . ' return a;' . chr(10) . ' }' . chr(10) . ' return fb();' . chr(10) . '};' . chr(10) . chr(10) . 'p5defined_or = function(a, fb) {' . chr(10) . ' if (a == null) {' . chr(10) . ' return fb();' . chr(10) . ' }' . chr(10) . ' return a;' . chr(10) . '};' . chr(10) . chr(10) . 'p5cmp = function(a, b) {' . chr(10) . ' return a > b ? 1 : a < b ? -1 : 0 ' . chr(10) . '};' . chr(10) . chr(10) . 'p5complement = function(a) {' . chr(10) . ' return a < 0 ? ~a : 4294967295 - a' . chr(10) . ' // return a < 0 ? ~a : 18446744073709551615 - a' . chr(10) . '};' . chr(10) . chr(10) . 'p5str_replicate = function(o, n) {' . chr(10) . ' n = p5num(n);' . chr(10) . ' return n ? Array(n + 1).join(o) : "";' . chr(10) . '};' . chr(10) . chr(10) . 'p5str_inc = function(s) {' . chr(10) . ' s = p5str(s);' . chr(10) . ' if (s.length < 2) {' . chr(10) . ' if (s.match(/[012345678ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy]/)) {' . chr(10) . ' return String.fromCharCode(s.charCodeAt(0) + 1);' . chr(10) . ' }' . chr(10) . ' if (s == "9") {' . chr(10) . ' return "10";' . chr(10) . ' }' . chr(10) . ' if (s == "Z") {' . chr(10) . ' return "AA";' . chr(10) . ' }' . chr(10) . ' if (s == "z") {' . chr(10) . ' return "aa";' . chr(10) . ' }' . chr(10) . ' return "1";' . chr(10) . ' }' . chr(10) . ' var c = p5str_inc(s.substr(s.length-1, 1));' . chr(10) . ' if (c.length == 1) {' . chr(10) . ' return s.substr(0, s.length-1) + c;' . chr(10) . ' }' . chr(10) . ' return p5str_inc(s.substr(0, s.length-1)) + c.substr(c.length-1, 1);' . chr(10) . '};' . chr(10) . chr(10) . 'p5for = function(namespace, func, args, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' try {' . chr(10) . ' func()' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { i--; _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' }' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . '};' . chr(10) . chr(10) . 'p5for_lex = function(func, args, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' try {' . chr(10) . ' func(args[i])' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { i--; _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '};' . chr(10) . chr(10) . 'p5while = function(func, cond, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' while (_redo || p5bool(cond())) {' . chr(10) . ' _redo = false;' . chr(10) . ' try {' . chr(10) . ' func()' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '};' . chr(10) . chr(10) . 'p5map = function(namespace, func, args) {' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' var out = [];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' var o = p5list_to_a(func(1));' . chr(10) . ' for(var j = 0; j < o.length; j++) {' . chr(10) . ' out.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'p5grep = function(namespace, func, args) {' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' var out = [];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' if (p5bool(func(0))) {' . chr(10) . ' out.push(args[i])' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'p5sort = function(namespace, func, args) {' . chr(10) . ' var a_old = namespace["v_a"];' . chr(10) . ' var b_old = namespace["v_b"];' . chr(10) . ' var out = ' . chr(10) . ' func == null' . chr(10) . ' ? args.sort()' . chr(10) . ' : args.sort(' . chr(10) . ' function(a, b) {' . chr(10) . ' namespace["v_a"] = a;' . chr(10) . ' namespace["v_b"] = b;' . chr(10) . ' return func(0);' . chr(10) . ' }' . chr(10) . ' );' . chr(10) . ' namespace["v_a"] = a_old;' . chr(10) . ' namespace["v_b"] = b_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'perl5_to_js = function( source, namespace, var_env_js, p5want ) {' . chr(10) . ' // CORE.say(["source: [" + source + "]"]);' . chr(10) . chr(10) . ' var strict_old = p5pkg["Perlito5"].v_STRICT;' . chr(10) . ' var var_env_js_old = p5pkg["Perlito5"].v_VAR;' . chr(10) . ' p5pkg["Perlito5"].v_VAR = var_env_js;' . chr(10) . chr(10) . ' var namespace_old = p5pkg["Perlito5"].v_PKG_NAME;' . chr(10) . ' p5pkg["Perlito5"].v_PKG_NAME = namespace;' . chr(10) . chr(10) . ' match = p5call(p5pkg["Perlito5::Grammar"], "exp_stmts", [source, 0]);' . chr(10) . chr(10) . ' if ( !match || match._hash_.to != source.length ) {' . chr(10) . ' CORE.die(["Syntax error in eval near pos ", match._hash_.to]);' . chr(10) . ' }' . chr(10) . chr(10) . ' ast = p5pkg.CORE.bless([' . chr(10) . ' new p5HashRef({' . chr(10) . ' block: p5pkg.CORE.bless([' . chr(10) . ' new p5HashRef({' . chr(10) . ' stmts: p5pkg["Perlito5::Match"].flat([match])' . chr(10) . ' }),' . chr(10) . ' p5pkg["Perlito5::AST::Lit::Block"]' . chr(10) . ' ])' . chr(10) . ' }),' . chr(10) . ' p5pkg["Perlito5::AST::Do"]' . chr(10) . ' ]);' . chr(10) . chr(10) . ' // CORE.say(["ast: [" + ast + "]"]);' . chr(10) . ' js_code = p5call(ast, "emit_javascript2", [0, p5want]);' . chr(10) . ' // CORE.say(["js-source: [" + js_code + "]"]);' . chr(10) . chr(10) . ' p5pkg["Perlito5"].v_PKG_NAME = namespace_old;' . chr(10) . ' p5pkg["Perlito5"].v_VAR = var_env_js_old;' . chr(10) . ' p5pkg["Perlito5"].v_STRICT = strict_old;' . chr(10) . ' return js_code;' . chr(10) . '}' . chr(10) . chr(10))))
+ return ((('//' . chr(10) . '// lib/Perlito5/Javascript2/Runtime.js' . chr(10) . '//' . chr(10) . '// Runtime for "Perlito" Perl5-in-Javascript2' . chr(10) . '//' . chr(10) . '// AUTHORS' . chr(10) . '//' . chr(10) . '// Flavio Soibelmann Glock fglock@gmail.com' . chr(10) . '//' . chr(10) . '// COPYRIGHT' . chr(10) . '//' . chr(10) . '// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.' . chr(10) . '//' . chr(10) . '// This program is free software; you can redistribute it and/or modify it' . chr(10) . '// under the same terms as Perl itself.' . chr(10) . '//' . chr(10) . '// See http://www.perl.com/perl/misc/Artistic.html' . chr(10) . chr(10) . 'var isNode = typeof require != "undefined";' . chr(10) . chr(10) . 'if (typeof p5pkg !== "object") {' . chr(10) . ' p5pkg = {};' . chr(10) . ' p5LOCAL = [];' . chr(10) . chr(10) . ' var universal = function () {};' . chr(10) . ' p5pkg.UNIVERSAL = new universal();' . chr(10) . ' p5pkg.UNIVERSAL._ref_ = "UNIVERSAL";' . chr(10) . ' p5pkg.UNIVERSAL.isa = function (List__) {' . chr(10) . ' // TODO - use @ISA' . chr(10) . ' return List__[0]._class_._ref_ == List__[1]' . chr(10) . ' };' . chr(10) . ' p5pkg.UNIVERSAL.can = function (List__) {' . chr(10) . ' var o = List__[0];' . chr(10) . ' var s = List__[1];' . chr(10) . ' if ( s.indexOf("::") == -1 ) {' . chr(10) . ' return p5method_lookup(s, o._class_._ref__, {})' . chr(10) . ' }' . chr(10) . ' var c = s.split("::");' . chr(10) . ' s = c.pop(); ' . chr(10) . ' return p5method_lookup(s, c.join("::"), {});' . chr(10) . ' };' . chr(10) . ' p5pkg.UNIVERSAL.DOES = p5pkg.UNIVERSAL.can;' . chr(10) . chr(10) . ' var core = function () {};' . chr(10) . ' p5pkg["CORE"] = new core();' . chr(10) . ' p5pkg["CORE"]._ref_ = "CORE";' . chr(10) . chr(10) . ' var core_global = function () {};' . chr(10) . ' core_global.prototype = p5pkg.CORE;' . chr(10) . ' p5pkg["CORE::GLOBAL"] = new core_global();' . chr(10) . ' p5pkg["CORE::GLOBAL"]._ref_ = "CORE::GLOBAL";' . chr(10) . chr(10) . ' p5_error = function (type, v) {' . chr(10) . ' this.type = type;' . chr(10) . ' this.v = v;' . chr(10) . ' this.toString = function(){' . chr(10) . ' if (this.type == ' . chr(39) . 'break' . chr(39) . ') {' . chr(10) . ' return ' . chr(39) . 'Can' . chr(92) . chr(39) . 't "break" outside a given block' . chr(39) . chr(10) . ' }' . chr(10) . ' if (this.type == ' . chr(39) . 'next' . chr(39) . ' || this.type == ' . chr(39) . 'last' . chr(39) . ' || this.type == ' . chr(39) . 'redo' . chr(39) . ') {' . chr(10) . ' if (this.v == "") { return ' . chr(39) . 'Can' . chr(92) . chr(39) . 't "' . chr(39) . ' + this.type + ' . chr(39) . '" outside a loop block' . chr(39) . ' }' . chr(10) . ' return ' . chr(39) . 'Label not found for "' . chr(39) . ' + this.type + ' . chr(39) . ' ' . chr(39) . ' + this.v + ' . chr(39) . '"' . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' return this.v;' . chr(10) . ' };' . chr(10) . ' };' . chr(10) . ' p5_error.prototype = Error.prototype;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5make_package(pkg_name) {' . chr(10) . ' if (!p5pkg.hasOwnProperty(pkg_name)) {' . chr(10) . ' var tmp = function () {};' . chr(10) . ' tmp.prototype = p5pkg["CORE::GLOBAL"];' . chr(10) . ' p5pkg[pkg_name] = new tmp();' . chr(10) . ' p5pkg[pkg_name]._ref_ = pkg_name;' . chr(10) . ' p5pkg[pkg_name]._class_ = p5pkg[pkg_name]; // XXX memory leak' . chr(10) . chr(10) . ' // TODO - add the other package global variables' . chr(10) . ' p5pkg[pkg_name]["List_ISA"] = [];' . chr(10) . ' p5pkg[pkg_name]["v_a"] = null;' . chr(10) . ' p5pkg[pkg_name]["v_b"] = null;' . chr(10) . ' p5pkg[pkg_name]["v__"] = null;' . chr(10) . ' p5pkg[pkg_name]["v_AUTOLOAD"] = null;' . chr(10) . ' }' . chr(10) . ' return p5pkg[pkg_name];' . chr(10) . '}' . chr(10) . chr(10) . 'function p5code_lookup_by_name(package_name, sub_name) {' . chr(10) . ' // sub_name can have an optional namespace' . chr(10) . ' var parts = sub_name.split(/::/);' . chr(10) . ' if (parts.length > 1) {' . chr(10) . ' sub_name = parts.pop();' . chr(10) . ' package_name = parts.join("::");' . chr(10) . ' }' . chr(10) . ' if (p5pkg.hasOwnProperty(package_name)) {' . chr(10) . ' var c = p5pkg[package_name];' . chr(10) . ' if ( c.hasOwnProperty(sub_name) ) {' . chr(10) . ' return c[sub_name]' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return null;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5get_class_for_method(method, class_name, seen) {' . chr(10) . ' // default mro' . chr(10) . ' // TODO - cache the methods that were already looked up' . chr(10) . ' if ( p5pkg[class_name].hasOwnProperty(method) ) {' . chr(10) . ' return class_name' . chr(10) . ' }' . chr(10) . ' var isa = p5pkg[class_name].List_ISA;' . chr(10) . ' for (var i = 0; i < isa.length; i++) {' . chr(10) . ' if (!seen[isa[i]]) {' . chr(10) . ' var m = p5get_class_for_method(method, isa[i]);' . chr(10) . ' if (m) {' . chr(10) . ' return m ' . chr(10) . ' }' . chr(10) . ' seen[isa[i]]++;' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '}' . chr(10) . chr(10) . 'function p5method_lookup(method, class_name, seen) {' . chr(10) . ' var c = p5get_class_for_method(method, class_name, seen);' . chr(10) . ' if (c) {' . chr(10) . ' return p5pkg[c][method]' . chr(10) . ' }' . chr(10) . ' if ( p5pkg.UNIVERSAL.hasOwnProperty(method) ) {' . chr(10) . ' return p5pkg.UNIVERSAL[method]' . chr(10) . ' }' . chr(10) . '}' . chr(10) . chr(10) . 'function p5call(invocant, method, list) {' . chr(10) . ' list.unshift(invocant);' . chr(10) . chr(10) . ' if (typeof invocant === "string") {' . chr(10) . ' invocant = p5make_package(invocant);' . chr(10) . ' }' . chr(10) . chr(10) . ' if ( invocant.hasOwnProperty("_class_") ) {' . chr(10) . chr(10) . ' if ( invocant._class_.hasOwnProperty(method) ) {' . chr(10) . ' return invocant._class_[method](list)' . chr(10) . ' }' . chr(10) . ' var m = p5method_lookup(method, invocant._class_._ref_, {});' . chr(10) . ' if (m) {' . chr(10) . ' return m(list)' . chr(10) . ' }' . chr(10) . chr(10) . ' // method can have an optional namespace' . chr(10) . ' var pkg_name = method.split(/::/);' . chr(10) . ' if (pkg_name.length > 1) {' . chr(10) . ' var name = pkg_name.pop();' . chr(10) . ' pkg_name = pkg_name.join("::");' . chr(10) . ' m = p5method_lookup(name, pkg_name, {});' . chr(10) . ' if (m) {' . chr(10) . ' return m(list)' . chr(10) . ' }' . chr(10) . ' p5pkg.CORE.die(["method not found: ", name, " in class ", pkg_name]);' . chr(10) . ' }' . chr(10) . chr(10) . ' pkg_name = p5get_class_for_method(' . chr(39) . 'AUTOLOAD' . chr(39) . ', invocant._class_._ref_, {}) || p5get_class_for_method(' . chr(39) . 'AUTOLOAD' . chr(39) . ', "UNIVERSAL", {});' . chr(10) . ' if (pkg_name) {' . chr(10) . ' p5pkg[pkg_name]["v_AUTOLOAD"] = invocant._class_._ref_ + "::" + method;' . chr(10) . ' return p5pkg[pkg_name]["AUTOLOAD"](list);' . chr(10) . ' }' . chr(10) . chr(10) . ' p5pkg.CORE.die(["method not found: ", method, " in class ", invocant._class_._ref_]);' . chr(10) . chr(10) . ' }' . chr(10) . chr(10) . ' p5pkg.CORE.die(["Can' . chr(39) . 't call method ", method, " on unblessed reference"]);' . chr(10) . chr(10) . '}' . chr(10) . chr(10) . 'p5make_package("main");' . chr(10) . 'p5pkg["main"]["v_@"] = []; // $@' . chr(10) . 'p5pkg["main"]["v_|"] = 0; // $|' . chr(10) . 'p5pkg["main"]["List_#"] = []; // @#' . chr(10) . 'p5pkg["main"]["v_^O"] = isNode ? "node.js" : "javascript2";' . chr(10) . 'p5pkg["main"]["List_INC"] = [];' . chr(10) . 'p5pkg["main"]["Hash_INC"] = {};' . chr(10) . 'p5pkg["main"]["List_ARGV"] = [];' . chr(10) . 'p5pkg["main"]["Hash_ENV"] = {};' . chr(10) . 'if (isNode) {' . chr(10) . ' p5pkg["main"]["List_ARGV"] = process.argv.splice(2);' . chr(10) . chr(10) . ' p5pkg["main"]["Hash_ENV"] = {};' . chr(10) . ' for (e in process.env) p5pkg["main"]["Hash_ENV"][e] = process.env[e];' . chr(10) . chr(10) . ' p5pkg["main"]["v_$"] = process.pid;' . chr(10) . '} else if (typeof arguments === "object") {' . chr(10) . ' p5pkg["main"]["List_ARGV"] = arguments;' . chr(10) . '}' . chr(10) . chr(10) . 'p5make_package("Perlito5");' . chr(10) . 'p5make_package("Perlito5::IO");' . chr(10) . 'p5make_package("Perlito5::Runtime");' . chr(10) . 'p5make_package("Perlito5::Grammar");' . chr(10) . chr(10) . 'function p5make_sub(pkg_name, sub_name, func) {' . chr(10) . ' p5pkg[pkg_name][sub_name] = func;' . chr(10) . '}' . chr(10) . chr(10) . 'var sigils = { ' . chr(39) . '@' . chr(39) . ' : ' . chr(39) . 'List_' . chr(39) . ', ' . chr(39) . '%' . chr(39) . ' : ' . chr(39) . 'Hash_' . chr(39) . ', ' . chr(39) . '$' . chr(39) . ' : ' . chr(39) . 'v_' . chr(39) . ' };' . chr(10) . chr(10) . 'function p5set_local(namespace, name, sigil) {' . chr(10) . ' var vname = sigils[sigil] + name;' . chr(10) . ' p5LOCAL.push([namespace, vname, namespace[vname]]);' . chr(10) . chr(10) . ' if (sigil == ' . chr(39) . '$' . chr(39) . ') {' . chr(10) . ' namespace[vname] = null;' . chr(10) . ' }' . chr(10) . ' else if (sigil == ' . chr(39) . '@' . chr(39) . ') {' . chr(10) . ' namespace[vname] = new p5Array([]);' . chr(10) . ' }' . chr(10) . ' else if (sigil == ' . chr(39) . '%' . chr(39) . ') {' . chr(10) . ' namespace[vname] = new p5Hash({});' . chr(10) . ' }' . chr(10) . ' return namespace[vname];' . chr(10) . '}' . chr(10) . chr(10) . 'function p5cleanup_local(idx, value) {' . chr(10) . ' while (p5LOCAL.length > idx) {' . chr(10) . ' l = p5LOCAL.pop();' . chr(10) . ' l[0][l[1]] = l[2];' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . '}' . chr(10) . chr(10) . 'function p5HashRef(o) {' . chr(10) . ' this._hash_ = o;' . chr(10) . ' this._ref_ = "HASH";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5ArrayRef(o) {' . chr(10) . ' this._array_ = o;' . chr(10) . ' this._ref_ = "ARRAY";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5ScalarRef(o) {' . chr(10) . ' this._scalar_ = o;' . chr(10) . ' this._ref_ = "SCALAR";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . 'function p5GlobRef(o) {' . chr(10) . ' this._scalar_ = o;' . chr(10) . ' this._ref_ = "GLOB";' . chr(10) . ' this.bool = function() { return 1 };' . chr(10) . '}' . chr(10) . chr(10) . chr(10) . '//-------- Array ' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' return this[i] ' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5aset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i, v) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = v;' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' if (this[i] == null) { this[i] = new p5ArrayRef([]) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Array.prototype, "p5aget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (i < 0) { i = this.length + i };' . chr(10) . ' if (this[i] == null) { this[i] = new p5HashRef({}) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'p5tie_array = function(v, List__) {' . chr(10) . ' var pkg_name = p5str(List__.shift());' . chr(10) . chr(10) . ' var res = p5call(pkg_name, ' . chr(39) . 'TIEARRAY' . chr(39) . ', List__, null);' . chr(10) . ' ' . chr(10) . ' // TODO' . chr(10) . ' ' . chr(10) . ' // A class implementing an ordinary array should have the following methods:' . chr(10) . ' // TIEARRAY pkg_name, LIST' . chr(10) . ' // FETCH this, key' . chr(10) . ' // STORE this, key, value' . chr(10) . ' // FETCHSIZE this' . chr(10) . ' // STORESIZE this, count' . chr(10) . ' // CLEAR this' . chr(10) . ' // PUSH this, LIST' . chr(10) . ' // POP this' . chr(10) . ' // SHIFT this' . chr(10) . ' // UNSHIFT this, LIST' . chr(10) . ' // SPLICE this, offset, length, LIST' . chr(10) . ' // EXTEND this, count' . chr(10) . ' // DESTROY this' . chr(10) . ' // UNTIE this' . chr(10) . ' ' . chr(10) . ' Object.defineProperty( v, "p5aget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' return p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5aset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i, value) {' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5incr(p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]));' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, p5incr(value)]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5decr(p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]));' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, p5decr(value)]);' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' ' . chr(10) . ' Object.defineProperty( v, "p5aget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' if (value == null) {' . chr(10) . ' value = new p5ArrayRef([]);' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5aget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' var value = p5call(res, ' . chr(39) . 'FETCH' . chr(39) . ', [i]);' . chr(10) . ' if (value == null) {' . chr(10) . ' value = new p5HashRef({});' . chr(10) . ' p5call(res, ' . chr(39) . 'STORE' . chr(39) . ', [i, value]);' . chr(10) . ' }' . chr(10) . ' return value;' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . ' Object.defineProperty( v, "p5untie", {' . chr(10) . ' enumerable : false,' . chr(10) . ' configurable : true,' . chr(10) . ' value : function (i) {' . chr(10) . ' return p5call(res, ' . chr(39) . 'UNTIE' . chr(39) . ', []);' . chr(10) . ' }' . chr(10) . ' });' . chr(10) . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . 'p5untie_array = function(v) {' . chr(10) . ' if (v.hasOwnProperty(' . chr(39) . 'p5untie' . chr(39) . ')) {' . chr(10) . ' var res = v.p5untie(); // call UNTIE' . chr(10) . ' delete v.p5aget;' . chr(10) . ' delete v.p5aset;' . chr(10) . ' delete v.p5incr;' . chr(10) . ' delete v.p5postincr;' . chr(10) . ' delete v.p5decr;' . chr(10) . ' delete v.p5postdecr;' . chr(10) . ' delete v.p5aget_array;' . chr(10) . ' delete v.p5aget_hash;' . chr(10) . ' delete v.p5untie;' . chr(10) . ' return res;' . chr(10) . ' }' . chr(10) . ' else {' . chr(10) . ' return null;' . chr(10) . ' }' . chr(10) . '};' . chr(10) . chr(10) . '//-------- Hash ' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) { return this[i] }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5hset", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i, v) { this[i] = v; return this[i] }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5incr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5postincr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5incr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5decr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return this[i];' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5postdecr", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' var v = this[i];' . chr(10) . ' this[i] = p5decr(this[i]);' . chr(10) . ' return v;' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget_array", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (this[i] == null) { this[i] = new p5ArrayRef([]) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . 'Object.defineProperty( Object.prototype, "p5hget_hash", {' . chr(10) . ' enumerable : false,' . chr(10) . ' value : function (i) {' . chr(10) . ' if (this[i] == null) { this[i] = new p5HashRef({}) }' . chr(10) . ' return this[i]' . chr(10) . ' }' . chr(10) . '});' . chr(10) . chr(10) . '//-------' . chr(10) . chr(10) . chr(10) . 'if (isNode) {' . chr(10) . ' var fs = require("fs");' . chr(10) . ' p5make_sub("Perlito5::IO", "slurp", function(List__) {' . chr(10) . ' return fs.readFileSync(List__[0],"utf8");' . chr(10) . ' });' . chr(10) . '} else {' . chr(10) . ' p5make_sub("Perlito5::IO", "slurp", function(List__) {' . chr(10) . ' var filename = List__[0];' . chr(10) . ' if (typeof readFile == "function") {' . chr(10) . ' return readFile(filename);' . chr(10) . ' }' . chr(10) . ' if (typeof read == "function") {' . chr(10) . ' // v8' . chr(10) . ' return read(filename);' . chr(10) . ' }' . chr(10) . ' p5pkg.CORE.die(["Perlito5::IO::slurp() not implemented"]);' . chr(10) . ' });' . chr(10) . '}' . chr(10) . chr(10) . 'p5context = function(List__, p5want) {' . chr(10) . ' if (p5want) {' . chr(10) . ' return p5list_to_a.apply(null, List__);' . chr(10) . ' }' . chr(10) . ' // scalar: return the last value' . chr(10) . ' var o = List__;' . chr(10) . ' while (o instanceof Array) {' . chr(10) . ' o = o.length' . chr(10) . ' ? o[o.length-1]' . chr(10) . ' : null;' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '}' . chr(10) . chr(10) . 'p5list_to_a = function() {' . chr(10) . ' var res = [];' . chr(10) . ' for (i = 0; i < arguments.length; i++) {' . chr(10) . ' var o = arguments[i];' . chr(10) . ' if ( o == null' . chr(10) . ' || o._class_ // perl5 blessed reference' . chr(10) . ' || o._ref_ // perl5 un-blessed reference' . chr(10) . ' )' . chr(10) . ' {' . chr(10) . ' res.push(o);' . chr(10) . ' }' . chr(10) . ' else if (o instanceof Array) {' . chr(10) . ' // perl5 array' . chr(10) . ' for (j = 0; j < o.length; j++) {' . chr(10) . ' res.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' else if (typeof o === "object") {' . chr(10) . ' // perl5 hash' . chr(10) . ' for(var j in o) {' . chr(10) . ' if (o.hasOwnProperty(j)) {' . chr(10) . ' res.push(j);' . chr(10) . ' res.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' else {' . chr(10) . ' // non-ref' . chr(10) . ' res.push(o);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . 'p5a_to_h = function(a) {' . chr(10) . ' var res = {};' . chr(10) . ' for (i = 0; i < a.length; i+=2) {' . chr(10) . ' res[p5str(a[i])] = a[i+1];' . chr(10) . ' }' . chr(10) . ' return res;' . chr(10) . '};' . chr(10) . chr(10) . 'p5idx = function(a, i) {' . chr(10) . ' return i >= 0 ? i : a.length + i' . chr(10) . '};' . chr(10) . chr(10) . 'p5str = function(o) {' . chr(10) . ' if (o == null) {' . chr(10) . ' return "";' . chr(10) . ' }' . chr(10) . ' if (typeof o === "object" && (o instanceof Array)) {' . chr(10) . ' return CORE.join(["", o]);' . chr(10) . ' }' . chr(10) . ' // if (typeof o.string === "function") {' . chr(10) . ' // return o.string();' . chr(10) . ' // }' . chr(10) . ' if (typeof o == "number" && Math.abs(o) < 0.0001 && o != 0) {' . chr(10) . ' return o.toExponential().replace(/e-(' . chr(92) . 'd)$/,"e-0$1");' . chr(10) . ' }' . chr(10) . ' if (typeof o === "boolean") {' . chr(10) . ' return o ? "1" : "";' . chr(10) . ' }' . chr(10) . ' if (typeof o !== "string") {' . chr(10) . ' return "" + o;' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '};' . chr(10) . chr(10) . 'p5num = function(o) {' . chr(10) . ' if (o == null) {' . chr(10) . ' return 0;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "object" && (o instanceof Array)) {' . chr(10) . ' return o.length;' . chr(10) . ' }' . chr(10) . ' // if (typeof o.num === "function") {' . chr(10) . ' // return o.num();' . chr(10) . ' // }' . chr(10) . ' if (typeof o !== "number") {' . chr(10) . ' return parseFloat(p5str(o));' . chr(10) . ' }' . chr(10) . ' return o;' . chr(10) . '};' . chr(10) . chr(10) . 'p5bool = function(o) {' . chr(10) . ' if (o) {' . chr(10) . ' if (typeof o === "boolean") {' . chr(10) . ' return o;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o;' . chr(10) . ' }' . chr(10) . ' if (typeof o === "string") {' . chr(10) . ' return o != "" && o != "0";' . chr(10) . ' }' . chr(10) . ' // if (typeof o.bool === "function") {' . chr(10) . ' // return o.bool();' . chr(10) . ' // }' . chr(10) . ' if (typeof o.length === "number") {' . chr(10) . ' return o.length;' . chr(10) . ' }' . chr(10) . ' if (o instanceof Error) {' . chr(10) . ' return true;' . chr(10) . ' }' . chr(10) . ' for (var i in o) {' . chr(10) . ' return true;' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' return false;' . chr(10) . '};' . chr(10) . chr(10) . 'p5incr = function(o) {' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o + 1;' . chr(10) . ' }' . chr(10) . ' return p5str_inc(p5str(o));' . chr(10) . '};' . chr(10) . chr(10) . 'p5decr = function(o) {' . chr(10) . ' if (typeof o === "number") {' . chr(10) . ' return o - 1;' . chr(10) . ' }' . chr(10) . ' return p5num(o) - 1;' . chr(10) . '};' . chr(10) . chr(10) . 'p5and = function(a, fb) {' . chr(10) . ' if (p5bool(a)) {' . chr(10) . ' return fb();' . chr(10) . ' }' . chr(10) . ' return a;' . chr(10) . '};' . chr(10) . chr(10) . 'p5or = function(a, fb) {' . chr(10) . ' if (p5bool(a)) {' . chr(10) . ' return a;' . chr(10) . ' }' . chr(10) . ' return fb();' . chr(10) . '};' . chr(10) . chr(10) . 'p5defined_or = function(a, fb) {' . chr(10) . ' if (a == null) {' . chr(10) . ' return fb();' . chr(10) . ' }' . chr(10) . ' return a;' . chr(10) . '};' . chr(10) . chr(10) . 'p5cmp = function(a, b) {' . chr(10) . ' return a > b ? 1 : a < b ? -1 : 0 ' . chr(10) . '};' . chr(10) . chr(10) . 'p5complement = function(a) {' . chr(10) . ' return a < 0 ? ~a : 4294967295 - a' . chr(10) . ' // return a < 0 ? ~a : 18446744073709551615 - a' . chr(10) . '};' . chr(10) . chr(10) . 'p5str_replicate = function(o, n) {' . chr(10) . ' n = p5num(n);' . chr(10) . ' return n ? Array(n + 1).join(o) : "";' . chr(10) . '};' . chr(10) . chr(10) . 'p5str_inc = function(s) {' . chr(10) . ' s = p5str(s);' . chr(10) . ' if (s.length < 2) {' . chr(10) . ' if (s.match(/[012345678ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy]/)) {' . chr(10) . ' return String.fromCharCode(s.charCodeAt(0) + 1);' . chr(10) . ' }' . chr(10) . ' if (s == "9") {' . chr(10) . ' return "10";' . chr(10) . ' }' . chr(10) . ' if (s == "Z") {' . chr(10) . ' return "AA";' . chr(10) . ' }' . chr(10) . ' if (s == "z") {' . chr(10) . ' return "aa";' . chr(10) . ' }' . chr(10) . ' return "1";' . chr(10) . ' }' . chr(10) . ' var c = p5str_inc(s.substr(s.length-1, 1));' . chr(10) . ' if (c.length == 1) {' . chr(10) . ' return s.substr(0, s.length-1) + c;' . chr(10) . ' }' . chr(10) . ' return p5str_inc(s.substr(0, s.length-1)) + c.substr(c.length-1, 1);' . chr(10) . '};' . chr(10) . chr(10) . 'p5for = function(namespace, func, args, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' try {' . chr(10) . ' func()' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { i--; _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' }' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . '};' . chr(10) . chr(10) . 'p5for_lex = function(func, args, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' try {' . chr(10) . ' func(args[i])' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { i--; _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '};' . chr(10) . chr(10) . 'p5while = function(func, cond, cont, label) {' . chr(10) . ' var _redo = false;' . chr(10) . ' while (_redo || p5bool(cond())) {' . chr(10) . ' _redo = false;' . chr(10) . ' try {' . chr(10) . ' func()' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' if (cont) {' . chr(10) . ' try {' . chr(10) . ' if (!_redo) { cont() }' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' if (err instanceof p5_error && err.v == label) {' . chr(10) . ' if (err.type == ' . chr(39) . 'last' . chr(39) . ') { return }' . chr(10) . ' else if (err.type == ' . chr(39) . 'redo' . chr(39) . ') { _redo = true }' . chr(10) . ' else if (err.type != ' . chr(39) . 'next' . chr(39) . ') { throw(err) }' . chr(10) . ' } ' . chr(10) . ' else {' . chr(10) . ' throw(err)' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . '};' . chr(10) . chr(10) . 'p5map = function(namespace, func, args) {' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' var out = [];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' var o = p5list_to_a(func(1));' . chr(10) . ' for(var j = 0; j < o.length; j++) {' . chr(10) . ' out.push(o[j]);' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'p5grep = function(namespace, func, args) {' . chr(10) . ' var v_old = namespace["v__"];' . chr(10) . ' var out = [];' . chr(10) . ' for(var i = 0; i < args.length; i++) {' . chr(10) . ' namespace["v__"] = args[i];' . chr(10) . ' if (p5bool(func(0))) {' . chr(10) . ' out.push(args[i])' . chr(10) . ' }' . chr(10) . ' }' . chr(10) . ' namespace["v__"] = v_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'p5sort = function(namespace, func, args) {' . chr(10) . ' var a_old = namespace["v_a"];' . chr(10) . ' var b_old = namespace["v_b"];' . chr(10) . ' var out = ' . chr(10) . ' func == null' . chr(10) . ' ? args.sort()' . chr(10) . ' : args.sort(' . chr(10) . ' function(a, b) {' . chr(10) . ' namespace["v_a"] = a;' . chr(10) . ' namespace["v_b"] = b;' . chr(10) . ' return func(0);' . chr(10) . ' }' . chr(10) . ' );' . chr(10) . ' namespace["v_a"] = a_old;' . chr(10) . ' namespace["v_b"] = b_old;' . chr(10) . ' return out;' . chr(10) . '};' . chr(10) . chr(10) . 'perl5_to_js = function( source, namespace, var_env_js, p5want ) {' . chr(10) . ' // CORE.say(["source: [" + source + "]"]);' . chr(10) . chr(10) . ' var strict_old = p5pkg["Perlito5"].v_STRICT;' . chr(10) . ' var var_env_js_old = p5pkg["Perlito5"].v_VAR;' . chr(10) . ' p5pkg["Perlito5"].v_VAR = var_env_js;' . chr(10) . chr(10) . ' var namespace_old = p5pkg["Perlito5"].v_PKG_NAME;' . chr(10) . ' p5pkg["Perlito5"].v_PKG_NAME = namespace;' . chr(10) . chr(10) . ' match = p5call(p5pkg["Perlito5::Grammar"], "exp_stmts", [source, 0]);' . chr(10) . chr(10) . ' if ( !match || match._hash_.to != source.length ) {' . chr(10) . ' CORE.die(["Syntax error in eval near pos ", match._hash_.to]);' . chr(10) . ' }' . chr(10) . chr(10) . ' ast = p5pkg.CORE.bless([' . chr(10) . ' new p5HashRef({' . chr(10) . ' block: p5pkg.CORE.bless([' . chr(10) . ' new p5HashRef({' . chr(10) . ' stmts: p5pkg["Perlito5::Match"].flat([match])' . chr(10) . ' }),' . chr(10) . ' p5pkg["Perlito5::AST::Lit::Block"]' . chr(10) . ' ])' . chr(10) . ' }),' . chr(10) . ' p5pkg["Perlito5::AST::Do"]' . chr(10) . ' ]);' . chr(10) . chr(10) . ' // CORE.say(["ast: [" + ast + "]"]);' . chr(10) . ' js_code = p5call(ast, "emit_javascript2", [0, p5want]);' . chr(10) . ' // CORE.say(["js-source: [" + js_code + "]"]);' . chr(10) . chr(10) . ' p5pkg["Perlito5"].v_PKG_NAME = namespace_old;' . chr(10) . ' p5pkg["Perlito5"].v_VAR = var_env_js_old;' . chr(10) . ' p5pkg["Perlito5"].v_STRICT = strict_old;' . chr(10) . ' return js_code;' . chr(10) . '}' . chr(10) . chr(10))))
};
1;
View
24 src5/lib/Perlito5/Javascript2/Emitter.pm
@@ -1812,6 +1812,30 @@ package Perlito5::AST::Apply;
return 'p5tie_' . $meth . '(' . $v->emit_javascript2( $level ) . ', ' . Perlito5::Javascript2::to_list(\@arguments) . ')';
},
+ 'untie' => sub {
+ my $self = shift;
+ my $level = shift;
+ my $wantarray = shift;
+
+ my @arguments = @{$self->{arguments}};
+ my $v = shift @arguments; # TODO - this argument can also be a 'Decl' instead of 'Var'
+
+ my $meth;
+ if ( $v->isa('Perlito5::AST::Var') && $v->sigil eq '%' ) {
+ $meth = 'hash';
+ }
+ elsif ( $v->isa('Perlito5::AST::Var') && $v->sigil eq '@' ) {
+ $meth = 'array';
+ }
+ elsif ( $v->isa('Perlito5::AST::Var') && $v->sigil eq '$' ) {
+ $meth = 'scalar';
+ }
+ else {
+ die "tie '", ref($v), "' not implemented";
+ }
+ return 'p5untie_' . $meth . '(' . $v->emit_javascript2( $level ) . ')';
+ },
+
'map' => sub {
my $self = shift;
my $level = shift;
View
34 src5/lib/Perlito5/Javascript2/Runtime.pm
@@ -354,12 +354,14 @@ p5tie_array = function(v, List__) {
Object.defineProperty( v, "p5aget", {
enumerable : false,
+ configurable : true,
value : function (i) {
return p5call(res, 'FETCH', [i]);
}
});
Object.defineProperty( v, "p5aset", {
enumerable : false,
+ configurable : true,
value : function (i, value) {
p5call(res, 'STORE', [i, value]);
return value;
@@ -367,6 +369,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5incr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5incr(p5call(res, 'FETCH', [i]));
p5call(res, 'STORE', [i, value]);
@@ -375,6 +378,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5postincr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
p5call(res, 'STORE', [i, p5incr(value)]);
@@ -383,6 +387,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5decr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5decr(p5call(res, 'FETCH', [i]));
p5call(res, 'STORE', [i, value]);
@@ -391,6 +396,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5postdecr", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
p5call(res, 'STORE', [i, p5decr(value)]);
@@ -400,6 +406,7 @@ p5tie_array = function(v, List__) {
Object.defineProperty( v, "p5aget_array", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
if (value == null) {
@@ -411,6 +418,7 @@ p5tie_array = function(v, List__) {
});
Object.defineProperty( v, "p5aget_hash", {
enumerable : false,
+ configurable : true,
value : function (i) {
var value = p5call(res, 'FETCH', [i]);
if (value == null) {
@@ -420,10 +428,36 @@ p5tie_array = function(v, List__) {
return value;
}
});
+ Object.defineProperty( v, "p5untie", {
+ enumerable : false,
+ configurable : true,
+ value : function (i) {
+ return p5call(res, 'UNTIE', []);
+ }
+ });
return res;
};
+p5untie_array = function(v) {
+ if (v.hasOwnProperty('p5untie')) {
+ var res = v.p5untie(); // call UNTIE
+ delete v.p5aget;
+ delete v.p5aset;
+ delete v.p5incr;
+ delete v.p5postincr;
+ delete v.p5decr;
+ delete v.p5postdecr;
+ delete v.p5aget_array;
+ delete v.p5aget_hash;
+ delete v.p5untie;
+ return res;
+ }
+ else {
+ return null;
+ }
+};
+
//-------- Hash
Object.defineProperty( Object.prototype, "p5hget", {
View
6 t5/01-perlito/30-tie-array.t
@@ -34,6 +34,10 @@ use feature 'say';
return;
}
}
+
+ sub UNTIE {
+ say "# UNTIE";
+ }
}
say '1..2';
@@ -51,3 +55,5 @@ say 'ok 1 # ', $list[0];
$list[1] = 'ok 2 # whatever';
+untie @list;
+
Please sign in to comment.
Something went wrong with that request. Please try again.