forked from Mirrors/wasm3
parent
14d6fa866b
commit
1580e4dc3b
@ -0,0 +1,42 @@
|
||||
@external("arduino", "millis")
|
||||
declare function millis(): u32;
|
||||
|
||||
@external("arduino", "delay")
|
||||
declare function delay(ms: u32): void;
|
||||
|
||||
@external("arduino", "pinMode")
|
||||
declare function pinMode(pin: u32, mode: u32): void;
|
||||
|
||||
@external("arduino", "digitalWrite")
|
||||
declare function digitalWrite(pin: u32, value: u32): void;
|
||||
|
||||
@external("arduino", "getPinLED")
|
||||
declare function getPinLED(): u32;
|
||||
|
||||
const LOW: u32 = 0;
|
||||
const HIGH: u32 = 1;
|
||||
|
||||
const INPUT: u32 = 0x0;
|
||||
const OUTPUT: u32 = 0x1;
|
||||
const INPUT_PULLUP: u32 = 0x2;
|
||||
|
||||
const LED: u32 = 19;
|
||||
|
||||
function setup(): void {
|
||||
pinMode(LED, OUTPUT);
|
||||
}
|
||||
|
||||
function run(): void {
|
||||
digitalWrite(LED, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(LED, LOW);
|
||||
delay(900);
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry point
|
||||
*/
|
||||
export function _start(): void {
|
||||
setup();
|
||||
while (1) run();
|
||||
}
|
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
unsigned char app_wasm[] = {
|
||||
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x03, 0x60,
|
||||
0x02, 0x7f, 0x7f, 0x00, 0x60, 0x00, 0x00, 0x60, 0x01, 0x7f, 0x00, 0x02,
|
||||
0x3a, 0x03, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x07, 0x70,
|
||||
0x69, 0x6e, 0x4d, 0x6f, 0x64, 0x65, 0x00, 0x00, 0x07, 0x61, 0x72, 0x64,
|
||||
0x75, 0x69, 0x6e, 0x6f, 0x0c, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c,
|
||||
0x57, 0x72, 0x69, 0x74, 0x65, 0x00, 0x00, 0x07, 0x61, 0x72, 0x64, 0x75,
|
||||
0x69, 0x6e, 0x6f, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x00, 0x02, 0x03,
|
||||
0x02, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x00, 0x07, 0x13, 0x02, 0x06,
|
||||
0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x06, 0x5f, 0x73, 0x74,
|
||||
0x61, 0x72, 0x74, 0x00, 0x03, 0x0a, 0x27, 0x01, 0x25, 0x00, 0x41, 0x13,
|
||||
0x41, 0x01, 0x10, 0x00, 0x03, 0x40, 0x41, 0x13, 0x41, 0x01, 0x10, 0x01,
|
||||
0x41, 0xe4, 0x00, 0x10, 0x02, 0x41, 0x13, 0x41, 0x00, 0x10, 0x01, 0x41,
|
||||
0x84, 0x07, 0x10, 0x02, 0x0c, 0x00, 0x00, 0x0b, 0x00, 0x0b
|
||||
};
|
||||
unsigned int app_wasm_len = 154;
|
@ -0,0 +1,12 @@
|
||||
# Compile
|
||||
npx asc app.ts -b app.wasm \
|
||||
-O3z \
|
||||
--runtime half \
|
||||
--noAssert \
|
||||
--use abort=
|
||||
|
||||
# Convert to WAT
|
||||
#wasm2wat app.wasm -o app.wat
|
||||
|
||||
# Convert to C header
|
||||
xxd -i app.wasm > app.wasm.h
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "npm run asbuild:optimized && xxd -i app.wasm > app.wasm.h",
|
||||
"asbuild:optimized": "npx asc app.ts -b app.wasm -O3z --runtime half --noAssert --use abort="
|
||||
},
|
||||
"devDependencies": {
|
||||
"assemblyscript": "^0.8.1-nightly.20200119"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./node_modules/assemblyscript/std/assembly.json",
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
assemblyscript@^0.8.1-nightly.20200119:
|
||||
version "0.8.1-nightly.20200119"
|
||||
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.8.1-nightly.20200119.tgz#8b62ce969a3e00e2fe7108802b25d17425723a2f"
|
||||
integrity sha512-KxIM7zmTz67Fo0Tjz0uUKcGXXZ9JS8upkvrChoe2bnVlYPWrGufKFCpGgGivClhOX2u49KvF99tAdQBKK2h3/A==
|
||||
dependencies:
|
||||
binaryen "90.0.0-nightly.20200101"
|
||||
long "^4.0.0"
|
||||
|
||||
binaryen@90.0.0-nightly.20200101:
|
||||
version "90.0.0-nightly.20200101"
|
||||
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-90.0.0-nightly.20200101.tgz#75fb065e4a2dd88852c2872085e05eee0883106c"
|
||||
integrity sha512-64lgruunUnkJD4YVD0DLCSRskqfo3xhoErM1H22GfkkWNT16/7tPTLG+MYqKLMALTiIyLL6L9UqmDaxOxDv0rw==
|
||||
|
||||
long@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
|
||||
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==
|
Loading…
Reference in new issue