Permalink
Browse files

Merge branch 'master' into parser

  • Loading branch information...
2 parents c4a6ef0 + 3bd8039 commit 27cb440685af875a2e3451d1710740ed6933c727 @j-pb j-pb committed Feb 3, 2012
Showing with 102 additions and 10 deletions.
  1. +1 −0 wee/CMakeLists.txt
  2. +24 −9 wee/block.cpp
  3. +5 −1 wee/block.hpp
  4. +1 −0 wee/gc.hpp
  5. +1 −0 wee/message.hpp
  6. +57 −0 wee/object.cpp
  7. +13 −0 wee/object.hpp
View
@@ -9,6 +9,7 @@ set(SRCS
"string.cpp"
"nil.cpp"
"object_space.cpp"
+ "block.cpp"
)
add_library(wee SHARED ${SRCS})
View
@@ -28,32 +28,47 @@
namespace Acute
{
- Block::Block(Message* body, ArgNames argNames, Object* ctx) : message(body), argumentNames(argNames), scope(ctx)
+ template<class T>
+ Block<T>::Block(Message* body, ArgNames argNames, Object* ctx) : message(body), argument_names(argNames), scope(ctx)
{
- locals = new Object();
}
- Object* Block::activate(Object* target, Object* locals, Message* body, Object* slot_context)
+ template<class T>
+ Object* Block<T>::activate(Object* target, Object* locals, Message* body, Object* slot_context)
{
Object* s = scope;
- Object* ctx = new Object();
+ my_locals = new Object();
if(!s)
s = target;
for(int i = 0; i < argument_names.size(); i++)
{
- Object* arg = message->object_at_arg(i);
- ctx->add_slot(argument_names.at(i));
+ Object* arg = message->object_at_arg(i, locals);
+ my_locals->add_slot(argument_names.at(i));
}
+ my_locals->add_slot("self", s);
- return message->perform_on(ctx, ctx);
+ return message->perform_on(my_locals, my_locals);
}
- void Block::walk()
+ template<class T>
+ Object* Block<T>::call(void)
+ {
+ if(this->builtin)
+ {
+ Object* locals = new Object(); // TODO: Need a real locals object
+ return builtin(locals, new Message());
+ }
+ // TODO: call activate.
+ return nullptr;
+ }
+
+ template<class T>
+ void Block<T>::walk()
{
generic_object_walk();
- collector->shade(locals);
+ collector->shade(my_locals);
if(scope)
collector->shade(scope);
collector->shade(message);
View
@@ -33,20 +33,24 @@ namespace Acute
{
typedef std::vector<std::string> ArgNames;
+ template<class T = Object>
class Block : public Object
{
private:
Message* message;
Object* scope;
ArgNames argument_names;
- Object* locals;
+ Object* my_locals;
+ typedef Object* (T::*builtin)(Object*, Message*);
public:
Block(Message*, ArgNames, Object*);
~Block();
Object* activate(Object*, Object*, Message*, Object*);
+ virtual Object* call(void);
+
virtual const std::string object_name();
virtual void walk();
};
View
@@ -26,6 +26,7 @@
#include <vector>
#include <stdint.h>
+#include <climits>
#include "address.hpp"
#define GC_MAX_FREE_OBJECTS 8192
View
@@ -43,6 +43,7 @@ namespace Acute
std::string get_name() { return name; }
std::vector<Message*> get_arguments() { return arguments; }
+ Message* message_at_arg(int n) { return arguments.at(n); }
Object* object_at_arg(int, Object*);
private:
View
@@ -27,6 +27,9 @@
#include "object.hpp"
#include "mailbox.hpp"
#include "integer.hpp"
+#include "string.hpp"
+#include "boolean.hpp"
+#include "block.hpp"
namespace Acute
{
@@ -181,4 +184,58 @@ namespace Acute
{
return "Object";
}
+
+ void Object::register_primitives()
+ {
+ // TODO: Implement.
+ }
+
+ Object* Object::clone(Object* locals, Message* m)
+ {
+ Object* obj = new Object();
+ Object* ctx = nullptr;
+ Block<Object>* func = dynamic_cast<Block<Object>*>(obj->lookup("init", ctx));
+ return func->call();
+ }
+
+ Object* Object::setSlot(Object* locals, Message* m)
+ {
+ String* str = dynamic_cast<String*>(m->object_at_arg(0, locals));
+ Object* val = m->object_at_arg(1, locals);
+ add_slot(str->stringValue(), val);
+ return this;
+ }
+
+ Object* Object::addTrait(Object* locals, Message* m)
+ {
+ Object* trait = m->object_at_arg(0, locals);
+ add_trait(trait);
+ return this;
+ }
+
+ Object* Object::doPrim(Object* locals, Message* m)
+ {
+ if(m->get_arguments().size() > 0)
+ {
+ Message* msg = m->message_at_arg(0);
+ msg->perform_on(this, this);
+ }
+ return this;
+ }
+
+ Object* Object::hasSlot(Object* locals, Message* m)
+ {
+ Boolean* b = nullptr;
+ String* name = dynamic_cast<String*>(m->object_at_arg(0, locals));
+ Object* tmp1 = nullptr;
+ Object* tmp2 = nullptr;
+ return dynamic_cast<Object*>(new Boolean(local_lookup(name->stringValue(), tmp1, tmp2)));
+ }
+
+ Object* Object::getSlot(Object* locals, Message* m)
+ {
+ String* str = dynamic_cast<String*>(m->object_at_arg(0, locals));
+ Object* slot_context = nullptr;
+ return lookup(str->stringValue(), slot_context);
+ }
}
View
@@ -94,6 +94,19 @@ namespace Acute
// Our object name.
virtual const std::string object_name();
+ //
+ // Exposed primitives
+ //
+
+ virtual void register_primitives();
+
+ virtual Object* clone(Object*, Message*);
+ virtual Object* setSlot(Object*, Message*);
+ virtual Object* addTrait(Object*, Message*);
+ virtual Object* doPrim(Object*, Message*);
+ virtual Object* hasSlot(Object*, Message*);
+ virtual Object* getSlot(Object*, Message*);
+
// The mailbox is where messages come into. This allows us to decouple
// message sending and message receiving.
Mailbox* mailbox;

0 comments on commit 27cb440

Please sign in to comment.