Example #1
0
	@dep('_nbind', '_removeAccessorPrefix')
	static _nbind_register_function(
		boundID: number,
		policyListPtr: number,
		typeListPtr: number,
		typeCount: number,
		ptr: number,
		direct: number,
		signatureType: SignatureType,
		namePtr: number,
		num: number,
		flags: TypeFlags
	) {
		const bindClass = _nbind.getType(boundID) as _class.BindClass;
		const policyTbl = _nbind.readPolicyList(policyListPtr);
		const typeList = _nbind.readTypeIdList(typeListPtr, typeCount);

		let specList: _class.MethodSpec[];

		if(signatureType == SignatureType.construct) {
			specList = [{
				direct: ptr,
				name: '__nbindConstructor',
				ptr: 0,
				title: bindClass.name + ' constructor',
				typeList: ['uint32_t'].concat(typeList.slice(1))
			}, {
				direct: direct,
				name: '__nbindValueConstructor',
				ptr: 0,
				title: bindClass.name + ' value constructor',
				typeList: ['void', 'uint32_t'].concat(typeList.slice(1))
			}];
		} else {
			let name = _nbind.readAsciiString(namePtr);
			const title = (bindClass.name && bindClass.name + '.') + name;

			if(signatureType == SignatureType.getter || signatureType == SignatureType.setter) {
				name = _removeAccessorPrefix(name);
			}

			specList = [{
				boundID: boundID,
				direct: direct,
				name: name,
				ptr: ptr,
				title: title,
				typeList: typeList
			}];
		}

		for(let spec of specList) {
			spec.signatureType = signatureType;
			spec.policyTbl = policyTbl;
			spec.num = num;
			spec.flags = flags;

			bindClass.addMethod(spec);
		}
	}
Example #2
0
	@dep('_nbind')
	static _nbind_register_primitive(id: number, size: number, flag: number) {
		const isSignless = flag & 16;
		const isConst    = flag & 8;
		const isPointer  = flag & 4;
		const isFloat    = flag & 2;
		const isUnsigned = flag & 1;

		let name = isConst ? 'const ' : '';

		if(isSignless) {
			name += 'char';
		} else if(isPointer) {
			if(isUnsigned) name += 'un';
			name += 'signed char';
		} else {
			name += (
				(isUnsigned ? 'u' : '') +
				(isFloat ? 'float' : 'int') +
				(size * 8 + '_t')
			);
		}

		if(isPointer) {
			// tslint:disable-next-line:no-unused-expression
			new _nbind.CStringType(id, name + ' *');
		} else if(size == 8 && !isFloat) {
			// tslint:disable-next-line:no-unused-expression
			new _nbind.Int64Type(id, name);
		} else {
			// tslint:disable-next-line:no-unused-expression
			new _nbind.PrimitiveType(id, name, size, !!isUnsigned, !!isFloat);
		}
	}
Example #3
0
	@dep('_nbind')
	static _nbind_register_function(
		typeID: number,
		policyListPtr: number,
		typeListPtr: number,
		typeCount: number,
		ptr: number,
		namePtr: number,
		num: number,
		direct: number
	) {
		const name = _nbind.readAsciiString(namePtr);
		const policyTbl = _nbind.readPolicyList(policyListPtr);
		const typeList = _nbind.readTypeIdList(typeListPtr, typeCount);
		let target: any;

		if(typeID) {
			target = (_nbind.typeList[typeID] as _class.BindClass).proto;
		} else {
			target = Module;
		}

		_nbind.addMethod(
			target,
			name,
			_nbind.makeCaller(ptr, num, direct, typeList, policyTbl),
			typeCount - 1
		);
	}
Example #4
0
	@dep('_nbind')
	static _nbind_register_constructor(
		typeID: number,
		typeListPtr: number,
		typeCount: number,
		ptr: number,
		ptrValue: number
	) {
		const typeList = _nbind.readTypeIdList(typeListPtr, typeCount);
		const proto = (_nbind.typeList[typeID] as _class.BindClass).proto.prototype;

		// The constructor returns a pointer to the new object.
		// It fits in uint32_t.

		typeList[0] = 'uint32_t';

		_nbind.addMethod(
			proto,
			'__nbindConstructor',
			_nbind.makeCaller(null, 0, ptr, typeList),
			typeCount - 1
		);

		// First argument is a pointer to the C++ object to construct in place.
		// It fits in uint32_t.

		typeList.splice(0, 1, 'void', 'uint32_t');

		_nbind.addMethod(
			proto,
			'__nbindValueConstructor',
			_nbind.makeCaller(null, 0, ptrValue, typeList),
			typeCount
		);
	}
Example #5
0
	@dep('_nbind')
	static _nbind_register_destructor(typeID: number, ptr: number) {
		_nbind.addMethod(
			(_nbind.typeList[typeID] as _class.BindClass).proto.prototype,
			'free',
			_nbind.makeMethodCaller(ptr, 0, typeID, ['void'], null),
			0
		);
	}
Example #6
0
	@dep('_nbind')
	static _nbind_register_primitive(id: number, size: number, flags: number) {
		const spec = {
			flags: TypeFlags.isArithmetic | flags,
			id: id,
			ptrSize: size
		};

		_nbind.makeType(_nbind.constructType, spec);
	}
Example #7
0
	@dep('_nbind')
	static _nbind_register_method_getter_setter_id(
		methodID: number,
		getterID: number,
		setterID: number
	) {
		_nbind.MethodType.method = methodID;
		_nbind.MethodType.getter = getterID;
		_nbind.MethodType.setter = setterID;
	}
Example #8
0
	@dep('_nbind')
	static _nbind_register_pool(
		pageSize: number,
		usedPtr: number,
		rootPtr: number,
		pagePtr: number
	) {
		_nbind.Pool.pageSize = pageSize;
		_nbind.Pool.usedPtr = usedPtr / 4;
		_nbind.Pool.rootPtr = rootPtr;
		_nbind.Pool.pagePtr = pagePtr / 4;

		HEAP32[usedPtr / 4] = 0x01020304;
		if(HEAP8[usedPtr] == 1) _nbind.bigEndian = true;
		HEAP32[usedPtr / 4] = 0;

		_nbind.makeTypeKindTbl = {
			[TypeFlags.isArithmetic]: _nbind.PrimitiveType,
			[TypeFlags.isBig]: _nbind.Int64Type,
			[TypeFlags.isClass]: _nbind.BindClass,
			[TypeFlags.isClassPtr]: _nbind.BindClassPtr,
			[TypeFlags.isSharedClassPtr]: _nbind.SharedClassPtr,
			[TypeFlags.isVector]: _nbind.ArrayType,
			[TypeFlags.isArray]: _nbind.ArrayType,
			[TypeFlags.isCString]: _nbind.CStringType,
			[TypeFlags.isCallback]: _nbind.CallbackType,
			[TypeFlags.isOther]: _nbind.BindType
		};

		_nbind.makeTypeNameTbl = {
			'Buffer': _nbind.BufferType,
			'External': _nbind.ExternalType,
			'Int64': _nbind.Int64Type,
			'_nbind_new': _nbind.CreateValueType,
			'bool': _nbind.BooleanType,
			// 'cbFunction': _nbind.CallbackType,
			'cbFunction &': _nbind.CallbackType,
			'const cbFunction &': _nbind.CallbackType,
			'const std::string &': _nbind.StringType,
			'std::string': _nbind.StringType
		};

		Module['toggleLightGC'] = _nbind.toggleLightGC;
		_nbind.callUpcast = Module['dynCall_ii'];

		const globalScope = _nbind.makeType(_nbind.constructType, {
			flags: TypeFlags.isClass,
			id: 0,
			name: ''
		}) as _class.BindClass;

		globalScope.proto = Module as any;
		_nbind.BindClass.list.push(globalScope);
	}
Example #9
0
	@dep('_nbind', '_typeModule')
	static _nbind_register_type(id: number, namePtr: number) {
		const name = _nbind.readAsciiString(namePtr);

		const spec = {
			flags: TypeFlags.isOther,
			id: id,
			name: name
		};

		_nbind.makeType(_nbind.constructType, spec);
	}
Example #10
0
	@dep('_nbind')
	static _nbind_register_pool(
		pageSize: number,
		usedPtr: number,
		rootPtr: number,
		pagePtr: number
	) {
		_nbind.Pool.pageSize = pageSize;
		_nbind.Pool.usedPtr = usedPtr / 4;
		_nbind.Pool.rootPtr = rootPtr;
		_nbind.Pool.pagePtr = pagePtr / 4;
	}