Permalink
Browse files

Bind instance variables within method bodies, allowing access to them…

…. Initial test for instance variables passing. Reia objects officially support hidden state!
  • Loading branch information...
Tony Arcieri
Tony Arcieri committed Jun 6, 2010
1 parent 6792abd commit 59650a160daecd1179105f8b2c2a143d371d31e3
Showing with 14 additions and 7 deletions.
  1. +1 −4 src/compiler/reia_classes.erl
  2. +13 −3 src/compiler/reia_ivars.erl
@@ -14,10 +14,7 @@ transform(Exprs, _Options) ->
reia_syntax:map_subtrees(fun transform/1, Exprs).

transform(#class{} = Expr) ->
io:format("Input class: ~p~n", [Expr]),
Res = reia_syntax:map_subtrees(fun transform/1, transform_class(Expr)),
io:format("Output class: ~p~n", [Res]),
Res;
reia_syntax:map_subtrees(fun transform/1, transform_class(Expr));

transform(Expr) ->
reia_syntax:map_subtrees(fun transform/1, Expr).
@@ -8,6 +8,7 @@
-module(reia_ivars).
-export([mutable_method/1, immutable_method/1]).
-include("reia_nodes.hrl").
-define(self(Line), (#var{line=Line, name='__reia_self'})).
-define(ivars(Line), (#var{line=Line, name='__reia_ivars'})).

% Transform for methods that are allowed to alter instance variables
@@ -20,8 +21,7 @@ mutable_method(Method) ->
Ivars = #native_call{
line = Line,
module = dict,
function = new,
args=[]
function = new
},

BindIvars = #match{line=Line, left=?ivars(Line), right=Ivars},
@@ -36,8 +36,18 @@ mutable_method_ivars(Expr) ->

% Methods which are not allowed to make changes to instance variables
immutable_method(Method) ->
Line = Method#function.line,

Ivars = #native_call{
line = Line,
module = erlang,
function = element,
args = [#integer{line=Line, value=3}, ?self(Line)]
},

BindIvars = #match{line=Line, left=?ivars(Line), right=Ivars},
Body = reia_syntax:map_subtrees(fun immutable_method_ivars/1, Method#function.body),
Method#function{body=Body}.
Method#function{body=[BindIvars|Body]}.

immutable_method_ivars(#match{} = Expr) ->
[Left] = reia_syntax:map_subtrees(fun immutable_match_context/1, [Expr#match.left]),

0 comments on commit 59650a1

Please sign in to comment.