本文整理汇总了C++中Address::getNode方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::getNode方法的具体用法?C++ Address::getNode怎么用?C++ Address::getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: binopInt
void binopInt(GEnvironment& environment, std::vector<Node>& heap)
{
Address rhs = environment.stack.pop();
Address lhs = environment.stack.top();
int result = func(lhs.getNode()->number, rhs.getNode()->number);
heap.push_back(Node(result));
environment.stack.top() = Address::number(&heap.back());
}
示例2: binopDouble
void binopDouble(GEnvironment& environment, std::vector<Node>& heap)
{
Address rhs = environment.stack.pop();
Address lhs = environment.stack.top();
double result = func(lhs.getNode()->numberDouble, rhs.getNode()->numberDouble);
heap.push_back(Node(result));
environment.stack.top() = Address::numberDouble(&heap.back());
}
示例3: executeMain
Address GMachine::executeMain()
{
SuperCombinator* main = getCombinator("main");
int mainIndex = -1;
for (size_t ii = 0; ii < globals.size(); ++ii)
{
Address addr = globals[ii];
if (addr.getType() == GLOBAL && addr.getNode()->global == main)
{
mainIndex = ii;
break;
}
}
assert(mainIndex != -1);
SuperCombinator sc;
sc.name == "__main";
sc.arity = 0;
sc.instructions = std::vector<GInstruction> { GInstruction(GOP::PUSH_GLOBAL, mainIndex), GInstruction(GOP::EVAL) };
return evaluate(sc);
}
示例4: execute
void GMachine::execute(GEnvironment& environment)
{
const std::vector<GInstruction>& code = environment.combinator->instructions;
StackFrame<Address>& stack = environment.stack;
for (size_t index = 0; index < code.size(); index++)
{
const GInstruction& instruction = code[index];
switch (instruction.op)
{
case GOP::ALLOC:
{
for (int i = 0; i < instruction.value; i++)
{
heap.push_back(Node(nullptr));
environment.stack.push(Address::indirection(&heap.back()));
}
}
break;
case GOP::EVAL:
{
static SuperCombinator unwind { "__uniwnd", Type(), 0, std::vector<GInstruction>{ GInstruction(GOP::UNWIND) } };
GEnvironment child = environment.child(&unwind);
child.stack.push(environment.stack.top());
execute(child);
environment.stack.top() = child.stack.top();
}
break;
case GOP::MKAP:
{
Address func = environment.stack.top();
environment.stack.pop();
Address arg = environment.stack.top();
heap.push_back(Node(func, arg));
environment.stack.top() = Address::application(&heap.back());
}
break;
case GOP::PACK:
{
int tag = instruction.value & (0xFFFF);//Low two bytes
int arity = instruction.value >> 16;//High two bytes
heap.push_back(Node(tag, new Address[arity+1]));
Node& ctor = heap.back();
for (int ii = 0; ii < arity; ii++)
{
ctor.constructor.arguments[ii] = stack.pop();
}
ctor.constructor.arguments[arity + 1] = Address::indirection(nullptr);//Use as end of this constructor
stack.push(Address::constructor(&ctor));
}
break;
case GOP::SPLIT:
{
Address top = stack.pop();
assert(top.getType() == CONSTRUCTOR);
ConstructorNode& ctor = top.getNode()->constructor;
for (int ii = 0; ii < instruction.value; ii++)
{
assert(ctor.arguments[ii].getType() != NodeType::INDIRECTION || ctor.arguments[ii].getNode() != nullptr);
stack.push(ctor.arguments[ii]);
}
}
break;
case GOP::CASEJUMP:
{
Address top = stack.top();
assert(top.getType() == CONSTRUCTOR);
ConstructorNode& ctor = top.getNode()->constructor;
if (ctor.tag != instruction.value)
index++;//Skip the next instruction which is the jump instruction
}
break;
case GOP::JUMP:
index = instruction.value - 1;
break;
case GOP::POP:
for (int i = 0; i < instruction.value; i++)
{
environment.stack.pop();
}
break;
case GOP::PUSH:
{
Address addr = environment.stack[instruction.value];
environment.stack.push(addr);
}
break;
case GOP::PUSH_DICTIONARY_MEMBER:
{
assert(stack.base().getType() == NodeType::CONSTRUCTOR);//Must be instance dictionary
ConstructorNode& ctor = stack.base().getNode()->constructor;
Address& func = ctor.arguments[instruction.value];
stack.push(func);
}
break;
case GOP::PUSH_GLOBAL:
{
Address addr = globals.at(instruction.value);
environment.stack.push(addr);
}
//.........这里部分代码省略.........