mirror of
https://github.com/janet-lang/janet
synced 2025-01-24 14:16:52 +00:00
Merge branch 'master' of github.com:bakpakin/dst
This commit is contained in:
commit
cac39aba67
6
Makefile
6
Makefile
@ -40,8 +40,10 @@ DST_LIBRARY=libdst.so
|
||||
DEBUGGER=gdb
|
||||
|
||||
UNAME:=$(shell uname -s)
|
||||
LDCONFIG:=ldconfig
|
||||
ifeq ($(UNAME), Darwin)
|
||||
# Add other macos/clang flags
|
||||
LDCONFIG:=
|
||||
else
|
||||
CFLAGS:=$(CFLAGS) -rdynamic
|
||||
endif
|
||||
@ -148,12 +150,12 @@ install: $(DST_TARGET)
|
||||
mkdir -p $(INCLUDEDIR)
|
||||
cp $(DST_HEADERS) $(INCLUDEDIR)
|
||||
cp $(DST_LIBRARY) $(LIBDIR)/$(DST_LIBRARY)
|
||||
-ldconfig
|
||||
$(LDCONFIG)
|
||||
|
||||
uninstall:
|
||||
-rm $(BINDIR)/$(DST_TARGET)
|
||||
-rm $(LIBDIR)/$(DST_LIBRARY)
|
||||
-rm -rf $(INCLUDEDIR)
|
||||
-ldconfig
|
||||
$(LDCONFIG)
|
||||
|
||||
.PHONY: clean install repl debug valgrind test valtest install uninstall
|
||||
|
@ -23,8 +23,8 @@ There is not much in the way of documentation yet because it is still a "persona
|
||||
I don't want to freeze features prematurely. You can look in the examples directory, the test directory,
|
||||
or the file `src/compiler/boot.dst` to get a sense of what dst code looks like.
|
||||
|
||||
For syntax highlightinh, there is some preliminary vim syntax highlighting in [dst.vim](https://github.com/bakpakin/dst.vim).
|
||||
Generic lisp synatx highlighting should provide good results, however.
|
||||
For syntax highlighting, there is some preliminary vim syntax highlighting in [dst.vim](https://github.com/bakpakin/dst.vim).
|
||||
Generic lisp syntax highlighting should provide good results, however.
|
||||
|
||||
## Features
|
||||
|
||||
@ -45,7 +45,7 @@ Generic lisp synatx highlighting should provide good results, however.
|
||||
* REPL
|
||||
* Interactive Environment
|
||||
|
||||
## Docmentation
|
||||
## Documentation
|
||||
|
||||
API documentation and design documents can be found in the
|
||||
[wiki](https://github.com/bakpakin/dst/wiki).
|
||||
|
@ -196,11 +196,24 @@ static int dst_io_fopen(DstArgs args) {
|
||||
DST_RETURN(args, f ? makef(f, flags) : dst_wrap_nil());
|
||||
}
|
||||
|
||||
/* Read up to n bytes into buffer. Return error string if error. */
|
||||
static const char *read_chunk(IOFile *iof, DstBuffer *buffer, int32_t nBytesMax) {
|
||||
if (!(iof->flags & (IO_READ | IO_UPDATE)))
|
||||
return "file is not readable";
|
||||
/* Ensure buffer size */
|
||||
if (dst_buffer_extra(buffer, nBytesMax))
|
||||
return "buffer overflow";
|
||||
size_t ntoread = nBytesMax;
|
||||
size_t nread = fread((char *)(buffer->data + buffer->count), 1, ntoread, iof->file);
|
||||
if (nread != ntoread && ferror(iof->file))
|
||||
return "could not read file";
|
||||
buffer->count += nread;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Read a certain number of bytes into memory */
|
||||
static int dst_io_fread(DstArgs args) {
|
||||
DstBuffer *b;
|
||||
int32_t len;
|
||||
size_t ntoread, nread;
|
||||
IOFile *iof = checkfile(args, 0);
|
||||
if (!iof) return 1;
|
||||
if (iof->flags & IO_CLOSED)
|
||||
@ -211,13 +224,23 @@ static int dst_io_fread(DstArgs args) {
|
||||
const uint8_t *sym = dst_unwrap_symbol(args.v[1]);
|
||||
if (!dst_cstrcmp(sym, ":all")) {
|
||||
/* Read whole file */
|
||||
long fsize;
|
||||
fseek(iof->file, 0, SEEK_END);
|
||||
fsize = ftell(iof->file);
|
||||
fseek(iof->file, 0, SEEK_SET);
|
||||
if (fsize > INT32_MAX) DST_THROW(args, "buffer overflow");
|
||||
len = fsize;
|
||||
/* Fall through to normal code */
|
||||
int status = fseek(iof->file, 0, SEEK_SET);
|
||||
if (status) {
|
||||
/* backwards fseek did not work (stream like popen) */
|
||||
int32_t sizeBefore;
|
||||
do {
|
||||
sizeBefore = b->count;
|
||||
const char *maybeErr = read_chunk(iof, b, 1024);
|
||||
if (maybeErr) DST_THROW(args, maybeErr);
|
||||
} while (sizeBefore < b->count);
|
||||
} else {
|
||||
fseek(iof->file, 0, SEEK_END);
|
||||
long fsize = ftell(iof->file);
|
||||
fseek(iof->file, 0, SEEK_SET);
|
||||
if (fsize > INT32_MAX) DST_THROW(args, "buffer overflow");
|
||||
const char *maybeErr = read_chunk(iof, b, (int32_t) fsize);;
|
||||
if (maybeErr) DST_THROW(args, maybeErr);
|
||||
}
|
||||
} else if (!dst_cstrcmp(sym, ":line")) {
|
||||
for (;;) {
|
||||
int x = fgetc(iof->file);
|
||||
@ -225,23 +248,17 @@ static int dst_io_fread(DstArgs args) {
|
||||
DST_THROW(args, "buffer overflow");
|
||||
if (x == EOF || x == '\n') break;
|
||||
}
|
||||
DST_RETURN(args, dst_wrap_buffer(b));
|
||||
} else {
|
||||
DST_THROW(args, "expected one of :all, :line");
|
||||
}
|
||||
} else if (!dst_checktype(args.v[1], DST_INTEGER)) {
|
||||
DST_THROW(args, "expected positive integer");
|
||||
} else {
|
||||
len = dst_unwrap_integer(args.v[1]);
|
||||
int32_t len = dst_unwrap_integer(args.v[1]);
|
||||
if (len < 0) DST_THROW(args, "expected positive integer");
|
||||
const char *maybeErr = read_chunk(iof, b, len);
|
||||
if (maybeErr) DST_THROW(args, maybeErr);
|
||||
}
|
||||
if (!(iof->flags & (IO_READ | IO_UPDATE))) DST_THROW(args, "file is not readable");
|
||||
/* Ensure buffer size */
|
||||
if (dst_buffer_extra(b, len)) DST_THROW(args, "buffer overflow");
|
||||
ntoread = len;
|
||||
nread = fread((char *)(b->data + b->count), 1, ntoread, iof->file);
|
||||
if (nread != ntoread && ferror(iof->file)) DST_THROW(args, "could not read file");
|
||||
b->count += nread;
|
||||
DST_RETURN(args, dst_wrap_buffer(b));
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ const uint8_t *dst_description(Dst x) {
|
||||
case DST_CFUNCTION:
|
||||
{
|
||||
Dst check = dst_table_get(dst_vm_registry, x);
|
||||
if (!dst_checktype(x, DST_NIL)) {
|
||||
if (dst_checktype(check, DST_SYMBOL)) {
|
||||
return dst_formatc("<cfunction %V>", check);
|
||||
}
|
||||
goto fallthrough;
|
||||
|
Loading…
Reference in New Issue
Block a user