diff options
author | Chad Austin <chad@imvu.com> | 2014-03-31 12:53:15 -0700 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2014-03-31 12:53:15 -0700 |
commit | ffed52a8ac686a54bfda83d722673c11b8e7093e (patch) | |
tree | 9965ff4ae70083c82465cb97a4efa994c773de2f /src | |
parent | 3c5aa9b566c8a824d6ac920600d10bf4085bd42e (diff) |
Remove 'vararg' from names of functions, per code review. Don't expand floats to doubles in argument packs.
Diffstat (limited to 'src')
-rw-r--r-- | src/embind/embind.js | 112 | ||||
-rw-r--r-- | src/embind/emval.js | 24 |
2 files changed, 73 insertions, 63 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 03ed4333..6ec07cd9 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -35,7 +35,7 @@ function throwUnboundTypeError(message, types) { seen[type] = true; } types.forEach(visit); - + throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', '])); } @@ -55,7 +55,7 @@ function ensureOverloadTable(proto, methodName, humanName) { // Move the previous function into the overload table. proto[methodName].overloadTable = []; proto[methodName].overloadTable[prevFunc.argCount] = prevFunc; - } + } } /* Registers a symbol (function, class, enum, ...) as part of the Module JS object so that @@ -72,7 +72,7 @@ function exposePublicSymbol(name, value, numArguments) { if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) { throwBindingError("Cannot register public name '" + name + "' twice"); } - + // We are exposing a function with the same name as an existing function. Create an overload table and a function selector // that routes between the two. ensureOverloadTable(Module, name, name); @@ -164,8 +164,8 @@ var typeDependencies = {}; var registeredPointers = {}; function registerType(rawType, registeredInstance) { - if (!('varArgAdvance' in registeredInstance)) { - throw new TypeError('registerType registeredInstance requires varArgAdvance'); + if (!('argPackAdvance' in registeredInstance)) { + throw new TypeError('registerType registeredInstance requires argPackAdvance'); } var name = registeredInstance.name; @@ -272,7 +272,7 @@ function __embind_register_void(rawType, name) { name = readLatin1String(name); registerType(rawType, { name: name, - 'varArgAdvance': 0, + 'argPackAdvance': 0, 'fromWireType': function() { return undefined; }, @@ -297,8 +297,8 @@ function __embind_register_bool(rawType, name, size, trueValue, falseValue) { 'toWireType': function(destructors, o) { return o ? trueValue : falseValue; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': function(pointer) { + 'argPackAdvance': 8, + 'readValueFromPointer': function(pointer) { // TODO: if heap is fixed (like in asm.js) this could be executed outside var heap; if (size === 1) { @@ -327,7 +327,7 @@ function getShiftFromSize(size) { } } -function integerReadValueFromPointer(shift, signed) { +function integerReadValueFromPointer(name, shift, signed) { switch (shift) { case 0: return function(pointer) { var heap = signed ? HEAP8 : HEAPU8; @@ -346,6 +346,19 @@ function integerReadValueFromPointer(shift, signed) { } } +function floatReadValueFromPointer(name, shift) { + switch (shift) { + case 2: return function(pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]); + }; + case 3: return function(pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]); + }; + default: + throw new TypeError("Unknown float type: " + name); + } +} + // When converting a number from JS to C++ side, the valid range of the number is // [minRange, maxRange], inclusive. function __embind_register_integer(primitiveType, name, size, minRange, maxRange) { @@ -372,12 +385,14 @@ function __embind_register_integer(primitiveType, name, size, minRange, maxRange } return value | 0; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': integerReadValueFromPointer(shift, minRange !== 0), + 'argPackAdvance': 8, + 'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0), destructorFunction: null, // This type does not need a destructor }); } + + function __embind_register_float(rawType, name, size) { var shift = getShiftFromSize(size); name = readLatin1String(name); @@ -394,13 +409,8 @@ function __embind_register_float(rawType, name, size) { } return value; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': function(pointer) { - // embind arg pack floats are always promoted to double. - // We could change this and have C++ pass floats to - // JavaScript without converting to double. - return this['fromWireType'](HEAPF64[pointer >> 3]); - }, + 'argPackAdvance': 8, + 'readValueFromPointer': floatReadValueFromPointer(name, shift), destructorFunction: null, // This type does not need a destructor }); } @@ -462,8 +472,8 @@ function __embind_register_std_string(rawType, name) { } return ptr; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': simpleReadValueFromPointer, + 'argPackAdvance': 8, + 'readValueFromPointer': simpleReadValueFromPointer, destructorFunction: function(ptr) { _free(ptr); }, }); } @@ -504,8 +514,8 @@ function __embind_register_std_wstring(rawType, charSize, name) { } return ptr; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': simpleReadValueFromPointer, + 'argPackAdvance': 8, + 'readValueFromPointer': simpleReadValueFromPointer, destructorFunction: function(ptr) { _free(ptr); }, }); } @@ -522,8 +532,8 @@ function __embind_register_emval(rawType, name) { 'toWireType': function(destructors, value) { return __emval_register(value); }, - 'varArgAdvance': 8, - 'readValueFromVarArg': simpleReadValueFromPointer, + 'argPackAdvance': 8, + 'readValueFromPointer': simpleReadValueFromPointer, destructorFunction: null, // This type does not need a destructor }); } @@ -537,7 +547,7 @@ function __embind_register_memory_view(rawType, name) { Int32Array, Uint32Array, Float32Array, - Float64Array, + Float64Array, ]; name = readLatin1String(name); @@ -550,8 +560,8 @@ function __embind_register_memory_view(rawType, name) { var TA = typeMapping[type]; return new TA(HEAP8.buffer, data, size); }, - 'varArgAdvance': 16, - 'readValueFromVarArg': function(ptr) { + 'argPackAdvance': 16, + 'readValueFromPointer': function(ptr) { return this['fromWireType'](ptr); }, }); @@ -609,7 +619,7 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp if (argCount < 2) { throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!"); } - + var isClassMethodFunc = (argTypes[1] !== null && classType !== null); if (!isClassMethodFunc && !FUNCTION_TABLE[cppTargetFunc]) { @@ -638,7 +648,7 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp // Determine if we need to use a dynamic stack to store the destructors for the function parameters. // TODO: Remove this completely once all function invokers are being dynamically generated. var needsDestructorStack = false; - + for(var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { // The type does not define a destructor function - must use dynamic stack needsDestructorStack = true; @@ -673,7 +683,7 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp invokerFnBody += (returns?"var rv = ":"") + "invoker(fn"+(argsListWired.length>0?", ":"")+argsListWired+");\n"; - + if (needsDestructorStack) { invokerFnBody += "runDestructors(destructors);\n"; } else { @@ -686,7 +696,7 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp } } } - + if (returns) { invokerFnBody += "return retType.fromWireType(rv);\n"; } @@ -754,7 +764,7 @@ function __embind_finalize_value_array(rawTupleType) { var rawConstructor = reg.rawConstructor; var rawDestructor = reg.rawDestructor; - + whenDependentTypesAreResolved([rawTupleType], elementTypes, function(elementTypes) { elements.forEach(function(elt, i) { var getterReturnType = elementTypes[i]; @@ -796,8 +806,8 @@ function __embind_finalize_value_array(rawTupleType) { } return ptr; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': simpleReadValueFromPointer, + 'argPackAdvance': 8, + 'readValueFromPointer': simpleReadValueFromPointer, destructorFunction: rawDestructor, }]; }); @@ -899,8 +909,8 @@ function __embind_finalize_value_object(structType) { } return ptr; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': simpleReadValueFromPointer, + 'argPackAdvance': 8, + 'readValueFromPointer': simpleReadValueFromPointer, destructorFunction: rawDestructor, }]; }); @@ -942,7 +952,7 @@ var genericPointerToWireType = function(destructors, handle) { if (undefined === handle.$$.smartPtr) { throwBindingError('Passing raw pointer to smart pointer is illegal'); } - + switch (this.sharingPolicy) { case 0: // NONE // no upcasting @@ -952,11 +962,11 @@ var genericPointerToWireType = function(destructors, handle) { throwBindingError('Cannot convert argument of type ' + (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + ' to parameter type ' + this.name); } break; - + case 1: // INTRUSIVE ptr = handle.$$.smartPtr; break; - + case 2: // BY_EMVAL if (handle.$$.smartPtrType === this) { ptr = handle.$$.smartPtr; @@ -973,7 +983,7 @@ var genericPointerToWireType = function(destructors, handle) { } } break; - + default: throwBindingError('Unsupporting sharing policy'); } @@ -1067,7 +1077,7 @@ function RegisteredPointer( this['toWireType'] = genericPointerToWireType; // Here we must leave this.destructorFunction undefined, since whether genericPointerToWireType returns // a pointer that needs to be freed up is runtime-dependent, and cannot be evaluated at registration time. - // TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in + // TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in // craftInvokerFunction altogether. } } @@ -1085,8 +1095,8 @@ RegisteredPointer.prototype.destructor = function(ptr) { } }; -RegisteredPointer.prototype['varArgAdvance'] = 8; -RegisteredPointer.prototype['readValueFromVarArg'] = simpleReadValueFromPointer; +RegisteredPointer.prototype['argPackAdvance'] = 8; +RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer; RegisteredPointer.prototype['fromWireType'] = function(ptr) { // ptr is a raw pointer (or a raw smartpointer) @@ -1195,7 +1205,7 @@ ClassHandle.prototype['isAliasOf'] = function(other) { right = rightClass.upcast(right); rightClass = rightClass.baseClass; } - + return leftClass === rightClass && left === right; }; @@ -1280,7 +1290,7 @@ Module['setDelayFunction'] = function setDelayFunction(fn) { delayFunction(flushPendingDeletes); } }; - + function RegisteredClass( name, constructor, @@ -1383,7 +1393,7 @@ function __embind_register_class( true, false, false); - + var pointerConverter = new RegisteredPointer( name + '*', registeredClass, @@ -1445,10 +1455,10 @@ function __embind_register_class_constructor( for (var i = 1; i < argCount; ++i) { args[i] = argTypes[i]['toWireType'](destructors, arguments[i - 1]); } - + var ptr = invoker.apply(null, args); runDestructors(destructors); - + return argTypes[0]['fromWireType'](ptr); }; return []; @@ -1532,7 +1542,7 @@ function __embind_register_class_function( } whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) { - + var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context); // Replace the initial unbound-handler-stub function with the appropriate member function, now that all types @@ -1732,8 +1742,8 @@ function __embind_register_enum( 'toWireType': function(destructors, c) { return c.value; }, - 'varArgAdvance': 8, - 'readValueFromVarArg': integerReadValueFromPointer(shift, isSigned), + 'argPackAdvance': 8, + 'readValueFromPointer': integerReadValueFromPointer(name, shift, isSigned), destructorFunction: null, }); exposePublicSymbol(name, constructor); diff --git a/src/embind/emval.js b/src/embind/emval.js index 24c42c3d..4007701a 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -108,7 +108,7 @@ function __emval_new_cstring(v) { function __emval_take_value(type, argv) { type = requireRegisteredType(type, '_emval_take_value'); - var v = type['readValueFromVarArg'](argv); + var v = type['readValueFromPointer'](argv); return __emval_register(v); } @@ -119,11 +119,11 @@ function craftEmvalAllocator(argCount) { /*This function returns a new function that looks like this: function emval_allocator_3(constructor, argTypes, args) { var argType0 = requireRegisteredType(HEAP32[(argTypes >> 2)], "parameter 0"); - var arg0 = argType0.readValueFromVarArg(args); + var arg0 = argType0.readValueFromPointer(args); var argType1 = requireRegisteredType(HEAP32[(argTypes >> 2) + 1], "parameter 1"); - var arg1 = argType1.readValueFromVarArg(args + 8); + var arg1 = argType1.readValueFromPointer(args + 8); var argType2 = requireRegisteredType(HEAP32[(argTypes >> 2) + 2], "parameter 2"); - var arg2 = argType2.readValueFromVarArg(args + 16); + var arg2 = argType2.readValueFromPointer(args + 16); var obj = new constructor(arg0, arg1, arg2); return __emval_register(obj); } */ @@ -137,10 +137,10 @@ function craftEmvalAllocator(argCount) { "return function emval_allocator_"+argCount+"(constructor, argTypes, args) {\n"; for(var i = 0; i < argCount; ++i) { - functionBody += + functionBody += "var argType"+i+" = requireRegisteredType(HEAP32[(argTypes >> 2) + "+i+"], \"parameter "+i+"\");\n" + - "var arg"+i+" = argType"+i+".readValueFromVarArg(args);\n" + - "args += argType"+i+".varArgAdvance;\n"; + "var arg"+i+" = argType"+i+".readValueFromPointer(args);\n" + + "args += argType"+i+".argPackAdvance;\n"; } functionBody += "var obj = new constructor("+argsList+");\n" + @@ -154,7 +154,7 @@ function craftEmvalAllocator(argCount) { function __emval_new(handle, argCount, argTypes, args) { handle = requireHandle(handle); - + var newer = __newers[argCount]; if (!newer) { newer = craftEmvalAllocator(argCount); @@ -206,8 +206,8 @@ function __emval_call(handle, argCount, argTypes, argv) { var args = new Array(argCount); for (var i = 0; i < argCount; ++i) { var type = types[i]; - args[i] = type['readValueFromVarArg'](argv); - argv += type.varArgAdvance; + args[i] = type['readValueFromPointer'](argv); + argv += type.argPackAdvance; } var rv = handle.apply(undefined, args); @@ -261,8 +261,8 @@ function __emval_get_method_caller(argCount, argTypes) { for (var i = 0; i < argCount - 1; ++i) { functionBody += - " var arg" + i + " = argType" + i + ".readValueFromVarArg(args);\n" + - " args += argType" + i + ".varArgAdvance;\n"; + " var arg" + i + " = argType" + i + ".readValueFromPointer(args);\n" + + " args += argType" + i + ".argPackAdvance;\n"; } functionBody += " var rv = handle[name](" + argsList + ");\n" + |