summaryrefslogtreecommitdiff
path: root/methods.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1994-08-10 15:54:46 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:30 +0900
commit6e3090413652b6592346556149fed1e9aec5495d (patch)
treebac97139bbeedc8cb67cb2e451a22ed4ddb2b2d4 /methods.c
parent200e0ee2fd3c1c006c528874a88f684447215524 (diff)
version 0.50v0_50
http://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.50.tar.gz Wed Aug 10 15:54:46 1994 Yukihiro Matsumoto (matz@ix-02) * variable.c: -vオプションが指定されている時は初期化されていない, 大域変数, インスタンス変数, ローカル変数を参照した時点でwarning を出すようにした. Tue Aug 9 11:50:48 1994 Yukihiro Matsumoto (matz@ix-02) * bignum.c: 冪乗に関しても多倍長演算を行なうように. 特に浮動小数点 数の範囲を越えた時の処理を的確に行なうように. * eval.c: メソッド定義後は構文木から, メソッド定義部分を外す. 無駄 な再定義が起こらないようにするためと2重にfree()されないため. * array.c(Fary_aref): 引数が1つでFixnumの時, Range checkを行なわな いように修正. * eval.c: 引数の数をコンパイル時に計算して若干の高速化. Mon Aug 8 13:06:24 1994 Yukihiro Matsumoto (matz@ix-02) * object.c: nilによる比較連鎖をなくした. * parse.y: bit演算子の優先順位を比較演算子よりも強くした. Cとは異 なることになるが, 直観には合致する. * gc.c: クラスを解放する時, 個々のメソッド毎にキャッシュをクリアす るのではなく, クラス単位でクリアするように. Thu Aug 4 18:45:09 1994 Yukihiro Matsumoto (matz@ix-02) * methods.c(method_free): 解放されたメソッドに関してキャッシュをク リアしておく必要があった. * gc.c: Dataクラスのデータ部分をfree()し忘れていた. Wed Aug 3 09:58:14 1994 Yukihiro Matsumoto (matz@ix-02) * parse.y: def func .. end形式による関数メソッドの定義はなくなった. * methods.c: func形式のメソッドをなくした. あっても, あまり意味が ないので. * eval.c: $0への代入でps(1)の出力が変化するように. * io.c(Fsyscall): syscall()を実現. Mon Aug 1 13:41:11 1994 Yukihiro Matsumoto (matz@ix-02) * parse.y: ダブルクォートで囲まれた文字列や正規表現中で"#{変数名}" または"#変数名"という形式で変数の内容を埋め込むことができるよう になった. * io.c: 関数メソッドsystem2()はなくなった. 今はバッククォートがあ るからね. * parse.y: `cmd`によってコマンドを文字列に展開することができるよう になった. * parse.y: __FILE__, __LINE__を追加. それぞれファイル名(文字列), 行番号(整数)を値とする疑似変数. Fri Jul 29 13:16:07 1994 Yukihiro Matsumoto (matz@ix-02) * methods.h: メソッドをオブジェクトとして扱うのをやめる. メソッド のメモリ管理にはリファレンスカウントを使うことにした. これでオブ ジェクトの数が減ってほんの少しだけGCが速くなる(かな). * purifyによってメモリ関係のバグを検査した(見つかる,見つかる…). * gc.c: GCをプログラマが変数をマークする形式から, スタックとレジス タからマークする方法に変更. 移植性が下がるような気もするが, siod やscmでも採用されているから多分大丈夫だろう. Linux on i486でも動 作を確認した. Wed Jul 27 16:13:13 1994 Yukihiro Matsumoto (matz@ix-02) * eval.c(Eval): トップレベルでは構造木をfreeしないように. どうせ解 放されるから時間の無駄である. * array.c, dict.c: "=="を構造一致に変更. Fri Jul 22 10:14:09 1994 Yukihiro Matsumoto (matz@ix-02) * error.c: 組み込みタイプの名前を登録し忘れていた. Thu Jul 21 14:06:48 1994 Yukihiro Matsumoto (matz@ix-02) * parse.y(freenode),eval.c(Eval): 解析木を解放し忘れていた. Mon Jul 18 10:19:15 1994 Yukihiro Matsumoto (matz@ix-02) * parse.y: 多重代入を処理するルールにバグがあって, 3要素以上の多重 代入に失敗していた. * eval.c(rb_eval): 多重代入で, 右辺が配列でない時には`to_a'メソッ ドで配列に変換して代入するようにした. 今までの仕様だと右辺値が第 1要素にそのまま代入されていたが, structなど配列に変換できるもの は変換した方が嬉しい気がする. * dbm.c,dict.c(delete_if): メソッド追加. * process.c(wait,waitpid): システムコールwaitpidまたはwait4がある 時はそちらを使うように. configureもそれらをチェックするように変更. * dbm.c, dict.c(clear): メソッド追加.
Diffstat (limited to 'methods.c')
-rw-r--r--methods.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/methods.c b/methods.c
index d861323444..b085799a45 100644
--- a/methods.c
+++ b/methods.c
@@ -14,6 +14,9 @@
#include "ident.h"
#include "env.h"
#include "node.h"
+#include "methods.h"
+
+void method_free();
#define CACHE_SIZE 577
#if 0
@@ -28,18 +31,18 @@ struct hash_entry { /* method hash table. */
ID mid; /* method's id */
struct RClass *class; /* receiver's class */
struct RClass *origin; /* where method defined */
- struct RMethod *method;
- enum mth_scope scope;
+ struct SMethod *method;
+ int undef;
};
static struct hash_entry cache[CACHE_SIZE];
-static struct RMethod*
+static struct SMethod*
search_method(class, id, origin)
struct RClass *class, **origin;
ID id;
{
- struct RMethod *body;
+ struct SMethod *body;
NODE *list;
while (!st_lookup(class->m_tbl, id, &body)) {
@@ -55,21 +58,19 @@ search_method(class, id, origin)
}
NODE*
-rb_get_method_body(class, id, envset, scope)
+rb_get_method_body(class, id, envset)
struct RClass *class;
ID id;
int envset;
- enum mth_scope scope;
{
int pos, i;
- int cscope;
- struct RMethod *method;
+ struct SMethod *method;
/* is it in the method cache? */
pos = EXPR1(class, id) % CACHE_SIZE;
if (cache[pos].class != class || cache[pos].mid != id) {
/* not in the cache */
- struct RMethod *body;
+ struct SMethod *body;
struct RClass *origin;
if ((body = search_method(class, id, &origin)) == Qnil) {
@@ -80,13 +81,11 @@ rb_get_method_body(class, id, envset, scope)
cache[pos].class = class;
cache[pos].origin = origin;
cache[pos].method = body;
- cache[pos].scope = body->scope;
+ cache[pos].undef = body->undef;
}
- cscope = cache[pos].scope;
method = cache[pos].method;
- if (cscope == MTH_UNDEF) return Qnil;
- if (cscope == MTH_FUNC && scope == MTH_METHOD) return Qnil;
+ if (cache[pos].undef) return Qnil;
if (envset) {
the_env->last_func = method->id;
the_env->last_class = cache[pos].origin;
@@ -99,21 +98,23 @@ rb_alias(class, name, def)
struct RClass *class;
ID name, def;
{
- struct RMethod *body;
+ struct SMethod *body;
if (st_lookup(class->m_tbl, name, &body)) {
if (verbose) {
Warning("redefine %s", rb_id2name(name));
}
- unliteralize(body);
+ rb_clear_cache(body);
+ method_free(body);
}
body = search_method(class, def, &body);
+ body->count++;
st_insert(class->m_tbl, name, body);
}
void
rb_clear_cache(body)
- struct RMethod *body;
+ struct SMethod *body;
{
int i;
@@ -129,17 +130,23 @@ void
rb_clear_cache2(class)
struct RClass *class;
{
+ int i;
- class = class->super;
- while (class) {
- int i;
-
- for (i = 0; i< CACHE_SIZE; i++ ) {
- if (cache[i].origin == class) {
- cache[i].class = Qnil;
- cache[i].mid = Qnil;
- }
+ for (i = 0; i< CACHE_SIZE; i++ ) {
+ if (cache[i].origin == class) {
+ cache[i].class = Qnil;
+ cache[i].mid = Qnil;
}
- class = class->super;
+ }
+}
+
+void
+method_free(body)
+ struct SMethod *body;
+{
+ body->count--;
+ if (body->count == 0) {
+ freenode(body->node);
+ free(body);
}
}