diff --git a/rbx/compiler/ast/assign.rb b/rbx/compiler/ast/assign.rb index 649162bf..3ca06d3d 100644 --- a/rbx/compiler/ast/assign.rb +++ b/rbx/compiler/ast/assign.rb @@ -16,6 +16,9 @@ def bytecode(g) elsif @ident.instance_variable? Rubinius::AST::InstanceVariableAssignment.new(line, @ident.name, @value). bytecode(g) + elsif @ident.class_variable? + Rubinius::AST::ClassVariableAssignment.new(line, @ident.name, @value). + bytecode(g) else Rubinius::AST::LocalVariableAssignment.new(line, @ident.name, @value). bytecode(g) diff --git a/rbx/compiler/ast/identifier.rb b/rbx/compiler/ast/identifier.rb index 4873bd54..8531c804 100644 --- a/rbx/compiler/ast/identifier.rb +++ b/rbx/compiler/ast/identifier.rb @@ -16,7 +16,7 @@ def constant? end def instance_variable? - @identifier =~ /^@/ + @identifier =~ /^@/ && !class_variable? end def class_variable? @@ -42,6 +42,8 @@ def nil? def name if constant? @identifier.to_sym + elsif class_variable? + @identifier[0..-1].to_sym elsif instance_variable? @identifier[1..-1].to_sym else diff --git a/rbx/examples/classes.fy b/rbx/examples/classes.fy index 950995cf..d5434012 100644 --- a/rbx/examples/classes.fy +++ b/rbx/examples/classes.fy @@ -1,4 +1,5 @@ def class Person { + @@a_classvar = "foo" def initialize: name { @name = name } @@ -6,7 +7,12 @@ def class Person { def to_s { "Person with name: " ++ @name } + + def Person class_var { + @@a_classvar + } } p = Person new: "Christopher" p println +Person class_var println diff --git a/tests/rbx_examples.fy b/tests/rbx_examples.fy index 92e88d19..c8d54999 100644 --- a/tests/rbx_examples.fy +++ b/tests/rbx_examples.fy @@ -33,7 +33,7 @@ FancySpec describe: "rbx/examples" with: { "x is: 1", "y is: 2", "3"] - example: 'classes should_output: ["Person with name: Christopher"] + example: 'classes should_output: ["Person with name: Christopher", "foo"] example: 'nested_classes should_output: ["foo got: yay!"]