mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
module testing;
|
|
import std::io;
|
|
|
|
fn void! main()
|
|
{
|
|
String[] s1;
|
|
String[] s2;
|
|
assert(false, "%s / %s", deep_print(s1), deep_print(s2)); // #error: This expression is of type
|
|
}
|
|
|
|
macro deep_print(a)
|
|
{
|
|
var $Type = $typeof(a);
|
|
$switch ($Type.kindof)
|
|
$case ARRAY:
|
|
$case SUBARRAY:
|
|
io::print("[");
|
|
foreach (i, x : a)
|
|
{
|
|
if (i > 0) io::print(", ");
|
|
deep_print(x);
|
|
}
|
|
io::print("]");
|
|
$case STRUCT:
|
|
io::print("{");
|
|
$foreach ($i, $m : $typeof(a).membersof)
|
|
if ($i > 0) io::print(", ");
|
|
deep_print(a.$eval($m.nameof));
|
|
$endforeach
|
|
io::print("}");
|
|
$default:
|
|
$switch ($Type.nameof)
|
|
$case "String":
|
|
$case "DString":
|
|
$case "WString":
|
|
$case "ZString":
|
|
io::printf(`"%s"`, a);
|
|
$default:
|
|
io::printf("%s", a);
|
|
$endswitch
|
|
$endswitch
|
|
} |