bug fix and renamed file builtin object to files

This commit is contained in:
cozis
2022-03-12 23:52:04 +01:00
parent af089fb81f
commit 6017f99b07
7 changed files with 20 additions and 15 deletions
+2 -2
View File
@@ -53,7 +53,7 @@ gcc -c src/runtime/o_staticmap.c -o temp/runtime/o_staticmap.o $FLAGS
mkdir temp/builtins
gcc -c src/builtins/basic.c -o temp/builtins/basic.o $FLAGS
gcc -c src/builtins/file.c -o temp/builtins/file.o $FLAGS
gcc -c src/builtins/files.c -o temp/builtins/files.o $FLAGS
gcc -c src/builtins/math.c -o temp/builtins/math.o $FLAGS
rm -rf build
@@ -101,7 +101,7 @@ gcc src/main.c \
temp/runtime/o_func.o \
temp/runtime/o_staticmap.o \
temp/builtins/basic.o \
temp/builtins/file.o \
temp/builtins/files.o \
temp/builtins/math.o \
temp/common/executable.o \
-o build/noja $FLAGS -Lbuild/ -lnoja-compile -lnoja-objects -lm
+7
View File
@@ -0,0 +1,7 @@
buff = newBuffer(1024);
name = 'samples/bubble_sort.noja';
hdle = files.openFile(name, files.READ);
n = files.read(hdle, buff);
resl = sliceBuffer(buff, 0, n);
print('Read ', n, ' bytes.\n');
print(resl);
+3 -3
View File
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "basic.h"
#include "file.h"
#include "files.h"
#include "math.h"
static Object *bin_print(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
@@ -129,8 +129,8 @@ static Object *bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int arg
}
const StaticMapSlot bins_basic[] = {
{ "math", SM_SMAP, .as_smap = bins_math, },
{ "file", SM_SMAP, .as_smap = bins_file, },
{ "math", SM_SMAP, .as_smap = bins_math, },
{ "files", SM_SMAP, .as_smap = bins_files, },
// { "net", SM_SMAP, .as_smap = bins_net, },
{ "newBuffer", SM_FUNCT, .as_funct = bin_newBuffer, .argc = 1 },
-2
View File
@@ -1,2 +0,0 @@
#include "../runtime/o_staticmap.h"
extern const StaticMapSlot bins_file[];
+6 -6
View File
@@ -1,6 +1,6 @@
#include <assert.h>
#include <errno.h>
#include "file.h"
#include "files.h"
enum {
MD_READ = 0,
@@ -20,7 +20,7 @@ static Object *bin_openFile(Runtime *runtime, Object **argv, unsigned int argc,
if(!Object_IsInt(argv[1]))
{
Error_Report(error, 0, "Expected second argument to be an int, but it's a %s", Object_GetName(argv[0]));
Error_Report(error, 0, "Expected second argument to be an int, but it's a %s", Object_GetName(argv[1]));
return NULL;
}
@@ -85,7 +85,7 @@ static Object *bin_read(Runtime *runtime, Object **argv, unsigned int argc, Erro
if(!Object_IsBuffer(argv[1]))
{
Error_Report(error, 0, "Expected first argument to be a buffer, but it's a %s", Object_GetName(argv[0]));
Error_Report(error, 0, "Expected second argument to be a buffer, but it's a %s", Object_GetName(argv[1]));
return NULL;
}
@@ -146,7 +146,7 @@ static Object *bin_write(Runtime *runtime, Object **argv, unsigned int argc, Err
if(!Object_IsBuffer(argv[1]))
{
Error_Report(error, 0, "Expected first argument to be a buffer, but it's a %s", Object_GetName(argv[0]));
Error_Report(error, 0, "Expected second argument to be a buffer, but it's a %s", Object_GetName(argv[1]));
return NULL;
}
@@ -265,14 +265,14 @@ static Object *bin_nextDirItem(Runtime *runtime, Object **argv, unsigned int arg
return Object_FromString(ent->d_name, -1, heap, error);
}
const StaticMapSlot bins_file[] = {
const StaticMapSlot bins_files[] = {
{ "READ", SM_INT, .as_int = MD_READ, },
{ "WRITE", SM_INT, .as_int = MD_WRITE, },
{ "APPEND", SM_INT, .as_int = MD_APPEND, },
{ "openFile", SM_FUNCT, .as_funct = bin_openFile, .argc = 2, },
{ "openDir", SM_FUNCT, .as_funct = bin_openDir, .argc = 1, },
{ "nextDirItem", SM_FUNCT, .as_funct = bin_nextDirItem, .argc = 1, },
{ "read", SM_FUNCT, .as_funct = bin_read, .argc = 2, },
{ "read", SM_FUNCT, .as_funct = bin_read, .argc = 3, },
{ "write", SM_FUNCT, .as_funct = bin_write, .argc = 3, },
{ NULL, SM_END, {}, {} },
};
+2
View File
@@ -0,0 +1,2 @@
#include "../runtime/o_staticmap.h"
extern const StaticMapSlot bins_files[];
-2
View File
@@ -44,8 +44,6 @@ static void print_error(const char *type, Error *error)
static Executable *build(Source *src)
{
// Compile the code. This section transforms
// a [Source] into an [Executable].
Executable *exe;
// Create a bump-pointer allocator to hold the AST.