feat: 命名参数 draw_rect(width: 10, height: 20)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
fn draw_rect(x: i64, y: i64, w: i64, h: i64) -> i64 {
|
||||
print_i64(x);
|
||||
print_i64(y);
|
||||
print_i64(w);
|
||||
print_i64(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn main() -> i64 {
|
||||
// 位置参数
|
||||
draw_rect(0, 0, 100, 200);
|
||||
|
||||
// 命名参数(任意顺序)
|
||||
draw_rect(w: 10, h: 20, x: 1, y: 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+3
-3
@@ -258,7 +258,7 @@ void test_codegen_enum() {
|
||||
AstNode* c_ident = ast_make_ident(&a, "c", loc_at(1, 1));
|
||||
c_ident->type.kind = TYPE_ENUM;
|
||||
AstNode* args[] = { c_ident };
|
||||
AstNode* print_call = ast_make_call(&a, "print_i64", args, 1, loc_at(1, 1));
|
||||
AstNode* print_call = ast_make_call(&a, "print_i64", args, NULL, 1, loc_at(1, 1));
|
||||
|
||||
/* return 0; */
|
||||
AstNode* ret = ast_make_return(&a, ast_make_literal_i64(&a, 0, loc_at(1, 1)), loc_at(1, 1));
|
||||
@@ -323,7 +323,7 @@ void test_codegen_array() {
|
||||
|
||||
// print_i64(arr[0]);
|
||||
AstNode* args[] = { idx_expr };
|
||||
AstNode* print_call = ast_make_call(&a, "print_i64", args, 1, loc_at(1, 1));
|
||||
AstNode* print_call = ast_make_call(&a, "print_i64", args, NULL, 1, loc_at(1, 1));
|
||||
|
||||
// return 0;
|
||||
AstNode* ret = ast_make_return(&a, ast_make_literal_i64(&a, 0, loc_at(1, 1)), loc_at(1, 1));
|
||||
@@ -393,7 +393,7 @@ void test_codegen_method_call() {
|
||||
AstNode* p_ident = ast_make_ident(&a, "p", loc_at(1, 1));
|
||||
p_ident->type.kind = TYPE_STRUCT;
|
||||
p_ident->type.struct_name = "Point";
|
||||
AstNode* method_call = ast_make_method_call(&a, p_ident, "get_x", NULL, 0, loc_at(1, 1));
|
||||
AstNode* method_call = ast_make_method_call(&a, p_ident, "get_x", NULL, NULL, 0, loc_at(1, 1));
|
||||
method_call->type.kind = TYPE_I64;
|
||||
|
||||
AstNode* ret_main = ast_make_return(&a, method_call, loc_at(1, 1));
|
||||
|
||||
Reference in New Issue
Block a user