Skip to content

Commit

Permalink
Added Self#init() method which creates the static singleton instance …
Browse files Browse the repository at this point in the history
…instead of doing so within Self#node()
  • Loading branch information
bakkdoor committed Sep 8, 2010
1 parent 49a9cd6 commit f1b90a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/bootstrap/core_classes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "../nil.h"
#include "../true.h"

#include "../parser/nodes/self.h"


namespace fancy {

/**
Expand Down Expand Up @@ -142,6 +145,9 @@ namespace fancy {
global_scope->define("true", t);
// a hack for "def NATIVE" method definitions:
global_scope->define("NATIVE", new FancyObject(ObjectClass));

// initialize Self node singleton instance
Self::init();
}

}
Expand Down
6 changes: 5 additions & 1 deletion src/parser/nodes/self.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ namespace fancy {

Self* Self::_self_node = NULL;
Self* Self::node()
{
return _self_node;
}

void Self::init()
{
if(!_self_node) {
_self_node = new Self();
}
return _self_node;
}

Self::Self() : Identifier("self")
Expand Down
1 change: 1 addition & 0 deletions src/parser/nodes/self.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace fancy {
{
public:
static Self* node();
static void init();
private:
Self();
virtual ~Self() {}
Expand Down

0 comments on commit f1b90a8

Please sign in to comment.