Permalink
Browse files

Perlito5 - js - tie() emitter

  • Loading branch information...
1 parent bc4bbb3 commit 9a2d51f46e573c3532acae4600eea10f59f337a8 @fglock committed Oct 4, 2012
View
@@ -326,6 +326,31 @@ Object.defineProperty( Array.prototype, "p5aget_hash", {
}
});
+p5tie_array = function(v, List__) {
+ var pkg_name = p5str(List__.shift());
+
+ var res = p5call(pkg_name, 'TIEARRAY', List__, null);
+
+ // TODO
+
+ // A class implementing an ordinary array should have the following methods:
+ // TIEARRAY pkg_name, LIST
+ // FETCH this, key
+ // STORE this, key, value
+ // FETCHSIZE this
+ // STORESIZE this, count
+ // CLEAR this
+ // PUSH this, LIST
+ // POP this
+ // SHIFT this
+ // UNSHIFT this, LIST
+ // SPLICE this, offset, length, LIST
+ // EXTEND this, count
+ // DESTROY this
+ // UNTIE this
+
+ return res;
+};
//-------- Hash
@@ -880,41 +905,6 @@ CORE.bless = function(List__) {
return o;
};
-CORE.tie = function(List__) {
- var v = List__[0];
- var pkg_name = List__[1];
- var args = List__[2];
-
- // array, scalar, hash, ... ??? -- could use some help from the emitter here
- if (v instanceof Array) {
-
- var res = p5call(pkg_name, 'TIEARRAY', args, null);
-
- // TODO
-
- // A class implementing an ordinary array should have the following methods:
- // TIEARRAY pkg_name, LIST
- // FETCH this, key
- // STORE this, key, value
- // FETCHSIZE this
- // STORESIZE this, count
- // CLEAR this
- // PUSH this, LIST
- // POP this
- // SHIFT this
- // UNSHIFT this, LIST
- // SPLICE this, offset, length, LIST
- // EXTEND this, count
- // DESTROY this
- // UNTIE this
-
- return res;
- }
-
- CORE.die("don't know how to tie() this");
-
-};
-
CORE.chr = function(List__) {
var v = p5num(List__[0]);
return String.fromCharCode(v >= 0 ? v : 65533);
@@ -3716,6 +3706,35 @@ var p5100 = p5pkg['main'];
return(err);
}
}
+ }, 'tie', 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([('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));
}, 'map', function (List__, p5want) {
var v_self = null;
(v_self = (p5pkg["Perlito5::AST::Apply"].shift([List__])));
View
Oops, something went wrong.
@@ -92,41 +92,6 @@ CORE.bless = function(List__) {
return o;
};
-CORE.tie = function(List__) {
- var v = List__[0];
- var pkg_name = List__[1];
- var args = List__[2];
-
- // array, scalar, hash, ... ??? -- could use some help from the emitter here
- if (v instanceof Array) {
-
- var res = p5call(pkg_name, 'TIEARRAY', args, null);
-
- // TODO
-
- // A class implementing an ordinary array should have the following methods:
- // TIEARRAY pkg_name, LIST
- // FETCH this, key
- // STORE this, key, value
- // FETCHSIZE this
- // STORESIZE this, count
- // CLEAR this
- // PUSH this, LIST
- // POP this
- // SHIFT this
- // UNSHIFT this, LIST
- // SPLICE this, offset, length, LIST
- // EXTEND this, count
- // DESTROY this
- // UNTIE this
-
- return res;
- }
-
- CORE.die("don't know how to tie() this");
-
-};
-
CORE.chr = function(List__) {
var v = p5num(List__[0]);
return String.fromCharCode(v >= 0 ? v : 65533);
@@ -1788,6 +1788,30 @@ package Perlito5::AST::Apply;
return Perlito5::Javascript2::pkg() . '.shift([List__])'
},
+ 'tie' => 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 'p5tie_' . $meth . '(' . $v->emit_javascript2( $level ) . ', ' . Perlito5::Javascript2::to_list(\@arguments) . ')';
+ },
+
'map' => sub {
my $self = shift;
my $level = shift;
@@ -332,6 +332,31 @@ Object.defineProperty( Array.prototype, "p5aget_hash", {
}
});
+p5tie_array = function(v, List__) {
+ var pkg_name = p5str(List__.shift());
+
+ var res = p5call(pkg_name, 'TIEARRAY', List__, null);
+
+ // TODO
+
+ // A class implementing an ordinary array should have the following methods:
+ // TIEARRAY pkg_name, LIST
+ // FETCH this, key
+ // STORE this, key, value
+ // FETCHSIZE this
+ // STORESIZE this, count
+ // CLEAR this
+ // PUSH this, LIST
+ // POP this
+ // SHIFT this
+ // UNSHIFT this, LIST
+ // SPLICE this, offset, length, LIST
+ // EXTEND this, count
+ // DESTROY this
+ // UNTIE this
+
+ return res;
+};
//-------- Hash

0 comments on commit 9a2d51f

Please sign in to comment.