« blib/lib/SPVM/Document/NativeAPI/BasicType.pm
↑ Summary
blib/lib/SPVM/Document/NativeAPI/ClassFile.pm »
| 1 | =head1 Name | ||
| 2 | |||
| 3 | SPVM::Document::NativeAPI::CFunction - C Function Native APIs | ||
| 4 | |||
| 5 | =head1 Description | ||
| 6 | |||
| 7 | Native APIs for C standard functions. | ||
| 8 | |||
| 9 | =head1 Details | ||
| 10 | |||
| 11 | These native APIs are provided to safely invoke C standard functions linked into the SPVM runtime. | ||
| 12 | |||
| 13 | These APIs are designed to allow precompiled C source code to function without depending on C standard header include paths, which is essential when performing JIT compilation using TCC or MIR. | ||
| 14 | |||
| 15 | =head1 Usage | ||
| 16 | |||
| 17 | SPVM_API_CFUNC* api_cfunc = env->api->cfunc; | ||
| 18 | |||
| 19 | =head1 Native APIs | ||
| 20 | |||
| 21 | =head2 c_strlen | ||
| 22 | |||
| 23 | C<size_t (*c_strlen)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const char* str);> | ||
| 24 | |||
| 25 | A wrapper for the C standard function L<strlen|https://linux.die.net/man/3/strlen>. | ||
| 26 | |||
| 27 | =head2 c_memcpy | ||
| 28 | |||
| 29 | C<void* (*c_memcpy)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, void* dest, const void* src, size_t n);> | ||
| 30 | |||
| 31 | A wrapper for the C standard function L<memcpy|https://linux.die.net/man/3/memcpy>. | ||
| 32 | |||
| 33 | =head2 c_memset | ||
| 34 | |||
| 35 | C<void* (*c_memset)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, void* s, int c, size_t n);> | ||
| 36 | |||
| 37 | A wrapper for the C standard function L<memset|https://linux.die.net/man/3/memset>. | ||
| 38 | |||
| 39 | =head2 c_memcmp | ||
| 40 | |||
| 41 | C<int (*c_memcmp)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const void* s1, const void* s2, size_t n);> | ||
| 42 | |||
| 43 | A wrapper for the C standard function L<memcmp|https://linux.die.net/man/3/memcmp>. | ||
| 44 | |||
| 45 | =head2 c_strtoll | ||
| 46 | |||
| 47 | C<long long (*c_strtoll)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const char* str, char** endptr, int base);> | ||
| 48 | |||
| 49 | A wrapper for the C standard function L<strtoll|https://linux.die.net/man/3/strtoll>. | ||
| 50 | |||
| 51 | =head2 c_strtof | ||
| 52 | |||
| 53 | C<float (*c_strtof)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const char* str, char** endptr);> | ||
| 54 | |||
| 55 | A wrapper for the C standard function L<strtof|https://linux.die.net/man/3/strtof>. | ||
| 56 | |||
| 57 | =head2 c_strtod | ||
| 58 | |||
| 59 | C<double (*c_strtod)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const char* str, char** endptr);> | ||
| 60 | |||
| 61 | A wrapper for the C standard function L<strtod|https://linux.die.net/man/3/strtod>. | ||
| 62 | |||
| 63 | =head2 c_fputs | ||
| 64 | |||
| 65 | C<int (*c_fputs)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, const char* s, void* stream);> | ||
| 66 | |||
| 67 | A wrapper for the C standard function L<fputs|https://linux.die.net/man/3/fputs>. | ||
| 68 | |||
| 69 | =head2 c_fgetc | ||
| 70 | |||
| 71 | C<int (*c_fgetc)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, void* stream);> | ||
| 72 | |||
| 73 | A wrapper for the C standard function L<fgetc|https://linux.die.net/man/3/fgetc>. | ||
| 74 | |||
| 75 | =head2 c_snprintf_len | ||
| 76 | |||
| 77 | C<int32_t (*c_snprintf_len)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, char* s, size_t n, const char* format, L<SPVM_VALUE* args|SPVM::Document::NativeClass/"Runtime Stack">, int32_t args_length);> | ||
| 78 | |||
| 79 | A wrapper for the C standard function L<snprintf|https://linux.die.net/man/3/snprintf>. | ||
| 80 | |||
| 81 | This function receives arguments as an array of L<SPVM_VALUE|SPVM::Document::NativeClass/"Runtime Stack"> instead of variadic arguments. | ||
| 82 | |||
| 83 | The format specifiers in the C<format> string must match the types of the values stored in C<args>. | ||
| 84 | |||
| 85 | For example: | ||
| 86 | * C<%d>, C<%x>: Expects an C<ival> (C<int32_t>). | ||
| 87 | * C<%ld>, C<%lld> (or C<PRId64>): Expects a C<lval> (C<int64_t>). | ||
| 88 | * C<%f>, C<%g>: Expects a C<dval> (C<double>). | ||
| 89 | * C<%s>, C<%p>: Expects an C<address> (C<void*>). | ||
| 90 | |||
| 91 | Returns the number of characters that would have been written if C<n> had been sufficiently large, not counting the terminating null character. | ||
| 92 | |||
| 93 | =head1 Native C Function API IDs | ||
| 94 | |||
| 95 | 0 c_strlen | ||
| 96 | 1 c_memcpy | ||
| 97 | 2 c_memset | ||
| 98 | 3 c_memcmp | ||
| 99 | 4 c_strtoll | ||
| 100 | 5 c_strtof | ||
| 101 | 6 c_strtod | ||
| 102 | 7 c_fputs | ||
| 103 | 8 c_fgetc | ||
| 104 | 9 c_snprintf_len | ||
| 105 | |||
| 106 | =head1 See Also | ||
| 107 | |||
| 108 | =over 2 | ||
| 109 | |||
| 110 | =item * L<SPVM::Document::NativeAPI> | ||
| 111 | |||
| 112 | =item * L<SPVM::Document::NativeClass> | ||
| 113 | |||
| 114 | =item * L<SPVM::Document> | ||
| 115 | |||
| 116 | =back | ||
| 117 | |||
| 118 | =head1 Copyright & License | ||
| 119 | |||
| 120 | Copyright (c) 2026 Yuki Kimoto | ||
| 121 | |||
| 122 | MIT License |