Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bf5361
commit fab592c
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type name_pool = { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import spidermonkey::jsapi::{JSContext, jsval}; | ||
|
||
impl methods<T: copy> for *T { | ||
unsafe fn +(idx: uint) -> *T { | ||
ptr::offset(self, idx) | ||
} | ||
unsafe fn [](idx: uint) -> T { | ||
*(self + idx) | ||
} | ||
} | ||
|
||
const JSVAL_VOID: u64 = 0x0001fff2_00000000_u64; | ||
const JSVAL_NULL: u64 = 0x0001fff6_00000000_u64; | ||
const JSVAL_ZERO: u64 = 0x0001fff1_00000000_u64; | ||
const JSVAL_ONE: u64 = 0x0001fff1_00000001_u64; | ||
const JSVAL_FALSE: u64 = 0x0001fff3_00000000_u64; | ||
const JSVAL_TRUE: u64 = 0x0001fff3_00000001_u64; | ||
|
||
unsafe fn JS_ARGV(_cx: *JSContext, vp: *jsval) -> *jsval { | ||
vp + 2u | ||
} | ||
|
||
unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *jsval, v: jsval) { | ||
let vp: *mut jsval = unsafe::reinterpret_cast(vp); | ||
*vp = v; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import libc::c_char; | ||
|
||
type name_pool = @{ | ||
mut strbufs: [str] | ||
}; | ||
|
||
fn name_pool() -> name_pool { | ||
@{mut strbufs: []} | ||
} | ||
|
||
impl methods for name_pool { | ||
fn add(-s: str) -> *c_char { | ||
let c_str = str::as_c_str(s) { |bytes| bytes }; | ||
self.strbufs += [s]; // in theory, this should *move* the str in here.. | ||
ret c_str; // ...and so this ptr ought to be valid. | ||
} | ||
} |