simplifying

This commit is contained in:
cozis
2022-03-13 15:46:57 +01:00
parent eae8536e3b
commit 43f13958ec
12 changed files with 51 additions and 146 deletions
+1 -1
View File
@@ -17,5 +17,5 @@
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>. ** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../runtime/o_staticmap.h" #include "../runtime/runtime.h"
extern const StaticMapSlot bins_basic[]; extern const StaticMapSlot bins_basic[];
+1 -1
View File
@@ -17,5 +17,5 @@
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>. ** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../runtime/o_staticmap.h" #include "../runtime/runtime.h"
extern const StaticMapSlot bins_files[]; extern const StaticMapSlot bins_files[];
+1 -1
View File
@@ -17,5 +17,5 @@
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>. ** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../runtime/o_staticmap.h" #include "../runtime/runtime.h"
extern const StaticMapSlot bins_math[]; extern const StaticMapSlot bins_math[];
-2
View File
@@ -24,8 +24,6 @@
#include "compiler/parse.h" #include "compiler/parse.h"
#include "compiler/compile.h" #include "compiler/compile.h"
#include "runtime/runtime.h" #include "runtime/runtime.h"
#include "runtime/runtime_error.h"
#include "runtime/o_staticmap.h"
#include "builtins/basic.h" #include "builtins/basic.h"
static const char usage[] = static const char usage[] =
-24
View File
@@ -1,24 +0,0 @@
/* Copyright (c) 2022 Francesco Cozzuto <francesco.cozzuto@gmail.com>
**
** This file is part of The Noja Interpreter.
**
** The Noja Interpreter is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as published
** by the Free Software Foundation, either version 3 of the License, or (at
** your option) any later version.
**
** The Noja Interpreter is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
** Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NOJAFUNC_H
#define NOJAFUNC_H
#include "runtime.h"
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, int argc, Object *closure, Heap *heap, Error *error);
#endif
-24
View File
@@ -1,24 +0,0 @@
/* Copyright (c) 2022 Francesco Cozzuto <francesco.cozzuto@gmail.com>
**
** This file is part of The Noja Interpreter.
**
** The Noja Interpreter is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as published
** by the Free Software Foundation, either version 3 of the License, or (at
** your option) any later version.
**
** The Noja Interpreter is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
** Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NOJAFUNC_H
#define NOJAFUNC_H
#include "runtime.h"
Object *Object_FromNativeFunction(Runtime *runtime, Object *(*callback)(Runtime*, Object**, unsigned int, Error*), int argc, Heap *heap, Error *error);
#endif
+1 -2
View File
@@ -46,8 +46,7 @@
*/ */
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "o_nfunc.h" #include "../runtime/runtime.h"
#include "o_staticmap.h"
#include "../utils/defs.h" #include "../utils/defs.h"
#include "../objects/objects.h" #include "../objects/objects.h"
-56
View File
@@ -1,56 +0,0 @@
/* Copyright (c) 2022 Francesco Cozzuto <francesco.cozzuto@gmail.com>
**
** This file is part of The Noja Interpreter.
**
** The Noja Interpreter is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as published
** by the Free Software Foundation, either version 3 of the License, or (at
** your option) any later version.
**
** The Noja Interpreter is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
** Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STATICMAP_H
#define STATICMAP_H
#include "../objects/objects.h"
#include "runtime.h"
typedef enum {
SM_END,
SM_BOOL,
SM_INT,
SM_FLOAT,
SM_FUNCT,
SM_STRING,
SM_SMAP,
SM_NONE,
SM_TYPE,
} StaticMapSlotKind;
typedef struct StaticMapSlot StaticMapSlot;
struct StaticMapSlot {
const char *name;
StaticMapSlotKind kind;
union {
const StaticMapSlot *as_smap;
const char *as_string;
_Bool as_bool;
long long int as_int;
double as_float;
Object *(*as_funct)(Runtime*, Object**, unsigned int, Error*);
TypeObject *as_type;
};
union { int argc; int length; };
};
Object *Object_NewStaticMap(const StaticMapSlot *slots, Runtime *runt, Error *error);
#endif
-1
View File
@@ -20,7 +20,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../utils/defs.h" #include "../utils/defs.h"
#include "../utils/stack.h" #include "../utils/stack.h"
#include "o_func.h"
#include "runtime.h" #include "runtime.h"
#define MAX_FRAME_STACK 16 #define MAX_FRAME_STACK 16
+46
View File
@@ -19,13 +19,16 @@
#ifndef RUNTIME_H #ifndef RUNTIME_H
#define RUNTIME_H #define RUNTIME_H
#include <stdio.h> // meh.. just for the definition of FILE. #include <stdio.h> // meh.. just for the definition of FILE.
#include "../utils/error.h" #include "../utils/error.h"
#include "../utils/stack.h" #include "../utils/stack.h"
#include "../objects/objects.h" #include "../objects/objects.h"
#include "../common/executable.h" #include "../common/executable.h"
typedef struct xRuntime Runtime; typedef struct xRuntime Runtime;
typedef struct xSnapshot Snapshot; typedef struct xSnapshot Snapshot;
Runtime* Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*)); Runtime* Runtime_New(int stack_size, int heap_size, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*));
Runtime* Runtime_New2(int stack_size, Heap *heap, _Bool free_heap, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*)); Runtime* Runtime_New2(int stack_size, Heap *heap, _Bool free_heap, void *callback_userp, _Bool (*callback_addr)(Runtime*, void*));
void Runtime_Free(Runtime *runtime); void Runtime_Free(Runtime *runtime);
@@ -41,4 +44,47 @@ Snapshot *Snapshot_New(Runtime *runtime);
void Snapshot_Free(Snapshot *snapshot); void Snapshot_Free(Snapshot *snapshot);
void Snapshot_Print(Snapshot *snapshot, FILE *fp); void Snapshot_Print(Snapshot *snapshot, FILE *fp);
Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object *closure, Object **argv, int argc); Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object *closure, Object **argv, int argc);
typedef enum {
SM_END,
SM_BOOL,
SM_INT,
SM_FLOAT,
SM_FUNCT,
SM_STRING,
SM_SMAP,
SM_NONE,
SM_TYPE,
} StaticMapSlotKind;
typedef struct StaticMapSlot StaticMapSlot;
struct StaticMapSlot {
const char *name;
StaticMapSlotKind kind;
union {
const StaticMapSlot *as_smap;
const char *as_string;
_Bool as_bool;
long long int as_int;
double as_float;
Object *(*as_funct)(Runtime*, Object**, unsigned int, Error*);
TypeObject *as_type;
};
union { int argc; int length; };
};
Object *Object_NewStaticMap(const StaticMapSlot *slots, Runtime *runt, Error *error);
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, int argc, Object *closure, Heap *heap, Error *error);
Object *Object_FromNativeFunction(Runtime *runtime, Object *(*callback)(Runtime*, Object**, unsigned int, Error*), int argc, Heap *heap, Error *error);
typedef struct {
Error base;
Runtime *runtime;
Snapshot *snapshot;
} RuntimeError;
void RuntimeError_Init(RuntimeError *error, Runtime *runtime);
void RuntimeError_Free(RuntimeError *error);
#endif #endif
+1 -1
View File
@@ -18,7 +18,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include "runtime_error.h" #include "runtime.h"
static void on_report(Error *error) static void on_report(Error *error)
{ {
-33
View File
@@ -1,33 +0,0 @@
/* Copyright (c) 2022 Francesco Cozzuto <francesco.cozzuto@gmail.com>
**
** This file is part of The Noja Interpreter.
**
** The Noja Interpreter is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as published
** by the Free Software Foundation, either version 3 of the License, or (at
** your option) any later version.
**
** The Noja Interpreter is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
** Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with The Noja Interpreter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RUNTIME_ERROR_H
#define RUNTIME_ERROR_H
#include "../utils/error.h"
#include "runtime.h"
typedef struct {
Error base;
Runtime *runtime;
Snapshot *snapshot;
} RuntimeError;
void RuntimeError_Init(RuntimeError *error, Runtime *runtime);
void RuntimeError_Free(RuntimeError *error);
#endif