Embedded Languages Footprint
One of my personal project has a requirement to have scripting support, and while the research of the options is still in progress, I’d like to share my preliminary results. The initial requirements for the scripting language were having the smallest footprint, but good functionality. That has given a start to the Embedded Languages Footprint project. The requirements are quite specific though (please see below), hence the most popular languages like Lua and Python are not considered suitable, but were included for the reference. For now, the most promising languages are Chibi-Scheme and Wasm3, but it’s still on-going research and final choice will be made later.
The major requirements:
-
C/C++ only (to ensure the best portability);
-
No extra compilation dependencies (to build with the bare devkits);
-
Actively maintained (to compile without its source code changes);
-
Strong typing (to reduce the number of possible errors);
-
Permissive license for both open source and commercial projects;
Additional requirement is ability to transform source code:
-
Bytecode is acceptable if its format is open and standardized;
-
One transformation is clean up the code from debug and unused functionality;
-
Another transformation is minifying private symbols;
-
Another optional transformation is removing new lines to reduce the final code size a little.
The original list of all possible languages is provided by another project: Embedded scripting languages. The example scripting code is the declaration of the function that concatenates the fixed string ("Hello, ") with the output of the external function ("read" that should return "world"). Resident set size (RSS) is measured during execution of "read" function.
- Platform
-
Linux amber 5.9.8-arch1-1 #1 SMP PREEMPT Tue, 10 Nov 2020 22:44:11 +0000 x86_64 GNU/Linux
Language | ELF Size (KiB) | RSS (KiB) | Example Code |
---|---|---|---|
TinyScheme |
84 |
3212 |
|
Wasm3 |
159 |
5904 |
N/A [1] |
MicroPython |
186 |
1976 |
|
Lua |
259 |
1832 |
|
Chibi-Scheme |
259 |
3504 |
|
Squirrel |
270 |
1812 |
|
ArkScript |
443 |
1828 |
|
Gravity |
516 |
3812 |
|
Janet |
561 |
4300 |
|
ChaiScript |
1342 |
5124 |
|
AngelScript |
1878 |
4908 |
|
Python |
3564 |
9460 |
|
[1] Wasm3 runs WebAssembly, therefore there is no reason to show the exact input as it would be the binary content. However, please see below the source code example that’s compiled into that binary.
_m3
-wrappers to exchange blobs with host)#[no_mangle]
pub fn r#fn() -> i32 {
let read_str = load_m3(unsafe { read() });
return store_m3(&format!("Hello, {}", read_str));
}
All the details are provided on the project page, however I’d like to share my personal opinion regarding few languages:
-
TinyScheme supports only subset of R5RS, used in Gimp. Chibi-Scheme supports full and newer R7RS, therefore looks much more promising.
-
ChaiScript is quite interesting, easy to embed and supported by major companies. However, it’s quite slow to compile and has a large footprint.
-
Gravity could be interested to people who like Swift as it has the similar syntax. It’s definitely interesting language, but it doesn’t have much documentation yet.
-
Squirrel is quite small, but I can’t say it’s very easy to embed and debug.
-
MicroPython is not so friendly to the embedding as it assumes its own
main
function. To properly embed it, one would need to write quite large Makefiles, and the lack of documentation regarding embedding doesn’t help too. -
Wasm3 is compact, but require external compiler to generate WASM-files. It could be acceptable for some products though.
Chibi-Scheme has quite good library, plus additional modules (including community-driven). I’d say that the only reason I’m still in doubt is that it’s quite slow for my needs, and doesn’t have all features I’d like to have. However, it’s definitely strong candidate for the embedding, and I’d definitely recommend you to take a look to it for your future projects.
Comments
Post a Comment