Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
7a06fb52
wa
项目概览
wa-lang
/
wa
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
7a06fb52
编写于
7月 13, 2023
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wir 增加原生 bool 类型
上级
bd7f9f25
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
108 addition
and
15 deletion
+108
-15
internal/backends/compiler_wat/compile_func.go
internal/backends/compiler_wat/compile_func.go
+8
-5
internal/backends/compiler_wat/compile_type.go
internal/backends/compiler_wat/compile_type.go
+10
-1
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+21
-6
internal/backends/compiler_wat/wir/module.go
internal/backends/compiler_wat/wir/module.go
+3
-1
internal/backends/compiler_wat/wir/value_basic.go
internal/backends/compiler_wat/wir/value_basic.go
+1
-1
internal/backends/compiler_wat/wir/value_type.go
internal/backends/compiler_wat/wir/value_type.go
+26
-1
internal/wazero/mvp.go
internal/wazero/mvp.go
+10
-0
waroot/src/runtime/runtime_chrome.wa
waroot/src/runtime/runtime_chrome.wa
+5
-0
waroot/src/runtime/runtime_mvp.wa
waroot/src/runtime/runtime_mvp.wa
+5
-0
waroot/src/runtime/runtime_wasi.wa
waroot/src/runtime/runtime_wasi.wa
+16
-0
waroot/src/syscall/mvp/mvp.wa
waroot/src/syscall/mvp/mvp.wa
+3
-0
未找到文件。
internal/backends/compiler_wat/compile_func.go
浏览文件 @
7a06fb52
...
...
@@ -63,9 +63,9 @@ func (g *functionGenerator) getValue(i ssa.Value) valueWrap {
case
types
.
Bool
,
types
.
UntypedBool
:
if
constant
.
BoolVal
(
v
.
Value
)
{
return
valueWrap
{
value
:
wir
.
NewConst
(
"1"
,
g
.
module
.
I32
)}
return
valueWrap
{
value
:
wir
.
NewConst
(
"1"
,
g
.
module
.
BOOL
)}
}
else
{
return
valueWrap
{
value
:
wir
.
NewConst
(
"0"
,
g
.
module
.
I32
)}
return
valueWrap
{
value
:
wir
.
NewConst
(
"0"
,
g
.
module
.
BOOL
)}
}
case
types
.
Uint8
:
...
...
@@ -628,7 +628,10 @@ func (g *functionGenerator) genBuiltin(call *ssa.CallCommon) (insts []wat.Inst,
insts
=
append
(
insts
,
wat
.
NewInstCall
(
"$runtime.waPrintRune"
))
}
if
avt
.
Equal
(
g
.
module
.
I32
)
{
if
avt
.
Equal
(
g
.
module
.
BOOL
)
{
insts
=
append
(
insts
,
av
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstCall
(
"$runtime.waPrintBool"
))
}
else
if
avt
.
Equal
(
g
.
module
.
I32
)
{
insts
=
append
(
insts
,
av
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstCall
(
"$runtime.waPrintI32"
))
}
else
if
avt
.
Equal
(
g
.
module
.
U8
)
||
avt
.
Equal
(
g
.
module
.
U16
)
||
avt
.
Equal
(
g
.
module
.
U32
)
{
...
...
@@ -769,8 +772,8 @@ func (g *functionGenerator) genStore(inst *ssa.Store) []wat.Inst {
func
(
g
*
functionGenerator
)
genIf
(
inst
*
ssa
.
If
)
[]
wat
.
Inst
{
cond
:=
g
.
getValue
(
inst
.
Cond
)
if
!
cond
.
value
.
Type
()
.
Equal
(
g
.
module
.
I32
)
{
logger
.
Fatal
(
"cond.type() !=
i32
"
)
if
!
cond
.
value
.
Type
()
.
Equal
(
g
.
module
.
BOOL
)
{
logger
.
Fatal
(
"cond.type() !=
bool
"
)
}
insts
:=
cond
.
value
.
EmitPush
()
...
...
internal/backends/compiler_wat/compile_type.go
浏览文件 @
7a06fb52
...
...
@@ -49,7 +49,10 @@ func (tLib *typeLib) compile(from types.Type) wir.ValueType {
switch
t
:=
from
.
(
type
)
{
case
*
types
.
Basic
:
switch
t
.
Kind
()
{
case
types
.
Bool
,
types
.
UntypedBool
,
types
.
Int
,
types
.
UntypedInt
:
case
types
.
Bool
,
types
.
UntypedBool
:
newType
=
tLib
.
module
.
BOOL
case
types
.
Int
,
types
.
UntypedInt
:
newType
=
tLib
.
module
.
I32
case
types
.
Int32
:
...
...
@@ -173,6 +176,12 @@ func (tLib *typeLib) compile(from types.Type) wir.ValueType {
newType
=
tLib
.
module
.
GenValueType_Dup
(
pkg_name
+
"."
+
obj_name
,
tLib
.
compile
(
ut
))
default
:
//pkg_name := ""
//if t.Obj().Pkg() != nil {
// pkg_name, _ = wir.GetPkgMangleName(t.Obj().Pkg().Path())
//}
//obj_name := wir.GenSymbolName(t.Obj().Name())
//newType = tLib.module.GenValueType_Dup(pkg_name+"."+obj_name, tLib.compile(ut))
logger
.
Fatalf
(
"Todo:%T"
,
ut
)
}
...
...
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
7a06fb52
...
...
@@ -42,11 +42,25 @@ func (m *Module) EmitUnOp(x Value, op wat.OpCode) (insts []wat.Inst, ret_type Va
insts
=
append
(
insts
,
NewConst
(
"0"
,
ret_type
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstSub
(
toWatType
(
ret_type
)))
if
ret_type
.
Equal
(
m
.
U8
)
{
insts
=
append
(
insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"255"
))
insts
=
append
(
insts
,
wat
.
NewInstAnd
(
wat
.
I32
{}))
}
else
if
ret_type
.
Equal
(
m
.
U16
)
{
insts
=
append
(
insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"65535"
))
insts
=
append
(
insts
,
wat
.
NewInstAnd
(
wat
.
I32
{}))
}
case
wat
.
OpCodeXor
:
insts
=
append
(
insts
,
NewConst
(
"-1"
,
ret_type
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstXor
(
toWatType
(
ret_type
)))
if
ret_type
.
Equal
(
m
.
U8
)
{
insts
=
append
(
insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"255"
))
insts
=
append
(
insts
,
wat
.
NewInstAnd
(
wat
.
I32
{}))
}
else
if
ret_type
.
Equal
(
m
.
U16
)
{
insts
=
append
(
insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"65535"
))
insts
=
append
(
insts
,
wat
.
NewInstAnd
(
wat
.
I32
{}))
}
case
wat
.
OpCodeNot
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
...
...
@@ -56,6 +70,7 @@ func (m *Module) EmitUnOp(x Value, op wat.OpCode) (insts []wat.Inst, ret_type Va
logger
.
Fatalf
(
"Todo: %[1]v: %[1]T"
,
op
)
}
return
}
...
...
@@ -138,37 +153,37 @@ func (m *Module) EmitBinOp(x, y Value, op wat.OpCode) (insts []wat.Inst, ret_typ
case
wat
.
OpCodeEql
:
ins
,
_
:=
x
.
emitEq
(
y
)
insts
=
append
(
insts
,
ins
...
)
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeNe
:
ins
,
_
:=
x
.
emitEq
(
y
)
insts
=
append
(
insts
,
ins
...
)
insts
=
append
(
insts
,
wat
.
NewInstEqz
(
wat
.
I32
{}))
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeLt
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
y
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstLt
(
toWatType
(
x
.
Type
())))
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeGt
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
y
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstGt
(
toWatType
(
x
.
Type
())))
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeLe
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
y
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstLe
(
toWatType
(
x
.
Type
())))
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeGe
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
y
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstGe
(
toWatType
(
x
.
Type
())))
ret_type
=
m
.
I32
ret_type
=
m
.
BOOL
case
wat
.
OpCodeAnd
:
ret_type
=
x
.
Type
()
...
...
internal/backends/compiler_wat/wir/module.go
浏览文件 @
7a06fb52
...
...
@@ -18,7 +18,7 @@ type fnSigWrap struct {
Module:
**************************************/
type
Module
struct
{
VOID
,
RUNE
,
U8
,
U16
,
I32
,
U32
,
UPTR
,
I64
,
U64
,
F32
,
F64
,
STRING
,
BYTES
ValueType
VOID
,
BOOL
,
RUNE
,
U8
,
U16
,
I32
,
U32
,
UPTR
,
I64
,
U64
,
F32
,
F64
,
STRING
,
BYTES
ValueType
types_map
map
[
string
]
ValueType
usedConcreteTypes
[]
ValueType
...
...
@@ -53,6 +53,7 @@ func NewModule() *Module {
var
m
Module
m
.
VOID
=
&
tVoid
{}
m
.
BOOL
=
&
tBool
{}
m
.
RUNE
=
&
tRune
{}
//m.I8 = &tI8{}
m
.
U8
=
&
tU8
{}
...
...
@@ -68,6 +69,7 @@ func NewModule() *Module {
m
.
types_map
=
make
(
map
[
string
]
ValueType
)
m
.
addValueType
(
m
.
VOID
)
m
.
addValueType
(
m
.
BOOL
)
m
.
addValueType
(
m
.
RUNE
)
//m.addValueType(m.I8)
m
.
addValueType
(
m
.
U8
)
...
...
internal/backends/compiler_wat/wir/value_basic.go
浏览文件 @
7a06fb52
...
...
@@ -27,7 +27,7 @@ func NewGlobal(name string, typ ValueType, as_pointer bool) Value {
func
newValue
(
name
string
,
kind
ValueKind
,
typ
ValueType
)
Value
{
switch
typ
:=
typ
.
(
type
)
{
case
*
tI8
,
*
tU8
,
*
tI16
,
*
tU16
,
*
tI32
,
*
tU32
,
*
tI64
,
*
tU64
,
*
tF32
,
*
tF64
,
*
tRune
:
case
*
tI8
,
*
tU8
,
*
tI16
,
*
tU16
,
*
tI32
,
*
tU32
,
*
tI64
,
*
tU64
,
*
tF32
,
*
tF64
,
*
tRune
,
*
tBool
:
return
newValue_Basic
(
name
,
kind
,
typ
)
case
*
Ptr
:
...
...
internal/backends/compiler_wat/wir/value_type.go
浏览文件 @
7a06fb52
...
...
@@ -12,6 +12,7 @@ type TypeKind uint8
const
(
kUnknown
TypeKind
=
iota
kVoid
kBool
kU8
kU16
kU32
...
...
@@ -41,7 +42,7 @@ func toWatType(t ValueType) wat.ValueType {
case
*
tI32
,
*
tRune
:
//Todo: *tI8, *tI16*
return
wat
.
I32
{}
case
*
tU32
,
*
tU8
,
*
tU16
:
case
*
tU32
,
*
tU8
,
*
tU16
,
*
tBool
:
return
wat
.
U32
{}
case
*
tI64
:
...
...
@@ -119,6 +120,30 @@ func (t *tVoid) EmitLoadFromAddr(addr Value, offset int) []wat.Inst {
return
nil
}
/**************************************
tBool:
**************************************/
type
tBool
struct
{
tCommon
}
func
(
t
*
tBool
)
Name
()
string
{
return
"bool"
}
func
(
t
*
tBool
)
Size
()
int
{
return
1
}
func
(
t
*
tBool
)
align
()
int
{
return
1
}
func
(
t
*
tBool
)
Kind
()
TypeKind
{
return
kBool
}
func
(
t
*
tBool
)
onFree
()
int
{
return
0
}
func
(
t
*
tBool
)
Raw
()
[]
wat
.
ValueType
{
return
[]
wat
.
ValueType
{
wat
.
I32
{}}
}
func
(
t
*
tBool
)
Equal
(
u
ValueType
)
bool
{
_
,
ok
:=
u
.
(
*
tBool
);
return
ok
}
func
(
t
*
tBool
)
EmitLoadFromAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
//if !addr.Type().(*Ptr).Base.Equal(t) {
// logger.Fatal("Type not match")
// return nil
//}
insts
:=
addr
.
EmitPush
()
insts
=
append
(
insts
,
wat
.
NewInstLoad
(
toWatType
(
t
),
offset
,
1
))
return
insts
}
/**************************************
tRune:
**************************************/
...
...
internal/wazero/mvp.go
浏览文件 @
7a06fb52
...
...
@@ -15,6 +15,16 @@ import (
func
MvpInstantiate
(
ctx
context
.
Context
,
rt
wazero
.
Runtime
)
(
api
.
Closer
,
error
)
{
return
rt
.
NewHostModuleBuilder
(
config
.
WaOS_mvp
)
.
// func waPrintBool(v: bool)
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
m
api
.
Module
,
v
uint32
)
{
w
:=
walang
.
ModCallContextSys
(
m
)
.
Stdout
()
b
:=
v
!=
0
fmt
.
Fprint
(
w
,
b
)
})
.
WithParameterNames
(
"v"
)
.
Export
(
"waPrintBool"
)
.
// func waPrintI32(v: i32)
NewFunctionBuilder
()
.
WithFunc
(
func
(
ctx
context
.
Context
,
m
api
.
Module
,
v
int32
)
{
...
...
waroot/src/runtime/runtime_chrome.wa
浏览文件 @
7a06fb52
...
...
@@ -38,6 +38,11 @@ func assert(ok: i32, pos_msg_ptr: i32, pos_msg_len: i32) {}
#wa:linkname $runtime.assertMessage
func assertMessage(ok: i32, msg_ptr: i32, msg_len: i32, pos_msg_ptr: i32, pos_msg_len: i32) {}
#wa:linkname $runtime.waPrintBool
func waPrintBool(i: bool) {
chrome.PrintBool(i)
}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {
chrome.PrintI32(i)
...
...
waroot/src/runtime/runtime_mvp.wa
浏览文件 @
7a06fb52
...
...
@@ -58,6 +58,11 @@ func assertWithMessage(ok: i32, msg_ptr: i32, msg_len: i32, pos_msg_ptr: i32, po
}
}
#wa:linkname $runtime.waPrintBool
func waPrintBool(i: bool) {
mvp.PrintBool(i)
}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {
mvp.PrintI32(i)
...
...
waroot/src/runtime/runtime_wasi.wa
浏览文件 @
7a06fb52
...
...
@@ -64,6 +64,22 @@ func puts(ptr: i32, len: i32)
#wa:linkname putchar
func putchar(ch: i32)
#wa:linkname $runtime.waPrintBool
func waPrintBool(i: bool) {
if i {
waPrintRune('t')
waPrintRune('r')
waPrintRune('u')
waPrintRune('e')
} else {
waPrintRune('f')
waPrintRune('a')
waPrintRune('l')
waPrintRune('s')
waPrintRune('e')
}
}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {
print_i32(i)
...
...
waroot/src/syscall/mvp/mvp.wa
浏览文件 @
7a06fb52
// 版权 @2023 凹语言 作者。保留所有权利。
#wa:import mvp waPrintBool
func PrintBool(i: bool)
#wa:import mvp waPrintI32
func PrintI32(i: i32)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录