[#636] doc/NEWS — Matt Armstrong <matt@...>

22 messages 2002/12/15

Re: [patch] doc/NEWS

From: nobu.nokada@...
Date: 2002-12-16 19:17:31 UTC
List: ruby-core #651
Hi,

At Tue, 17 Dec 2002 03:26:00 +0900,
Yukihiro Matsumoto wrote:
> |> |If an assignment method which doesn't return an argument is not
> |> |intuitive, why don't ruby force it?
> |> 
> |> Agreed.  Last time I thought that, I was too lazy to modify compiler
> |> itself, and then forgot.  I will fix it someday.
> |
> |Is it better to define NODE_ASGN?
> 
> Yes, I'd name it NODE_ATTRSET...oops, we already have that one.
> How about NODE_ATTRASGN?

When a.b= is defined, defined?(a.b = 1) should be "method" or
"assignment"?


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.360
diff -u -2 -p -r1.360 eval.c
--- eval.c	15 Dec 2002 03:18:04 -0000	1.360
+++ eval.c	16 Dec 2002 18:46:50 -0000
@@ -1882,4 +1882,5 @@ is_defined(self, node, buf)
 
       case NODE_CALL:
+      case NODE_ATTRASGN:
 	PUSH_TAG(PROT_NONE);
 	if ((state = EXEC_TAG()) == 0) {
@@ -2741,4 +2742,23 @@ rb_eval(self, n)
 	result = rb_ary_push(rb_ary_dup(rb_eval(self, node->nd_head)),
 			     rb_eval(self, node->nd_body));
+	break;
+
+      case NODE_ATTRASGN:
+	{
+	    VALUE recv;
+	    int argc; VALUE *argv; /* used in SETUP_ARGS */
+	    TMP_PROTECT;
+
+	    BEGIN_CALLARGS;
+	    recv = rb_eval(self, node->nd_recv);
+	    SETUP_ARGS(node->nd_args);
+	    END_CALLARGS;
+
+	    SET_CURRENT_SOURCE();
+	    if (argc != 1)
+		rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc);
+	    result = argv[0];
+	    rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0);
+	}
 	break;
 
Index: node.h
===================================================================
RCS file: /cvs/ruby/src/ruby/node.h,v
retrieving revision 1.37
diff -u -2 -p -r1.37 node.h
--- node.h	7 Nov 2002 19:18:10 -0000	1.37
+++ node.h	16 Dec 2002 18:31:57 -0000
@@ -124,4 +124,5 @@ enum node_type {
     NODE_IFUNC,
     NODE_DSYM,
+    NODE_ATTRASGN,
     NODE_LAST
 };
@@ -333,4 +334,5 @@ typedef struct RNode {
 #define NEW_DMETHOD(b) rb_node_newnode(NODE_DMETHOD,0,0,b)
 #define NEW_BMETHOD(b) rb_node_newnode(NODE_BMETHOD,0,0,b)
+#define NEW_ATTRASGN(r,m,a) rb_node_newnode(NODE_ATTRASGN,r,m,a)
 
 #define NOEX_PUBLIC    0
Index: parse.y
===================================================================
RCS file: /cvs/ruby/src/ruby/parse.y,v
retrieving revision 1.232
diff -u -2 -p -r1.232 parse.y
--- parse.y	16 Dec 2002 06:56:33 -0000	1.232
+++ parse.y	16 Dec 2002 18:59:44 -0000
@@ -4706,5 +4706,5 @@ attrset(recv, id)
 {
     value_expr(recv);
-    return NEW_CALL(recv, rb_id_attrset(id), 0);
+    return NEW_ATTRASGN(recv, rb_id_attrset(id), 0);
 }
 
@@ -4768,4 +4768,8 @@ node_assign(lhs, rhs)
       case NODE_CALL:
 	lhs->nd_args = arg_add(lhs->nd_args, rhs);
+	break;
+
+      case NODE_ATTRASGN:
+	lhs->nd_args = rhs;
 	break;
 


-- 
Nobu Nakada

In This Thread