Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
a89e8072
wa
项目概览
wa-lang
/
wa
大约 1 年 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a89e8072
编写于
11月 27, 2022
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
本地增加 arduino 模拟执行
上级
42a5c407
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
91 addition
and
38 deletion
+91
-38
Makefile
Makefile
+5
-1
arduino.wa
arduino.wa
+1
-1
internal/app/apputil/wabt_wat2wasm.go
internal/app/apputil/wabt_wat2wasm.go
+18
-2
internal/app/waruntime/arduino.go
internal/app/waruntime/arduino.go
+52
-2
internal/app/waruntime/chrome.go
internal/app/waruntime/chrome.go
+1
-1
internal/app/waruntime/walang.go
internal/app/waruntime/walang.go
+1
-1
internal/app/waruntime/wasi.go
internal/app/waruntime/wasi.go
+3
-2
internal/waroot/_waroot/src/runtime/runtime_arduino.wa
internal/waroot/_waroot/src/runtime/runtime_arduino.wa
+5
-1
internal/waroot/_waroot/src/syscall/arduino/arduino.wa
internal/waroot/_waroot/src/syscall/arduino/arduino.wa
+5
-27
未找到文件。
Makefile
浏览文件 @
a89e8072
...
...
@@ -12,8 +12,12 @@ build-wasm:
win-exe-icon
:
windres
-o
main_rc_windows.syso main.rc
arduino
:
arduino-run
:
go run main.go
-target
=
arduino arduino.wa
arduino-build
:
go run main.go build
-target
=
arduino arduino.wa
wat2wasm a.out.wat
-o
a.out.wasm
xxd
-i
a.out.wasm
>
app.wasm.h
clean
:
arduino.wa
浏览文件 @
a89e8072
...
...
@@ -6,7 +6,7 @@ var LED = arduino.GetPinLED()
fn init() {
arduino.PinMode(LED, 1)
arduino.Println("Wa is running 😎")
arduino.Println("Wa
/Arduino
is running 😎")
}
fn main() {
...
...
internal/app/apputil/wabt_wat2wasm.go
浏览文件 @
a89e8072
...
...
@@ -41,9 +41,25 @@ func RunWasm(cfg *config.Config, filename string) (stdoutStderr []byte, err erro
r
:=
wazero
.
NewRuntime
(
ctx
)
defer
r
.
Close
(
ctx
)
switch
cfg
.
WaOS
{
case
config
.
WaOS_Arduino
:
if
_
,
err
=
waruntime
.
ArduinoInstantiate
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
case
config
.
WaOS_Chrome
:
if
_
,
err
=
waruntime
.
ChromeInstantiate
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
case
config
.
WaOS_Walang
:
if
_
,
err
=
waruntime
.
WalangInstantiate
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
case
config
.
WaOS_Wasi
:
if
_
,
err
=
waruntime
.
WasiInstantiate
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
}
_
,
err
=
r
.
InstantiateModuleFromBinary
(
ctx
,
wasmBytes
)
if
err
!=
nil
{
...
...
internal/app/waruntime/arduino.go
浏览文件 @
a89e8072
...
...
@@ -4,12 +4,62 @@ package waruntime
import
(
"context"
"fmt"
"time"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/wa-lang/wa/internal/config"
)
func
ArduinoInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Module
,
error
)
{
return
rt
.
NewHostModuleBuilder
(
config
.
WaOS_Arduino
)
.
Instantiate
(
ctx
,
rt
)
func
ArduinoInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Closer
,
error
)
{
startTime
:=
time
.
Now
()
return
rt
.
NewHostModuleBuilder
(
config
.
WaOS_Arduino
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
m
api
.
Module
)
int32
{
t
:=
time
.
Now
()
.
Sub
(
startTime
)
.
Milliseconds
()
fmt
.
Printf
(
"arduino.millis(): %v
\n
"
,
t
)
return
int32
(
t
)
})
.
WithParameterNames
()
.
Export
(
"millis"
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
ms
uint32
)
{
fmt
.
Printf
(
"arduino.delay(%d)...
\n
"
,
ms
)
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
ms
))
})
.
WithParameterNames
(
"ms"
)
.
Export
(
"delay"
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
pin
,
mode
int32
)
{
if
mode
==
0
{
fmt
.
Printf
(
"arduino.pinMode(%d, %s)
\n
"
,
pin
,
"LOW"
)
}
else
{
fmt
.
Printf
(
"arduino.pinMode(%d, %s)
\n
"
,
pin
,
"HIGH"
)
}
})
.
WithParameterNames
(
"pin"
,
"mode"
)
.
Export
(
"pinMode"
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
pin
,
value
int32
)
{
fmt
.
Printf
(
"arduino.digitalWrite(%d, %d)
\n
"
,
pin
,
value
)
})
.
WithParameterNames
(
"pin"
,
"value"
)
.
Export
(
"digitalWrite"
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
)
int32
{
const
pin
=
13
fmt
.
Printf
(
"arduino.getPinLED(): %v
\n
"
,
pin
)
return
pin
})
.
WithParameterNames
()
.
Export
(
"getPinLED"
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
m
api
.
Module
,
ptr
,
len
uint32
)
{
bytes
,
_
:=
m
.
Memory
()
.
Read
(
ctx
,
ptr
,
len
)
fmt
.
Printf
(
"arduino.print(%q)
\n
"
,
string
(
bytes
))
})
.
WithParameterNames
(
"ptr"
,
"len"
)
.
Export
(
"print"
)
.
Instantiate
(
ctx
,
rt
)
}
internal/app/waruntime/chrome.go
浏览文件 @
a89e8072
...
...
@@ -10,6 +10,6 @@ import (
"github.com/wa-lang/wa/internal/config"
)
func
ChromeInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Module
,
error
)
{
func
ChromeInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Closer
,
error
)
{
return
rt
.
NewHostModuleBuilder
(
config
.
WaOS_Chrome
)
.
Instantiate
(
ctx
,
rt
)
}
internal/app/waruntime/walang.go
浏览文件 @
a89e8072
...
...
@@ -12,7 +12,7 @@ import (
const
envWalang
=
"wa_js_env"
func
WalangInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Module
,
error
)
{
func
WalangInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Closer
,
error
)
{
return
rt
.
NewHostModuleBuilder
(
envWalang
)
.
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
m
api
.
Module
,
pos
,
len
uint32
)
{
...
...
internal/app/waruntime/wasi.go
浏览文件 @
a89e8072
...
...
@@ -6,9 +6,10 @@ import (
"context"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)
func
WasiInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
{
wasi_snapshot_preview1
.
Must
Instantiate
(
ctx
,
rt
)
func
WasiInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Closer
,
error
)
{
return
wasi_snapshot_preview1
.
Instantiate
(
ctx
,
rt
)
}
internal/waroot/_waroot/src/runtime/runtime_arduino.wa
浏览文件 @
a89e8072
# 版权 @2022 凹语言 作者。保留所有权利。
import "syscall/arduino"
var WAOS = "arduino"
#wa:linkname $runtime.waPrintI32
...
...
@@ -9,4 +11,6 @@ fn waPrintI32(i: i32) {}
fn waPrintRune(ch: i32) {}
#wa:linkname $runtime.waPuts
fn waPuts(ptr: i32, len: i32) {}
fn waPuts(ptr: i32, len: i32) {
arduino.PrintRawString(ptr, len)
}
internal/waroot/_waroot/src/syscall/arduino/arduino.wa
浏览文件 @
a89e8072
...
...
@@ -10,49 +10,27 @@ var (
)
#wa:import arduino millis
#wa:linkname $waMillis
fn Millis() => i32
#wa:import arduino delay
#wa:linkname $waDelay
fn Delay(ms: i32)
#wa:import arduino pinMode
#wa:linkname $waPinMode
fn PinMode(pin, mode: i32)
#wa:import arduino digitalWrite
#wa:linkname $waDigitalWrite
fn DigitalWrite(pin, value: i32)
#wa:import arduino getPinLED
#wa:linkname $waGetPinLED
fn GetPinLED() => i32
#wa:import arduino print
#wa:linkname $waPrint
fn Print(s: string)
fn PrintRawString(ptr: i32, len: i32)
#wa:import arduino getGreeting
#wa:linkname $waGetGreeting
fn _getGreeting(buf: *byte, maxlen: i32)
fn Println(s: string) {
Print(s)
Print("\n")
}
#wa:linkname $waPrintI32
fn waPrintI32(i: i32) {
# TODO
fn Print(s: string) {
print(s)
}
#wa:linkname $waPrintRune
fn waPrintRune(ch: i32) {
# TODO
}
#wa:linkname $waPuts
fn waPuts(ptr: i32, len: i32) {
# TODO
fn Println(s: string) {
println(s)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录