// Push args onto Lua stack. // Used by Call() and Return() below // Returns no of args pushed. // Called recursively to flatten vectors of variables static int PushLuaArgs(lua_State* L, const Variable& v) { int numPushed = 0; if (v.IsIntType()) { int intArg = v.GetInt(); lua_pushnumber(L, intArg); numPushed = 1; } else if (v.IsFloatType()) { float fArg = v.GetFloat(); lua_pushnumber(L, fArg); numPushed = 1; } else if (v.IsStringType()) { lua_pushstring(L, v.GetString().c_str()); numPushed = 1; } else if (v.IsVectorType()) { VariableVec vec = v.GetVector(); int numArgs = vec.size(); for (int i = 0; i < numArgs; i++) { const Variable& vv = vec[i]; numPushed += PushLuaArgs(L, vv); } } else { // TODO std::cout << "LUA: c++: Type not handled yet! Get on it dude!\n"; Assert(0); } return numPushed; }
void WasmAssertReturnNan::Codegen(WasmFile* file) { // Just one thing before we do anything. Find out if the caller was 64-bit or not. ReturnExpression* return_expr = dynamic_cast<ReturnExpression*>(expr_); assert(return_expr != nullptr); IfExpression* if_expr = dynamic_cast<IfExpression*>(return_expr->GetResult()); assert(if_expr!= nullptr); Binop* binop = dynamic_cast<Binop*>(if_expr->GetCondition()); assert(binop != nullptr); CallExpression* call = dynamic_cast<CallExpression*>(binop->GetLeft()); assert(call != nullptr); Variable* var = call->GetVariable(); const char* name = var->GetString(); // Get the function. WasmFunction* fct = file->GetWasmFunction(name); assert(fct != nullptr); ETYPE result = fct->GetResult(); if (result == FLOAT_64) { // We need to just fix the right hand side of the comparison. ValueHolder* vh = new ValueHolder(std::numeric_limits<double>::quiet_NaN()); Const* expr = new Const(FLOAT_64, vh); binop->SetRight(expr); } // Now generate the code... WasmAssertReturn::Codegen(file); }
int Configuration::loadImpl( Variable& variable, bool substitute ) { variable.ClearValues(); if ( variable.Name.IsEmpty() ) { ALIB_WARNING( "Empty variable name given" ); return 0; } // search variable int priority= 0; for ( auto& ppp : plugins ) if ( ppp.second->Load( variable ) ) { priority= ppp.first; break; } // not found? if ( !substitute || priority == 0 ) return 0; // substitution in all values of variable for ( int valueNo= 0; valueNo < variable.Size(); valueNo++ ) { int searchStartIdx= 0; int maxReplacements = 50; do { AString& value= *variable.GetString( valueNo ); // search start int repStart= value.IndexOf( SubstitutionVariableStart, searchStartIdx ); if ( repStart < 0 ) break; searchStartIdx= repStart; int varStart= repStart + SubstitutionVariableStart.Length(); Variable replVar; int repLen; int varLen; // search end in two different ways depending on setting of public field "SubstitutionVariableEnd" if ( SubstitutionVariableEnd.IsEmpty() ) { int idx= value.IndexOfAny( SubstitutionVariableDelimiters, Inclusion::Include, varStart ); if ( idx < 0 ) idx= value.Length(); varLen= idx - varStart; repLen= idx - repStart; } else { int idx= value.IndexOf ( SubstitutionVariableEnd, varStart ); if (idx < 0 ) { ALIB_WARNING_S512( "End of substitution variable not found (while start was found). Variable name: " << variable.Fullname << " Value: \"" << variable.GetString() << "\"." ); break; } varLen= idx - varStart; repLen= idx + SubstitutionVariableEnd.Length() - repStart; } // get variable name string Substring replVarCategory; Substring replVarName( value, varStart, varLen ); if ( replVarName.IsEmpty() ) { searchStartIdx+= SubstitutionVariableStart.Length() + SubstitutionVariableEnd.Length(); continue; } // parse category from name int catSeparatorIdx= replVarName.IndexOf( '_' ); if (catSeparatorIdx >= 0 ) { replVarCategory.Set( replVarName, 0 , catSeparatorIdx ); replVarName .Set( replVarName, catSeparatorIdx + 1); } // load replacement variable if ( replVarName.IsNotEmpty() ) { replVar.Define( replVarCategory, replVarName, variable.Delim ); loadImpl( replVar, false ); } else replVar.ClearValues(); // do the replacement (even if no variable was found) if ( replVar.Size() == 1 ) value.ReplaceSubstring( replVar.GetString(), repStart, repLen ); else if ( replVar.Size() > 1 ) { variable.ReplaceValue( valueNo, replVar ); // repeat replacements in current value, as current value changed valueNo--; break; } else value.ReplaceSubstring( "", repStart, repLen ); } while( --maxReplacements ); // warn if max replacements if( maxReplacements <= 0 ) ALIB_WARNING_S512( "Too many substitutions in variable " << variable.Fullname << ". Probably a recursive variable definition was made. "); } return priority; }