summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-18 16:44:09 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-19 08:29:26 -0400
commitae393879a7a03643075d559bd2773997c84c7ed0 (patch)
tree450906060b509e83c03d9c14ba92bedeaca209db /src
parentd93bd4b127c39e2f0e8d2ec3bbec3f7c118890f4 (diff)
cleanup: Move C extern code to src/binding.rs
Diffstat (limited to 'src')
-rw-r--r--src/binding.rs50
-rw-r--r--src/handlers.rs23
-rw-r--r--src/main.rs37
3 files changed, 55 insertions, 55 deletions
diff --git a/src/binding.rs b/src/binding.rs
new file mode 100644
index 000000000..62d727627
--- /dev/null
+++ b/src/binding.rs
@@ -0,0 +1,50 @@
+// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
+// All rights reserved. MIT License.
+#![allow(dead_code)]
+
+extern crate libc;
+use libc::c_char;
+use libc::c_int;
+use libc::c_void;
+use libc::uint32_t;
+
+#[repr(C)]
+pub struct DenoC {
+ _unused: [u8; 0],
+}
+
+#[repr(C)]
+pub struct deno_buf {
+ alloc_ptr: *mut u8,
+ alloc_len: usize,
+ data_ptr: *mut u8,
+ data_len: usize,
+}
+
+type DenoRecvCb = unsafe extern "C" fn(d: *const DenoC, buf: deno_buf);
+
+extern "C" {
+ pub fn deno_init();
+ pub fn deno_v8_version() -> *const c_char;
+ pub fn deno_set_flags(argc: *mut c_int, argv: *mut *mut c_char);
+ pub fn deno_new(data: *const c_void, cb: DenoRecvCb) -> *const DenoC;
+ pub fn deno_delete(d: *const DenoC);
+ pub fn deno_last_exception(d: *const DenoC) -> *const c_char;
+ pub fn deno_set_response(d: *const DenoC, buf: deno_buf);
+ pub fn deno_execute(
+ d: *const DenoC,
+ js_filename: *const c_char,
+ js_source: *const c_char,
+ ) -> c_int;
+ pub fn deno_handle_msg_from_js(d: *const DenoC, buf: deno_buf);
+ pub fn deno_reply_error(d: *const DenoC, cmd_id: uint32_t, msg: *const c_char);
+ pub fn deno_reply_null(d: *const DenoC, cmd_id: uint32_t);
+ pub fn deno_reply_code_fetch(
+ d: *const DenoC,
+ cmd_id: uint32_t,
+ module_name: *const c_char,
+ filename: *const c_char,
+ source_code: *const c_char,
+ output_code: *const c_char,
+ );
+}
diff --git a/src/handlers.rs b/src/handlers.rs
index a9221a8cb..8929d79de 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -6,7 +6,6 @@ extern crate log;
extern crate url;
use libc::c_char;
-use libc::uint32_t;
use std::ffi::CStr;
use std::ffi::CString;
use std::fs::File;
@@ -14,26 +13,8 @@ use std::io::Read;
use std::path::Path;
use url::Url;
-// TODO(ry) Share this with the def in src/main.rs.
-#[repr(C)]
-pub struct DenoC {
- _unused: [u8; 0],
-}
-
-// TODO(ry) Share this extern block with those in main.rs.
-// See src/reply.h
-extern "C" {
- pub fn deno_reply_error(d: *const DenoC, cmd_id: uint32_t, msg: *const c_char);
- pub fn deno_reply_null(d: *const DenoC, cmd_id: uint32_t);
- pub fn deno_reply_code_fetch(
- d: *const DenoC,
- cmd_id: uint32_t,
- module_name: *const c_char,
- filename: *const c_char,
- source_code: *const c_char,
- output_code: *const c_char,
- );
-}
+mod binding;
+use binding::{deno_reply_code_fetch, deno_reply_error, DenoC};
// TODO(ry) SRC_DIR is just a placeholder for future caching functionality.
static SRC_DIR: &str = "/Users/rld/.deno/src/";
diff --git a/src/main.rs b/src/main.rs
index 3af299428..e1284d303 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,45 +2,14 @@ extern crate libc;
#[macro_use]
extern crate log;
-use libc::c_char;
use libc::c_int;
-use libc::c_void;
use std::ffi::CStr;
use std::ffi::CString;
use std::ptr;
-#[repr(C)]
-struct deno_buf {
- alloc_ptr: *mut u8,
- alloc_len: usize,
- data_ptr: *mut u8,
- data_len: usize,
-}
-
-#[repr(C)]
-struct DenoC {
- _unused: [u8; 0],
-}
-
-type DenoRecvCb = unsafe extern "C" fn(d: *const DenoC, buf: deno_buf);
-
-#[link(name = "deno", kind = "static")]
-extern "C" {
- fn deno_init();
- #[allow(dead_code)]
- fn deno_v8_version() -> *const c_char;
- fn deno_set_flags(argc: *mut c_int, argv: *mut *mut c_char);
-
- fn deno_new(data: *const c_void, cb: DenoRecvCb) -> *const DenoC;
- fn deno_delete(d: *const DenoC);
- fn deno_last_exception(d: *const DenoC) -> *const c_char;
- #[allow(dead_code)]
- fn deno_set_response(d: *const DenoC, buf: deno_buf);
- fn deno_execute(d: *const DenoC, js_filename: *const c_char, js_source: *const c_char)
- -> c_int;
-
- fn deno_handle_msg_from_js(d: *const DenoC, buf: deno_buf);
-}
+mod binding;
+use binding::{deno_delete, deno_execute, deno_handle_msg_from_js, deno_init, deno_last_exception,
+ deno_new, deno_set_flags, DenoC};
// Pass the command line arguments to v8.
// Returns a vector of command line arguments that v8 did not understand.