Skip to content

Commit

Permalink
adds primitive block
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytregunna committed Jan 25, 2012
1 parent 7fba31f commit ad0fb29
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
17 changes: 17 additions & 0 deletions wee/block.cpp
Expand Up @@ -33,6 +33,23 @@ namespace Acute
locals = new Object();
}

Object* Block::activate(Object* target, Object* locals, Message* body, Object* slot_context)
{
Object* s = scope;
Object* ctx = 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));
}

return message->perform_on(ctx, ctx);
}

void Block::walk()
{
generic_object_walk();
Expand Down
4 changes: 3 additions & 1 deletion wee/block.hpp
Expand Up @@ -38,13 +38,15 @@ namespace Acute
private:
Message* message;
Object* scope;
ArgNames argumentNames;
ArgNames argument_names;
Object* locals;

public:
Block(Message*, ArgNames, Object*);
~Block();

Object* activate(Object*, Object*, Message*, Object*);

virtual const std::string object_name();
virtual void walk();
};
Expand Down
8 changes: 7 additions & 1 deletion wee/message.cpp
Expand Up @@ -27,7 +27,7 @@

namespace Acute
{
Object* Message::performOn(Object* target, Object* locals)
Object* Message::perform_on(Object* target, Object* locals)
{
Object* result = target;
Message* m = this;
Expand All @@ -41,6 +41,12 @@ namespace Acute
return result;
}

Object* Message::object_at_arg(int num, Object* ctx)
{
Message* msg = arguments.at(num);
return msg->perform_on(ctx, ctx);
}

const std::string Message::object_name()
{
return "Message";
Expand Down
4 changes: 3 additions & 1 deletion wee/message.hpp
Expand Up @@ -36,13 +36,15 @@ namespace Acute
Message() : name(""), arguments() {}
Message(const std::string& n, std::vector<Message*> args) : name(n), arguments(args) {}

Object* performOn(Object*, Object*);
Object* perform_on(Object*, Object*);

virtual const std::string object_name();

std::string get_name() { return name; }
std::vector<Message*> get_arguments() { return arguments; }

Object* object_at_arg(int, Object*);

private:
std::string name;
std::vector<Message*> arguments;
Expand Down

0 comments on commit ad0fb29

Please sign in to comment.