aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <caustin@gmail.com>2014-03-24 01:22:46 -0700
committerChad Austin <chad@chadaustin.me>2014-03-28 23:56:41 -0700
commit6e9b2e3c06eb9f98ecd5ed2dadc4dcce833b8343 (patch)
tree0cd10e3b848042c81b61c2a935a0af520185f8c9 /src
parentfa3e4f460a86ee2e0212fe2471690f67b9b4280c (diff)
Rename readValueFromPointer to readValueFromVarArg to make its sometimes odd behavior a little clearer
Diffstat (limited to 'src')
-rw-r--r--src/embind/embind.js80
-rw-r--r--src/embind/emval.js10
2 files changed, 19 insertions, 71 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 1fb9403f..f2e70a0c 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -298,7 +298,7 @@ function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
return o ? trueValue : falseValue;
},
'varArgAdvance': 8,
- 'readValueFromPointer': function(pointer) {
+ 'readValueFromVarArg': function(pointer) {
// TODO: if heap is fixed (like in asm.js) this could be executed outside
var heap;
if (size === 1) {
@@ -312,20 +312,6 @@ function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
}
return this['fromWireType'](heap[pointer >> shift]);
},
- writeValueToPointer: function(value, pointer, _destructors) {
- // TODO: if heap is fixed (like in asm.js) this could be executed outside
- var heap;
- if (size === 1) {
- heap = HEAP8;
- } else if (size === 2) {
- heap = HEAP16;
- } else if (size === 4) {
- heap = HEAP32;
- } else {
- throw new TypeError("Unknown boolean type size: " + name);
- }
- heap[pointer >> shift] = this['toWireType'](_destructors, value);
- },
destructorFunction: null, // This type does not need a destructor
});
}
@@ -345,6 +331,8 @@ function getShiftFromSize(size) {
}
function integerReadValueFromPointer(shift, signed) {
+ // TODO: varargs always promote integer arguments to int... could
+ // that break this code?
if (shift === 0) {
return function(pointer) {
var heap = signed ? HEAP8 : HEAPU8;
@@ -365,27 +353,6 @@ function integerReadValueFromPointer(shift, signed) {
}
}
-function integerWriteValueToPointer(shift, signed) {
- if (shift === 0) {
- return function(value, pointer, _destructors) {
- var heap = signed ? HEAP8 : HEAPU8;
- heap[pointer] = this['toWireType'](_destructors, value);
- };
- } else if (shift === 1) {
- return function(value, pointer, _destructors) {
- var heap = signed ? HEAP16 : HEAPU16;
- heap[pointer >> 1] = this['toWireType'](_destructors, value);
- };
- } else if (shift === 2) {
- return function(value, pointer, _destructors) {
- var heap = signed ? HEAP32 : HEAPU32;
- heap[pointer >> 2] = this['toWireType'](_destructors, value);
- };
- } else {
- throw new TypeError("Unknown integer 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) {
@@ -413,8 +380,7 @@ function __embind_register_integer(primitiveType, name, size, minRange, maxRange
return value | 0;
},
'varArgAdvance': 8,
- 'readValueFromPointer': integerReadValueFromPointer(shift, minRange !== 0),
- writeValueToPointer: integerWriteValueToPointer(shift, minRange !== 0),
+ 'readValueFromVarArg': integerReadValueFromPointer(shift, minRange !== 0),
destructorFunction: null, // This type does not need a destructor
});
}
@@ -436,16 +402,10 @@ function __embind_register_float(rawType, name, size) {
return value;
},
'varArgAdvance': 8,
- 'readValueFromPointer': function(pointer) {
- // TODO: rename readValueFromPointer to
- // readValueFromVarArg in clang/emscripten, it appears
- // floats are passed in varargs via HEAPF64
+ 'readValueFromVarArg': function(pointer) {
+ // vararg floats always promote to double
return this['fromWireType'](HEAPF64[pointer >> 3]);
},
- writeValueToPointer: function(value, pointer, _destructors) {
- var heap = (shift === 2) ? HEAPF32 : HEAPF64;
- heap[pointer >> shift] = this['toWireType'](_destructors, value);
- },
destructorFunction: null, // This type does not need a destructor
});
}
@@ -454,10 +414,6 @@ function __embind_register_float(rawType, name, size) {
function simpleReadValueFromPointer(pointer) {
return this['fromWireType'](HEAPU32[pointer >> 2]);
}
-function simpleWriteValueToPointer(value, pointer, destructors) {
- var wt = this['toWireType'](destructors, value);
- HEAPU32[pointer >> 2] = wt;
-}
function __embind_register_std_string(rawType, name) {
name = readLatin1String(name);
@@ -512,8 +468,7 @@ function __embind_register_std_string(rawType, name) {
return ptr;
},
'varArgAdvance': 8,
- 'readValueFromPointer': simpleReadValueFromPointer,
- writeValueToPointer: simpleWriteValueToPointer,
+ 'readValueFromVarArg': simpleReadValueFromPointer,
destructorFunction: function(ptr) { _free(ptr); },
});
}
@@ -555,8 +510,7 @@ function __embind_register_std_wstring(rawType, charSize, name) {
return ptr;
},
'varArgAdvance': 8,
- 'readValueFromPointer': simpleReadValueFromPointer,
- writeValueToPointer: simpleWriteValueToPointer,
+ 'readValueFromVarArg': simpleReadValueFromPointer,
destructorFunction: function(ptr) { _free(ptr); },
});
}
@@ -574,8 +528,7 @@ function __embind_register_emval(rawType, name) {
return __emval_register(value);
},
'varArgAdvance': 8,
- 'readValueFromPointer': simpleReadValueFromPointer,
- writeValueToPointer: simpleWriteValueToPointer,
+ 'readValueFromVarArg': simpleReadValueFromPointer,
destructorFunction: null, // This type does not need a destructor
});
}
@@ -603,7 +556,7 @@ function __embind_register_memory_view(rawType, name) {
return new TA(HEAP8.buffer, data, size);
},
'varArgAdvance': 16,
- 'readValueFromPointer': function(ptr) {
+ 'readValueFromVarArg': function(ptr) {
return this['fromWireType'](ptr);
},
});
@@ -849,8 +802,7 @@ function __embind_finalize_value_array(rawTupleType) {
return ptr;
},
'varArgAdvance': 8,
- 'readValueFromPointer': simpleReadValueFromPointer,
- writeValueToPointer: simpleWriteValueToPointer,
+ 'readValueFromVarArg': simpleReadValueFromPointer,
destructorFunction: rawDestructor,
}];
});
@@ -953,8 +905,7 @@ function __embind_finalize_value_object(structType) {
return ptr;
},
'varArgAdvance': 8,
- 'readValueFromPointer': simpleReadValueFromPointer,
- writeValueToPointer: simpleWriteValueToPointer,
+ 'readValueFromVarArg': simpleReadValueFromPointer,
destructorFunction: rawDestructor,
}];
});
@@ -1140,9 +1091,7 @@ RegisteredPointer.prototype.destructor = function(ptr) {
};
RegisteredPointer.prototype['varArgAdvance'] = 8;
-RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer;
-
-RegisteredPointer.prototype.writeValueToPointer = simpleWriteValueToPointer;
+RegisteredPointer.prototype['readValueFromVarArg'] = simpleReadValueFromPointer;
RegisteredPointer.prototype['fromWireType'] = function(ptr) {
// ptr is a raw pointer (or a raw smartpointer)
@@ -1789,8 +1738,7 @@ function __embind_register_enum(
return c.value;
},
'varArgAdvance': 8,
- 'readValueFromPointer': integerReadValueFromPointer(shift, isSigned),
- writeValueToPointer: integerWriteValueToPointer(shift, isSigned),
+ 'readValueFromVarArg': integerReadValueFromPointer(shift, isSigned),
destructorFunction: null,
});
exposePublicSymbol(name, constructor);
diff --git a/src/embind/emval.js b/src/embind/emval.js
index 3dfe0f00..0fe6404e 100644
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -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.readValueFromPointer(args);
+ var arg0 = argType0.readValueFromVarArg(args);
var argType1 = requireRegisteredType(HEAP32[(argTypes >> 2) + 1], "parameter 1");
- var arg1 = argType1.readValueFromPointer(args + 8);
+ var arg1 = argType1.readValueFromVarArg(args + 8);
var argType2 = requireRegisteredType(HEAP32[(argTypes >> 2) + 2], "parameter 2");
- var arg2 = argType2.readValueFromPointer(args + 16);
+ var arg2 = argType2.readValueFromVarArg(args + 16);
var obj = new constructor(arg0, arg1, arg2);
return __emval_register(obj);
} */
@@ -139,7 +139,7 @@ function craftEmvalAllocator(argCount) {
for(var i = 0; i < argCount; ++i) {
functionBody +=
"var argType"+i+" = requireRegisteredType(HEAP32[(argTypes >> 2) + "+i+"], \"parameter "+i+"\");\n" +
- "var arg"+i+" = argType"+i+".readValueFromPointer(args);\n" +
+ "var arg"+i+" = argType"+i+".readValueFromVarArg(args);\n" +
"args += argType"+i+".varArgAdvance;\n";
}
functionBody +=
@@ -259,7 +259,7 @@ function __emval_get_method_caller(argCount, argTypes) {
for (var i = 0; i < argCount - 1; ++i) {
functionBody +=
- " var arg" + i + " = argType" + i + ".readValueFromPointer(args);\n" +
+ " var arg" + i + " = argType" + i + ".readValueFromVarArg(args);\n" +
" args += argType" + i + ".varArgAdvance;\n";
}
functionBody +=