using PhpefRuntimeCore;

static int failures = 0;

static void compare_zval(string label, string name, Zval native_result, Zval embed_result) {
    if (native_result.kind != embed_result.kind || native_result.to_php_string() != embed_result.to_php_string()) {
        stderr.printf("%s(%s) mismatch: native kind=%d value='%s', embed kind=%d value='%s'\n",
            label, name, (int) native_result.kind, native_result.to_php_string(), (int) embed_result.kind, embed_result.to_php_string());
        failures++;
    }
}

static void compare_constant(string name) {
    var arg = Zval.from_string(name);
    compare_zval("constant", name, PhpefRuntimeNativeStandard.phpfunc_constant(arg), PhpefRuntimeEmbed.phpfunc_constant(arg));
}

static void compare_typed_constant(string name) {
    compare_zval("constant_typed_zval_arg1_string", name,
        PhpefRuntimeNativeStandard.phpfunc_constant_typed_zval_arg1_string(name),
        PhpefRuntimeEmbed.phpfunc_constant(Zval.from_string(name)));
}

public static int main(string[] args) {
    PhpefRuntimeEmbed.engine_start(args);

    compare_constant("PHP_EOL");
    compare_constant("PHP_VERSION");
    compare_constant("PHP_VERSION_ID");
    compare_constant("PHP_OS_FAMILY");
    compare_constant("DIRECTORY_SEPARATOR");
    compare_constant("PATH_SEPARATOR");
    compare_constant("INF");
    compare_constant("NAN");

    compare_typed_constant("PHP_EOL");
    compare_typed_constant("PHP_VERSION_ID");
    compare_typed_constant("INF");

    PhpefRuntimeEmbed.engine_stop();
    return failures == 0 ? 0 : 1;
}
