|
Ruby 4.1.0dev (2026-03-30 revision 3379c7efbdc34b7936f322a6bc2de4834c8c65fc)
|
An opaque type representing the source code being parsed, regardless of origin (constant memory, file, memory-mapped file, or stream). More...
#include "prism/compiler/exported.h"#include "prism/compiler/filesystem.h"#include "prism/compiler/nodiscard.h"#include "prism/compiler/nonnull.h"#include <stddef.h>#include <stdint.h>

Go to the source code of this file.
Typedefs | |
| typedef struct pm_source_t | pm_source_t |
| An opaque type representing source code being parsed. | |
| typedef char *() | pm_source_stream_fgets_t(char *string, int size, void *stream) |
| This function is used to retrieve a line of input from a stream. | |
| typedef int() | pm_source_stream_feof_t(void *stream) |
| This function is used to check whether a stream is at EOF. | |
Enumerations | |
| enum | pm_source_init_result_t { PM_SOURCE_INIT_SUCCESS = 0 , PM_SOURCE_INIT_ERROR_GENERIC = 1 , PM_SOURCE_INIT_ERROR_DIRECTORY = 2 , PM_SOURCE_INIT_ERROR_NON_REGULAR = 3 } |
| Represents the result of initializing a source from a file. More... | |
An opaque type representing the source code being parsed, regardless of origin (constant memory, file, memory-mapped file, or stream).
Definition in file source.h.
| typedef int() pm_source_stream_feof_t(void *stream) |
| typedef char *() pm_source_stream_fgets_t(char *string, int size, void *stream) |
| typedef struct pm_source_t pm_source_t |
Represents the result of initializing a source from a file.
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_constant_new | ( | const uint8_t * | data, |
| size_t | length | ||
| ) |
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_file_new | ( | const char * | filepath, |
| pm_source_init_result_t * | result | ||
| ) |
Create a new source by reading a file into a heap-allocated buffer.
| filepath | The path to the file to read. |
| result | Out parameter for the result of the initialization. |
| PRISM_EXPORTED_FUNCTION void pm_source_free | ( | pm_source_t * | source | ) |
| PRISM_EXPORTED_FUNCTION size_t pm_source_length | ( | const pm_source_t * | source | ) |
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_mapped_new | ( | const char * | filepath, |
| int | open_flags, | ||
| pm_source_init_result_t * | result | ||
| ) |
Create a new source by memory-mapping a file.
Falls back to file reading on platforms without mmap support.
If the file is a non-regular file (e.g. a pipe or character device), PM_SOURCE_INIT_ERROR_NON_REGULAR is returned, allowing the caller to handle it appropriately (e.g. by reading it through their own I/O layer).
| filepath | The path to the file to read. |
| open_flags | Additional flags to pass to open(2) (e.g. O_NONBLOCK). |
| result | Out parameter for the result of the initialization. |
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_owned_new | ( | uint8_t * | data, |
| size_t | length | ||
| ) |
Create a new source that owns its memory.
The memory will be freed with xfree when the source is freed.
| data | The pointer to the heap-allocated source data. |
| length | The length of the source data in bytes. |
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_shared_new | ( | const uint8_t * | data, |
| size_t | length | ||
| ) |
Create a new source that wraps existing shared memory.
The memory is not owned and will not be freed. Semantically a "slice" of another source.
| data | The pointer to the source data. |
| length | The length of the source data in bytes. |
| PRISM_EXPORTED_FUNCTION const uint8_t * pm_source_source | ( | const pm_source_t * | source | ) |
| PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_stream_new | ( | void * | stream, |
| pm_source_stream_fgets_t * | fgets, | ||
| pm_source_stream_feof_t * | feof | ||
| ) |
Create a new source by reading from a stream using the provided callbacks.
| stream | The stream to read from. |
| fgets | The function to use to read from the stream. |
| feof | The function to use to check if the stream is at EOF. |
Create a new source by reading from a stream using the provided callbacks.
This allocates the source but does not read from the stream yet. Use pm_source_stream_read to read data.