Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
ce6cdae5
wa
项目概览
wa-lang
/
wa
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
ce6cdae5
编写于
5月 18, 2023
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ref类型更名为SPtr
上级
cd33d191
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
80 addition
and
79 deletion
+80
-79
internal/backends/compiler_wat/compile.go
internal/backends/compiler_wat/compile.go
+1
-1
internal/backends/compiler_wat/compile_func.go
internal/backends/compiler_wat/compile_func.go
+1
-1
internal/backends/compiler_wat/compile_type.go
internal/backends/compiler_wat/compile_type.go
+2
-2
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+16
-16
internal/backends/compiler_wat/wir/module.go
internal/backends/compiler_wat/wir/module.go
+9
-9
internal/backends/compiler_wat/wir/util.go
internal/backends/compiler_wat/wir/util.go
+1
-1
internal/backends/compiler_wat/wir/value_basic.go
internal/backends/compiler_wat/wir/value_basic.go
+2
-2
internal/backends/compiler_wat/wir/value_closure.go
internal/backends/compiler_wat/wir/value_closure.go
+1
-1
internal/backends/compiler_wat/wir/value_interface.go
internal/backends/compiler_wat/wir/value_interface.go
+2
-2
internal/backends/compiler_wat/wir/value_slice.go
internal/backends/compiler_wat/wir/value_slice.go
+3
-3
internal/backends/compiler_wat/wir/value_sptr.go
internal/backends/compiler_wat/wir/value_sptr.go
+39
-39
internal/backends/compiler_wat/wir/value_type.go
internal/backends/compiler_wat/wir/value_type.go
+2
-1
internal/waroot/_waroot/src/runtime/runtime_type.wa
internal/waroot/_waroot/src/runtime/runtime_type.wa
+1
-1
未找到文件。
internal/backends/compiler_wat/compile.go
浏览文件 @
ce6cdae5
...
...
@@ -25,7 +25,7 @@ type Compiler struct {
func
New
()
*
Compiler
{
p
:=
new
(
Compiler
)
p
.
module
=
wir
.
NewModule
()
p
.
module
.
AddGlobal
(
"$wa.RT.closure_data"
,
p
.
module
.
GenValueType_
Ref
(
p
.
module
.
VOID
),
false
,
nil
)
p
.
module
.
AddGlobal
(
"$wa.RT.closure_data"
,
p
.
module
.
GenValueType_
SPtr
(
p
.
module
.
VOID
),
false
,
nil
)
wir
.
SetCurrentModule
(
p
.
module
)
return
p
}
...
...
internal/backends/compiler_wat/compile_func.go
浏览文件 @
ce6cdae5
...
...
@@ -1113,7 +1113,7 @@ func (g *functionGenerator) genSizer(f *ssa.Function) *wir.Function {
return
nil
}
value_type
:=
g
.
tLib
.
compile
(
f
.
Params
[
0
]
.
Type
())
t_size
:=
value_type
.
(
*
wir
.
Ref
)
.
Base
.
Size
()
t_size
:=
value_type
.
(
*
wir
.
SPtr
)
.
Base
.
Size
()
wir_fn
.
Insts
=
append
(
wir_fn
.
Insts
,
wir
.
NewConst
(
strconv
.
Itoa
(
t_size
),
g
.
module
.
I32
)
.
EmitPush
()
...
)
...
...
internal/backends/compiler_wat/compile_type.go
浏览文件 @
ce6cdae5
...
...
@@ -106,7 +106,7 @@ func (tLib *typeLib) compile(from types.Type) wir.ValueType {
}
case
*
types
.
Pointer
:
newType
=
tLib
.
module
.
GenValueType_
Ref
(
tLib
.
compile
(
t
.
Elem
()))
newType
=
tLib
.
module
.
GenValueType_
SPtr
(
tLib
.
compile
(
t
.
Elem
()))
uncommanFlag
=
true
case
*
types
.
Named
:
...
...
@@ -152,7 +152,7 @@ func (tLib *typeLib) compile(from types.Type) wir.ValueType {
method
.
Name
=
ut
.
Method
(
i
)
.
Name
()
var
fnSig
wir
.
FnSig
fnSig
.
Params
=
append
(
fnSig
.
Params
,
tLib
.
module
.
GenValueType_
Ref
(
tLib
.
module
.
VOID
))
fnSig
.
Params
=
append
(
fnSig
.
Params
,
tLib
.
module
.
GenValueType_
SPtr
(
tLib
.
module
.
VOID
))
fnSig
.
Params
=
append
(
fnSig
.
Params
,
method
.
Sig
.
Params
...
)
fnSig
.
Results
=
method
.
Sig
.
Results
...
...
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
ce6cdae5
...
...
@@ -131,9 +131,9 @@ func (m *Module) EmitLoad(addr Value) (insts []wat.Inst, ret_type ValueType) {
default
:
switch
addr
:=
addr
.
(
type
)
{
case
*
a
Ref
:
case
*
a
SPtr
:
insts
=
append
(
insts
,
addr
.
emitGetValue
()
...
)
ret_type
=
addr
.
Type
()
.
(
*
Ref
)
.
Base
ret_type
=
addr
.
Type
()
.
(
*
SPtr
)
.
Base
case
*
aPtr
:
insts
=
append
(
insts
,
addr
.
emitGetValue
()
...
)
...
...
@@ -165,9 +165,9 @@ func (m *Module) EmitStore(addr, value Value) (insts []wat.Inst) {
default
:
switch
addr
:=
addr
.
(
type
)
{
case
*
a
Ref
:
case
*
a
SPtr
:
if
value
==
nil
{
zero_value
:=
NewConst
(
"0"
,
addr
.
Type
()
.
(
*
Ref
)
.
Base
)
zero_value
:=
NewConst
(
"0"
,
addr
.
Type
()
.
(
*
SPtr
)
.
Base
)
insts
=
append
(
insts
,
addr
.
emitSetValue
(
zero_value
)
...
)
}
else
{
insts
=
append
(
insts
,
addr
.
emitSetValue
(
value
)
...
)
...
...
@@ -190,7 +190,7 @@ func (m *Module) EmitStore(addr, value Value) (insts []wat.Inst) {
}
func
(
m
*
Module
)
EmitHeapAlloc
(
typ
ValueType
)
(
insts
[]
wat
.
Inst
,
ret_type
ValueType
)
{
ref_typ
:=
m
.
GenValueType_
Ref
(
typ
)
ref_typ
:=
m
.
GenValueType_
SPtr
(
typ
)
ret_type
=
ref_typ
insts
=
ref_typ
.
emitHeapAlloc
()
return
...
...
@@ -229,9 +229,9 @@ func (m *Module) EmitGenFieldAddr(x Value, field_name string) (insts []wat.Inst,
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
var
field
*
StructField
switch
addr
:=
x
.
(
type
)
{
case
*
a
Ref
:
field
=
addr
.
Type
()
.
(
*
Ref
)
.
Base
.
(
*
Struct
)
.
findFieldByName
(
field_name
)
ret_type
=
m
.
GenValueType_
Ref
(
field
.
Type
())
case
*
a
SPtr
:
field
=
addr
.
Type
()
.
(
*
SPtr
)
.
Base
.
(
*
Struct
)
.
findFieldByName
(
field_name
)
ret_type
=
m
.
GenValueType_
SPtr
(
field
.
Type
())
case
*
aPtr
:
field
=
addr
.
Type
()
.
(
*
Ptr
)
.
Base
.
(
*
Struct
)
.
findFieldByName
(
field_name
)
ret_type
=
m
.
GenValueType_Ptr
(
field
.
Type
())
...
...
@@ -265,15 +265,15 @@ func (m *Module) EmitGenIndexAddr(x, id Value) (insts []wat.Inst, ret_type Value
logger
.
Fatalf
(
"Todo: %T"
,
typ
)
}
case
*
a
Ref
:
switch
typ
:=
x
.
Type
()
.
(
*
Ref
)
.
Base
.
(
type
)
{
case
*
a
SPtr
:
switch
typ
:=
x
.
Type
()
.
(
*
SPtr
)
.
Base
.
(
type
)
{
case
*
Array
:
insts
=
append
(
insts
,
x
.
EmitPush
()
...
)
insts
=
append
(
insts
,
NewConst
(
strconv
.
Itoa
(
typ
.
Base
.
Size
()),
m
.
I32
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
id
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstMul
(
wat
.
I32
{}))
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
ret_type
=
m
.
GenValueType_
Ref
(
typ
.
Base
)
ret_type
=
m
.
GenValueType_
SPtr
(
typ
.
Base
)
default
:
logger
.
Fatalf
(
"Todo: %T"
,
typ
)
...
...
@@ -287,7 +287,7 @@ func (m *Module) EmitGenIndexAddr(x, id Value) (insts []wat.Inst, ret_type Value
insts
=
append
(
insts
,
id
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstMul
(
wat
.
I32
{}))
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
ret_type
=
m
.
GenValueType_
Ref
(
base_type
)
ret_type
=
m
.
GenValueType_
SPtr
(
base_type
)
default
:
logger
.
Fatalf
(
"Todo: %T"
,
x
)
...
...
@@ -323,8 +323,8 @@ func (m *Module) EmitGenSlice(x, low, high Value) (insts []wat.Inst, ret_type Va
insts
=
x
.
emitSub
(
low
,
high
)
ret_type
=
x
.
Type
()
case
*
a
Ref
:
switch
btype
:=
x
.
Type
()
.
(
*
Ref
)
.
Base
.
(
type
)
{
case
*
a
SPtr
:
switch
btype
:=
x
.
Type
()
.
(
*
SPtr
)
.
Base
.
(
type
)
{
case
*
Slice
:
slt
:=
m
.
GenValueType_Slice
(
btype
.
Base
)
insts
=
slt
.
emitGenFromRefOfSlice
(
x
,
low
,
high
)
...
...
@@ -442,14 +442,14 @@ func (m *Module) EmitGenMakeInterface(x Value, itype ValueType) (insts []wat.Ins
x_type
:=
x
.
Type
()
m
.
markConcreteTypeUsed
(
x_type
)
m
.
markInterfaceUsed
(
itype
)
x_ref_type
:=
m
.
GenValueType_
Ref
(
x_type
)
x_ref_type
:=
m
.
GenValueType_
SPtr
(
x_type
)
return
itype
.
(
*
Interface
)
.
emitGenMake
(
x
,
x_ref_type
)
}
func
(
m
*
Module
)
EmitInvoke
(
i
Value
,
params
[]
Value
,
mid
int
,
typeName
string
)
(
insts
[]
wat
.
Inst
)
{
iface
:=
i
.
(
*
aInterface
)
insts
=
append
(
insts
,
iface
.
Extract
(
"data"
)
.
(
*
a
Ref
)
.
emitGetValue
()
...
)
insts
=
append
(
insts
,
iface
.
Extract
(
"data"
)
.
(
*
a
SPtr
)
.
emitGetValue
()
...
)
for
_
,
v
:=
range
params
{
insts
=
append
(
insts
,
v
.
EmitPush
()
...
)
...
...
internal/backends/compiler_wat/wir/module.go
浏览文件 @
ce6cdae5
...
...
@@ -220,8 +220,8 @@ func (m *Module) genGlobalAlloc() *Function {
continue
}
ref
:=
g
.
v
.
(
*
a
Ref
)
t
:=
ref
.
Type
()
.
(
*
Ref
)
.
Base
ref
:=
g
.
v
.
(
*
a
SPtr
)
t
:=
ref
.
Type
()
.
(
*
SPtr
)
.
Base
f
.
Insts
=
append
(
f
.
Insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
strconv
.
Itoa
(
t
.
Size
())))
f
.
Insts
=
append
(
f
.
Insts
,
wat
.
NewInstCall
(
"$waHeapAlloc"
))
f
.
Insts
=
append
(
f
.
Insts
,
ref
.
Extract
(
"data"
)
.
EmitPop
()
...
)
...
...
@@ -464,12 +464,12 @@ func (m *Module) buildTypeInfo(t ValueType) int {
typ
.
addr
=
m
.
DataSeg
.
Append
(
_slice
.
Bin
(),
8
)
return
typ
.
addr
case
*
Ref
:
_
ref
:=
NewConst
(
"0"
,
m
.
types_map
[
"runtime._ref
Type"
])
.
(
*
aStruct
)
typ
.
addr
=
m
.
DataSeg
.
Alloc
(
len
(
_
ref
.
Bin
()),
8
)
case
*
SPtr
:
_
sptr
:=
NewConst
(
"0"
,
m
.
types_map
[
"runtime._sptr
Type"
])
.
(
*
aStruct
)
typ
.
addr
=
m
.
DataSeg
.
Alloc
(
len
(
_
sptr
.
Bin
()),
8
)
_
ref
.
setFieldConstValue
(
"$_type"
,
_type
)
_
ref
.
setFieldConstValue
(
"elemType"
,
NewConst
(
strconv
.
Itoa
(
m
.
buildTypeInfo
(
typ
.
Base
)),
m
.
UPTR
))
_
sptr
.
setFieldConstValue
(
"$_type"
,
_type
)
_
sptr
.
setFieldConstValue
(
"elemType"
,
NewConst
(
strconv
.
Itoa
(
m
.
buildTypeInfo
(
typ
.
Base
)),
m
.
UPTR
))
if
len
(
typ
.
methods
)
>
0
{
_uncommon
:=
NewConst
(
"0"
,
m
.
types_map
[
"runtime._uncommonType"
])
.
(
*
aStruct
)
_uncommon
.
setFieldConstValue
(
"methodCount"
,
NewConst
(
strconv
.
Itoa
(
len
(
typ
.
methods
)),
m
.
U32
))
...
...
@@ -481,10 +481,10 @@ func (m *Module) buildTypeInfo(t ValueType) int {
_method
.
setFieldConstValue
(
"fnID"
,
NewConst
(
strconv
.
Itoa
(
m
.
AddTableElem
(
method
.
FullFnName
)),
m
.
U32
))
_uncommon_bin
=
append
(
_uncommon_bin
,
_method
.
Bin
()
...
)
}
_
ref
.
setFieldConstValue
(
"uncommon"
,
NewConst
(
strconv
.
Itoa
(
m
.
DataSeg
.
Append
(
_uncommon_bin
,
8
)),
m
.
UPTR
))
_
sptr
.
setFieldConstValue
(
"uncommon"
,
NewConst
(
strconv
.
Itoa
(
m
.
DataSeg
.
Append
(
_uncommon_bin
,
8
)),
m
.
UPTR
))
}
m
.
DataSeg
.
Set
(
_
ref
.
Bin
(),
typ
.
addr
)
m
.
DataSeg
.
Set
(
_
sptr
.
Bin
(),
typ
.
addr
)
return
typ
.
addr
case
*
Closure
:
...
...
internal/backends/compiler_wat/wir/util.go
浏览文件 @
ce6cdae5
...
...
@@ -273,7 +273,7 @@ func ExtractField(x Value, field_name string) Value {
case
*
aStruct
:
return
x
.
Extract
(
field_name
)
case
*
a
Ref
:
case
*
a
SPtr
:
return
x
.
Extract
(
field_name
)
case
*
aClosure
:
...
...
internal/backends/compiler_wat/wir/value_basic.go
浏览文件 @
ce6cdae5
...
...
@@ -36,8 +36,8 @@ func newValue(name string, kind ValueKind, typ ValueType) Value {
case
*
Block
:
return
newValue_Block
(
name
,
kind
,
typ
)
case
*
Ref
:
return
newValue_
Ref
(
name
,
kind
,
typ
)
case
*
SPtr
:
return
newValue_
SPtr
(
name
,
kind
,
typ
)
case
*
Array
:
return
newValue_Array
(
name
,
kind
,
typ
)
...
...
internal/backends/compiler_wat/wir/value_closure.go
浏览文件 @
ce6cdae5
...
...
@@ -76,7 +76,7 @@ func (m *Module) GenValueType_Closure(sig FnSig) *Closure {
closure_t
.
underlying
=
m
.
genInternalStruct
(
closure_t
.
Name
()
+
".underlying"
)
closure_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"fn_index"
,
m
.
U32
))
closure_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
m
.
GenValueType_
Ref
(
m
.
VOID
)))
closure_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
m
.
GenValueType_
SPtr
(
m
.
VOID
)))
closure_t
.
underlying
.
Finish
()
m
.
addValueType
(
&
closure_t
)
...
...
internal/backends/compiler_wat/wir/value_interface.go
浏览文件 @
ce6cdae5
...
...
@@ -27,7 +27,7 @@ func (m *Module) GenValueType_Interface(name string) *Interface {
interface_t
.
name
=
name
interface_t
.
underlying
=
m
.
genInternalStruct
(
interface_t
.
Name
()
+
".underlying"
)
interface_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
m
.
GenValueType_
Ref
(
m
.
GenValueType_Ref
(
m
.
VOID
))))
interface_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
m
.
GenValueType_
SPtr
(
m
.
GenValueType_SPtr
(
m
.
VOID
))))
interface_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"itab"
,
m
.
U32
))
interface_t
.
underlying
.
Finish
()
...
...
@@ -52,7 +52,7 @@ func (t *Interface) EmitLoadFromAddr(addr Value, offset int) []wat.Inst {
return
t
.
underlying
.
EmitLoadFromAddr
(
addr
,
offset
)
}
func
(
t
*
Interface
)
emitGenMake
(
x
Value
,
x_ref
*
Ref
)
(
insts
[]
wat
.
Inst
)
{
func
(
t
*
Interface
)
emitGenMake
(
x
Value
,
x_ref
*
SPtr
)
(
insts
[]
wat
.
Inst
)
{
insts
=
append
(
insts
,
x_ref
.
emitHeapAlloc
()
...
)
insts
=
append
(
insts
,
x
.
emitStore
(
0
)
...
)
...
...
internal/backends/compiler_wat/wir/value_slice.go
浏览文件 @
ce6cdae5
...
...
@@ -63,7 +63,7 @@ func (t *Slice) EmitLoadFromAddr(addr Value, offset int) []wat.Inst {
}
/*这个函数极其不优雅*/
func
(
t
*
Slice
)
emitGenFromRefOfSlice
(
x
*
a
Ref
,
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
func
(
t
*
Slice
)
emitGenFromRefOfSlice
(
x
*
a
SPtr
,
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
//block
insts
=
append
(
insts
,
x
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstLoad
(
wat
.
U32
{},
0
,
1
))
...
...
@@ -101,7 +101,7 @@ func (t *Slice) emitGenFromRefOfSlice(x *aRef, low, high Value) (insts []wat.Ins
return
}
func
(
t
*
Slice
)
emitGenFromRefOfArray
(
x
*
a
Ref
,
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
func
(
t
*
Slice
)
emitGenFromRefOfArray
(
x
*
a
SPtr
,
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
//block
insts
=
append
(
insts
,
x
.
Extract
(
"block"
)
.
EmitPush
()
...
)
...
...
@@ -116,7 +116,7 @@ func (t *Slice) emitGenFromRefOfArray(x *aRef, low, high Value) (insts []wat.Ins
insts
=
append
(
insts
,
wat
.
NewInstMul
(
wat
.
U32
{}))
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
U32
{}))
array_len
:=
NewConst
(
strconv
.
Itoa
(
x
.
Type
()
.
(
*
Ref
)
.
Base
.
(
*
Array
)
.
Capacity
),
t
.
_u32
)
array_len
:=
NewConst
(
strconv
.
Itoa
(
x
.
Type
()
.
(
*
SPtr
)
.
Base
.
(
*
Array
)
.
Capacity
),
t
.
_u32
)
//len:
if
high
==
nil
{
...
...
internal/backends/compiler_wat/wir/value_
ref
.go
→
internal/backends/compiler_wat/wir/value_
sptr
.go
浏览文件 @
ce6cdae5
...
...
@@ -10,9 +10,9 @@ import (
)
/**************************************
Ref
:
SPtr
:
**************************************/
type
Ref
struct
{
type
SPtr
struct
{
tCommon
Base
ValueType
underlying
*
Struct
...
...
@@ -20,40 +20,40 @@ type Ref struct {
_void
ValueType
}
func
(
m
*
Module
)
GenValueType_
Ref
(
base
ValueType
)
*
Ref
{
ref_t
:=
Ref
{
Base
:
base
}
t
,
ok
:=
m
.
findValueType
(
ref
_t
.
Name
())
func
(
m
*
Module
)
GenValueType_
SPtr
(
base
ValueType
)
*
SPtr
{
sptr_t
:=
SPtr
{
Base
:
base
}
t
,
ok
:=
m
.
findValueType
(
sptr
_t
.
Name
())
if
ok
{
return
t
.
(
*
Ref
)
return
t
.
(
*
SPtr
)
}
ref
_t
.
_base_block
=
m
.
GenValueType_Block
(
base
)
ref
_t
.
_void
=
m
.
VOID
sptr
_t
.
_base_block
=
m
.
GenValueType_Block
(
base
)
sptr
_t
.
_void
=
m
.
VOID
base_ptr
:=
m
.
GenValueType_Ptr
(
base
)
ref_t
.
underlying
=
m
.
genInternalStruct
(
ref
_t
.
Name
()
+
".underlying"
)
ref_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"block"
,
ref
_t
.
_base_block
))
ref
_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
base_ptr
))
ref
_t
.
underlying
.
Finish
()
sptr_t
.
underlying
=
m
.
genInternalStruct
(
sptr
_t
.
Name
()
+
".underlying"
)
sptr_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"block"
,
sptr
_t
.
_base_block
))
sptr
_t
.
underlying
.
AppendField
(
m
.
NewStructField
(
"data"
,
base_ptr
))
sptr
_t
.
underlying
.
Finish
()
m
.
addValueType
(
&
ref
_t
)
return
&
ref
_t
m
.
addValueType
(
&
sptr
_t
)
return
&
sptr
_t
}
func
(
t
*
Ref
)
Name
()
string
{
return
t
.
Base
.
Name
()
+
".$ref
"
}
func
(
t
*
Ref
)
Size
()
int
{
return
t
.
underlying
.
Size
()
}
func
(
t
*
Ref
)
align
()
int
{
return
t
.
underlying
.
align
()
}
func
(
t
*
Ref
)
Kind
()
TypeKind
{
return
kRef
}
func
(
t
*
Ref
)
onFree
()
int
{
return
t
.
underlying
.
onFree
()
}
func
(
t
*
Ref
)
Raw
()
[]
wat
.
ValueType
{
return
t
.
underlying
.
Raw
()
}
func
(
t
*
Ref
)
Equal
(
u
ValueType
)
bool
{
if
ut
,
ok
:=
u
.
(
*
Ref
);
ok
{
func
(
t
*
SPtr
)
Name
()
string
{
return
t
.
Base
.
Name
()
+
".$sptr
"
}
func
(
t
*
SPtr
)
Size
()
int
{
return
t
.
underlying
.
Size
()
}
func
(
t
*
SPtr
)
align
()
int
{
return
t
.
underlying
.
align
()
}
func
(
t
*
SPtr
)
Kind
()
TypeKind
{
return
kSPtr
}
func
(
t
*
SPtr
)
onFree
()
int
{
return
t
.
underlying
.
onFree
()
}
func
(
t
*
SPtr
)
Raw
()
[]
wat
.
ValueType
{
return
t
.
underlying
.
Raw
()
}
func
(
t
*
SPtr
)
Equal
(
u
ValueType
)
bool
{
if
ut
,
ok
:=
u
.
(
*
SPtr
);
ok
{
return
t
.
Base
.
Equal
(
ut
.
Base
)
}
return
false
}
func
(
t
*
Ref
)
emitHeapAlloc
()
(
insts
[]
wat
.
Inst
)
{
func
(
t
*
SPtr
)
emitHeapAlloc
()
(
insts
[]
wat
.
Inst
)
{
//insts = append(insts, wat.NewBlank())
//insts = append(insts, wat.NewComment("Ref.emitHeapAlloc start"))
...
...
@@ -68,7 +68,7 @@ func (t *Ref) emitHeapAlloc() (insts []wat.Inst) {
return
}
func
(
t
*
Ref
)
emitStackAlloc
()
(
insts
[]
wat
.
Inst
)
{
func
(
t
*
SPtr
)
emitStackAlloc
()
(
insts
[]
wat
.
Inst
)
{
//insts = append(insts, wat.NewBlank())
//insts = append(insts, wat.NewComment("Ref.emitStackAlloc start"))
...
...
@@ -83,42 +83,42 @@ func (t *Ref) emitStackAlloc() (insts []wat.Inst) {
return
}
func
(
t
*
Ref
)
EmitLoadFromAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
func
(
t
*
SPtr
)
EmitLoadFromAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
return
t
.
underlying
.
EmitLoadFromAddr
(
addr
,
offset
)
}
/**************************************
a
Ref
:
a
SPtr
:
**************************************/
type
a
Ref
struct
{
type
a
SPtr
struct
{
aStruct
typ
*
Ref
typ
*
SPtr
}
func
newValue_
Ref
(
name
string
,
kind
ValueKind
,
typ
*
Ref
)
*
aRef
{
var
v
a
Ref
func
newValue_
SPtr
(
name
string
,
kind
ValueKind
,
typ
*
SPtr
)
*
aSPtr
{
var
v
a
SPtr
v
.
typ
=
typ
v
.
aStruct
=
*
newValue_Struct
(
name
,
kind
,
typ
.
underlying
)
return
&
v
}
func
(
v
*
a
Ref
)
Type
()
ValueType
{
return
v
.
typ
}
func
(
v
*
a
SPtr
)
Type
()
ValueType
{
return
v
.
typ
}
func
(
v
*
a
Ref
)
raw
()
[]
wat
.
Value
{
return
v
.
aStruct
.
raw
()
}
func
(
v
*
a
Ref
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitInit
()
}
func
(
v
*
a
Ref
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPush
()
}
func
(
v
*
a
Ref
)
EmitPop
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPop
()
}
func
(
v
*
a
Ref
)
EmitRelease
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitRelease
()
}
func
(
v
*
a
SPtr
)
raw
()
[]
wat
.
Value
{
return
v
.
aStruct
.
raw
()
}
func
(
v
*
a
SPtr
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitInit
()
}
func
(
v
*
a
SPtr
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPush
()
}
func
(
v
*
a
SPtr
)
EmitPop
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPop
()
}
func
(
v
*
a
SPtr
)
EmitRelease
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitRelease
()
}
func
(
v
*
a
Ref
)
emitStoreToAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
func
(
v
*
a
SPtr
)
emitStoreToAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
return
v
.
aStruct
.
emitStoreToAddr
(
addr
,
offset
)
}
func
(
v
*
a
Ref
)
emitGetValue
()
[]
wat
.
Inst
{
func
(
v
*
a
SPtr
)
emitGetValue
()
[]
wat
.
Inst
{
return
v
.
typ
.
Base
.
EmitLoadFromAddr
(
v
.
aStruct
.
Extract
(
"data"
),
0
)
}
func
(
v
*
a
Ref
)
emitSetValue
(
d
Value
)
[]
wat
.
Inst
{
func
(
v
*
a
SPtr
)
emitSetValue
(
d
Value
)
[]
wat
.
Inst
{
if
!
d
.
Type
()
.
Equal
(
v
.
typ
.
Base
)
&&
!
v
.
typ
.
Base
.
Equal
(
v
.
typ
.
_void
)
{
logger
.
Fatal
(
"Type not match"
)
return
nil
...
...
internal/backends/compiler_wat/wir/value_type.go
浏览文件 @
ce6cdae5
...
...
@@ -27,12 +27,13 @@ const (
kBlock
kStruct
kTuple
k
Ref
k
SPtr
kString
kSlice
kArray
kMap
kInterface
kRef
)
func
toWatType
(
t
ValueType
)
wat
.
ValueType
{
...
...
internal/waroot/_waroot/src/runtime/runtime_type.wa
浏览文件 @
ce6cdae5
...
...
@@ -11,7 +11,7 @@ type _type struct {
name: string
}
type _
ref
Type struct {
type _
sptr
Type struct {
_type
elemType: uintptr //@_type
uncommon: uintptr //@_uncommonType
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录