write is now pluggable
This commit is contained in:
parent
4e1aaf8b89
commit
2ca7e630f0
2
Makefile
2
Makefile
|
@ -71,7 +71,7 @@ test: test-contribs test-nostdlib test-issue
|
|||
test-contribs: bin/picrin $(CONTRIB_TESTS)
|
||||
|
||||
test-nostdlib:
|
||||
$(CC) -I extlib/benz/include -D'PIC_ENABLE_LIBC=0' -D'PIC_ENABLE_STDIO=0' -ffreestanding -nostdlib -Os -fPIC -shared -std=c89 -pedantic -Wall -Wextra -Werror -o lib/libbenz-tiny.so $(BENZ_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
$(CC) -I extlib/benz/include -D'PIC_USE_LIBC=0' -D'PIC_USE_STDIO=0' -D'PIC_USE_WRITE=0' -ffreestanding -nostdlib -Os -fPIC -shared -std=c89 -pedantic -Wall -Wextra -Werror -o lib/libbenz-tiny.so $(BENZ_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
strip lib/libbenz-tiny.so
|
||||
ls -lh lib/libbenz-tiny.so
|
||||
rm -f lib/libbenz-tiny.so
|
||||
|
|
|
@ -35,6 +35,8 @@ pic_get_backtrace(pic_state *pic)
|
|||
return trace;
|
||||
}
|
||||
|
||||
#if PIC_USE_WRITE
|
||||
|
||||
void
|
||||
pic_print_error(pic_state *pic, xFILE *file)
|
||||
{
|
||||
|
@ -65,3 +67,5 @@ pic_print_error(pic_state *pic, xFILE *file)
|
|||
xfputs(pic, pic_str(pic, pic_obj_value(e->stack)), file);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,7 +14,7 @@ pic_panic(pic_state *pic, const char *msg)
|
|||
pic->panicf(pic, msg);
|
||||
}
|
||||
|
||||
#if PIC_ENABLE_STDIO
|
||||
#if PIC_USE_STDIO
|
||||
fprintf(stderr, "picrin panic!: %s\n", msg);
|
||||
#endif
|
||||
|
||||
|
@ -26,6 +26,7 @@ pic_panic(pic_state *pic, const char *msg)
|
|||
void
|
||||
pic_warnf(pic_state *pic, const char *fmt, ...)
|
||||
{
|
||||
xFILE *file = pic_fileno(pic, pic_stderr(pic));
|
||||
va_list ap;
|
||||
pic_value err;
|
||||
|
||||
|
@ -33,7 +34,7 @@ pic_warnf(pic_state *pic, const char *fmt, ...)
|
|||
err = pic_vstrf_value(pic, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
pic_fprintf(pic, pic_stderr(pic), "warn: %s\n", pic_str(pic, err));
|
||||
xfprintf(pic, file, "warn: %s\n", pic_str(pic, err));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -364,7 +364,7 @@ xFILE *xfile_xstdin(pic_state *pic) { return &pic->files[0]; }
|
|||
xFILE *xfile_xstdout(pic_state *pic) { return &pic->files[1]; }
|
||||
xFILE *xfile_xstderr(pic_state *pic) { return &pic->files[2]; }
|
||||
|
||||
#if PIC_ENABLE_STDIO
|
||||
#if PIC_USE_STDIO
|
||||
|
||||
static int
|
||||
file_read(pic_state *PIC_UNUSED(pic), void *cookie, char *ptr, int size) {
|
||||
|
|
|
@ -82,7 +82,7 @@ pic_heap_close(pic_state *pic, struct heap *heap)
|
|||
pic_free(pic, heap);
|
||||
}
|
||||
|
||||
#if PIC_ENABLE_LIBC
|
||||
#if PIC_USE_LIBC
|
||||
void *
|
||||
pic_default_allocf(void *PIC_UNUSED(userdata), void *ptr, size_t size)
|
||||
{
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
* See Copyright Notice in picrin.h
|
||||
*/
|
||||
|
||||
/** no dependency on libc */
|
||||
/* #define PIC_ENABLE_LIBC 1 */
|
||||
/** no dependency on libc? */
|
||||
/* #define PIC_USE_LIBC 1 */
|
||||
|
||||
/** use stdio or not */
|
||||
/* #define PIC_ENABLE_STDIO 1 */
|
||||
/* #define PIC_USE_STDIO 1 */
|
||||
|
||||
/** enable some specific features? */
|
||||
/* #define PIC_USE_WRITE 1 */
|
||||
|
||||
/** essential external functions */
|
||||
/* #define PIC_JMPBUF jmp_buf */
|
||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
#if PIC_ENABLE_LIBC
|
||||
#if PIC_USE_LIBC
|
||||
void *pic_default_allocf(void *, void *, size_t);
|
||||
#endif
|
||||
|
||||
|
@ -23,9 +23,11 @@ pic_value pic_eval(pic_state *, pic_value program, const char *lib);
|
|||
void pic_load(pic_state *, pic_value port);
|
||||
void pic_load_cstr(pic_state *, const char *);
|
||||
|
||||
#if PIC_USE_WRITE
|
||||
void pic_printf(pic_state *, const char *fmt, ...);
|
||||
void pic_fprintf(pic_state *, pic_value port, const char *fmt, ...);
|
||||
void pic_vfprintf(pic_state *, pic_value port, const char *fmt, va_list ap);
|
||||
#endif
|
||||
|
||||
/* extra xfile methods */
|
||||
|
||||
|
@ -35,7 +37,7 @@ xFILE *xfile_xstderr(pic_state *);
|
|||
#define xstdin (xfile_xstdin(pic))
|
||||
#define xstdout (xfile_xstdout(pic))
|
||||
#define xstderr (xfile_xstderr(pic))
|
||||
#if PIC_ENABLE_STDIO
|
||||
#if PIC_USE_STDIO
|
||||
xFILE *xfopen_file(pic_state *, FILE *, const char *mode);
|
||||
#endif
|
||||
xFILE *xfopen_buf(pic_state *, const char *buf, int len, const char *mode);
|
||||
|
@ -109,7 +111,9 @@ pic_value pic_err(pic_state *);
|
|||
|
||||
void pic_warnf(pic_state *, const char *, ...);
|
||||
pic_value pic_get_backtrace(pic_state *);
|
||||
#if PIC_USE_WRITE
|
||||
void pic_print_error(pic_state *, xFILE *);
|
||||
#endif
|
||||
|
||||
pic_value pic_library_environment(pic_state *, const char *);
|
||||
|
||||
|
|
|
@ -4,12 +4,16 @@
|
|||
|
||||
#include "picrin/config.h"
|
||||
|
||||
#ifndef PIC_ENABLE_LIBC
|
||||
# define PIC_ENABLE_LIBC 1
|
||||
#ifndef PIC_USE_LIBC
|
||||
# define PIC_USE_LIBC 1
|
||||
#endif
|
||||
|
||||
#ifndef PIC_ENABLE_STDIO
|
||||
# define PIC_ENABLE_STDIO 1
|
||||
#ifndef PIC_USE_STDIO
|
||||
# define PIC_USE_STDIO 1
|
||||
#endif
|
||||
|
||||
#ifndef PIC_USE_WRITE
|
||||
# define PIC_USE_WRITE 1
|
||||
#endif
|
||||
|
||||
#ifndef PIC_JMPBUF
|
||||
|
@ -156,7 +160,7 @@ typedef unsigned long uint32_t;
|
|||
} while (0)
|
||||
|
||||
|
||||
#if PIC_ENABLE_LIBC
|
||||
#if PIC_USE_LIBC
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
@ -375,7 +379,7 @@ atof(const char *nptr)
|
|||
|
||||
#endif
|
||||
|
||||
#if PIC_ENABLE_STDIO
|
||||
#if PIC_USE_STDIO
|
||||
# include <stdio.h>
|
||||
|
||||
PIC_INLINE void
|
||||
|
|
|
@ -175,7 +175,7 @@ pic_make_library(pic_state *pic, const char *lib)
|
|||
|
||||
it = kh_put(ltable, h, pic_str(pic, name), &ret);
|
||||
if (ret == 0) { /* if exists */
|
||||
pic_error(pic, "library name already in use", pic_cstr_value(pic, lib));
|
||||
pic_error(pic, "library name already in use", 1, pic_cstr_value(pic, lib));
|
||||
}
|
||||
|
||||
kh_val(h, it).name = pic_str_ptr(pic, name);
|
||||
|
|
|
@ -168,7 +168,6 @@ pic_init_core(pic_state *pic)
|
|||
pic_init_error(pic); DONE;
|
||||
pic_init_str(pic); DONE;
|
||||
pic_init_var(pic); DONE;
|
||||
pic_init_write(pic); DONE;
|
||||
pic_init_read(pic); DONE;
|
||||
pic_init_dict(pic); DONE;
|
||||
pic_init_record(pic); DONE;
|
||||
|
@ -176,6 +175,10 @@ pic_init_core(pic_state *pic)
|
|||
pic_init_lib(pic); DONE;
|
||||
pic_init_weak(pic); DONE;
|
||||
|
||||
#if PIC_USE_WRITE
|
||||
pic_init_write(pic); DONE;
|
||||
#endif
|
||||
|
||||
pic_defun(pic, "features", pic_features);
|
||||
|
||||
pic_load_cstr(pic, &pic_boot[0][0]);
|
||||
|
@ -275,7 +278,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
|||
|
||||
/* file pool */
|
||||
memset(pic->files, 0, sizeof pic->files);
|
||||
#if PIC_ENABLE_STDIO
|
||||
#if PIC_USE_STDIO
|
||||
xfopen_file(pic, stdin, "r");
|
||||
xfopen_file(pic, stdout, "w");
|
||||
xfopen_file(pic, stderr, "w");
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
|
||||
#if PIC_USE_WRITE
|
||||
|
||||
struct writer_control {
|
||||
int mode;
|
||||
int op;
|
||||
|
@ -501,3 +503,5 @@ pic_init_write(pic_state *pic)
|
|||
pic_defun(pic, "write-shared", pic_write_write_shared);
|
||||
pic_defun(pic, "display", pic_write_display);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue