TypePtr recordType(RecordPtr record, const vector<ObjectPtr> ¶ms) { int h = pointerHash(record.ptr()); vector<ObjectPtr>::const_iterator pi, pend; for (pi = params.begin(), pend = params.end(); pi != pend; ++pi) h += objectHash(*pi); h &= recordTypes.size() - 1; vector<RecordTypePtr>::iterator i, end; for (i = recordTypes[h].begin(), end = recordTypes[h].end(); i != end; ++i) { RecordType *t = i->ptr(); if ((t->record == record) && objectVectorEquals(t->params, params)) return t; } RecordTypePtr t = new RecordType(record); for (pi = params.begin(), pend = params.end(); pi != pend; ++pi) t->params.push_back(*pi); recordTypes[h].push_back(t); initializeRecordFields(t); return t.ptr(); }
static ModulePtr makePrimitivesModule() { ModulePtr prims = new Module("__primitives__"); addPrim(prims, "Bool", boolType.ptr()); addPrim(prims, "Int8", int8Type.ptr()); addPrim(prims, "Int16", int16Type.ptr()); addPrim(prims, "Int32", int32Type.ptr()); addPrim(prims, "Int64", int64Type.ptr()); addPrim(prims, "Int128", int128Type.ptr()); addPrim(prims, "UInt8", uint8Type.ptr()); addPrim(prims, "UInt16", uint16Type.ptr()); addPrim(prims, "UInt32", uint32Type.ptr()); addPrim(prims, "UInt64", uint64Type.ptr()); addPrim(prims, "UInt128", uint128Type.ptr()); addPrim(prims, "Float32", float32Type.ptr()); addPrim(prims, "Float64", float64Type.ptr()); addPrim(prims, "Float80", float80Type.ptr()); addPrim(prims, "Imag32", imag32Type.ptr()); addPrim(prims, "Imag64", imag64Type.ptr()); addPrim(prims, "Imag80", imag80Type.ptr()); addPrim(prims, "Complex32", complex32Type.ptr()); addPrim(prims, "Complex64", complex64Type.ptr()); addPrim(prims, "Complex80", complex80Type.ptr()); GlobalAliasPtr v = new GlobalAlias(new Identifier("ExceptionsEnabled?"), PUBLIC, vector<PatternVar>(), NULL, vector<IdentifierPtr>(), NULL, new BoolLiteral(exceptionsEnabled())); addPrim(prims, "ExceptionsEnabled?", v.ptr()); vector<IdentifierPtr> recordParams; RecordBodyPtr recordBody = new RecordBody(vector<RecordFieldPtr>()); recordParams.push_back(new Identifier("T")); RecordPtr byRefRecord = new Record(new Identifier("ByRef"), PUBLIC, vector<PatternVar>(), NULL, recordParams, NULL, recordBody); byRefRecord->env = new Env(prims); addPrim(prims, "ByRef", byRefRecord.ptr()); recordParams.clear(); recordParams.push_back(new Identifier("Properties")); recordParams.push_back(new Identifier("Fields")); RecordPtr rwpRecord = new Record(new Identifier("RecordWithProperties"), PUBLIC, vector<PatternVar>(), NULL, recordParams, NULL, recordBody); rwpRecord->env = new Env(prims); addPrim(prims, "RecordWithProperties", rwpRecord.ptr()); #define PRIMITIVE(x) addPrimOp(prims, toPrimStr(#x), new PrimOp(PRIM_##x)) PRIMITIVE(TypeP); PRIMITIVE(TypeSize); PRIMITIVE(TypeAlignment); PRIMITIVE(StaticCallDefinedP); PRIMITIVE(StaticCallOutputTypes); PRIMITIVE(StaticMonoP); PRIMITIVE(StaticMonoInputTypes); PRIMITIVE(bitcopy); PRIMITIVE(bitcast); PRIMITIVE(boolNot); PRIMITIVE(integerEqualsP); PRIMITIVE(integerLesserP); PRIMITIVE(numericAdd); PRIMITIVE(numericSubtract); PRIMITIVE(numericMultiply); PRIMITIVE(floatDivide); PRIMITIVE(numericNegate); PRIMITIVE(integerQuotient); PRIMITIVE(integerRemainder); PRIMITIVE(integerShiftLeft); PRIMITIVE(integerShiftRight); PRIMITIVE(integerBitwiseAnd); PRIMITIVE(integerBitwiseOr); PRIMITIVE(integerBitwiseXor); PRIMITIVE(integerBitwiseNot); PRIMITIVE(numericConvert); PRIMITIVE(integerAddChecked); PRIMITIVE(integerSubtractChecked); PRIMITIVE(integerMultiplyChecked); PRIMITIVE(integerQuotientChecked); PRIMITIVE(integerRemainderChecked); PRIMITIVE(integerShiftLeftChecked); PRIMITIVE(integerNegateChecked); PRIMITIVE(integerConvertChecked); PRIMITIVE(floatOrderedEqualsP); PRIMITIVE(floatOrderedLesserP); PRIMITIVE(floatOrderedLesserEqualsP); PRIMITIVE(floatOrderedGreaterP); PRIMITIVE(floatOrderedGreaterEqualsP); PRIMITIVE(floatOrderedNotEqualsP); PRIMITIVE(floatOrderedP); PRIMITIVE(floatUnorderedEqualsP); PRIMITIVE(floatUnorderedLesserP); PRIMITIVE(floatUnorderedLesserEqualsP); PRIMITIVE(floatUnorderedGreaterP); PRIMITIVE(floatUnorderedGreaterEqualsP); PRIMITIVE(floatUnorderedNotEqualsP); PRIMITIVE(floatUnorderedP); PRIMITIVE(Pointer); PRIMITIVE(addressOf); PRIMITIVE(pointerDereference); PRIMITIVE(pointerOffset); PRIMITIVE(pointerToInt); PRIMITIVE(intToPointer); PRIMITIVE(nullPointer); PRIMITIVE(CodePointer); PRIMITIVE(makeCodePointer); PRIMITIVE(AttributeStdCall); PRIMITIVE(AttributeFastCall); PRIMITIVE(AttributeCCall); PRIMITIVE(AttributeThisCall); PRIMITIVE(AttributeLLVMCall); PRIMITIVE(AttributeDLLImport); PRIMITIVE(AttributeDLLExport); PRIMITIVE(ExternalCodePointer); PRIMITIVE(makeExternalCodePointer); PRIMITIVE(callExternalCodePointer); PRIMITIVE(Array); PRIMITIVE(arrayRef); PRIMITIVE(arrayElements); PRIMITIVE(Vec); PRIMITIVE(Tuple); PRIMITIVE(TupleElementCount); PRIMITIVE(tupleRef); PRIMITIVE(tupleElements); PRIMITIVE(Union); PRIMITIVE(UnionMemberCount); PRIMITIVE(RecordP); PRIMITIVE(RecordFieldCount); PRIMITIVE(RecordFieldName); PRIMITIVE(RecordWithFieldP); PRIMITIVE(recordFieldRef); PRIMITIVE(recordFieldRefByName); PRIMITIVE(recordFields); PRIMITIVE(VariantP); PRIMITIVE(VariantMemberIndex); PRIMITIVE(VariantMemberCount); PRIMITIVE(VariantMembers); PRIMITIVE(variantRepr); PRIMITIVE(Static); PRIMITIVE(ModuleName); PRIMITIVE(StaticName); PRIMITIVE(staticIntegers); PRIMITIVE(integers); PRIMITIVE(staticFieldRef); PRIMITIVE(EnumP); PRIMITIVE(EnumMemberCount); PRIMITIVE(EnumMemberName); PRIMITIVE(enumToInt); PRIMITIVE(intToEnum); PRIMITIVE(IdentifierP); PRIMITIVE(IdentifierSize); PRIMITIVE(IdentifierConcat); PRIMITIVE(IdentifierSlice); PRIMITIVE(IdentifierModuleName); PRIMITIVE(IdentifierStaticName); PRIMITIVE(OrderUnordered); PRIMITIVE(OrderMonotonic); PRIMITIVE(OrderAcquire); PRIMITIVE(OrderRelease); PRIMITIVE(OrderAcqRel); PRIMITIVE(OrderSeqCst); PRIMITIVE(FlagP); PRIMITIVE(Flag); PRIMITIVE(atomicFence); PRIMITIVE(atomicRMW); PRIMITIVE(atomicLoad); PRIMITIVE(atomicStore); PRIMITIVE(atomicCompareExchange); PRIMITIVE(RMWXchg); PRIMITIVE(RMWAdd); PRIMITIVE(RMWSubtract); PRIMITIVE(RMWAnd); PRIMITIVE(RMWNAnd); PRIMITIVE(RMWOr); PRIMITIVE(RMWXor); PRIMITIVE(RMWMin); PRIMITIVE(RMWMax); PRIMITIVE(RMWUMin); PRIMITIVE(RMWUMax); PRIMITIVE(activeException); PRIMITIVE(memcpy); PRIMITIVE(memmove); PRIMITIVE(countValues); PRIMITIVE(nthValue); PRIMITIVE(withoutNthValue); PRIMITIVE(takeValues); PRIMITIVE(dropValues); PRIMITIVE(LambdaRecordP); PRIMITIVE(LambdaSymbolP); PRIMITIVE(LambdaMonoP); PRIMITIVE(LambdaMonoInputTypes); PRIMITIVE(GetOverload); #undef PRIMITIVE return prims; }