12 Commits

Author SHA1 Message Date
BjoernSchilberg
dc88d74e42 Merge 937ccf60c9 into dbeb242fb2 2023-03-21 23:43:36 -04:00
dbeb242fb2 add support for br_table instruction when packing cart 2023-03-20 23:08:42 +01:00
BjoernSchilberg
937ccf60c9 Added a tinygo example. 2023-02-12 22:24:16 +01:00
4fe4bce0ad token env var has changed 2023-01-31 00:14:25 +01:00
fe86153562 use fixed version of zola-deploy-action 2023-01-31 00:01:07 +01:00
c9dadaca2e try add safe.directory 2023-01-30 09:48:57 +01:00
5dc3e281ce and again 2023-01-30 09:45:28 +01:00
ce3afb821f another attempt changing the owner to fix permission issue 2023-01-30 09:43:54 +01:00
2652a351ad remove chown again 2023-01-30 09:38:57 +01:00
9109722409 fix main.yml 2023-01-30 09:37:12 +01:00
f861c262a1 update ci actions, hopefully fix permission error 2023-01-30 09:15:09 +01:00
bbfb5eba49 add back event debouncing in file watcher 2023-01-30 00:09:25 +01:00
10 changed files with 119 additions and 28 deletions

View File

@@ -30,9 +30,9 @@ jobs:
run: sudo apt-get install -y libxkbcommon-dev libasound2-dev
if: matrix.os == 'ubuntu-latest'
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Cache build dirs
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
@@ -44,7 +44,7 @@ jobs:
- name: Build
run: cargo build --release --verbose
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: uw8-${{ matrix.build }}
path: target/release/${{ matrix.exe }}

View File

@@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: build_and_deploy
uses: shalzz/zola-deploy-action@v0.14.1
uses: shalzz/zola-deploy-action@70a101a14bbdeed13e7a42a9ed06b35c9e9e826e
env:
# Target branch
PAGES_BRANCH: gh-pages
BUILD_DIR: site
# Provide personal access token
TOKEN: $GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

13
Cargo.lock generated
View File

@@ -2069,6 +2069,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "notify-debouncer-mini"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e23e9fa24f094b143c1eb61f90ac6457de87be6987bc70746e0179f7dbc9007b"
dependencies = [
"notify",
]
[[package]]
name = "num-complex"
version = "0.4.3"
@@ -3374,7 +3383,7 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "uw8"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"ansi_term",
"anyhow",
@@ -3382,7 +3391,7 @@ dependencies = [
"curlywas",
"env_logger",
"log",
"notify",
"notify-debouncer-mini",
"pico-args 0.5.0",
"rubato",
"same-file",

View File

@@ -16,7 +16,7 @@ anyhow = "1"
env_logger = "0.10"
log = "0.4"
uw8-window = { path = "uw8-window", optional = true }
notify = "5"
notify-debouncer-mini = { version = "0.2.1", default-features = false }
pico-args = "0.5"
curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "0e7ea50" }
wat = "1"

6
examples/tinygo/build.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
tinygo build -o cart.wasm -target target.json ./main.go
uw8 filter-exports cart.wasm cart.wasm && \
#wasm-opt -Oz --fast-math --strip-producers -o cart.wasm cart.wasm && \
uw8 pack -l 9 cart.wasm cart.uw8

38
examples/tinygo/main.go Normal file
View File

@@ -0,0 +1,38 @@
package main
import (
"math"
"unsafe"
)
//go:wasm-module env
//export atan2
func atan2(x, y float32) float32
//go:wasm-module env
//export time
func time() float32
func sqrt(v float32) float32 {
return float32(math.Sqrt(float64(v)))
}
var FRAMEBUFFER = (*[320 * 240]byte)(unsafe.Pointer(uintptr(120)))
//export upd
func upd() {
var i int
for i < 320*240 {
t := time() * 63.0
x := float32(i%320 - 160)
y := float32(i/320 - 120)
d := float32(40000.0) / sqrt(x*x+y*y)
u := atan2(x, y) * 512.0 / 3.141
c := uint8((int(d+t*2.0) ^ int(u+t)) >> 4)
FRAMEBUFFER[i] = c
i++
}
}
func main() {
}

View File

@@ -0,0 +1,23 @@
{
"llvm-target": "wasm32--wasi",
"build-tags": [ "tinygo.wasm" ],
"goos": "js",
"goarch": "wasm",
"linker": "wasm-ld",
"libc": "wasi-libc",
"cflags": [
"--target=wasm32--wasi",
"--sysroot={root}/lib/wasi-libc/sysroot",
"-Oz"
],
"ldflags": [
"--no-entry",
"--export-all",
"--import-memory",
"--initial-memory=262144",
"--global-base=81920",
"-zstack-size=4096",
"--strip-all"
],
"wasm-abi": "js"
}

View File

@@ -1,23 +1,35 @@
use anyhow::{anyhow, bail, Result};
use notify::{Event, EventKind, RecommendedWatcher, Watcher};
use std::{collections::BTreeSet, path::PathBuf, sync::mpsc};
use notify_debouncer_mini::{
new_debouncer,
notify::{self, RecommendedWatcher},
DebouncedEvent, DebouncedEventKind, Debouncer,
};
use std::{collections::BTreeSet, path::PathBuf, sync::mpsc, time::Duration};
pub struct FileWatcher {
watcher: RecommendedWatcher,
debouncer: Debouncer<RecommendedWatcher>,
watched_files: BTreeSet<PathBuf>,
directories: BTreeSet<PathBuf>,
rx: mpsc::Receiver<Event>,
rx: mpsc::Receiver<DebouncedEvent>,
}
impl FileWatcher {
pub fn new() -> Result<FileWatcher> {
let (tx, rx) = mpsc::channel();
let watcher = notify::recommended_watcher(move |res| match res {
Ok(event) => _ = tx.send(event),
Err(err) => eprintln!("Error watching for file changes: {err}"),
let debouncer = new_debouncer(Duration::from_millis(100), None, move |res| match res {
Ok(events) => {
for event in events {
let _ = tx.send(event);
}
}
Err(errs) => {
for err in errs {
eprintln!("Error watching for file changes: {err}");
}
}
})?;
Ok(FileWatcher {
watcher,
debouncer,
watched_files: BTreeSet::new(),
directories: BTreeSet::new(),
rx,
@@ -29,7 +41,8 @@ impl FileWatcher {
let parent = path.parent().ok_or_else(|| anyhow!("File has no parent"))?;
if !self.directories.contains(parent) {
self.watcher
self.debouncer
.watcher()
.watch(parent, notify::RecursiveMode::NonRecursive)?;
self.directories.insert(parent.to_path_buf());
}
@@ -41,13 +54,11 @@ impl FileWatcher {
pub fn poll_changed_file(&self) -> Result<Option<PathBuf>> {
match self.rx.try_recv() {
Ok(event) => match event.kind {
EventKind::Create(_) | EventKind::Modify(_) => {
for path in event.paths {
let handle = same_file::Handle::from_path(&path)?;
for file in &self.watched_files {
if handle == same_file::Handle::from_path(file)? {
return Ok(Some(path));
}
DebouncedEventKind::Any => {
let handle = same_file::Handle::from_path(&event.path)?;
for file in &self.watched_files {
if handle == same_file::Handle::from_path(file)? {
return Ok(Some(event.path));
}
}
}

View File

@@ -2,17 +2,18 @@ import "env.memory" memory(4);
import "env.pow" fn pow(f32, f32) -> f32;
import "env.sin" fn sin(f32) -> f32;
import "env.cls" fn cls(i32);
import "env.exp" fn exp(f32) -> f32;
import "env.rectangle" fn rectangle(f32, f32, f32, f32, i32);
include "../platform/src/ges.cwa"
export fn snd(t: i32) -> f32 {
gesSnd(t)
sndGes(t)
}
export fn upd() {
80?0 = 32!32 / 200 & 2 | 0x41;
80?3 = (32!32 / 400)%7*12/7 + 40;
80?3 = (32!32 / 400)%8*12/7 + 40;
let pulse = (32!32 * 256 / 2000) & 511;
if pulse >= 256 {
pulse = 511 - pulse;

View File

@@ -767,7 +767,10 @@ fn remap_function(
De::End => En::End,
De::Br { relative_depth } => En::Br(relative_depth),
De::BrIf { relative_depth } => En::BrIf(relative_depth),
De::BrTable { .. } => todo!(),
De::BrTable { targets } => En::BrTable(
targets.targets().collect::<Result<Vec<u32>, _>>()?.into(),
targets.default(),
),
De::Return => En::Return,
De::Call { function_index } => En::Call(
*function_map