--- nono/lib/header.h 2026/04/29 17:05:05 1.1.1.14 +++ nono/lib/header.h 2026/04/29 17:05:08 1.1.1.15 @@ -4,12 +4,16 @@ // Licensed under nono-license.txt // +// +// 基本ヘッダ +// + #pragma once #define NONO_MAJOR_VER (0) -#define NONO_MINOR_VER (2) -#define NONO_PATCH_VER (3) -#define NONO_DATE "2021/10/03" +#define NONO_MINOR_VER (3) +#define NONO_PATCH_VER (0) +#define NONO_DATE "2022/04/30" #include "config-nono.h" #include @@ -27,7 +31,6 @@ #include #include #include -#include #include using uint8 = uint8_t; @@ -39,18 +42,12 @@ using int16 = int16_t; using int32 = int32_t; using int64 = int64_t; -#if defined(HAVE_ENDIAN_H) -#include -#elif defined(HAVE_SYS_ENDIAN_H) -#include -#else -#include "missing_endian.h" -#endif - #if defined(HAVE_BSD_BSD_H) #include #endif +#include "myendian.h" + #if !defined(__printflike) #if defined(HAVE___ATTRIBUTE_FORMAT) # define __printflike(a,b) __attribute__((__format__(__printf__, (a), (b)))) @@ -127,7 +124,7 @@ using int64 = int64_t; // 64ビット数と2つの32ビット数を扱う共用体。 // 構造はまったく同じだが名前だけ場所に合わせてつけたい。 -#if _BYTE_ORDER == _LITTLE_ENDIAN +#if BYTE_ORDER == LITTLE_ENDIAN #define DEF_UNION64(NAME, Q, H, L) \ union NAME { \ uint64 Q; \ @@ -151,8 +148,13 @@ DEF_UNION64(union64, q, h, l); #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #endif +#ifndef rounddown +#define rounddown(x, y) (((x)/(y))*(y)) +#endif + // メッセージ付きの assert。 // 本当は後ろに足したいのだがそれは無理なので、せめてそれっぽく1行にしてみる。 +#if !defined(NDEBUG) #define assertmsg(expr, ...) do { \ if (__predict_false(!(expr))) { \ fprintf(stderr, __VA_ARGS__); \ @@ -160,6 +162,9 @@ DEF_UNION64(union64, q, h, l); assert(expr); \ } \ } while (0) +#else +#define assertmsg(expr, ...) +#endif // atomic_compare_exchange_strong() の短縮マクロ。 // ライブラリ実装は第2引数の expected が値ではなくポインタなので一旦代入操作を @@ -179,7 +184,12 @@ DEF_UNION64(union64, q, h, l); atomic_compare_exchange_strong((varp), &expected, (uint32)(newval)); \ }) -// ログ +// パニック (PC を表示しない) #define PANIC(...) panic(__PRETTY_FUNCTION__, __VA_ARGS__) [[noreturn]] extern void panic(const char *funcname, const char *fmt, ...) __printflike(2, 3); + +// VM 用パニック (PC を表示する) +#define VMPANIC(...) vmpanic(__PRETTY_FUNCTION__, __VA_ARGS__) +[[noreturn]] extern void vmpanic(const char *funcname, const char *fmt, ...) + __printflike(2, 3);