-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on having the compiler in wasm, it compiles and loads #47
- Loading branch information
Showing
12 changed files
with
99 additions
and
2 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
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,13 @@ | ||
default-target = "wasm32-unknown-emscripten" | ||
#prepend-js = ["src/runtime.js", "src/mango/ui/webi/static/prepend-general.js"] | ||
|
||
[cargo-web] | ||
minimum-version = "0.6.0" | ||
|
||
[target.wasm32-unknown-emscripten] | ||
prepend-js = ["src/mango/ui/webi/static/prepend-general.js", "src/mango/ui/webi/static/prepend-emscripten.js"] | ||
link-args = ["-s", "USE_SDL=2", "-s", "EXPORTED_FUNCTIONS=['_compile_string']"] | ||
|
||
## You can also specify the target by its full name. | ||
#[target.wasm32-unknown-unknown] | ||
#prepend-js = "src/native_runtime.js" |
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
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
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 @@ | ||
pub fn main() { | ||
println!("welcome to Mango CLI!"); | ||
} |
File renamed without changes.
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 @@ | ||
pub mod cli; | ||
pub use self::cli::*; | ||
|
||
pub mod webi; | ||
pub use self::webi::*; |
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,21 @@ | ||
use std::ffi::CStr; | ||
use std::ffi::CString; | ||
use std::os::raw::c_char; | ||
|
||
// Convert a c-string, e.g. from javascript, into a Rust String. | ||
fn str_to_rust(external_str: *const c_char) -> String { | ||
unsafe { CStr::from_ptr(external_str).to_string_lossy().into_owned() } | ||
} | ||
|
||
// Convert a Rust string into a c-string. | ||
fn str_from_rust(internal_str: String) -> *mut c_char { | ||
CString::new(internal_str.as_str()).unwrap().into_raw() | ||
} | ||
|
||
#[no_mangle] | ||
pub fn compile_string(codechrs: *const c_char) -> *mut c_char { | ||
let code = str_to_rust(codechrs); | ||
// TODO | ||
println!("compiling {}", code); | ||
str_from_rust(code) | ||
} |
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,2 @@ | ||
pub mod compile_str; | ||
pub use self::compile_str::compile_string; |
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 @@ | ||
/** | ||
* Mango: Javascript prefix for emscripten target. | ||
*/ |
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 @@ | ||
/** | ||
* Mango: General javascript prefix. | ||
*/ |
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,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" name="viewport" /> | ||
<script> | ||
var Module = {}; | ||
var __cargo_web = {}; | ||
Object.defineProperty( Module, 'canvas', { | ||
get: function() { | ||
if( __cargo_web.canvas ) { | ||
return __cargo_web.canvas; | ||
} | ||
|
||
var canvas = document.createElement( 'canvas' ); | ||
document.querySelector( 'body' ).appendChild( canvas ); | ||
__cargo_web.canvas = canvas; | ||
|
||
return canvas; | ||
} | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<script src="mango.js"></script> | ||
<script> | ||
|
||
</script> | ||
</body> | ||
</html> |