Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
5aa6e7ba
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,发现更多精彩内容 >>
提交
5aa6e7ba
编写于
11月 26, 2022
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化String结构
优化Slice结构
上级
b694219b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
25 deletion
+29
-25
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+3
-3
internal/backends/compiler_wat/wir/value_slice.go
internal/backends/compiler_wat/wir/value_slice.go
+2
-0
internal/backends/compiler_wat/wir/value_string.go
internal/backends/compiler_wat/wir/value_string.go
+24
-22
未找到文件。
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
5aa6e7ba
...
@@ -381,7 +381,7 @@ func EmitGenLen(x Value) (insts []wat.Inst) {
...
@@ -381,7 +381,7 @@ func EmitGenLen(x Value) (insts []wat.Inst) {
insts
=
x
.
Extract
(
"len"
)
.
EmitPush
()
insts
=
x
.
Extract
(
"len"
)
.
EmitPush
()
case
*
aString
:
case
*
aString
:
insts
=
x
.
underlying
.
Extract
(
"len"
)
.
EmitPush
()
insts
=
x
.
Extract
(
"len"
)
.
EmitPush
()
default
:
default
:
logger
.
Fatalf
(
"Todo: %T"
,
x
)
logger
.
Fatalf
(
"Todo: %T"
,
x
)
...
@@ -393,8 +393,8 @@ func EmitGenLen(x Value) (insts []wat.Inst) {
...
@@ -393,8 +393,8 @@ func EmitGenLen(x Value) (insts []wat.Inst) {
func
EmitPrintString
(
v
Value
)
(
insts
[]
wat
.
Inst
)
{
func
EmitPrintString
(
v
Value
)
(
insts
[]
wat
.
Inst
)
{
s
:=
v
.
(
*
aString
)
s
:=
v
.
(
*
aString
)
insts
=
append
(
insts
,
s
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
s
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
s
.
underlying
.
Extract
(
"len"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
s
.
Extract
(
"len"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstCall
(
"$runtime.waPuts"
))
insts
=
append
(
insts
,
wat
.
NewInstCall
(
"$runtime.waPuts"
))
return
return
}
}
...
...
internal/backends/compiler_wat/wir/value_slice.go
浏览文件 @
5aa6e7ba
...
@@ -335,6 +335,8 @@ func newValueSlice(name string, kind ValueKind, base_type ValueType) *aSlice {
...
@@ -335,6 +335,8 @@ func newValueSlice(name string, kind ValueKind, base_type ValueType) *aSlice {
return
&
v
return
&
v
}
}
func
(
v
*
aSlice
)
Type
()
ValueType
{
return
v
.
typ
}
func
(
v
*
aSlice
)
raw
()
[]
wat
.
Value
{
return
v
.
aStruct
.
raw
()
}
func
(
v
*
aSlice
)
raw
()
[]
wat
.
Value
{
return
v
.
aStruct
.
raw
()
}
func
(
v
*
aSlice
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitInit
()
}
func
(
v
*
aSlice
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitInit
()
}
func
(
v
*
aSlice
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPush
()
}
func
(
v
*
aSlice
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPush
()
}
...
...
internal/backends/compiler_wat/wir/value_string.go
浏览文件 @
5aa6e7ba
...
@@ -49,14 +49,14 @@ func (t String) genAppendStrFunc() string {
...
@@ -49,14 +49,14 @@ func (t String) genAppendStrFunc() string {
f
.
Params
=
append
(
f
.
Params
,
y
)
f
.
Params
=
append
(
f
.
Params
,
y
)
f
.
Results
=
append
(
f
.
Results
,
t
)
f
.
Results
=
append
(
f
.
Results
,
t
)
x_len
:=
NewLocal
(
"x_len"
,
x
.
underlying
.
Extract
(
"len"
)
.
Type
())
x_len
:=
NewLocal
(
"x_len"
,
x
.
Extract
(
"len"
)
.
Type
())
f
.
Locals
=
append
(
f
.
Locals
,
x_len
)
f
.
Locals
=
append
(
f
.
Locals
,
x_len
)
f
.
Insts
=
append
(
f
.
Insts
,
x
.
underlying
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
x_len
.
EmitPop
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
x_len
.
EmitPop
()
...
)
y_len
:=
NewLocal
(
"y_len"
,
y
.
underlying
.
Extract
(
"len"
)
.
Type
())
y_len
:=
NewLocal
(
"y_len"
,
y
.
Extract
(
"len"
)
.
Type
())
f
.
Locals
=
append
(
f
.
Locals
,
y_len
)
f
.
Locals
=
append
(
f
.
Locals
,
y_len
)
f
.
Insts
=
append
(
f
.
Insts
,
y
.
underlying
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y_len
.
EmitPop
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y_len
.
EmitPop
()
...
)
//gen new_len:
//gen new_len:
...
@@ -88,7 +88,7 @@ func (t String) genAppendStrFunc() string {
...
@@ -88,7 +88,7 @@ func (t String) genAppendStrFunc() string {
//x->new
//x->new
{
{
f
.
Insts
=
append
(
f
.
Insts
,
x
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
x
.
Extract
(
"data"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
src
.
EmitPop
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
src
.
EmitPop
()
...
)
block
:=
wat
.
NewInstBlock
(
"block2"
)
block
:=
wat
.
NewInstBlock
(
"block2"
)
...
@@ -126,7 +126,7 @@ func (t String) genAppendStrFunc() string {
...
@@ -126,7 +126,7 @@ func (t String) genAppendStrFunc() string {
//y->new
//y->new
{
{
f
.
Insts
=
append
(
f
.
Insts
,
y
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y
.
Extract
(
"data"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
src
.
EmitPop
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
src
.
EmitPop
()
...
)
block
:=
wat
.
NewInstBlock
(
"block3"
)
block
:=
wat
.
NewInstBlock
(
"block3"
)
...
@@ -174,8 +174,8 @@ func (t String) genAppendStrFunc() string {
...
@@ -174,8 +174,8 @@ func (t String) genAppendStrFunc() string {
aString:
aString:
**************************************/
**************************************/
type
aString
struct
{
type
aString
struct
{
a
Value
a
Struct
underlying
aStruct
typ
String
}
}
func
newValueString
(
name
string
,
kind
ValueKind
)
*
aString
{
func
newValueString
(
name
string
,
kind
ValueKind
)
*
aString
{
...
@@ -187,36 +187,38 @@ func newValueString(name string, kind ValueKind) *aString {
...
@@ -187,36 +187,38 @@ func newValueString(name string, kind ValueKind) *aString {
string_type
.
findFieldByName
(
"data"
)
.
const_val
=
NewConst
(
strconv
.
Itoa
(
ptr
),
NewPointer
(
U8
{}))
string_type
.
findFieldByName
(
"data"
)
.
const_val
=
NewConst
(
strconv
.
Itoa
(
ptr
),
NewPointer
(
U8
{}))
string_type
.
findFieldByName
(
"len"
)
.
const_val
=
NewConst
(
strconv
.
Itoa
(
len
(
name
)),
U32
{})
string_type
.
findFieldByName
(
"len"
)
.
const_val
=
NewConst
(
strconv
.
Itoa
(
len
(
name
)),
U32
{})
}
}
v
.
aValue
=
aValue
{
name
:
name
,
kind
:
kind
,
typ
:
string_type
}
v
.
typ
=
string_type
v
.
underlying
=
*
newValueStruct
(
name
,
kind
,
string_type
.
Struct
)
v
.
aStruct
=
*
newValueStruct
(
name
,
kind
,
string_type
.
Struct
)
return
&
v
return
&
v
}
}
func
(
v
*
aString
)
raw
()
[]
wat
.
Value
{
return
v
.
underlying
.
raw
()
}
func
(
v
*
aString
)
Type
()
ValueType
{
return
v
.
typ
}
func
(
v
*
aString
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
underlying
.
EmitInit
()
}
func
(
v
*
aString
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
underlying
.
EmitPush
()
}
func
(
v
*
aString
)
raw
()
[]
wat
.
Value
{
return
v
.
aStruct
.
raw
()
}
func
(
v
*
aString
)
EmitPop
()
[]
wat
.
Inst
{
return
v
.
underlying
.
EmitPop
()
}
func
(
v
*
aString
)
EmitInit
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitInit
()
}
func
(
v
*
aString
)
EmitRelease
()
[]
wat
.
Inst
{
return
v
.
underlying
.
EmitRelease
()
}
func
(
v
*
aString
)
EmitPush
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPush
()
}
func
(
v
*
aString
)
EmitPop
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitPop
()
}
func
(
v
*
aString
)
EmitRelease
()
[]
wat
.
Inst
{
return
v
.
aStruct
.
EmitRelease
()
}
func
(
v
*
aString
)
emitStoreToAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
func
(
v
*
aString
)
emitStoreToAddr
(
addr
Value
,
offset
int
)
[]
wat
.
Inst
{
return
v
.
underlying
.
emitStoreToAddr
(
addr
,
offset
)
return
v
.
aStruct
.
emitStoreToAddr
(
addr
,
offset
)
}
}
func
(
v
*
aString
)
emitSub
(
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
func
(
v
*
aString
)
emitSub
(
low
,
high
Value
)
(
insts
[]
wat
.
Inst
)
{
//block
//block
insts
=
append
(
insts
,
v
.
underlying
.
Extract
(
"block"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
v
.
Extract
(
"block"
)
.
EmitPush
()
...
)
//data:
//data:
if
low
==
nil
{
if
low
==
nil
{
low
=
NewConst
(
"0"
,
U32
{})
low
=
NewConst
(
"0"
,
U32
{})
}
}
insts
=
append
(
insts
,
v
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
v
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
low
.
EmitPush
()
...
)
insts
=
append
(
insts
,
low
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
U32
{}))
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
U32
{}))
//len:
//len:
if
high
==
nil
{
if
high
==
nil
{
high
=
v
.
underlying
.
Extract
(
"len"
)
high
=
v
.
Extract
(
"len"
)
}
}
insts
=
append
(
insts
,
high
.
EmitPush
()
...
)
insts
=
append
(
insts
,
high
.
EmitPush
()
...
)
insts
=
append
(
insts
,
low
.
EmitPush
()
...
)
insts
=
append
(
insts
,
low
.
EmitPush
()
...
)
...
@@ -226,7 +228,7 @@ func (v *aString) emitSub(low, high Value) (insts []wat.Inst) {
...
@@ -226,7 +228,7 @@ func (v *aString) emitSub(low, high Value) (insts []wat.Inst) {
}
}
func
(
v
*
aString
)
emitAt
(
index
Value
)
(
insts
[]
wat
.
Inst
)
{
func
(
v
*
aString
)
emitAt
(
index
Value
)
(
insts
[]
wat
.
Inst
)
{
insts
=
append
(
insts
,
v
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
v
.
Extract
(
"data"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
index
.
EmitPush
()
...
)
insts
=
append
(
insts
,
index
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
insts
=
append
(
insts
,
wat
.
NewInstLoad8u
(
0
,
1
))
insts
=
append
(
insts
,
wat
.
NewInstLoad8u
(
0
,
1
))
...
@@ -234,13 +236,13 @@ func (v *aString) emitAt(index Value) (insts []wat.Inst) {
...
@@ -234,13 +236,13 @@ func (v *aString) emitAt(index Value) (insts []wat.Inst) {
}
}
func
(
v
*
aString
)
emitAt_CommaOk
(
index
Value
)
(
insts
[]
wat
.
Inst
)
{
func
(
v
*
aString
)
emitAt_CommaOk
(
index
Value
)
(
insts
[]
wat
.
Inst
)
{
insts
=
append
(
insts
,
v
.
underlying
.
Extract
(
"len"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
v
.
Extract
(
"len"
)
.
EmitPush
()
...
)
insts
=
append
(
insts
,
index
.
EmitPush
()
...
)
insts
=
append
(
insts
,
index
.
EmitPush
()
...
)
insts
=
append
(
insts
,
wat
.
NewInstGt
(
wat
.
U32
{}))
insts
=
append
(
insts
,
wat
.
NewInstGt
(
wat
.
U32
{}))
{
{
var
instsTrue
,
instsFalse
[]
wat
.
Inst
var
instsTrue
,
instsFalse
[]
wat
.
Inst
instsTrue
=
append
(
instsTrue
,
v
.
underlying
.
Extract
(
"data"
)
.
EmitPush
()
...
)
instsTrue
=
append
(
instsTrue
,
v
.
Extract
(
"data"
)
.
EmitPush
()
...
)
instsTrue
=
append
(
instsTrue
,
index
.
EmitPush
()
...
)
instsTrue
=
append
(
instsTrue
,
index
.
EmitPush
()
...
)
instsTrue
=
append
(
instsTrue
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
instsTrue
=
append
(
instsTrue
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
instsTrue
=
append
(
instsTrue
,
wat
.
NewInstLoad8u
(
0
,
1
))
instsTrue
=
append
(
instsTrue
,
wat
.
NewInstLoad8u
(
0
,
1
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录