-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP a prototype crate design for ops #3025
Closed
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
282b175
prototype op_hello
ry 404892c
WIP
ry 2c203d7
wip
ry ce4ae67
wip
ry 834a2b9
x
ry 775f56a
x
ry e9e0e80
Maybe we can use split file namespaces
ry 21aa00a
elegant url
ry d8c20c0
x
ry 607aeae
Add op_hello_js
ry f6f169d
simplify
ry b04616a
adjust
ry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@ | ||
[package] | ||
name = "op_hello" | ||
version = "0.1.0" | ||
authors = ["Ryan Dahl <ry@tinyclouds.org>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
deno = "0.19.0" | ||
deno_std = "0.19.0" # TODO deno_std is not yet published as crate | ||
|
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,5 @@ | ||
const OP_HELLO = Deno.ops.add("hello"); | ||
|
||
export function hello() { | ||
Deno.send(OP_HELLO); | ||
} |
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,19 @@ | ||
// TODO We need some way to import test modules. | ||
// Attempt one: | ||
// | ||
// import { test } from "../../js/test_util.ts"; | ||
// | ||
// Here it is referencing files across crate boundaries, which will break | ||
// 'cargo package' and means the crate is not useable outside the deno tree. | ||
// This might be okay for a first pass, but it's not the best solution. | ||
// | ||
// Attempt two: | ||
// we invent a new URL for referencing files in other crates. | ||
// this is magic and not browser compatible.. Browser compatibility for | ||
// ops is not so important. | ||
import { test } from "crate://deno_std@0.19.0/testing/mod.ts"; | ||
import { hello } from "./hello.ts"; | ||
|
||
test("hello test", () => { | ||
hello(); | ||
}); |
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,30 @@ | ||
extern crate deno; | ||
use deno::*; | ||
|
||
pub fn init(&mut isolate: Isolate) -> Result<(), ErrBox> { | ||
isolate.register_op("hello", op_hello); | ||
|
||
// TODO Somehow define register_deno_global | ||
isolate.register_deno_global("src/hello.ts", "hello") | ||
} | ||
|
||
fn op_hello(_control_buf: &[u8], _zero_copy_buf: Option<PinnedBuf>) -> CoreOp { | ||
println!("Hello world"); | ||
CoreOp::Sync(Box::new([])) | ||
} | ||
|
||
#[test] | ||
fn hello_rust() { | ||
match op_hello() { | ||
CoreOp::Sync(buf) => { | ||
assert_eq!(buf.len(), 0); | ||
} | ||
CoreOp::Async(_) => unreachable!(), | ||
} | ||
} | ||
|
||
#[test] | ||
fn hello_js() { | ||
// TODO need to define run_js_test somehow... | ||
run_js_test("src/hello_test.ts"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afinch7 is this along the lines of what you were thinking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. It's very nice that all the relevant info is encoded into standard elements of the url structure. No need to design fancy parsing.