aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compile.c19
-rw-r--r--src/stdlib/print.h4
-rw-r--r--src/stdlib/stdlib.h15
-rw-r--r--src/stdlib/util.h8
4 files changed, 33 insertions, 13 deletions
diff --git a/src/compile.c b/src/compile.c
index 95a79ec5..052fe309 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -1044,7 +1044,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
}
auto enum_t = Match(subject_t, EnumType);
- CORD code = CORD_all("WHEN(", compile(env, when->subject), ", _when_subject, {\n");
+ CORD code = CORD_all("WHEN(", compile_type(subject_t), ", ", compile(env, when->subject), ", _when_subject, {\n");
for (when_clause_t *clause = when->clauses; clause; clause = clause->next) {
if (clause->pattern->tag == Var) {
const char *clause_tag_name = Match(clause->pattern, Var)->name;
@@ -1207,19 +1207,26 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
}
if (test->expected) {
return CORD_asprintf(
- "%rtest(%r, %r, %r, %ld, %ld);",
- setup, test_code,
+ "%rtest(%r, %r, %r, %r, %ld, %ld);",
+ setup, compile_type(expr_t), test_code,
compile_to_type(env, test->expected, expr_t),
compile_type_info(expr_t),
(int64_t)(test->expr->start - test->expr->file->text),
(int64_t)(test->expr->end - test->expr->file->text));
} else {
- return CORD_asprintf(
- "%rinspect(%r, %r, %ld, %ld);",
+ if (expr_t->tag == VoidType || expr_t->tag == AbortType) {
+ return CORD_asprintf("%rinspect_void(%r, %r, %ld, %ld);",
setup, test_code,
compile_type_info(expr_t),
(int64_t)(test->expr->start - test->expr->file->text),
(int64_t)(test->expr->end - test->expr->file->text));
+ }
+ return CORD_asprintf(
+ "%rinspect(%r, %r, %r, %ld, %ld);",
+ setup, compile_type(expr_t), test_code,
+ compile_type_info(expr_t),
+ (int64_t)(test->expr->start - test->expr->file->text),
+ (int64_t)(test->expr->end - test->expr->file->text));
}
}
case Declare: {
@@ -2998,7 +3005,7 @@ CORD compile(env_t *env, ast_t *ast)
CORD userdata;
if (Table$length(closed_vars) == 0) {
- code = CORD_cat(code, "void *)");
+ code = CORD_cat(code, "void *_)");
userdata = "NULL";
} else {
userdata = CORD_all("new(", name, "$userdata_t");
diff --git a/src/stdlib/print.h b/src/stdlib/print.h
index 60c9c139..243826e0 100644
--- a/src/stdlib/print.h
+++ b/src/stdlib/print.h
@@ -33,8 +33,12 @@
// GCC lets you define macro-like functions which are always inlined and never
// compiled using this combination of flags. See: https://gcc.gnu.org/onlinedocs/gcc/Inline.html
#ifndef PRINT_FN
+#ifdef __TINYC__
+#define PRINT_FN static inline __attribute__((gnu_inline, always_inline)) int
+#else
#define PRINT_FN extern inline __attribute__((gnu_inline, always_inline)) int
#endif
+#endif
typedef struct {
uint64_t n;
diff --git a/src/stdlib/stdlib.h b/src/stdlib/stdlib.h
index ae2079e3..a452a04b 100644
--- a/src/stdlib/stdlib.h
+++ b/src/stdlib/stdlib.h
@@ -68,16 +68,21 @@ __attribute__((nonnull))
void start_inspect(const char *filename, int64_t start, int64_t end);
__attribute__((nonnull))
void end_inspect(const void *expr, const TypeInfo_t *type);
-#define inspect(expr, typeinfo, start, end) {\
+#define inspect(type, expr, typeinfo, start, end) {\
start_inspect(__SOURCE_FILE__, start, end); \
- auto _expr = expr; \
+ type _expr = expr; \
end_inspect(&_expr, typeinfo); \
}
+#define inspect_void(expr, typeinfo, start, end) {\
+ start_inspect(__SOURCE_FILE__, start, end); \
+ expr; \
+ end_inspect(NULL, typeinfo); \
+}
__attribute__((nonnull))
void test_value(const char *filename, int64_t start, int64_t end, const void *expr, const void *expected, const TypeInfo_t *type);
-#define test(expr, expected, typeinfo, start, end) {\
- auto _expr = expr; \
- auto _expected = expected; \
+#define test(type, expr, expected, typeinfo, start, end) {\
+ type _expr = expr; \
+ type _expected = expected; \
test_value(__SOURCE_FILE__, start, end, &_expr, &_expected, typeinfo); \
}
diff --git a/src/stdlib/util.h b/src/stdlib/util.h
index 45bf1d7b..4cb1b375 100644
--- a/src/stdlib/util.h
+++ b/src/stdlib/util.h
@@ -19,12 +19,12 @@
#define IF_DECLARE(decl, expr, block) if (({ decl; expr ? ({ block; 1; }) : 0; })) {}
-#define WHEN(subj, var, body) { auto var = subj; switch (var.$tag) body }
-
#ifndef auto
#define auto __auto_type
#endif
+#define WHEN(type, subj, var, body) { type var = subj; switch (var.$tag) body }
+
#ifndef public
#define public __attribute__ ((visibility ("default")))
#endif
@@ -52,7 +52,11 @@
// GCC lets you define macro-like functions which are always inlined and never
// compiled using this combination of flags. See: https://gcc.gnu.org/onlinedocs/gcc/Inline.html
#ifndef MACROLIKE
+#ifdef __TINYC__
+#define MACROLIKE static inline __attribute__((gnu_inline, always_inline))
+#else
#define MACROLIKE extern inline __attribute__((gnu_inline, always_inline))
#endif
+#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0