Skip to content

Commit 883e264

Browse files
committed
drop @@Package vars misfeature
1 parent 3d14d41 commit 883e264

File tree

4 files changed

+58
-60
lines changed

4 files changed

+58
-60
lines changed

examples/rubyish/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Implemented:
1515
- simple strings 'Hello World!' %q{...}
1616
- interpolating strings: "number #{37+5}" %Q{Hello #{planet}!}
1717
- quoted words: `%w[aa bb cc]`
18-
- basic scoping, including $globals, @class_instance and @@package variables
18+
- basic scoping, including $globals and class @attribute variables
1919
- conditional blocks: `if ... then ... elsif ... else ... endif`, `unless..end`
2020
- nqp opcode calls: `nqp::sleep(5)`
2121
- a few built-ins: `abort`, `print`, `puts`, `sleep`

examples/rubyish/rubyish.nqp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
200200
token var {
201201
:my $*MAYBE_DECL := 0;
202202
\+?
203-
[$<sigil>=[ \$ | \@\@? ] | <pkg=.ident>'::'<?before <[A..Z]>> | <!keyword> ]
203+
[$<sigil>=[ \$ | \@ ] | <pkg=.ident>'::'<?before <[A..Z]>> | <!keyword> ]
204204
<ident><!before [\!|\?|<hs>\(]>
205205
[ <?before <hs> <bind-op> { $*MAYBE_DECL := 1 }> || <?> ]
206206
}
@@ -662,10 +662,6 @@ class Rubyish::Actions is HLL::Actions {
662662
elsif $sigil eq '@' {
663663
$block := $*CLASS_BLOCK;
664664
}
665-
elsif $sigil eq '@@' {
666-
$block := $*CLASS_BLOCK;
667-
$decl := 'static';
668-
}
669665
else {
670666
nqp::die("unhandled sigil: $sigil");
671667
}

examples/rubyish/t/inheritance.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
puts "1..10"
22

3+
$tst = -1
4+
35
class Point
4-
@@tst = -1
56
def initialize(x, y)
6-
puts "ok #{ @@tst = @@tst + 2 } - Point.initialize called"
7+
puts "ok #{ $tst = $tst + 2 } - Point.initialize called"
78
@x = x
89
@y = y
910
end

examples/rubyish/t/scoping.t

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
puts "1..21"
1+
puts "1..19"
22

3-
a = "ok 1"
4-
b = "ok 2"
5-
$a = "ok 3"
6-
$c = "nok 4"
3+
class BaseClass
4+
Y = 16;
75

8-
def some_sub
9-
b = "nok 2"
10-
$c = "ok 4"
11-
$d = "ok 5"
12-
end
13-
some_sub()
14-
15-
class MyClass
16-
@@final_test = 17
17-
18-
def set_class(v); @@c = v; b = 'wtf'; end
19-
def get_class; @@c; end
20-
def set_inst(v1,v2); @i1 = v1; @i2= v2 end
6+
def set_inst1(v); @i1 = v; end
7+
def set_inst2(v); @i2 = v; end
218
def get_inst1; @i1; end
229
def get_inst2; @i2; end
23-
def class_const; @@final_test ; end
2410
def tickle_f(f); @f = f ; end
2511

26-
Y = 18
2712
def const_tests
28-
puts "ok #{MyClass::Y} - package constant qualified"
13+
puts "ok #{BaseClass::Y} - package constant qualified"
2914
puts "ok #{Y + 1} - package constant unqualified"
3015
end
3116
end
3217

33-
class OtherClass
34-
def set_class(v); @@c = v; end
35-
def get_class; @@c; end
36-
def set_inst(v1,v2); @i1 = v1; @i2= v2 end
18+
class DerivedClass < BaseClass
19+
def set_inst1_child(v); @i1 = v; end
20+
def get_inst1_child; @i1; end
21+
end
22+
23+
class DisjointClass
24+
def set_inst1(v); @i1 = v; end
25+
def set_inst2(v); @i2 = v; end
3726
def get_inst1; @i1; end
3827
def get_inst2; @i2; end
3928

4029
def more_const_tests
41-
puts "ok #{MyClass::Y + 2} - package constant cross reference"
30+
puts "ok #{BaseClass::Y + 2} - package constant cross reference"
4231
puts "ok #{Y} - package constant internal reference"
4332
end
4433

4534
end
4635

47-
obj1 = MyClass.new;
48-
obj2 = MyClass.new;
49-
obj3 = OtherClass.new;
36+
a = "ok 1"
37+
b = "ok 2"
38+
$a = "ok 3"
39+
$c = "nok 4"
40+
41+
base_obj = BaseClass.new;
42+
sibling_obj = BaseClass.new;
43+
disjoint_obj = DisjointClass.new;
44+
child_obj = DerivedClass.new;
5045

51-
obj1.set_class(8)
52-
obj3.set_class(10)
46+
def some_sub
47+
b = "nok 2"
48+
$c = "ok 4"
49+
$d = "ok 5"
50+
end
51+
some_sub()
5352

5453
puts "#{a} - local: main"
5554
puts "#{b} - local: main, function"
@@ -59,27 +58,29 @@ puts "#{$d} - $global: function"
5958

6059
@e=6
6160
@f='ok'
62-
obj1.tickle_f('nok')
61+
base_obj.tickle_f('nok')
6362
puts "ok #{@e} - @instance: main"
6463
puts "#{@f} 7 - @instance: main, object"
6564

66-
puts "ok #{obj1.get_class} - @@class access"
67-
puts "ok #{obj2.get_class() + 1} - @@class access"
68-
puts "ok #{obj3.get_class} - @@class variable"
69-
70-
obj1.set_inst(11,12)
71-
obj2.set_inst(13,14)
72-
obj3.set_inst(15,16)
73-
74-
puts "ok #{obj1.get_inst1} - @instance access"
75-
puts "ok #{obj1.get_inst2} - @instance access"
76-
puts "ok #{obj2.get_inst1} - @instance access"
77-
puts "ok #{obj2.get_inst2} - @instance access"
78-
puts "ok #{obj3.get_inst1} - @instance access"
79-
puts "ok #{obj3.get_inst2} - @instance access"
80-
puts "ok #{obj2.class_const} - @@class constant"
81-
82-
obj1.const_tests
83-
84-
OtherClass::Y = 21
85-
obj3.more_const_tests
65+
t = 7
66+
base_obj.set_inst1(t+=1)
67+
base_obj.set_inst2(t+=1)
68+
sibling_obj.set_inst1(t+=1)
69+
sibling_obj.set_inst2(t+=1)
70+
disjoint_obj.set_inst1(t+=1)
71+
disjoint_obj.set_inst2(t+=1)
72+
child_obj.set_inst1(t+=1)
73+
74+
puts "ok #{base_obj.get_inst1} - @instance access (base)"
75+
puts "ok #{base_obj.get_inst2} - @instance access (base)"
76+
puts "ok #{sibling_obj.get_inst1} - @instance access (sibling)"
77+
puts "ok #{sibling_obj.get_inst2} - @instance access (sibling)"
78+
puts "ok #{disjoint_obj.get_inst1} - @instance access (disjoint)"
79+
puts "ok #{disjoint_obj.get_inst2} - @instance access (disjoint)"
80+
puts "ok #{child_obj.get_inst1} - @instance access (child)"
81+
puts "ok #{child_obj.get_inst1_child+1} - @instance access (child)"
82+
83+
base_obj.const_tests
84+
85+
DisjointClass::Y = t+5
86+
disjoint_obj.more_const_tests

0 commit comments

Comments
 (0)