Beispiel #1
0
CodeBlock YpAssign(CBorLit lhs, CodeBlock rhs)
{
  long initialPC;
  if (IS_LITERAL(lhs)) {
    /* this is definition of a variable */
    long name= CBL_VALUE(lhs);
    int undecided= !(literalTypes[name]&L_REFERENCE);
    initialPC= rhs;
    if (CheckCodeSpace(2)) return initialPC;
    vmCode[nextPC++].Action= previousOp= &Define;
    VariableReference(name);
    if (undecided) {
      literalTypes[name]|= L_LOCAL;
      nLocal++;
    }

  } else {
    /* this is assignment to an lvalue */
    initialPC= CBL_VALUE(lhs);
    if (CheckCodeSpace(1)) return initialPC;
    vmCode[nextPC++].Action= previousOp= ≔
    WillPopStack(1L);
  }
  return initialPC;
}
Beispiel #2
0
void madara::knowledge::containers::FlexMap::set_name(
    const std::string& var_name, KnowledgeBase& knowledge)
{
  if (context_ != &(knowledge.get_context()) || name_ != var_name)
  {
    context_ = &(knowledge.get_context());

    ContextGuard context_guard(*context_);
    MADARA_GUARD_TYPE guard(mutex_);

    name_ = var_name;

    if (context_->exists(var_name, settings_))
    {
      KnowledgeUpdateSettings keep_local(true);

      variable_ = context_->get_ref(var_name, keep_local);
    }
    else
    {
      // reset variable reference
      variable_ = VariableReference();
    }
  }
}
Beispiel #3
0
Integer Process::registerVariableReference( Variable* aVariable,
                                            Integer aCoefficient,
                                            const bool isAccessor )
{
    theVariableReferenceVector.push_back(
            VariableReference(
                theNextSerial, aVariable, aCoefficient, isAccessor ) );
    return theNextSerial++;
}
Beispiel #4
0
Integer Process::registerVariableReference( String const& aName,
                                            Variable* aVariable,
                                            Integer aCoefficient,
                                            const bool isAccessor )
{
    theVariableReferenceVector.push_back(
            VariableReference(
                theNextSerial, aVariable, aCoefficient, isAccessor ) );
    theVariableReferenceVector.back().setName( aName );
    return theNextSerial++;
}
Beispiel #5
0
void YpKeyword(Literal name, CodeBlock value)
{
  int undecided = !(literalTypes[name] & L_REFERENCE);
  if (CheckCodeSpace(2)) return;
  vmCode[nextPC++].Action= previousOp= &FormKeyword;
  VariableReference(name);
  if (undecided) {  /* default is for keywords to become local, not extern */
    literalTypes[name] &= ~L_REFERENCE;
    literalTypes[name] |= L_LOCAL;  /* note nLocal does not increment */
  }
  WillPushStack();
}
Beispiel #6
0
CodeBlock YpNextArg(int which)
{
  long initialPC= nextPC;
  if (!(hasPosList&1)) {
    YpError("next_arg() or more_args() needs .. function parameter");
  } else {
    Literal name= YpName("*va*", 4L);
    if (CheckCodeSpace(2)) return initialPC;
    vmCode[nextPC++].Action= previousOp= which? &MoreArgs : &NextArg;
    VariableReference(name);
    WillPushStack();
  }
  return initialPC;
}
Beispiel #7
0
CodeBlock YpVariable(Literal name)
{
  long initialPC= nextPC;
  if (CheckCodeSpace(2)) return initialPC;
  if (stackDepth==0 && reparsing) RecordLineNumber(nextPC);
  vmCode[nextPC++].Action= previousOp= &PushVariable;
  /* set wasUndecided flag if this is the first reference of this variable */
  wasUndecided= !(literalTypes[name]&L_REFERENCE);
  if (wasUndecided && (literalTypes[name]&L_LOCAL))
    literalTypes[name] &= ~L_LOCAL;  /* now seen as other than keyword */
  VariableReference(name);
  WillPushStack();
  return initialPC;
}
Beispiel #8
0
CodeBlock YpIncrement(CodeBlock lhs, int assop, CodeBlock rhs)
{
  /* assop is 0-9:
     += -= *= /= %= <<= >>= &= ~= |=   */
  if (lhs+2==rhs && vmCode[lhs].Action==&PushVariable) {
    /* this is increment and redefine a variable */
    if (CheckCodeSpace(3)) return lhs;
    vmCode[nextPC++].Action= Binaries[assopMap[assop]];
    vmCode[nextPC++].Action= previousOp= &Define;
    VariableReference(vmCode[lhs+1].index);
    WillPopStack(1L);

  } else {
    /* this is increment of an lvalue */
    if (CheckCodeSpace(3)) return lhs;
    vmCode[nextPC++].Action= &DupUnder;
    WillPushStack();
    vmCode[nextPC++].Action= Binaries[assopMap[assop]];
    vmCode[nextPC++].Action= previousOp= &Assign;
    WillPopStack(2L);
  }
  return lhs;
}
Beispiel #9
0
void madara::knowledge::containers::FlexMap::set_name(
    const std::string& var_name, Variables& knowledge)
{
  if (context_ != knowledge.get_context() || name_ != var_name)
  {
    context_ = knowledge.get_context();

    ContextGuard context_guard(*context_);
    MADARA_GUARD_TYPE guard(mutex_);

    name_ = var_name;

    if (context_->exists(var_name, settings_))
    {
      update_variable();
    }
    else
    {
      // reset variable reference
      variable_ = VariableReference();
    }
  }
}