Skip to content

Commit

Permalink
Added class variable assignment & small fixed to identifier ast node …
Browse files Browse the repository at this point in the history
…class.
  • Loading branch information
bakkdoor committed Oct 7, 2010
1 parent 77e3ea8 commit 64dae93
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rbx/compiler/ast/assign.rb
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion rbx/compiler/ast/identifier.rb
Expand Up @@ -16,7 +16,7 @@ def constant?
end

def instance_variable?
@identifier =~ /^@/
@identifier =~ /^@/ && !class_variable?
end

def class_variable?
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions rbx/examples/classes.fy
@@ -1,12 +1,18 @@
def class Person {
@@a_classvar = "foo"
def initialize: name {
@name = name
}

def to_s {
"Person with name: " ++ @name
}

def Person class_var {
@@a_classvar
}
}

p = Person new: "Christopher"
p println
Person class_var println
2 changes: 1 addition & 1 deletion tests/rbx_examples.fy
Expand Up @@ -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!"]

Expand Down

0 comments on commit 64dae93

Please sign in to comment.