Skip to content

Commit

Permalink
Python backend - set attribute returns the value
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Apr 13, 2011
1 parent fddf3ba commit 196fb17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/Perlito/Python/Emitter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ class CompUnit {
push @s, Python::tab($level+4) ~ "v_self.__dict__[k] = mp6_Scalar()";
push @s, Python::tab($level+4) ~ "v_self.__dict__[k].f_set(arg[k])";

push @s, Python::tab($level+2) ~ "def __setattr__(v_self, k, v):";
push @s, Python::tab($level+3) ~ "v_self.__dict__[k].f_set(v)";
push @s, Python::tab($level+2) ~ "def f__setattr__(v_self, k, v):";
push @s, Python::tab($level+3) ~ "return v_self.__dict__[k].f_set(v)";
push @s, Python::tab($level+2) ~ "def f_isa(v_self, name):";
push @s, Python::tab($level+3) ~ "return name == '" ~ $.name ~ "'";
push @s, Python::tab($level+2) ~ "def f_bool(self):";
Expand Down Expand Up @@ -491,7 +491,7 @@ class Apply {

if $code eq 'self' { return 'v_self' };
if $code eq 'Mu' { return 'mp6_Mu()' };
if $code eq 'make' { return "v_MATCH.__setattr__('v_capture', " ~ (@.arguments[0]).emit_python() ~ ')' }
if $code eq 'make' { return "v_MATCH.f__setattr__('v_capture', " ~ (@.arguments[0]).emit_python() ~ ')' }
if $code eq 'False' { return 'False' };
if $code eq 'True' { return 'True' };

Expand Down Expand Up @@ -610,7 +610,7 @@ class Apply {
if $parameters.isa( 'Call' ) {
# $var.attr = 3;
return
($parameters.invocant).emit_python() ~ ".__setattr__('v_" ~ $parameters.method() ~ "', " ~ $arguments.emit_python() ~ ")";
($parameters.invocant).emit_python() ~ ".f__setattr__('v_" ~ $parameters.method() ~ "', " ~ $arguments.emit_python() ~ ")";
}

if $parameters.isa( 'Var' ) && $parameters.sigil eq '@'
Expand Down
7 changes: 4 additions & 3 deletions lib/Perlito/Python/Runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def mp6_to_num(s):
except TypeError:
return 0


class mp6_Array:
def __init__(self, l):
self.l = l
Expand Down Expand Up @@ -418,13 +417,13 @@ def __init__(self, **arg):
for k in arg:
self.__dict__[k] = mp6_Scalar()
self.__dict__[k].f_set(arg[k])
def __setattr__(self, k, v):
def f__setattr__(self, k, v):
try:
self.__dict__[k].f_set(v)
except KeyError:
self.__dict__[k] = mp6_Scalar()
self.__dict__[k].f_set(v)
return v
return self.__dict__[k]
def __str__(self):
if mp6_to_bool(self.v_bool):
if not(mp6_isa(self.v_capture,'Mu')):
Expand Down Expand Up @@ -508,6 +507,7 @@ def __init__(self, **arg):
self.__dict__.update(arg)
def __setattr__(v_self, k, v):
v_self.__dict__[k] = v
return v_self.__dict__[k]
def f_bool(self):
return 1
def f_isa(v_self, name):
Expand Down Expand Up @@ -544,6 +544,7 @@ def __init__(v_self, **arg):
v_self.__dict__.update(arg)
def __setattr__(v_self, k, v):
v_self.__dict__[k] = v
return v_self.__dict__[k]
def f_bool(self):
return 1
def f_isa(v_self, name):
Expand Down
Loading

0 comments on commit 196fb17

Please sign in to comment.