Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Dukboot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
dukboot
Dukboot
Commits
a6f2373c
Unverified
Commit
a6f2373c
authored
May 17, 2017
by
Will Hilton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Launch 2 JS threads per native thread AND hide global Duktape object from 2nd thread.
parent
b342c88a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
2 deletions
+75
-2
example.js
example.js
+11
-0
src/app_stash_global_string.c
src/app_stash_global_string.c
+6
-0
src/app_unstash_global_string.c
src/app_unstash_global_string.c
+6
-0
src/main.c
src/main.c
+50
-0
test.sh
test.sh
+2
-2
No files found.
example.js
View file @
a6f2373c
...
...
@@ -2,6 +2,17 @@ function (args) {
var
env
=
args
.
environ
;
var
argv
=
args
.
argv
;
var
modules
=
args
.
modules
;
if
(
typeof
global
===
'
undefined
'
)
{
(
function
()
{
var
global
=
new
Function
(
'
return this;
'
)();
Object
.
defineProperty
(
global
,
'
global
'
,
{
value
:
global
,
writable
:
true
,
enumerable
:
false
,
configurable
:
true
});
})();
}
var
result
=
modules
.
dir
(
'
./src
'
);
result
.
sort
();
modules
.
print
(
JSON
.
stringify
(
result
));
...
...
src/app_stash_global_string.c
0 → 100644
View file @
a6f2373c
void
app_stash_global_string
(
duk_context
*
ctx
,
char
*
name
)
{
duk_push_global_stash
(
ctx
);
// summon the magic stash object
duk_get_global_string
(
ctx
,
name
);
duk_put_prop_string
(
ctx
,
-
2
,
name
);
// save as property on magic stash object
duk_pop
(
ctx
);
// Disappear the stash
}
src/app_unstash_global_string.c
0 → 100644
View file @
a6f2373c
void
app_unstash_global_string
(
duk_context
*
ctx
,
char
*
name
)
{
duk_push_global_stash
(
ctx
);
// summon the magic stash object
// TODO: Throw an error if property not found. (Right now just returns undefined)
duk_get_prop_string
(
ctx
,
-
1
,
name
);
// retrieve property
duk_remove
(
ctx
,
-
2
);
// Disappear the stash
}
src/main.c
View file @
a6f2373c
...
...
@@ -18,6 +18,8 @@ extern char **environ;
#include "app_push_dir.c"
#include "native_print.c"
#include "native_import.c"
#include "app_stash_global_string.c"
#include "app_unstash_global_string.c"
int
main
(
int
argc
,
char
*
argv
[]
/* char *environ[] */
)
{
// Re-open stdin and stdout in binary mode
...
...
@@ -35,11 +37,21 @@ int main(int argc, char *argv[] /* char *environ[] */) {
exit
(
0
);
}
// Fork into native (gcc) threads.
duk_int_t
result
;
#pragma omp parallel
{
// Create a JS environment
duk_context
*
ctx
=
duk_create_heap_default
();
// Save a copy of the Duktape object...
app_stash_global_string
(
ctx
,
"Duktape"
);
// ...then make it inaccessible to JS code.
duk_push_undefined
(
ctx
);
duk_put_global_string
(
ctx
,
"Duktape"
);
// Creat a 2nd JS thread (yes, it's possible in Duktape!)
duk_push_thread
(
ctx
);
// TODO: Use duk_push_thread_new_globalenv for modules?
duk_context
*
ctx2
=
duk_get_context
(
ctx
,
-
1
);
// Load top-level function module
duk_int_t
ret
=
native_import
(
ctx
,
argv
[
1
]);
...
...
@@ -62,6 +74,8 @@ int main(int argc, char *argv[] /* char *environ[] */) {
duk_put_prop_string
(
ctx
,
-
2
,
"dir"
);
duk_push_c_function
(
ctx
,
native_print
,
DUK_VARARGS
);
duk_put_prop_string
(
ctx
,
-
2
,
"print"
);
app_unstash_global_string
(
ctx
,
"Duktape"
);
// summon from the magic stash
duk_put_prop_string
(
ctx
,
-
2
,
"Duktape"
);
duk_put_prop_string
(
ctx
,
-
2
,
"modules"
);
// Run top-level module, passing the god arg as the sole argument.
...
...
@@ -75,6 +89,42 @@ int main(int argc, char *argv[] /* char *environ[] */) {
// printf("%s\n", duk_to_string(ctx, -1));
// }
// Load top-level function module
ret
=
native_import
(
ctx2
,
argv
[
1
]);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx2
,
-
1
));
goto
finally
;
}
// Construct the all-powerful god argument
duk_push_object
(
ctx2
);
// Create argv object
app_push_argv
(
ctx2
,
argc
,
argv
);
duk_put_prop_string
(
ctx2
,
-
2
,
"argv"
);
// Create environment variables object
app_push_environ
(
ctx2
);
duk_put_prop_string
(
ctx2
,
-
2
,
"environ"
);
// Provide access to native functions
duk_push_object
(
ctx2
);
duk_push_c_function
(
ctx2
,
app_push_dir
,
1
);
duk_put_prop_string
(
ctx2
,
-
2
,
"dir"
);
duk_push_c_function
(
ctx2
,
native_print
,
DUK_VARARGS
);
duk_put_prop_string
(
ctx2
,
-
2
,
"print"
);
duk_get_global_string
(
ctx2
,
"Duktape"
);
duk_put_prop_string
(
ctx2
,
-
2
,
"Duktape"
);
duk_put_prop_string
(
ctx2
,
-
2
,
"modules"
);
// Run top-level module, passing the god arg as the sole argument.
ret
=
duk_pcall
(
ctx2
,
1
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx2
,
-
1
));
goto
finally
;
}
// else {
// duk_push_context_dump(ctx);
// printf("%s\n", duk_to_string(ctx, -1));
// }
finally:
duk_destroy_heap
(
ctx
);
#pragma omp critical
...
...
test.sh
View file @
a6f2373c
...
...
@@ -2,9 +2,9 @@
DUKBOOTS
=
"
${
1
:-
./dukboots
}
"
NUM_CORES
=
"
$(
grep
-c
^processor /proc/cpuinfo
)
"
echo
"
$NUM_CORES
cores"
EXPECT_ONE
=
'[".","..","app_push_argv.c","app_push_dir.c","app_push_environ.c","main.c","native_import.c","native_print.c"]'
EXPECT_ONE
=
'[".","..","app_push_argv.c","app_push_dir.c","app_push_environ.c","
app_stash_global_string.c","app_unstash_global_string.c","
main.c","native_import.c","native_print.c"]'
EXPECT
=
"
$EXPECT_ONE
"
for
n
in
$(
seq
2
$
NUM_CORES
)
;
do
for
n
in
$(
seq
2
$
((
NUM_CORES
*
2
))
)
;
do
EXPECT
=
"
$EXPECT
$EXPECT_ONE
"
done
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment