Develop and Download Open Source Software

Browse CVS Repository

Contents of /netruby/netruby/Symbol.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Mon Apr 8 13:30:04 2002 UTC (22 years ago) by arton
Branch: MAIN, vendor
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
initial version 0.8

1 /*
2 Copyright(C) 2001-2002 arton
3
4 Permission is granted for use, copying, modification, distribution,
5 and distribution of modified versions of this work as long as the
6 above copyright notice is included.
7 */
8
9 using System;
10 using System.Collections;
11 using System.Reflection;
12 using System.Security;
13
14 namespace arton.NETRuby
15 {
16 public class Symbol : RBasic
17 {
18 const uint SYMBOL_FLAG = 16;
19
20 private Symbol(NetRuby rb) :
21 base(rb, rb.cSymbol)
22 {
23 val = 0;
24 }
25 internal Symbol(NetRuby rb, uint v) :
26 base(rb, rb.cSymbol)
27 {
28 val = v;
29 }
30 static internal uint ID2SYM(uint u)
31 {
32 return (u << 8) | SYMBOL_FLAG;
33 }
34
35 static internal uint SYM2ID(uint u)
36 {
37 return u >> 8;
38 }
39
40 static internal bool IsSymbol(object o)
41 {
42 if (o is uint)
43 {
44 uint u = (uint)o;
45 if ((u & 0xff) == SYMBOL_FLAG)
46 return true;
47 }
48 return false;
49 }
50
51 public override string ToString()
52 {
53 return ruby.id2name(val >> 8);
54 }
55
56 uint val;
57 internal Symbol SetData(uint u)
58 {
59 val = u;
60 return this;
61 }
62
63 static object to_i(RBasic rcver, params object[] args)
64 {
65 int i = (int)SYM2ID(((Symbol)rcver).val);
66 return i;
67 }
68 static object inspect(RBasic rcver, params object[] args)
69 {
70 return new RString(rcver.ruby, ":" + rcver.ToString());
71 }
72 static object to_s(RBasic rcver, params object[] args)
73 {
74 return new RString(rcver.ruby, rcver.ToString());
75 }
76 static object id2name(RBasic rcver, params object[] args)
77 {
78 return new RString(rcver.ruby, rcver.ToString());
79 }
80 static object intern(RBasic rcver, params object[] args)
81 {
82 return ((Symbol)rcver).val;
83 }
84
85 static internal void Init(NetRuby rb)
86 {
87 RClass sym = rb.DefineClass("Symbol", rb.cObject);
88 rb.cSymbol = sym;
89 rb.oSymbol = new Symbol(rb);
90 sym.DefineMethod("to_i", new RMethod(to_i), 0);
91 sym.DefineMethod("to_int", new RMethod(to_i), 0);
92 sym.DefineMethod("inspect", new RMethod(inspect), 0);
93 sym.DefineMethod("to_s", new RMethod(to_s), 0);
94 sym.DefineMethod("id2name", new RMethod(to_s), 0);
95 }
96 }
97 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26