const std::string NodeBinaryOpEqualShift::methodNameForCodeGen() { std::ostringstream methodname; //methodname << "_Shift"; determined by each op UlamType * nut = m_state.getUlamTypeByIndex(getNodeType()); // common part of name ULAMTYPE etyp = nut->getUlamTypeEnum(); switch(etyp) { case Int: case Unsigned: case Bool: case Unary: case Bits: methodname << UlamType::getUlamTypeEnumAsString(etyp); break; default: m_state.abortUndefinedUlamPrimitiveType(); break; }; methodname << nut->getTotalWordSize(); return methodname.str(); } //methodNameForCodeGen
const std::string NodeBinaryOpCompare::methodNameForCodeGen() { std::ostringstream methodname; //methodname << "_BitwiseOr"; determined by each op UlamType * lut = m_state.getUlamTypeByIndex(m_nodeLeft->getNodeType()); // common part of name ULAMTYPE etyp = lut->getUlamTypeEnum(); switch(etyp) { case Int: methodname << "Int"; break; case Unsigned: methodname << "Unsigned"; break; case Bits: methodname << "Bits"; break; case Bool: methodname << "Bool"; break; case String: methodname << "String"; break; default: m_state.abortUndefinedUlamPrimitiveType(); methodname << "NAV"; break; }; methodname << lut->getTotalWordSize(); return methodname.str(); } // methodNameForCodeGen
const std::string UlamType::castMethodForCodeGen(UTI nodetype) { std::ostringstream rtnMethod; UlamType * nut = m_state.getUlamTypeByIndex(nodetype); //base types e.g. Int, Bool, Unary, Foo, Bar.. u32 sizeByIntBitsToBe = getTotalWordSize(); u32 sizeByIntBits = nut->getTotalWordSize(); if(sizeByIntBitsToBe != sizeByIntBits) { std::ostringstream msg; msg << "Casting different word sizes; " << sizeByIntBits; msg << ", Value Type and size was: " << nut->getUlamTypeName().c_str(); msg << ", to be: " << sizeByIntBitsToBe << " for type: "; msg << getUlamTypeName().c_str(); MSG(m_state.getFullLocationAsString(m_state.m_locOfNextLineText).c_str(), msg.str().c_str(), DEBUG); //use the larger word size if(sizeByIntBitsToBe < sizeByIntBits) //downcast using larger sizeByIntBitsToBe = sizeByIntBits; else sizeByIntBits = sizeByIntBitsToBe; } rtnMethod << "_" << nut->getUlamTypeNameOnly().c_str() << sizeByIntBits << "To"; rtnMethod << getUlamTypeNameOnly().c_str() << sizeByIntBitsToBe; return rtnMethod.str(); } //castMethodForCodeGen
const std::string NodeBinaryOpEqualArith::methodNameForCodeGen() { std::ostringstream methodname; //methodname << "_BitwiseOr"; determined by each op UlamType * nut = m_state.getUlamTypeByIndex(getNodeType()); // common part of name ULAMTYPE etyp = nut->getUlamTypeEnum(); switch(etyp) { case Int: case Unsigned: case Bool: case Unary: methodname << UlamType::getUlamTypeEnumAsString(etyp); break; case Bits: default: assert(0); methodname << "NAV"; break; }; methodname << nut->getTotalWordSize(); return methodname.str(); } //methodNameForCodeGen
FORECAST UlamTypePrimitiveUnary::safeCast(UTI typidx) { FORECAST scr = UlamType::safeCast(typidx); if(scr != CAST_CLEAR) return scr; bool brtn = true; UlamType * vut = m_state.getUlamTypeByIndex(typidx); s32 valbitsize = vut->getBitSize(); s32 bitsize = getBitSize(); ULAMTYPE valtypEnum = vut->getUlamTypeEnum(); switch(valtypEnum) { case Unsigned: { u32 vwordsize = vut->getTotalWordSize(); if(vwordsize <= MAXBITSPERINT) brtn = ((u32) bitsize >= (u32) vut->getMax()); else brtn = ((u64) bitsize >= vut->getMax()); } break; case Unary: brtn = (bitsize >= valbitsize); break; case Int: case Bool: case Bits: case Void: case UAtom: case Class: brtn = false; break; default: m_state.abortUndefinedUlamType(); //std::cerr << "UlamTypePrimitiveUnary (cast) error! Value Type was: " << valtypidx << std::endl; brtn = false; }; return brtn ? CAST_CLEAR : CAST_BAD; } //safeCast
void SymbolWithValue::printPostfixValueScalar(File * fp) { u64 val = 0; bool oktoprint = getValueReadyToPrint(val); if(oktoprint) { UTI tuti = getUlamTypeIdx(); UlamType * tut = m_state.getUlamTypeByIndex(tuti); u32 twordsize = tut->getTotalWordSize(); //must be commplete s32 tbs = tut->getBitSize(); ULAMTYPE etyp = tut->getUlamTypeEnum(); switch(etyp) { case Int: { if(twordsize <= MAXBITSPERINT) { s32 sval = _Int32ToCs32((u32) val, tbs); fp->write_decimal(sval); } else if(twordsize <= MAXBITSPERLONG) { s64 sval = _Int64ToCs64(val, tbs); fp->write_decimal_long(sval); } else m_state.abortGreaterThanMaxBitsPerLong(); } break; case Bool: { bool bval = _Bool64ToCbool(val, tbs); if(bval) fp->write("true"); else fp->write("false"); } break; case Unary: case Unsigned: case Bits: { // NO CASTING NEEDED, assume saved in its ulam-native format if( tbs <= MAXBITSPERINT) fp->write_decimal_unsigned(val); else if( tbs <= MAXBITSPERLONG) fp->write_decimal_unsignedlong(val); else m_state.abortGreaterThanMaxBitsPerLong(); //TBD > 64 fp->write("u"); } break; case String: // scalar strings generate comments (output value rather than index) e.g. t3951,2 fp->write(m_state.getDataAsFormattedUserString(val).c_str()); break; default: m_state.abortUndefinedUlamPrimitiveType(); }; } else fp->write("NONREADYCONST"); } //printPostfixValueScalar