diff --git a/src/compiler/copying.c b/src/compiler/copying.c index df84430d1..cb8a341b0 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -573,7 +573,7 @@ TypeInfo *copy_type_info(CopyStruct *c, TypeInfo *source) return copy; case TYPE_INFO_EVALTYPE: case TYPE_INFO_EXPRESSION: - case TYPE_INFO_VAARG_TYPE: + case TYPE_INFO_VATYPE: assert(source->resolve_status == RESOLVE_NOT_DONE); copy->unresolved_type_expr = copy_expr(c, source->unresolved_type_expr); return copy; diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 8773ad44a..84e74e36f 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -357,7 +357,7 @@ typedef enum TYPE_INFO_IDENTIFIER, TYPE_INFO_CT_IDENTIFIER, TYPE_INFO_EXPRESSION, - TYPE_INFO_VAARG_TYPE, + TYPE_INFO_VATYPE, TYPE_INFO_EVALTYPE, TYPE_INFO_ARRAY, TYPE_INFO_VECTOR, @@ -560,12 +560,12 @@ typedef enum TOKEN_CT_TYPEOF, // $typeof TOKEN_CT_CONVERTIBLE, // $convertible TOKEN_CT_CASTABLE, // $castable - TOKEN_CT_VAARG_COUNT, // $vaarg_count - TOKEN_CT_VAARG_GET_TYPE, // $vaarg_get_type - TOKEN_CT_VAARG_GET_CONST, // $vaarg_get_const, - TOKEN_CT_VAARG_GET_REF, // $vaarg_get_ref, - TOKEN_CT_VAARG_GET_ARG, // $vaarg_get_arg, - TOKEN_CT_VAARG_GET_EXPR, // $vaarg_get_expr, + TOKEN_CT_VACOUNT, // $vacount + TOKEN_CT_VATYPE, // $vatype + TOKEN_CT_VACONST, // $vaconst, + TOKEN_CT_VAREF, // $varef, + TOKEN_CT_VAARG, // $vaarg, + TOKEN_CT_VAEXPR, // $vaexpr, TOKEN_DOCS_START, // /** TOKEN_DOCS_END, // */ (may start with an arbitrary number of `*` TOKEN_DOC_DIRECTIVE, // Any doc directive @@ -585,7 +585,7 @@ typedef enum #define TYPE_TOKENS NON_VOID_TYPE_TOKENS: case TOKEN_VOID #define TYPELIKE_TOKENS TYPE_TOKENS: case TOKEN_TYPE_IDENT: \ case TOKEN_CT_TYPE_IDENT: case TOKEN_CT_TYPEOF: case TOKEN_CT_EVALTYPE: \ - case TOKEN_CT_VAARG_GET_TYPE + case TOKEN_CT_VATYPE // Note that ordering matters here. If ordering is changed, // So must type_find_max_type and friends. diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index 6a0d1babb..992f76ea7 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -918,10 +918,10 @@ static Expr *parse_ct_arg(ParseContext *c, Expr *left) assert(!left && "Unexpected left hand side"); Expr *expr = EXPR_NEW_TOKEN(EXPR_CT_ARG); TokenType type = expr->ct_arg_expr.type = c->tok; - assert(type != TOKEN_CT_VAARG_GET_TYPE); + assert(type != TOKEN_CT_VATYPE); advance(c); CONSUME_OR_RET(TOKEN_LPAREN, poisoned_expr); - if (type != TOKEN_CT_VAARG_COUNT) + if (type != TOKEN_CT_VACOUNT) { ASSIGN_EXPRID_OR_RET(expr->ct_arg_expr.arg, parse_expr(c), poisoned_expr); } @@ -1756,10 +1756,10 @@ ParseRule rules[TOKEN_EOF + 1] = { [TOKEN_CT_CONVERTIBLE] = { parse_ct_conv, NULL, PREC_NONE }, [TOKEN_CT_CASTABLE] = { parse_ct_conv, NULL, PREC_NONE }, [TOKEN_LBRACE] = { parse_initializer_list, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_COUNT] = { parse_ct_arg, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_GET_ARG] = { parse_ct_arg, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_GET_REF] = { parse_ct_arg, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_GET_TYPE] = { parse_type_expr, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_GET_EXPR] = { parse_ct_arg, NULL, PREC_NONE }, - [TOKEN_CT_VAARG_GET_CONST] = { parse_ct_arg, NULL, PREC_NONE }, + [TOKEN_CT_VACOUNT] = { parse_ct_arg, NULL, PREC_NONE }, + [TOKEN_CT_VAARG] = { parse_ct_arg, NULL, PREC_NONE }, + [TOKEN_CT_VAREF] = { parse_ct_arg, NULL, PREC_NONE }, + [TOKEN_CT_VATYPE] = { parse_type_expr, NULL, PREC_NONE }, + [TOKEN_CT_VAEXPR] = { parse_ct_arg, NULL, PREC_NONE }, + [TOKEN_CT_VACONST] = { parse_ct_arg, NULL, PREC_NONE }, }; diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 7d414eb43..33a41c052 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -491,9 +491,9 @@ static inline TypeInfo *parse_base_type(ParseContext *c) RANGE_EXTEND_PREV(type_info); return type_info; } - if (try_consume(c, TOKEN_CT_VAARG_GET_TYPE)) + if (try_consume(c, TOKEN_CT_VATYPE)) { - TypeInfo *type_info = type_info_new(TYPE_INFO_VAARG_TYPE, c->prev_span); + TypeInfo *type_info = type_info_new(TYPE_INFO_VATYPE, c->prev_span); CONSUME_OR_RET(TOKEN_LPAREN, poisoned_type_info); ASSIGN_EXPR_OR_RET(type_info->unresolved_type_expr, parse_expr(c), poisoned_type_info); CONSUME_OR_RET(TOKEN_RPAREN, poisoned_type_info); diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 45fc0da1d..d53c2e83c 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1210,11 +1210,11 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_CATCH: case TOKEN_BYTES: case TOKEN_BUILTIN: - case TOKEN_CT_VAARG_COUNT: - case TOKEN_CT_VAARG_GET_ARG: - case TOKEN_CT_VAARG_GET_EXPR: - case TOKEN_CT_VAARG_GET_CONST: - case TOKEN_CT_VAARG_GET_REF: + case TOKEN_CT_VACOUNT: + case TOKEN_CT_VAARG: + case TOKEN_CT_VAEXPR: + case TOKEN_CT_VACONST: + case TOKEN_CT_VAREF: return parse_expr_stmt(c); case TOKEN_ASSERT: return parse_assert_stmt(c); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 31eaf8dde..8643767c7 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -7551,7 +7551,7 @@ RETRY: if (!decl_ok(decl)) return poisoned_type; return decl->type->canonical; } - case TYPE_INFO_VAARG_TYPE: + case TYPE_INFO_VATYPE: if (!sema_resolve_type_info(context, type_info)) return poisoned_type; return type_info->type->canonical; case TYPE_INFO_EXPRESSION: @@ -7719,10 +7719,10 @@ static inline bool sema_expr_analyse_ct_arg(SemaContext *context, Expr *expr) } switch (type) { - case TOKEN_CT_VAARG_COUNT: + case TOKEN_CT_VACOUNT: expr_rewrite_const_int(expr, type_usize, vec_size(context->macro_varargs), true); return true; - case TOKEN_CT_VAARG_GET_ARG: + case TOKEN_CT_VAARG: { // A normal argument, this means we only evaluate it once. ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, exprptr(expr->ct_arg_expr.arg)), false); @@ -7752,14 +7752,14 @@ static inline bool sema_expr_analyse_ct_arg(SemaContext *context, Expr *expr) expr->type = decl->type; return true; } - case TOKEN_CT_VAARG_GET_EXPR: + case TOKEN_CT_VAEXPR: { // An expr argument, this means we copy and evaluate. ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, exprptr(expr->ct_arg_expr.arg)), false); expr_replace(expr, expr_macro_copy(arg_expr)); return true; } - case TOKEN_CT_VAARG_GET_CONST: + case TOKEN_CT_VACONST: { // An expr argument, this means we copy and evaluate. ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, exprptr(expr->ct_arg_expr.arg)), false); @@ -7772,7 +7772,7 @@ static inline bool sema_expr_analyse_ct_arg(SemaContext *context, Expr *expr) expr_replace(expr, arg_expr); return true; } - case TOKEN_CT_VAARG_GET_REF: + case TOKEN_CT_VAREF: { // A normal argument, this means we only evaluate it once. ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, exprptr(expr->ct_arg_expr.arg)), false); @@ -7805,7 +7805,7 @@ static inline bool sema_expr_analyse_ct_arg(SemaContext *context, Expr *expr) expr->type = decl->type; return true; } - case TOKEN_CT_VAARG_GET_TYPE: + case TOKEN_CT_VATYPE: default: UNREACHABLE; } diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 4e8ac0e69..0a7311562 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -254,7 +254,7 @@ RETRY: { case TYPE_INFO_POISON: UNREACHABLE - case TYPE_INFO_VAARG_TYPE: + case TYPE_INFO_VATYPE: if (context->current_macro) { ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, type_info->unresolved_type_expr), false); @@ -267,7 +267,7 @@ RETRY: assert(type_info->resolve_status == RESOLVE_DONE); return true; } - SEMA_ERROR(type_info, "'%s' can only be used inside of a macro.", token_type_to_string(TOKEN_CT_VAARG_GET_TYPE)); + SEMA_ERROR(type_info, "'%s' can only be used inside of a macro.", token_type_to_string(TOKEN_CT_VATYPE)); return false; case TYPE_INFO_CT_IDENTIFIER: case TYPE_INFO_IDENTIFIER: diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index a0f09a33d..460362969 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -356,18 +356,18 @@ const char *token_type_to_string(TokenType type) return "$extnameof"; case TOKEN_CT_IF: return "$if"; - case TOKEN_CT_VAARG_COUNT: - return "$vaarg_count"; - case TOKEN_CT_VAARG_GET_TYPE: - return "$vaarg_get_type"; - case TOKEN_CT_VAARG_GET_CONST: - return "$vaarg_get_const"; - case TOKEN_CT_VAARG_GET_ARG: - return "$vaarg_get_arg"; - case TOKEN_CT_VAARG_GET_REF: - return "$vaarg_get_ref"; - case TOKEN_CT_VAARG_GET_EXPR: - return "$vaarg_get_expr"; + case TOKEN_CT_VACOUNT: + return "$vacount"; + case TOKEN_CT_VATYPE: + return "$vatype"; + case TOKEN_CT_VACONST: + return "$vaconst"; + case TOKEN_CT_VAARG: + return "$vaarg"; + case TOKEN_CT_VAREF: + return "$varef"; + case TOKEN_CT_VAEXPR: + return "$vaexpr"; case TOKEN_CT_NAMEOF: return "$nameof"; case TOKEN_CT_OFFSETOF: @@ -395,6 +395,6 @@ const char *token_type_to_string(TokenType type) bool token_is_any_type(TokenType type) { - return (type >= TOKEN_VOID && type <= TOKEN_TYPEID) || type == TOKEN_CT_TYPE_IDENT || type == TOKEN_TYPE_IDENT || type == TOKEN_CT_VAARG_GET_TYPE; + return (type >= TOKEN_VOID && type <= TOKEN_TYPEID) || type == TOKEN_CT_TYPE_IDENT || type == TOKEN_TYPE_IDENT || type == TOKEN_CT_VATYPE; } diff --git a/src/version.h b/src/version.h index 76bd411a3..d8efbd2e2 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.34" \ No newline at end of file +#define COMPILER_VERSION "0.3.35" \ No newline at end of file diff --git a/test/test_suite/macros/macro_untyped_varargs.c3 b/test/test_suite/macros/macro_untyped_varargs.c3 index 6360af3c1..2084ccac4 100644 --- a/test/test_suite/macros/macro_untyped_varargs.c3 +++ b/test/test_suite/macros/macro_untyped_varargs.c3 @@ -1,20 +1,20 @@ macro foo(...) { - $vaarg_get_arg("hello"); // #error: Expected the argument index here + $vaarg("hello"); // #error: Expected the argument index here int x; - $vaarg_get_arg(x); // #error: Vararg functions need a constant argument - $vaarg_get_arg(-1); // #error: negative - $vaarg_get_arg(100); // #error: varargs exist + $vaarg(x); // #error: Vararg functions need a constant argument + $vaarg(-1); // #error: negative + $vaarg(100); // #error: varargs exist } macro foo2(...) { - $vaarg_get_const(0); + $vaconst(0); } macro foo3(...) { - $vaarg_get_type(0) a; + $vatype(0) a; } fn void main() { diff --git a/test/test_suite/macros/macro_untyped_varargs_2.c3t b/test/test_suite/macros/macro_untyped_varargs_2.c3t index 7f736d08d..dbd0feffa 100644 --- a/test/test_suite/macros/macro_untyped_varargs_2.c3t +++ b/test/test_suite/macros/macro_untyped_varargs_2.c3t @@ -6,37 +6,37 @@ import std::io; macro @foo(...) { - int i = $vaarg_get_arg(1) + $vaarg_get_arg(1); - int j = $vaarg_get_expr(2) + $vaarg_get_expr(2); - $for (var $i = 0; $i < $vaarg_count(); $i++): - io::printfln("%d", $vaarg_get_arg($i)); + int i = $vaarg(1) + $vaarg(1); + int j = $vaexpr(2) + $vaexpr(2); + $for (var $i = 0; $i < $vacount(); $i++): + io::printfln("%d", $vaarg($i)); $endfor; } macro foo2(...) { - $for (var $i = 0; $i < $vaarg_count(); $i++): + $for (var $i = 0; $i < $vacount(); $i++): { - $vaarg_get_type($i) x; + $vatype($i) x; } - io::printfln("%s", $nameof($vaarg_get_type($i))); + io::printfln("%s", $nameof($vatype($i))); $endfor; } macro foo3(...) { var $x = 0; - $for (var $i = 0; $i < $vaarg_count(); $i++): - $x += $vaarg_get_const($i); + $for (var $i = 0; $i < $vacount(); $i++): + $x += $vaconst($i); $endfor; return $x; } macro @foo4(...) { - $typeof($vaarg_get_ref(0)) a = $vaarg_get_ref(0); - $vaarg_get_ref(0) = $vaarg_get_ref(1); - $vaarg_get_ref(1) = a; + $typeof($varef(0)) a = $varef(0); + $varef(0) = $varef(1); + $varef(1) = a; } fn int ping(int val) { diff --git a/test/test_suite2/macros/macro_untyped_varargs.c3 b/test/test_suite2/macros/macro_untyped_varargs.c3 index 6360af3c1..2084ccac4 100644 --- a/test/test_suite2/macros/macro_untyped_varargs.c3 +++ b/test/test_suite2/macros/macro_untyped_varargs.c3 @@ -1,20 +1,20 @@ macro foo(...) { - $vaarg_get_arg("hello"); // #error: Expected the argument index here + $vaarg("hello"); // #error: Expected the argument index here int x; - $vaarg_get_arg(x); // #error: Vararg functions need a constant argument - $vaarg_get_arg(-1); // #error: negative - $vaarg_get_arg(100); // #error: varargs exist + $vaarg(x); // #error: Vararg functions need a constant argument + $vaarg(-1); // #error: negative + $vaarg(100); // #error: varargs exist } macro foo2(...) { - $vaarg_get_const(0); + $vaconst(0); } macro foo3(...) { - $vaarg_get_type(0) a; + $vatype(0) a; } fn void main() { diff --git a/test/test_suite2/macros/macro_untyped_varargs_2.c3t b/test/test_suite2/macros/macro_untyped_varargs_2.c3t index 74aa8cb33..f3f4f9807 100644 --- a/test/test_suite2/macros/macro_untyped_varargs_2.c3t +++ b/test/test_suite2/macros/macro_untyped_varargs_2.c3t @@ -6,37 +6,37 @@ import std::io; macro @foo(...) { - int i = $vaarg_get_arg(1) + $vaarg_get_arg(1); - int j = $vaarg_get_expr(2) + $vaarg_get_expr(2); - $for (var $i = 0; $i < $vaarg_count(); $i++): - io::printfln("%d", $vaarg_get_arg($i)); + int i = $vaarg(1) + $vaarg(1); + int j = $vaexpr(2) + $vaexpr(2); + $for (var $i = 0; $i < $vacount(); $i++): + io::printfln("%d", $vaarg($i)); $endfor; } macro foo2(...) { - $for (var $i = 0; $i < $vaarg_count(); $i++): + $for (var $i = 0; $i < $vacount(); $i++): { - $vaarg_get_type($i) x; + $vatype($i) x; } - io::printfln("%s", $nameof($vaarg_get_type($i))); + io::printfln("%s", $nameof($vatype($i))); $endfor; } macro foo3(...) { var $x = 0; - $for (var $i = 0; $i < $vaarg_count(); $i++): - $x += $vaarg_get_const($i); + $for (var $i = 0; $i < $vacount(); $i++): + $x += $vaconst($i); $endfor; return $x; } macro @foo4(...) { - $typeof($vaarg_get_ref(0)) a = $vaarg_get_ref(0); - $vaarg_get_ref(0) = $vaarg_get_ref(1); - $vaarg_get_ref(1) = a; + $typeof($varef(0)) a = $varef(0); + $varef(0) = $varef(1); + $varef(1) = a; } fn int ping(int val) {