8000 🐎 Threaded interpreter by tolauwae · Pull Request #261 · TOPLLab/WARDuino · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🐎 Threaded interpreter #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ core
venv

*.wasm

./platforms/Arduino/node_modules
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ if (BUILD_EMULATOR)
src/Edward/RFC.cpp
)

add_definitions(-DINFO=0)
add_definitions(-DDEBUG=0)
add_definitions(-DTRACE=0)
add_definitions(-DINFO=1)
add_definitions(-DDEBUG=1)
add_definitions(-DTRACE=1)
add_definitions(-DWARN=0)

# Set default compile flags for GCC
if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-g -v -Wall -Wextra -Wunused -O3)
endif (CMAKE_COMPILER_IS_GNUCXX)

add_compile_options(-g )
# WARDuino CLI
add_executable(wdcli platforms/CLI-Emulator/main.cpp ${SOURCE_FILES})
target_link_libraries(wdcli PRIVATE Threads::Threads)
Expand Down
6 changes: 4 additions & 2 deletions benchmarks/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ int run_benchmarks(size_t num_benchmarks, string benchmarks[],
}

int main(int argc, const char *argv[]) {
string benchmarks[] = {"tak", "fib", "fac", "gcd", "catalan", "primes"};
uint32_t expected[] = {7, 91, 82, 62882, 244, 1824};
string benchmarks[] = {"tak", "fac", "fib", "gcd", "catalan", "primes"};
uint32_t expected[] = {7, 82, 91, 62882, 244, 1824};

size_t num = (size_t)(sizeof(benchmarks) / sizeof(string *));
size_t correct = run_benchmarks(num, benchmarks, expected);

bool pass = (num == correct);
printf("SUMMARY: %s (%zu / %zu)\n", pass ? "PASS" : "FAIL", correct, num);
return pass ? 0 : 1;
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ DEBUGFLAGS = -DDEBUG=$(DEBUG) -DTRACE=$(TRACE) -DINFO=$(INFO) -DWARN=$(WARN)

CXX = g++
CC = gcc
CFLAGS = -g -Wall -c
CXXFLAGS = -g -v -std=c++11 -I ../lib/json/single_include -Wall
CFLAGS = -Wall -c O3
CXXFLAGS = -v -O3 -std=c++11 -I ../lib/json/single_include -Wall



Expand All @@ -35,11 +35,11 @@ CXXSOURCES = \
../src/WARDuino/CallbackHandler.cpp \
../src/Primitives/emulated.cpp \
../src/Interpreter/instructions.cpp \
../src/Interpreter/interpreter.cpp \
../src/Edward/RFC.cpp \
../src/Edward/proxy.cpp \
../src/Edward/proxy_supervisor.cpp \
../src/Utils/sockets.cpp \
../lib/json/single_include/nlohmann/json.hpp \
benchmarks.cpp

all: $(OUTPUTDIR)$(TARGET) $(addprefix tasks/,$(addsuffix /wast/impl.wasm, $(TASKS)))
Expand Down
2 changes: 1 addition & 1 deletion platforms/Arduino/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ compile: Arduino.ino
ifndef FQBN
$(error FQBN is not set. Use a .config file)
endif
arduino-cli compile --fqbn $(FQBN) Arduino.ino
arduino-cli compile --fqbn $(FQBN) Arduino.ino --build-property build.partitions=huge_app --build-property upload.maximum_size=3145728

recompile: clean compile

9E81 Expand Down
32 changes: 32 additions & 0 deletions platforms/Arduino/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"entries": [
"src/main.ts"
],
"targets": {
"debug": {
"debug": true,
"outFile": "blink.wasm",
"textFile": "bin/main.debug.wast"
},
"release": {
"converge": true,
"optimizeLevel": 3,
"outFile": "blink.wasm",
"shrinkLevel": 2
}
},
"options": {
"disable": [
"mutable-globals",
"sign-extension",
"nontrapping-f2i",
"bulk-memory"
],
"exportTable": true,
"exportRuntime": false,
"maximumMemory": 2,
"noAssert": false,
"runtime": "stub",
"sourceMap": true
}
}
1 change: 1 addition & 0 deletions platforms/Arduino/blink.wasm.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions platforms/Arduino/display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Blinking LED example
@external("env", "chip_pin_mode") export declare function pinMode(pin: u32, mode: u32): void;
@external("env", "chip_digital_write") export declare function digitalWrite(pin: u32, value: u32): void;
@external("env", "chip_delay") export declare function delay(ms: u32): void;


enum PinVoltage {
/** Low voltage on a digital I/O pin */
LOW = 0,
/** High voltage on a digital I/O pin */
HIGH = 1,
}


export function main(): void {
const led: u32 = 4;
const pause: u32 = 1000;
const OUTPUT: u32 = 3;

pinMode(led, OUTPUT);

while (true) {
digitalWrite(led, PinVoltage.HIGH);
delay(pause);
digitalWrite(led, PinVoltage.LOW);
delay(pause);
}
}
50 changes: 50 additions & 0 deletions platforms/Arduino/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions platforms/Arduino/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"assemblyscript": "^0.27.29"
}
}
34 changes: 34 additions & 0 deletions platforms/Arduino/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Blinking LED example
@external("env", "chip_pin_mode") export declare function pinMode(pin: u32, mode: u32): void;
@external("env", "chip_digital_write") export declare function digitalWrite(pin: u32, value: u32): void;
@external("env", "chip_delay") export declare function delay(ms: u32): void;
@external("env", "display_init") export declare function initDisplay(): void;
@external("env", "display_draw_rect") export declare function displayDrawRect(x:i32,y:i32,w:i32,h:i32): void;

enum PinVoltage {
/** Low voltage on a digital I/O pin */
LOW = 0,
/** High voltage on a digital I/O pin */
HIGH = 1,
}


export function main(): void {
const led: u32 = 4;
const pause: u32 = 1000;
const OUTPUT: u32 = 3;
let x:i32 = 0;

pinMode(led, OUTPUT);
initDisplay();


while (true) {
digitalWrite(led, PinVoltage.HIGH);
delay(pause);
digitalWrite(led, PinVoltage.LOW);
delay(pause);
displayDrawRect(x,0,150,150);
x = x+10;
}
}
Loading
Loading
0