Rename $vaarg functions. Bump version to 0.3.35.

This commit is contained in:
Christoffer Lerno
2022-09-07 10:28:41 +02:00
committed by Christoffer Lerno
parent 7cb03de16b
commit 8eefce235f
13 changed files with 83 additions and 83 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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 },
};

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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:

View File

@@ -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;
}

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.34"
#define COMPILER_VERSION "0.3.35"

View File

@@ -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()
{

View File

@@ -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)
{

View File

@@ -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()
{

View File

@@ -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)
{