language

Some fools attempt at an interpreted language
Log | Files | Refs

commit 45f317248e37f74eb6cf0c0aa79ab9c39c121840
parent 6b96af5a7c6930d2e2b1c395ff97efd03a0ff948
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Sun Feb 28 13:38:30 2016

Got her to compile. Next is to implement opcode subroutines and get it running

Diffstat:
 src/vm/Makefile      |  28 +++++++-----
 src/vm/inc/ins_def.h |   7 ++-
 src/vm/inc/is.h      |   4 ++-
 src/vm/inc/proc.h    |   1 +-
 src/vm/inc/rt.h      |   4 +-
 src/vm/src/ins_def.c | 117 ++++++++++++++++++++++++++++------------------------
 src/vm/src/is.c      |   1 +-
 src/vm/src/proc.c    |   9 ++--
 src/vm/src/rt.c      |  15 +++----
 9 files changed, 108 insertions(+), 78 deletions(-)

diff --git a/src/vm/Makefile b/src/vm/Makefile @@ -12,18 +12,26 @@ DEPS = $(INC_DIR)/is_mdata.h \ var.h \ stk.h \ ht.h \ - ns.h + ns.h \ + pc.h \ + rt.h \ + ins_def.h \ + proc.h -OBJ = $(SRC_DIR)/main.o \ - $(SRC_DIR)/fh.o \ - $(SRC_DIR)/bc.o \ - $(SRC_DIR)/is.o \ - $(SRC_DIR)/var.o \ - $(SRC_DIR)/stk.o \ - $(SRC_DIR)/ht.o \ - $(SRC_DIR)/ns.o +OBJ = $(SRC_DIR)/main.o \ + $(SRC_DIR)/fh.o \ + $(SRC_DIR)/bc.o \ + $(SRC_DIR)/is.o \ + $(SRC_DIR)/var.o \ + $(SRC_DIR)/stk.o \ + $(SRC_DIR)/ht.o \ + $(SRC_DIR)/ns.o \ + $(SRC_DIR)/pc.o \ + $(SRC_DIR)/rt.o \ + $(SRC_DIR)/ins_def.o \ + $(SRC_DIR)/proc.o -OUT = main +OUT = toi %.o: %.c $(DEPS) $(CC) $(CFLAGS) -c -o $@ $< diff --git a/src/vm/inc/ins_def.h b/src/vm/inc/ins_def.h @@ -16,13 +16,18 @@ #include "helper.h" // This array is populated by init_ins_def( void ); -void INS_DEF[0xFF]; +void (*INS_DEF[0xFF])(rt_t*, byte_t*); /* Initializes INS_DEF with pointers to each instructions function * Populates INS_DEF */ void init_ins_def( void ); +/* Checks if instruction exists. + * byte_t - opcode + */ +int ins_def_is_valid(bc_cont*); + void _ins_def_NULL (rt_t*, byte_t*); void _ins_def_SYNC (rt_t*, byte_t*); void _ins_def_ARGB (rt_t*, byte_t*); diff --git a/src/vm/inc/is.h b/src/vm/inc/is.h @@ -5,7 +5,11 @@ be handled by this file. */ +#ifndef IS_H + #include "ins_mdata.h" +#include "bc.h" +#include "fh.h" // This array is populated by inc/is_mdata.h byte_t INS_MDATA[0xFF]; diff --git a/src/vm/inc/proc.h b/src/vm/inc/proc.h @@ -11,6 +11,7 @@ #include "bc.h" #include "stk.h" #include "var.h" +#include "ns.h" #include "pc.h" #include "helper.h" diff --git a/src/vm/inc/rt.h b/src/vm/inc/rt.h @@ -10,6 +10,7 @@ #include "bc.h" #include "stk.h" #include "var.h" +#include "ns.h" #include "pc.h" #include "helper.h" @@ -28,7 +29,6 @@ typedef struct rt_t { stk_t* stack; stk_t* argstk; ns_t* vars; - ns_cont* gvars; } rt_t; /* Creates new runtime context. @@ -36,7 +36,7 @@ typedef struct rt_t { * stk_t* - Arguement stack * ns_cont*- Copy of the global namespace */ -rt_t* rt_ctx_new(char*, stk_t*, ns_cont*); +rt_t* rt_ctx_new(char*, stk_t*); /* Destroys runtime context. This can be *very* slow. */ diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -64,7 +64,7 @@ void init_ins_def( void ) INS_DEF[0x81] = _ins_def_DEL; INS_DEF[0x82] = _ins_def_GET; INS_DEF[0x83] = _ins_def_GETP; - INS_DEF[0x84] = _ins_def_GETM; + INS_DEF[0x84] = _ins_def_CALLM; INS_DEF[0xF0] = _ins_def_RETURN; INS_DEF[0xF1] = _ins_def_NEW; @@ -73,168 +73,179 @@ void init_ins_def( void ) INS_DEF[0xFF] = _ins_def_DEFUN; } -void _ins_def_NULL (rt_t*, byte_t*) +int ins_def_is_valid(bc_cont* line) +{ + int rv = 0; + + if(INS_DEF[line->op] != NULL) + { + rv = 1; + } + return rv; +} + +void _ins_def_NULL (rt_t* ctx, byte_t* args) { } -void _ins_def_SYNC (rt_t*, byte_t*) +void _ins_def_SYNC (rt_t* ctx, byte_t* args) { } -void _ins_def_ARGB (rt_t*, byte_t*) +void _ins_def_ARGB (rt_t* ctx, byte_t* args) { } -void _ins_def_LIBC (rt_t*, byte_t*) +void _ins_def_LIBC (rt_t* ctx, byte_t* args) { } -void _ins_def_POP (rt_t*, byte_t*) +void _ins_def_POP (rt_t* ctx, byte_t* args) { } -void _ins_def_ROT (rt_t*, byte_t*) +void _ins_def_ROT (rt_t* ctx, byte_t* args) { } -void _ins_def_DUP (rt_t*, byte_t*) +void _ins_def_DUP (rt_t* ctx, byte_t* args) { } -void _ins_def_ROT_THREE(rt_t*, byte_t*) +void _ins_def_ROT_THREE(rt_t* ctx, byte_t* args) { } -void _ins_def_DEC (rt_t*, byte_t*) +void _ins_def_DEC (rt_t* ctx, byte_t* args) { } -void _ins_def_LOV (rt_t*, byte_t*) +void _ins_def_LOV (rt_t* ctx, byte_t* args) { } -void _ins_def_STV (rt_t*, byte_t*) +void _ins_def_STV (rt_t* ctx, byte_t* args) { } -void _ins_def_LOC (rt_t*, byte_t*) +void _ins_def_LOC (rt_t* ctx, byte_t* args) { } -void _ins_def_CTS (rt_t*, byte_t*) +void _ins_def_CTS (rt_t* ctx, byte_t* args) { } -void _ins_def_TYPEOF (rt_t*, byte_t*) +void _ins_def_TYPEOF (rt_t* ctx, byte_t* args) { } -void _ins_def_CAST (rt_t*, byte_t*) +void _ins_def_CAST (rt_t* ctx, byte_t* args) { } -void _ins_def_ADD (rt_t*, byte_t*) +void _ins_def_ADD (rt_t* ctx, byte_t* args) { } -void _ins_def_SUB (rt_t*, byte_t*) +void _ins_def_SUB (rt_t* ctx, byte_t* args) { } -void _ins_def_MULT (rt_t*, byte_t*) +void _ins_def_MULT (rt_t* ctx, byte_t* args) { } -void _ins_def_DIV (rt_t*, byte_t*) +void _ins_def_DIV (rt_t* ctx, byte_t* args) { } -void _ins_def_POW (rt_t*, byte_t*) +void _ins_def_POW (rt_t* ctx, byte_t* args) { } -void _ins_def_BRT (rt_t*, byte_t*) +void _ins_def_BRT (rt_t* ctx, byte_t* args) { } -void _ins_def_SIN (rt_t*, byte_t*) +void _ins_def_SIN (rt_t* ctx, byte_t* args) { } -void _ins_def_COS (rt_t*, byte_t*) +void _ins_def_COS (rt_t* ctx, byte_t* args) { } -void _ins_def_TAN (rt_t*, byte_t*) +void _ins_def_TAN (rt_t* ctx, byte_t* args) { } -void _ins_def_ISIN (rt_t*, byte_t*) +void _ins_def_ISIN (rt_t* ctx, byte_t* args) { } -void _ins_def_ICOS (rt_t*, byte_t*) +void _ins_def_ICOS (rt_t* ctx, byte_t* args) { } -void _ins_def_ITAN (rt_t*, byte_t*) +void _ins_def_ITAN (rt_t* ctx, byte_t* args) { } -void _ins_def_MOD (rt_t*, byte_t*) +void _ins_def_MOD (rt_t* ctx, byte_t* args) { } -void _ins_def_OR (rt_t*, byte_t*) +void _ins_def_OR (rt_t* ctx, byte_t* args) { } -void _ins_def_XOR (rt_t*, byte_t*) +void _ins_def_XOR (rt_t* ctx, byte_t* args) { } -void _ins_def_NAND (rt_t*, byte_t*) +void _ins_def_NAND (rt_t* ctx, byte_t* args) { } -void _ins_def_GTHAN (rt_t*, byte_t*) +void _ins_def_GTHAN (rt_t* ctx, byte_t* args) { } -void _ins_def_LTHAN (rt_t*, byte_t*) +void _ins_def_LTHAN (rt_t* ctx, byte_t* args) { } -void _ins_def_EQ (rt_t*, byte_t*) +void _ins_def_EQ (rt_t* ctx, byte_t* args) { } -void _ins_def_NOT (rt_t*, byte_t*) +void _ins_def_NOT (rt_t* ctx, byte_t* args) { } -void _ins_def_STARTL (rt_t*, byte_t*) +void _ins_def_STARTL (rt_t* ctx, byte_t* args) { } -void _ins_def_CLOOP (rt_t*, byte_t*) +void _ins_def_CLOOP (rt_t* ctx, byte_t* args) { } -void _ins_def_BREAK (rt_t*, byte_t*) +void _ins_def_BREAK (rt_t* ctx, byte_t* args) { } -void _ins_def_DONE (rt_t*, byte_t*) +void _ins_def_DONE (rt_t* ctx, byte_t* args) { } -void _ins_def_GOTO (rt_t*, byte_t*) +void _ins_def_GOTO (rt_t* ctx, byte_t* args) { } -void _ins_def_JUMPF (rt_t*, byte_t*) +void _ins_def_JUMPF (rt_t* ctx, byte_t* args) { } -void _ins_def_CALL (rt_t*, byte_t*) +void _ins_def_CALL (rt_t* ctx, byte_t* args) { } -void _ins_def_PUSH (rt_t*, byte_t*) +void _ins_def_PUSH (rt_t* ctx, byte_t* args) { } -void _ins_def_DEL (rt_t*, byte_t*) +void _ins_def_DEL (rt_t* ctx, byte_t* args) { } -void _ins_def_GET (rt_t*, byte_t*) +void _ins_def_GET (rt_t* ctx, byte_t* args) { } -void _ins_def_GETP (rt_t*, byte_t*) +void _ins_def_GETP (rt_t* ctx, byte_t* args) { } -void _ins_def_CALLM (rt_t*, byte_t*) +void _ins_def_CALLM (rt_t* ctx, byte_t* args) { } -void _ins_def_RETURN (rt_t*, byte_t*) +void _ins_def_RETURN (rt_t* ctx, byte_t* args) { } -void _ins_def_NEW (rt_t*, byte_t*) +void _ins_def_NEW (rt_t* ctx, byte_t* args) { } -void _ins_def_LSIZE (rt_t*, byte_t*) +void _ins_def_LSIZE (rt_t* ctx, byte_t* args) { } -void _ins_def_DECLASS (rt_t*, byte_t*) +void _ins_def_DECLASS (rt_t* ctx, byte_t* args) { } -void _ins_def_DEFUN (rt_t*, byte_t*) +void _ins_def_DEFUN (rt_t* ctx, byte_t* args) { } diff --git a/src/vm/src/is.c b/src/vm/src/is.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include "is.h" +#include "ins_mdata.h" #include "bc.h" #include "fh.h" diff --git a/src/vm/src/proc.c b/src/vm/src/proc.c @@ -8,6 +8,7 @@ #include "bc.h" #include "stk.h" #include "var.h" +#include "ns.h" #include "pc.h" #include "helper.h" @@ -17,7 +18,7 @@ rt_t* proc_init(char* fname) { N_ASSERT(fname); - rt_t* ctx = rt_ctx_new(fname, stk_new(), ns_cont_new(1024)); + rt_t* ctx = rt_ctx_new(fname, stk_new()); return ctx; } @@ -54,7 +55,7 @@ void proc_clean(rt_t* ctx) var_cont* proc_callfun(rt_t* ctx, var_cont* func) { N_ASSERT(ctx); - + return 0; } /* Set a variable subroutine @@ -67,7 +68,7 @@ var_cont* proc_callfun(rt_t* ctx, var_cont* func) */ void proc_setvar(rt_t* ctx, int scope, ns_addr name, var_cont* var) { - + } /* Get a variable subroutine @@ -77,7 +78,7 @@ void proc_setvar(rt_t* ctx, int scope, ns_addr name, var_cont* var) */ var_cont* proc_getvar(rt_t* ctx, int scope, ns_addr name) { - + return 0; } diff --git a/src/vm/src/rt.c b/src/vm/src/rt.c @@ -4,6 +4,7 @@ #include "bc.h" #include "stk.h" #include "var.h" +#include "ns.h" #include "pc.h" #include "helper.h" @@ -12,20 +13,18 @@ * stk_t* - Arguement stack (non-null) * ns_cont*- Copy of the global namespace */ -rt_t* rt_ctx_new(char* fname, stk_t* args, ns_cont* gvars) +rt_t* rt_ctx_new(char* fname, stk_t* args) { N_ASSERT(fname); N_ASSERT(args); - N_ASSERT(gvars); + rt_t* ctx = (rt_t*)malloc(sizeof(rt_t)); M_ASSERT(ctx); ctx->pc = pc_new(fname); ctx->stack = stk_new(); - ctx->vars = ns_new(1024); + ctx->vars = ns_init(1024); ctx->argstk = args; - ctx->gvars = gvars; - return ctx; } @@ -42,10 +41,10 @@ void rt_ctx_del(rt_t* ctx) N_ASSERT(ctx->argstk); stk_del(ctx->argstk); - N_ASSERT(ctx->ns); - ns_del(ctx->ns); + N_ASSERT(ctx->vars); + ns_del(ctx->vars); - N_ASERT(ctx->pc); + N_ASSERT(ctx->pc); pc_del(ctx->pc); }