53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
#ifndef __SMCC_RT_API_DEF_H__
|
|
#define __SMCC_RT_API_DEF_H__
|
|
|
|
#include "rt_type.h"
|
|
|
|
#ifndef __RT_SIZE_TYPE__
|
|
#define __RT_SIZE_TYPE__
|
|
typedef usz_t rt_size_t;
|
|
#endif
|
|
typedef void* (*rt_malloc)(rt_size_t size);
|
|
typedef void (*rt_free)(void* ptr);
|
|
typedef void (*rt_exit)(int code);
|
|
|
|
#ifndef __RT_FILE_TYPE__
|
|
#define __RT_FILE_TYPE__
|
|
typedef void* rt_file_t;
|
|
#endif
|
|
extern rt_file_t rt_stdin;
|
|
extern rt_file_t rt_stdout;
|
|
extern rt_file_t rt_stderr;
|
|
typedef rt_file_t (*rt_fopen_t)(const char* file_name, const char* mode);
|
|
typedef int (*rt_fflush_t)(rt_file_t*file);
|
|
typedef int (*rt_fclose_t)(rt_file_t file);
|
|
typedef int (*rt_fread_t)(void * dst_buf, rt_size_t elem_size, rt_size_t count, rt_file_t file);
|
|
typedef int (*rt_fwrite_t)(const void * buf, rt_size_t size, rt_size_t count, rt_file_t file);
|
|
|
|
typedef int (*rt_fprintf_t)(void * file, const char *format, ...);
|
|
typedef int (*rt_snprintf_t)(char * stream, rt_size_t n, const char * format, ...);
|
|
typedef void* (*rt_realloc_t)(void *memory, rt_size_t new_size);
|
|
|
|
typedef struct smcc_rt {
|
|
rt_malloc _malloc;
|
|
rt_free _free;
|
|
rt_exit exit;
|
|
|
|
rt_fopen_t fopen;
|
|
rt_fflush_t fflush;
|
|
rt_fclose_t fclose;
|
|
rt_fread_t fread;
|
|
rt_fwrite_t fwrite;
|
|
|
|
// Optional useful runtime
|
|
rt_fprintf_t fprintf;
|
|
rt_snprintf_t snprintf;
|
|
rt_realloc_t _realloc;
|
|
} smcc_rt_t;
|
|
|
|
extern const smcc_rt_t rt;
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
#endif
|