Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compiler/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,26 @@ generate_identifier_expression(SVM_Executable *exe, Block *block,
}
}

static void
generate_push_argument(SVM_Executable *exe, Block *block,
ArgumentList *arg_list, OpcodeBuf *ob)
{
ArgumentList *arg_pos;

for (arg_pos = arg_list; arg_pos; arg_pos = arg_pos->next) {
generate_expression(exe, block, arg_pos->expr, ob);
}
}

static void
generate_function_call_expression(SVM_Executable *exe, Block *block,
Expression *expr, OpcodeBuf *ob)
{
FuncCallExpression *fce = &expr->u.func_call_expression;
generate_push_argument(exe, block, fce->argument_list, ob);
generate_expression(exe, block, fce->argument_list->expr, ob);
// which op for func call?
// generate_code(ob, code);
}

static void
Expand Down
39 changes: 39 additions & 0 deletions main/test/superconduct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 三个资产类型全局常量,可以先用全局变量实现
// asset资产类型,32个字节长度的资产
assetX := asset(1) // int类型强转
Copy link
Contributor

@shenao78 shenao78 Aug 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全局变量定义用var来定义
var (
......
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个几种定义方式都可以的吧

assetY := asset(2)
assetM := asset(3)

// struct结构描述合约结构:field为三资产池状态数据,function为存取兑解锁函数
// 暂通过全局函数实现

// 三资产池状态数据[poolAmtX,poolAmtY,poolAmtM]构造交易时传入,存入辅栈

// 全局函数实现存取兑

// 构造交易时传入参数:兑换资产idassetX, 数量amtX, 选择swap兑换功能,checkoutput缠绕合约的program
// 如:[][]byte{assetX.Bytes(),amtX,swap,program}
// 状态数据传入参数,三资产池资产数量state [poolAmtX,poolAmtY,poolAmtM]
// 注意这里传参summoner的处理过程
// 如:[][]byte{vm.Int64Bytes(10), vm.Int64Bytes(100), vm.Int64Bytes(1000)}
func Swap(amtX amount) { // 资产数量amount无符号整型,可为uint64类型别名
verify(amtX > 0) // 暂builtin实现
verify(poolAmtX * poolAmtY == poolAmtM)

newPoolAmtX := poolAmtX + amtX // 暂不计算手续费
newPoolAmtY := poolAmtM / newPoolAmtX

lock(newPoolAmtX, assetX, program, state) // 注:state经过summoner取算存的过程
lock(newPoolAmtY, assetY, program, state)
lock(poolAmtM, assetM, program, state)
}

// TOOD
func AddLiquidity(amtX amount, amtY amount) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型首字母大写

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是否需要跟golang保持一致 还有函数的首字母

}

// TOOD
func RemoveLiquidity(amtX amount, amtY amount) {
}