Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
6b2266b2
wa
项目概览
wa-lang
/
wa
10 个月 前同步成功
通知
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 搜索 >>
提交
6b2266b2
编写于
2月 19, 2023
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加 string 的 = 和 != 函数
上级
ea73f508
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
4 deletion
+91
-4
internal/backends/compiler_wat/wir/instruction_emitter.go
internal/backends/compiler_wat/wir/instruction_emitter.go
+13
-3
internal/backends/compiler_wat/wir/value_string.go
internal/backends/compiler_wat/wir/value_string.go
+78
-1
未找到文件。
internal/backends/compiler_wat/wir/instruction_emitter.go
浏览文件 @
6b2266b2
...
...
@@ -51,7 +51,7 @@ func (m *Module) EmitBinOp(x, y Value, op wat.OpCode) (insts []wat.Inst, ret_typ
switch
op
{
case
wat
.
OpCodeAdd
:
if
rtype
.
Equal
(
m
.
STRING
)
{
insts
=
append
(
insts
,
wat
.
NewInstCall
(
m
.
STRING
.
(
*
String
)
.
gen
AppendStrFunc
()))
insts
=
append
(
insts
,
wat
.
NewInstCall
(
m
.
STRING
.
(
*
String
)
.
gen
Func_Append
()))
}
else
{
insts
=
append
(
insts
,
wat
.
NewInstAdd
(
toWatType
(
rtype
)))
}
...
...
@@ -74,11 +74,21 @@ func (m *Module) EmitBinOp(x, y Value, op wat.OpCode) (insts []wat.Inst, ret_typ
ret_type
=
rtype
case
wat
.
OpCodeEql
:
insts
=
append
(
insts
,
wat
.
NewInstEq
(
toWatType
(
rtype
)))
if
rtype
.
Equal
(
m
.
STRING
)
{
insts
=
append
(
insts
,
wat
.
NewInstCall
(
m
.
STRING
.
(
*
String
)
.
genFunc_Equal
()))
}
else
{
insts
=
append
(
insts
,
wat
.
NewInstEq
(
toWatType
(
rtype
)))
}
ret_type
=
m
.
I32
case
wat
.
OpCodeNe
:
insts
=
append
(
insts
,
wat
.
NewInstNe
(
toWatType
(
rtype
)))
if
rtype
.
Equal
(
m
.
STRING
)
{
insts
=
append
(
insts
,
wat
.
NewInstCall
(
m
.
STRING
.
(
*
String
)
.
genFunc_Equal
()))
insts
=
append
(
insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"1"
))
insts
=
append
(
insts
,
wat
.
NewInstXor
(
wat
.
I32
{}))
}
else
{
insts
=
append
(
insts
,
wat
.
NewInstNe
(
toWatType
(
rtype
)))
}
ret_type
=
m
.
I32
case
wat
.
OpCodeLt
:
...
...
internal/backends/compiler_wat/wir/value_string.go
浏览文件 @
6b2266b2
...
...
@@ -15,6 +15,7 @@ type String struct {
*
Struct
_u8
ValueType
_u32
ValueType
_i32
ValueType
_u8_block
*
Block
_u8_ptr
ValueType
}
...
...
@@ -28,6 +29,7 @@ func (m *Module) GenValueType_String() *String {
str_t
.
_u8
=
m
.
U8
str_t
.
_u32
=
m
.
U32
str_t
.
_i32
=
m
.
I32
str_t
.
_u8_block
=
m
.
GenValueType_Block
(
m
.
U8
)
str_t
.
_u8_ptr
=
m
.
GenValueType_Ptr
(
m
.
U8
)
...
...
@@ -52,7 +54,7 @@ func (t *String) EmitLoadFromAddr(addr Value, offset int) []wat.Inst {
return
t
.
Struct
.
EmitLoadFromAddr
(
addr
,
offset
)
}
func
(
t
*
String
)
gen
AppendStrFunc
()
string
{
func
(
t
*
String
)
gen
Func_Append
()
string
{
fn_name
:=
"$"
+
t
.
Name
()
+
".appendstr"
if
currentModule
.
FindFunc
(
fn_name
)
!=
nil
{
return
fn_name
...
...
@@ -187,6 +189,81 @@ func (t *String) genAppendStrFunc() string {
return
fn_name
}
func
(
t
*
String
)
genFunc_Equal
()
string
{
fn_name
:=
"$"
+
t
.
Name
()
+
".equal"
if
currentModule
.
FindFunc
(
fn_name
)
!=
nil
{
return
fn_name
}
var
f
Function
f
.
InternalName
=
fn_name
x
:=
newValue_String
(
"x"
,
ValueKindLocal
,
t
)
y
:=
newValue_String
(
"y"
,
ValueKindLocal
,
t
)
f
.
Params
=
append
(
f
.
Params
,
x
)
f
.
Params
=
append
(
f
.
Params
,
y
)
f
.
Results
=
append
(
f
.
Results
,
t
.
_i32
)
ret
:=
NewLocal
(
"ret"
,
t
.
_u32
)
f
.
Locals
=
append
(
f
.
Locals
,
ret
)
f
.
Insts
=
append
(
f
.
Insts
,
wat
.
NewInstConst
(
wat
.
I32
{},
"1"
))
f
.
Insts
=
append
(
f
.
Insts
,
ret
.
EmitPop
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y
.
Extract
(
"len"
)
.
EmitPush
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
wat
.
NewInstNe
(
wat
.
I32
{}))
inst_if
:=
wat
.
NewInstIf
(
nil
,
nil
,
nil
)
{
inst_if
.
True
=
append
(
inst_if
.
True
,
wat
.
NewInstConst
(
wat
.
I32
{},
"0"
))
inst_if
.
True
=
append
(
inst_if
.
True
,
ret
.
EmitPop
()
...
)
}
{
loop
:=
wat
.
NewInstLoop
(
"loop1"
)
{
loop
.
Insts
=
append
(
loop
.
Insts
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
{
if1
:=
wat
.
NewInstIf
(
nil
,
nil
,
nil
)
if1
.
True
=
append
(
if1
.
True
,
x
.
Extract
(
"data"
)
.
EmitPush
()
...
)
if1
.
True
=
append
(
if1
.
True
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
if1
.
True
=
append
(
if1
.
True
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
if1
.
True
=
append
(
if1
.
True
,
wat
.
NewInstLoad8u
(
0
,
1
))
if1
.
True
=
append
(
if1
.
True
,
y
.
Extract
(
"data"
)
.
EmitPush
()
...
)
if1
.
True
=
append
(
if1
.
True
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
if1
.
True
=
append
(
if1
.
True
,
wat
.
NewInstAdd
(
wat
.
I32
{}))
if1
.
True
=
append
(
if1
.
True
,
wat
.
NewInstLoad8u
(
0
,
1
))
if1
.
True
=
append
(
if1
.
True
,
wat
.
NewInstEq
(
wat
.
I32
{}))
if2
:=
wat
.
NewInstIf
(
nil
,
nil
,
nil
)
{
if2
.
True
=
append
(
if2
.
True
,
x
.
Extract
(
"len"
)
.
EmitPush
()
...
)
if2
.
True
=
append
(
if2
.
True
,
wat
.
NewInstConst
(
wat
.
I32
{},
"1"
))
if2
.
True
=
append
(
if2
.
True
,
wat
.
NewInstSub
(
wat
.
I32
{}))
if2
.
True
=
append
(
if2
.
True
,
x
.
Extract
(
"len"
)
.
EmitPop
()
...
)
if2
.
True
=
append
(
if2
.
True
,
wat
.
NewInstBr
(
"loop1"
))
}
if1
.
True
=
append
(
if1
.
True
,
if2
)
loop
.
Insts
=
append
(
loop
.
Insts
,
if1
)
}
}
inst_if
.
False
=
append
(
inst_if
.
False
,
loop
)
}
f
.
Insts
=
append
(
f
.
Insts
,
inst_if
)
f
.
Insts
=
append
(
f
.
Insts
,
x
.
EmitRelease
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
y
.
EmitRelease
()
...
)
f
.
Insts
=
append
(
f
.
Insts
,
ret
.
EmitPush
()
...
)
currentModule
.
AddFunc
(
&
f
)
return
fn_name
}
/**************************************
aString:
**************************************/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录