Permalink
Browse files

Eliminate Rust/C stub function overhead.

  • Loading branch information...
1 parent 1dbbc2e commit 71078d8f423474991ff441647dd101a7e690535b @jdm jdm committed Aug 24, 2012
Showing with 60 additions and 2 deletions.
  1. +7 −1 gen.py
  2. +26 −0 glue.rs
  3. +27 −1 jsglue.c
View
8 gen.py
@@ -8,7 +8,7 @@
]
sysincludes = [
"-isystem", "/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/include",
- "-isystem", "/usr/lib/gcc/x86_64-redhat-linux/4.7.0/include"
+ "-isystem", "/usr/lib/gcc/x86_64-redhat-linux/4.7.0/include",
]
args = [
@@ -23,3 +23,9 @@
# To generate jsglue:
# DYLD_LIBRARY_PATH=~/versioned/rust-mozilla/build/llvm/x86_64-apple-darwin/Release+Asserts/lib/ ~/versioned/rust-bindgen/bindgen ./jsglue.c -I ../../build/src/mozjs/dist/include/ -match glue > glue.rs
+
+# jdm used
+# LD_LIBRARY_PATH=~/sdb/rust/build/llvm/x86_64-unknown-linux-gnu/Release+Asserts/lib/ ~/sdb/rust-bindgen/bindgen ./jsglue.c -I ../../build/src/mozjs/dist/include/ -isystem /usr/lib/gcc/x86_64-redhat-linux/4.7.0/include/ -match glue >glue.rs
+# on Fedora 17
+#
+# and remember to mark all generated functions as #[rust_stack]
View
26 glue.rs
@@ -2,14 +2,26 @@
import libc::*;
+type enum_StubType = c_uint;
+const PROPERTY_STUB: u32 = 0_u32;
+const STRICT_PROPERTY_STUB: u32 = 1_u32;
+const ENUMERATE_STUB: u32 = 2_u32;
+const CONVERT_STUB: u32 = 3_u32;
+const RESOLVE_STUB: u32 = 4_u32;
+
#[link_name="jsglue"]
extern mod bindgen {
#[rust_stack]
+fn GetJSClassHookStubPointer(++_type: enum_StubType) -> *c_void;
+
+#[rust_stack]
fn RUST_JSVAL_IS_NULL(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_IS_VOID(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_IS_INT(++v: jsval) -> JSBool;
#[rust_stack]
@@ -18,20 +30,28 @@ fn RUST_JSVAL_TO_INT(++v: jsval) -> int32_t;
#[rust_stack]
fn RUST_INT_TO_JSVAL(++v: int32_t) -> jsval;
+#[rust_stack]
fn RUST_JSVAL_IS_DOUBLE(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_TO_DOUBLE(++v: jsval) -> c_double;
+#[rust_stack]
fn RUST_DOUBLE_TO_JSVAL(++v: c_double) -> jsval;
+#[rust_stack]
fn RUST_UINT_TO_JSVAL(++v: uint32_t) -> jsval;
+#[rust_stack]
fn RUST_JSVAL_IS_NUMBER(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_IS_STRING(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_TO_STRING(++v: jsval) -> *JSString;
+#[rust_stack]
fn RUST_STRING_TO_JSVAL(++v: *JSString) -> jsval;
#[rust_stack]
@@ -43,16 +63,22 @@ fn RUST_JSVAL_TO_OBJECT(++v: jsval) -> *JSObject;
#[rust_stack]
fn RUST_OBJECT_TO_JSVAL(++v: *JSObject) -> jsval;
+#[rust_stack]
fn RUST_JSVAL_IS_BOOLEAN(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_TO_BOOLEAN(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_BOOLEAN_TO_JSVAL(++v: JSBool) -> jsval;
+#[rust_stack]
fn RUST_JSVAL_IS_PRIMITIVE(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_IS_GCTHING(++v: jsval) -> JSBool;
+#[rust_stack]
fn RUST_JSVAL_TO_GCTHING(++v: jsval) -> *c_void;
#[rust_stack]
View
@@ -1,5 +1,31 @@
#include "jsapi.h"
+enum StubType {
+ PROPERTY_STUB,
+ STRICT_PROPERTY_STUB,
+ ENUMERATE_STUB,
+ CONVERT_STUB,
+ RESOLVE_STUB,
+};
+
+void*
+GetJSClassHookStubPointer(enum StubType type)
+{
+ switch (type) {
+ case PROPERTY_STUB:
+ return JS_PropertyStub;
+ case STRICT_PROPERTY_STUB:
+ return JS_StrictPropertyStub;
+ case ENUMERATE_STUB:
+ return JS_EnumerateStub;
+ case CONVERT_STUB:
+ return JS_ConvertStub;
+ case RESOLVE_STUB:
+ return JS_ResolveStub;
+ }
+ return NULL;
+}
+
JSBool
RUST_JSVAL_IS_NULL(jsval v)
{
@@ -81,7 +107,7 @@ RUST_STRING_TO_JSVAL(JSString *v)
JSBool
RUST_JSVAL_IS_OBJECT(jsval v)
{
- return JSVAL_IS_OBJECT(v);
+ return !JSVAL_IS_PRIMITIVE(v) || JSVAL_IS_NULL(v);
}
JSObject *

0 comments on commit 71078d8

Please sign in to comment.