Skip to content

Commit

Permalink
Improve wasm tutorial (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer authored Aug 11, 2024
1 parent 570ec64 commit efab32f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .run/spice build.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice build" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="build -O0 -d -ir -g ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice build" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="build -O3 --no-entry --target-arch=wasm32 -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="LLVM_ADDITIONAL_FLAGS" value="-lole32 -lws2_32" />
<env name="LLVM_BUILD_INCLUDE_DIR" value="$PROJECT_DIR$/../llvm-project-latest/build/include" />
Expand Down
7 changes: 2 additions & 5 deletions docs/docs/how-to/web-assembly.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Compile to WebAssembly
title: Compile for WebAssembly
---

Due to the fact, that Spice uses LLVM as compiler backbone, it is capable of cross-compiling to many different target
Expand All @@ -17,14 +17,11 @@ package. On Windows you can download MinGW64 with Clang from e.g. [winlibs.com](
For the sake of example, we write a recursive fibonacci algorithm in Spice, which we can make accessible to JavaScript.

```spice
#[core.compiler.mangle = false]
public f<int> fibo(int n) {
if n <= 1 { return n; }
return fibo(n - 1) + fibo(n - 2);
}
f<int> main() {
printf("%d", fibo(45));
}
```

You can test, if the code works by compiling and running it, using the following command: <br>
Expand Down
9 changes: 4 additions & 5 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "std/os/syscall";

f<int> main() {
string str = "Hello World!\n";
syscallWrite(FileDescriptor::STDOUT, str);
#[core.compiler.mangle = false]
public f<int> fibo(int n) {
if n <= 1 { return n; }
return fibo(n - 1) + fibo(n - 2);
}

0 comments on commit efab32f

Please sign in to comment.