Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
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
1d862c02
Unverified
Commit
1d862c02
authored
May 16, 2017
by
Will Hilton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add naive parallelism
parent
ed165b9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
37 deletions
+47
-37
build.sh
build.sh
+1
-0
src/main.c
src/main.c
+46
-37
No files found.
build.sh
View file @
1d862c02
...
...
@@ -7,6 +7,7 @@ WINBASH='/c/Windows/System32/bash'
# Who needs a build system? KISS
gcc
-o
$NAME
\
-Os
-pedantic
-std
=
c99
-Wall
-fstrict-aliasing
-fomit-frame-pointer
\
-fopenmp
\
-I
./lib/duktape
\
lib/duktape/duktape.c
\
src/main.c
\
...
...
src/main.c
View file @
1d862c02
...
...
@@ -4,12 +4,13 @@ extern char **environ;
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include "duktape.h"
#ifdef _WIN32
// @see [1]
#include <io.h>
#include <fcntl.h>
#endif
#include <omp.h>
#include "duktape.h"
// Include helper functions
#include "app_push_argv.c"
...
...
@@ -34,46 +35,54 @@ int main(int argc, char *argv[] /* char *environ[] */) {
exit
(
0
);
}
// Create a JS environment
duk_int_t
ret
=
0
;
duk_context
*
ctx
=
duk_create_heap_default
();
duk_int_t
result
;
#pragma omp parallel
{
// Create a JS environment
duk_context
*
ctx
=
duk_create_heap_default
();
// Load top-level function module
ret
=
native_import
(
ctx
,
argv
[
1
]);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx
,
-
1
));
goto
finally
;
}
// Load top-level function module
duk_int_t
ret
=
native_import
(
ctx
,
argv
[
1
]);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx
,
-
1
));
goto
finally
;
}
// Construct the all-powerful god argument
duk_idx_t
god_arg_idx
=
duk_push_object
(
ctx
);
ret
=
app_push_argv
(
ctx
,
argc
,
argv
);
duk_put_prop_string
(
ctx
,
god_arg_idx
,
"argv"
);
// Create environment variables object
ret
=
app_push_environ
(
ctx
);
duk_put_prop_string
(
ctx
,
god_arg_idx
,
"environ"
);
// Provide access to native functions
ret
=
duk_push_object
(
ctx
);
duk_push_c_function
(
ctx
,
app_push_dir
,
1
);
duk_put_prop_string
(
ctx
,
ret
,
"dir"
);
duk_push_c_function
(
ctx
,
native_print
,
DUK_VARARGS
);
duk_put_prop_string
(
ctx
,
ret
,
"print"
);
duk_put_prop_string
(
ctx
,
god_arg_idx
,
"modules"
);
// Construct the all-powerful god argument
duk_push_object
(
ctx
);
// Create argv object
app_push_argv
(
ctx
,
argc
,
argv
);
duk_put_prop_string
(
ctx
,
-
2
,
"argv"
);
// Create environment variables object
app_push_environ
(
ctx
);
duk_put_prop_string
(
ctx
,
-
2
,
"environ"
);
// Provide access to native functions
duk_push_object
(
ctx
);
duk_push_c_function
(
ctx
,
app_push_dir
,
1
);
duk_put_prop_string
(
ctx
,
-
2
,
"dir"
);
duk_push_c_function
(
ctx
,
native_print
,
DUK_VARARGS
);
duk_put_prop_string
(
ctx
,
-
2
,
"print"
);
duk_put_prop_string
(
ctx
,
-
2
,
"modules"
);
// Run top-level module, passing the god arg as the sole argument.
ret
=
duk_pcall
(
ctx
,
1
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx
,
-
1
));
goto
finally
;
}
// else {
// duk_push_context_dump(ctx);
// printf("%s\n", duk_to_string(ctx, -1));
// }
// Run top-level module, passing the god arg as the sole argument.
ret
=
duk_pcall
(
ctx
,
1
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx
,
-
1
));
goto
finally
;
}
// else {
// duk_push_context_dump(ctx);
// printf("%s\n", duk_to_string(ctx, -1));
// }
finally:
duk_destroy_heap
(
ctx
);
return
ret
;
finally:
duk_destroy_heap
(
ctx
);
#pragma omp critical
// For now we will OR the exit codes for each thread.
// That lets you easily check the result against multiple flags.
result
|=
ret
;
}
return
result
;
}
/**
...
...
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