本文整理汇总了C++中Executer::exec方法的典型用法代码示例。如果您正苦于以下问题:C++ Executer::exec方法的具体用法?C++ Executer::exec怎么用?C++ Executer::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Executer
的用法示例。
在下文中一共展示了Executer::exec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
variant execution_context::execute()
{
size_t isz = instructions_.size();
while(pc_ < isz)
{
instruction& i = instructions_[pc_];
//td: a fuction table would be better, no?
switch(i.id)
{
case i_jump:
{
pc_ = i.data.value;
jump_ = true;
break;
}
case i_jump_if:
{
bool control = pop();
if (control)
{
pc_ = i.data.value;
jump_ = true;
}
break;
}
case i_jump_if_not:
{
bool control = variant_cast<bool>(pop(), false); //td: its bool or false
if (!control)
{
pc_ = i.data.value;
jump_ = true;
}
break;
}
case i_store:
{
stack_[i.data.value] = pop();
break;
}
case i_load:
{
operands_.push(stack_[i.data.value]);
break;
}
case i_load_constant:
{
operands_.push(constants_[i.data.value]);
break;
}
case i_return: return variant();
case i_return_value: return operands_.top();
case i_dup_top:
{
variant top = operands_.top();
operands_.push( top );
break;
}
case i_pop: operands_.pop(); break;
case i_binary_operator:
{
operator_exec* e = operators_.get_operator(i.data.value);
variant arg2 = pop();
variant arg1 = pop();
variant result = e->exec(arg1, arg2);
operands_.push(result);
break;
}
case i_unary_operator:
{
operator_exec* e = operators_.get_operator(i.data.value);
variant arg1 = pop();
variant useless;
variant result = e->exec(arg1, useless);
operands_.push(result);
break;
}
case i_dynamic_binary_operator:
{
variant arg2 = pop();
variant arg1 = pop();
schema* type1 = true_type(arg1); assert(type1);
schema* type2 = true_type(arg2); assert(type2);
variant result;
operator_type opid = (operator_type)i.data.value;
operator_exec* opexec = operators_.get_operator(opid, type1, type2);
if (!opexec)
{
//.........这里部分代码省略.........