mirror of
https://github.com/janet-lang/janet
synced 2025-02-03 18:59:09 +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
|
DEBUGGER=gdb
|
||||||
|
|
||||||
UNAME:=$(shell uname -s)
|
UNAME:=$(shell uname -s)
|
||||||
|
LDCONFIG:=ldconfig
|
||||||
ifeq ($(UNAME), Darwin)
|
ifeq ($(UNAME), Darwin)
|
||||||
# Add other macos/clang flags
|
# Add other macos/clang flags
|
||||||
|
LDCONFIG:=
|
||||||
else
|
else
|
||||||
CFLAGS:=$(CFLAGS) -rdynamic
|
CFLAGS:=$(CFLAGS) -rdynamic
|
||||||
endif
|
endif
|
||||||
@ -148,12 +150,12 @@ install: $(DST_TARGET)
|
|||||||
mkdir -p $(INCLUDEDIR)
|
mkdir -p $(INCLUDEDIR)
|
||||||
cp $(DST_HEADERS) $(INCLUDEDIR)
|
cp $(DST_HEADERS) $(INCLUDEDIR)
|
||||||
cp $(DST_LIBRARY) $(LIBDIR)/$(DST_LIBRARY)
|
cp $(DST_LIBRARY) $(LIBDIR)/$(DST_LIBRARY)
|
||||||
-ldconfig
|
$(LDCONFIG)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
-rm $(BINDIR)/$(DST_TARGET)
|
-rm $(BINDIR)/$(DST_TARGET)
|
||||||
-rm $(LIBDIR)/$(DST_LIBRARY)
|
-rm $(LIBDIR)/$(DST_LIBRARY)
|
||||||
-rm -rf $(INCLUDEDIR)
|
-rm -rf $(INCLUDEDIR)
|
||||||
-ldconfig
|
$(LDCONFIG)
|
||||||
|
|
||||||
.PHONY: clean install repl debug valgrind test valtest install uninstall
|
.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,
|
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.
|
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).
|
For syntax highlighting, 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.
|
Generic lisp syntax highlighting should provide good results, however.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ Generic lisp synatx highlighting should provide good results, however.
|
|||||||
* REPL
|
* REPL
|
||||||
* Interactive Environment
|
* Interactive Environment
|
||||||
|
|
||||||
## Docmentation
|
## Documentation
|
||||||
|
|
||||||
API documentation and design documents can be found in the
|
API documentation and design documents can be found in the
|
||||||
[wiki](https://github.com/bakpakin/dst/wiki).
|
[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());
|
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 */
|
/* Read a certain number of bytes into memory */
|
||||||
static int dst_io_fread(DstArgs args) {
|
static int dst_io_fread(DstArgs args) {
|
||||||
DstBuffer *b;
|
DstBuffer *b;
|
||||||
int32_t len;
|
|
||||||
size_t ntoread, nread;
|
|
||||||
IOFile *iof = checkfile(args, 0);
|
IOFile *iof = checkfile(args, 0);
|
||||||
if (!iof) return 1;
|
if (!iof) return 1;
|
||||||
if (iof->flags & IO_CLOSED)
|
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]);
|
const uint8_t *sym = dst_unwrap_symbol(args.v[1]);
|
||||||
if (!dst_cstrcmp(sym, ":all")) {
|
if (!dst_cstrcmp(sym, ":all")) {
|
||||||
/* Read whole file */
|
/* Read whole file */
|
||||||
long fsize;
|
int status = fseek(iof->file, 0, SEEK_SET);
|
||||||
fseek(iof->file, 0, SEEK_END);
|
if (status) {
|
||||||
fsize = ftell(iof->file);
|
/* backwards fseek did not work (stream like popen) */
|
||||||
fseek(iof->file, 0, SEEK_SET);
|
int32_t sizeBefore;
|
||||||
if (fsize > INT32_MAX) DST_THROW(args, "buffer overflow");
|
do {
|
||||||
len = fsize;
|
sizeBefore = b->count;
|
||||||
/* Fall through to normal code */
|
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")) {
|
} else if (!dst_cstrcmp(sym, ":line")) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int x = fgetc(iof->file);
|
int x = fgetc(iof->file);
|
||||||
@ -225,23 +248,17 @@ static int dst_io_fread(DstArgs args) {
|
|||||||
DST_THROW(args, "buffer overflow");
|
DST_THROW(args, "buffer overflow");
|
||||||
if (x == EOF || x == '\n') break;
|
if (x == EOF || x == '\n') break;
|
||||||
}
|
}
|
||||||
DST_RETURN(args, dst_wrap_buffer(b));
|
|
||||||
} else {
|
} else {
|
||||||
DST_THROW(args, "expected one of :all, :line");
|
DST_THROW(args, "expected one of :all, :line");
|
||||||
}
|
}
|
||||||
} else if (!dst_checktype(args.v[1], DST_INTEGER)) {
|
} else if (!dst_checktype(args.v[1], DST_INTEGER)) {
|
||||||
DST_THROW(args, "expected positive integer");
|
DST_THROW(args, "expected positive integer");
|
||||||
} else {
|
} 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");
|
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));
|
DST_RETURN(args, dst_wrap_buffer(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ const uint8_t *dst_description(Dst x) {
|
|||||||
case DST_CFUNCTION:
|
case DST_CFUNCTION:
|
||||||
{
|
{
|
||||||
Dst check = dst_table_get(dst_vm_registry, x);
|
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);
|
return dst_formatc("<cfunction %V>", check);
|
||||||
}
|
}
|
||||||
goto fallthrough;
|
goto fallthrough;
|
||||||
|
Loading…
Reference in New Issue
Block a user