language

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

commit a30b4d501f2e34a522f9b9538a20945354afeb76
parent 45f317248e37f74eb6cf0c0aa79ab9c39c121840
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Sun Feb 28 21:46:06 2016

More tweaking, is in a running state, arguement parsing to useable values to be implemented next (ins_adata)

Diffstat:
 doc/SPECIFICATION      |   2 +-
 src/vm/Makefile        |  24 +++----
 src/vm/inc/bc.h        |   8 ++-
 src/vm/inc/ins_adata.h |  26 +++++++-
 src/vm/inc/ins_def.h   | 123 +++++++++++++++++------------------
 src/vm/inc/ins_mdata.h |   1 +-
 src/vm/inc/pc.h        |   2 +-
 src/vm/src/bc.c        |  15 ++--
 src/vm/src/ins_adata.c |  17 +++++-
 src/vm/src/ins_def.c   | 174 ++++++++++++++++++++++++++++++++++----------------
 src/vm/src/is.c        |   1 +-
 src/vm/src/main.c      |   8 +-
 src/vm/src/pc.c        |  18 +-----
 src/vm/src/proc.c      |  11 ++-
 src/vm/src/rt.c        |   4 +-
 src/vm/src/stk.c       |  21 ++++--
 src/vm/src/var.c       |   5 +-
 17 files changed, 287 insertions(+), 173 deletions(-)

diff --git a/doc/SPECIFICATION b/doc/SPECIFICATION @@ -210,8 +210,6 @@ FF DEFUN A<ref> S<type> D<args> - Un-funs everything. no, no- it defines a FE DECLASS A<ref> D<args> - Defines a class. -F2 LSIZE W<size> - Dictates local scope size for function/class - F1 NEW A<ref> - Instantiates class F0 RETURN - Returns from function diff --git a/src/vm/Makefile b/src/vm/Makefile @@ -15,20 +15,22 @@ DEPS = $(INC_DIR)/is_mdata.h \ ns.h \ pc.h \ rt.h \ + ins_adata.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 \ - $(SRC_DIR)/pc.o \ - $(SRC_DIR)/rt.o \ - $(SRC_DIR)/ins_def.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_adata.o\ + $(SRC_DIR)/ins_def.o \ $(SRC_DIR)/proc.o OUT = toi diff --git a/src/vm/inc/bc.h b/src/vm/inc/bc.h @@ -17,6 +17,9 @@ typedef unsigned short int bc_addr; typedef struct bc_cont { byte_t op; byte_t* args[3]; + void* a1; + void* a2; + void* a3; byte_t mdata; bc_addr real_addr; struct bc_cont* next; @@ -49,6 +52,11 @@ byte_t* get_byte_arg(FILE*); byte_t* get_word_arg(FILE*); byte_t* get_dync_arg(FILE*); +/* Process arguements into typed & readable data + * bc_cont* - bytecode container + */ +void process_args(bc_cont*); + /* Scan to +/- int in bytecode chain * bc_cont* - bytecode container [0] * int - +/- up/down [1] diff --git a/src/vm/inc/ins_adata.h b/src/vm/inc/ins_adata.h @@ -0,0 +1,26 @@ +/* `ins_adata.h` provides per-opcode arguement type data. + * Provides subroutines for individual opcodes + */ + +#ifndef INS_MDATA_H +#define INS_MDATA_H + +#include <stdlib.h> +#include <stdio.h> + +#include "bc.h" +#include "is.h" +#include "var.h" +#include "helper.h" + +void init_adata( void ); + +/* TODO: figure out how to deserialize the following: + * + * Byte to integer + * Word to address type + * Dynamic length arguement to arguement type list + * Dynamic length arguement to typed data + */ + +#endif //INS_MDATA_H diff --git a/src/vm/inc/ins_def.h b/src/vm/inc/ins_def.h @@ -16,7 +16,7 @@ #include "helper.h" // This array is populated by init_ins_def( void ); -void (*INS_DEF[0xFF])(rt_t*, byte_t*); +void (*INS_DEF[0xFF])(rt_t*, bc_cont*); /* Initializes INS_DEF with pointers to each instructions function * Populates INS_DEF @@ -28,66 +28,65 @@ void init_ins_def( void ); */ 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*); -void _ins_def_LIBC (rt_t*, byte_t*); - -void _ins_def_POP (rt_t*, byte_t*); -void _ins_def_ROT (rt_t*, byte_t*); -void _ins_def_DUP (rt_t*, byte_t*); -void _ins_def_ROT_THREE(rt_t*, byte_t*); - -void _ins_def_DEC (rt_t*, byte_t*); -void _ins_def_LOV (rt_t*, byte_t*); -void _ins_def_STV (rt_t*, byte_t*); -void _ins_def_LOC (rt_t*, byte_t*); -void _ins_def_CTS (rt_t*, byte_t*); - -void _ins_def_TYPEOF (rt_t*, byte_t*); -void _ins_def_CAST (rt_t*, byte_t*); - -void _ins_def_ADD (rt_t*, byte_t*); -void _ins_def_SUB (rt_t*, byte_t*); -void _ins_def_MULT (rt_t*, byte_t*); -void _ins_def_DIV (rt_t*, byte_t*); -void _ins_def_POW (rt_t*, byte_t*); -void _ins_def_BRT (rt_t*, byte_t*); -void _ins_def_SIN (rt_t*, byte_t*); -void _ins_def_COS (rt_t*, byte_t*); -void _ins_def_TAN (rt_t*, byte_t*); -void _ins_def_ISIN (rt_t*, byte_t*); -void _ins_def_ICOS (rt_t*, byte_t*); -void _ins_def_ITAN (rt_t*, byte_t*); -void _ins_def_MOD (rt_t*, byte_t*); -void _ins_def_OR (rt_t*, byte_t*); -void _ins_def_XOR (rt_t*, byte_t*); -void _ins_def_NAND (rt_t*, byte_t*); - -void _ins_def_GTHAN (rt_t*, byte_t*); -void _ins_def_LTHAN (rt_t*, byte_t*); -void _ins_def_EQ (rt_t*, byte_t*); -void _ins_def_NOT (rt_t*, byte_t*); - -void _ins_def_STARTL (rt_t*, byte_t*); -void _ins_def_CLOOP (rt_t*, byte_t*); -void _ins_def_BREAK (rt_t*, byte_t*); -void _ins_def_DONE (rt_t*, byte_t*); - -void _ins_def_GOTO (rt_t*, byte_t*); -void _ins_def_JUMPF (rt_t*, byte_t*); -void _ins_def_CALL (rt_t*, byte_t*); - -void _ins_def_PUSH (rt_t*, byte_t*); -void _ins_def_DEL (rt_t*, byte_t*); -void _ins_def_GET (rt_t*, byte_t*); -void _ins_def_GETP (rt_t*, byte_t*); -void _ins_def_CALLM (rt_t*, byte_t*); - -void _ins_def_RETURN (rt_t*, byte_t*); -void _ins_def_NEW (rt_t*, byte_t*); -void _ins_def_LSIZE (rt_t*, byte_t*); -void _ins_def_DECLASS (rt_t*, byte_t*); -void _ins_def_DEFUN (rt_t*, byte_t*); +void _ins_def_NULL (rt_t*, bc_cont*); +void _ins_def_SYNC (rt_t*, bc_cont*); +void _ins_def_ARGB (rt_t*, bc_cont*); +void _ins_def_LIBC (rt_t*, bc_cont*); + +void _ins_def_POP (rt_t*, bc_cont*); +void _ins_def_ROT (rt_t*, bc_cont*); +void _ins_def_DUP (rt_t*, bc_cont*); +void _ins_def_ROT_THREE(rt_t*, bc_cont*); + +void _ins_def_DEC (rt_t*, bc_cont*); +void _ins_def_LOV (rt_t*, bc_cont*); +void _ins_def_STV (rt_t*, bc_cont*); +void _ins_def_LOC (rt_t*, bc_cont*); +void _ins_def_CTS (rt_t*, bc_cont*); + +void _ins_def_TYPEOF (rt_t*, bc_cont*); +void _ins_def_CAST (rt_t*, bc_cont*); + +void _ins_def_ADD (rt_t*, bc_cont*); +void _ins_def_SUB (rt_t*, bc_cont*); +void _ins_def_MULT (rt_t*, bc_cont*); +void _ins_def_DIV (rt_t*, bc_cont*); +void _ins_def_POW (rt_t*, bc_cont*); +void _ins_def_BRT (rt_t*, bc_cont*); +void _ins_def_SIN (rt_t*, bc_cont*); +void _ins_def_COS (rt_t*, bc_cont*); +void _ins_def_TAN (rt_t*, bc_cont*); +void _ins_def_ISIN (rt_t*, bc_cont*); +void _ins_def_ICOS (rt_t*, bc_cont*); +void _ins_def_ITAN (rt_t*, bc_cont*); +void _ins_def_MOD (rt_t*, bc_cont*); +void _ins_def_OR (rt_t*, bc_cont*); +void _ins_def_XOR (rt_t*, bc_cont*); +void _ins_def_NAND (rt_t*, bc_cont*); + +void _ins_def_GTHAN (rt_t*, bc_cont*); +void _ins_def_LTHAN (rt_t*, bc_cont*); +void _ins_def_EQ (rt_t*, bc_cont*); +void _ins_def_NOT (rt_t*, bc_cont*); + +void _ins_def_STARTL (rt_t*, bc_cont*); +void _ins_def_CLOOP (rt_t*, bc_cont*); +void _ins_def_BREAK (rt_t*, bc_cont*); +void _ins_def_DONE (rt_t*, bc_cont*); + +void _ins_def_GOTO (rt_t*, bc_cont*); +void _ins_def_JUMPF (rt_t*, bc_cont*); +void _ins_def_CALL (rt_t*, bc_cont*); + +void _ins_def_PUSH (rt_t*, bc_cont*); +void _ins_def_DEL (rt_t*, bc_cont*); +void _ins_def_GET (rt_t*, bc_cont*); +void _ins_def_GETP (rt_t*, bc_cont*); +void _ins_def_CALLM (rt_t*, bc_cont*); + +void _ins_def_RETURN (rt_t*, bc_cont*); +void _ins_def_NEW (rt_t*, bc_cont*); +void _ins_def_DECLASS (rt_t*, bc_cont*); +void _ins_def_DEFUN (rt_t*, bc_cont*); #endif //INS_DEF_H diff --git a/src/vm/inc/ins_mdata.h b/src/vm/inc/ins_mdata.h @@ -78,7 +78,6 @@ \ /* RETURN */ INS_MDATA[0xF0] = encode(0, A_NULL, A_NULL, A_NULL); \ /* NEW */ INS_MDATA[0xF1] = encode(1, A_WORD, A_NULL, A_NULL); \ -/* LSIZE */ INS_MDATA[0xF2] = encode(1, A_WORD, A_NULL, A_NULL); \ /* DECLASS */ INS_MDATA[0xFE] = encode(2, A_WORD, A_DYNC, A_NULL); \ /* DEFUN */ INS_MDATA[0xFF] = encode(3, A_WORD, A_BYTE, A_DYNC); diff --git a/src/vm/inc/pc.h b/src/vm/inc/pc.h @@ -37,8 +37,6 @@ void pc_update(pc_t*); */ void pc_inc(pc_t*, pc_addr); -int pc_safe(pc_t*); - /* Branch */ void pc_branch(pc_t*, pc_addr); diff --git a/src/vm/src/bc.c b/src/vm/src/bc.c @@ -2,6 +2,8 @@ #include <stdio.h> #include "bc.h" + +#include "ins_adata.h" #include "is.h" #include "fh.h" #include "helper.h" @@ -48,8 +50,8 @@ void bc_cont_del(bc_cont* root) free(root); } -/* Deallocates all the things, assuming the arguement is the root. - * bc_cont* - bytecode container, root node (hopefully) +/* Given a file object, and an instance of `bc_cont` with proper metadata, this + * function will read arguements into bc_cont. */ void get_args(FILE* f, bc_cont* ins) { @@ -74,21 +76,23 @@ void get_args(FILE* f, bc_cont* ins) } } } - byte_t* get_byte_arg(FILE* f) { return read_bytes(f, 1); } - byte_t* get_word_arg(FILE* f) { return read_bytes(f, 2); } - byte_t* get_dync_arg(FILE* f) { return read_until_null(f); } + +void process_args(bc_cont* ins) +{ + +} /* Scan to +/- int in bytecode chain * bc_cont* - bytecode container [0] @@ -137,6 +141,7 @@ bc_cont* bc_read(char* fname) byte = read_byte(f); get_opcode(byte, ptr); get_args(f, ptr); + process_args(ptr); ptr->real_addr = addr; diff --git a/src/vm/src/ins_adata.c b/src/vm/src/ins_adata.c @@ -0,0 +1,17 @@ +/* `ins_adata.h` provides per-opcode arguement type data. + * Provides subroutines for individual opcodes + */ + +#include <stdlib.h> +#include <stdio.h> + +#include "ins_adata.h" + +#include "bc.h" +#include "is.h" +#include "var.h" +#include "helper.h" + +void init_adata( void ) +{ +} diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -68,7 +68,6 @@ void init_ins_def( void ) INS_DEF[0xF0] = _ins_def_RETURN; INS_DEF[0xF1] = _ins_def_NEW; - INS_DEF[0xF2] = _ins_def_LSIZE; INS_DEF[0xFE] = _ins_def_DECLASS; INS_DEF[0xFF] = _ins_def_DEFUN; } @@ -84,168 +83,233 @@ int ins_def_is_valid(bc_cont* line) return rv; } -void _ins_def_NULL (rt_t* ctx, byte_t* args) +void _ins_def_NULL (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_SYNC (rt_t* ctx, byte_t* args) +void _ins_def_SYNC (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ARGB (rt_t* ctx, byte_t* args) +void _ins_def_ARGB (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_LIBC (rt_t* ctx, byte_t* args) +void _ins_def_LIBC (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_POP (rt_t* ctx, byte_t* args) +void _ins_def_POP (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ROT (rt_t* ctx, byte_t* args) +void _ins_def_ROT (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DUP (rt_t* ctx, byte_t* args) +void _ins_def_DUP (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ROT_THREE(rt_t* ctx, byte_t* args) +void _ins_def_ROT_THREE(rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DEC (rt_t* ctx, byte_t* args) +void _ins_def_DEC (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_LOV (rt_t* ctx, byte_t* args) +void _ins_def_LOV (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_STV (rt_t* ctx, byte_t* args) +void _ins_def_STV (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_LOC (rt_t* ctx, byte_t* args) +void _ins_def_LOC (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_CTS (rt_t* ctx, byte_t* args) +void _ins_def_CTS (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_TYPEOF (rt_t* ctx, byte_t* args) +void _ins_def_TYPEOF (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_CAST (rt_t* ctx, byte_t* args) +void _ins_def_CAST (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ADD (rt_t* ctx, byte_t* args) +void _ins_def_ADD (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_SUB (rt_t* ctx, byte_t* args) +void _ins_def_SUB (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_MULT (rt_t* ctx, byte_t* args) +void _ins_def_MULT (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DIV (rt_t* ctx, byte_t* args) +void _ins_def_DIV (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_POW (rt_t* ctx, byte_t* args) +void _ins_def_POW (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_BRT (rt_t* ctx, byte_t* args) +void _ins_def_BRT (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_SIN (rt_t* ctx, byte_t* args) +void _ins_def_SIN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_COS (rt_t* ctx, byte_t* args) +void _ins_def_COS (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_TAN (rt_t* ctx, byte_t* args) +void _ins_def_TAN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ISIN (rt_t* ctx, byte_t* args) +void _ins_def_ISIN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ICOS (rt_t* ctx, byte_t* args) +void _ins_def_ICOS (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_ITAN (rt_t* ctx, byte_t* args) +void _ins_def_ITAN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_MOD (rt_t* ctx, byte_t* args) +void _ins_def_MOD (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_OR (rt_t* ctx, byte_t* args) +void _ins_def_OR (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_XOR (rt_t* ctx, byte_t* args) +void _ins_def_XOR (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_NAND (rt_t* ctx, byte_t* args) +void _ins_def_NAND (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_GTHAN (rt_t* ctx, byte_t* args) +void _ins_def_GTHAN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_LTHAN (rt_t* ctx, byte_t* args) +void _ins_def_LTHAN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_EQ (rt_t* ctx, byte_t* args) +void _ins_def_EQ (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_NOT (rt_t* ctx, byte_t* args) +void _ins_def_NOT (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_STARTL (rt_t* ctx, byte_t* args) +void _ins_def_STARTL (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_CLOOP (rt_t* ctx, byte_t* args) +void _ins_def_CLOOP (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_BREAK (rt_t* ctx, byte_t* args) +void _ins_def_BREAK (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DONE (rt_t* ctx, byte_t* args) +void _ins_def_DONE (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_GOTO (rt_t* ctx, byte_t* args) +void _ins_def_GOTO (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_JUMPF (rt_t* ctx, byte_t* args) +void _ins_def_JUMPF (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_CALL (rt_t* ctx, byte_t* args) +void _ins_def_CALL (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_PUSH (rt_t* ctx, byte_t* args) +void _ins_def_PUSH (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DEL (rt_t* ctx, byte_t* args) +void _ins_def_DEL (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_GET (rt_t* ctx, byte_t* args) +void _ins_def_GET (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_GETP (rt_t* ctx, byte_t* args) +void _ins_def_GETP (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_CALLM (rt_t* ctx, byte_t* args) +void _ins_def_CALLM (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_RETURN (rt_t* ctx, byte_t* args) +void _ins_def_RETURN (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_NEW (rt_t* ctx, byte_t* args) +void _ins_def_NEW (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_LSIZE (rt_t* ctx, byte_t* args) +void _ins_def_DECLASS (rt_t* ctx, bc_cont* line) { + pc_inc(ctx->pc, 1); } -void _ins_def_DECLASS (rt_t* ctx, byte_t* args) -{ -} -void _ins_def_DEFUN (rt_t* ctx, byte_t* args) +void _ins_def_DEFUN (rt_t* ctx, bc_cont* line) { + //ns_dec(ctx->vars, FUNC, 0, arg_to_int(0, 0, line)); + + int nsize; + + for (nsize = 0; ctx->pc->line->next != NULL; pc_update(ctx->pc)) + { + pc_inc(ctx->pc, 1); + if (ctx->pc->line->op == 0xF0) + { + break; + } else + if (ctx->pc->line->op == 0x20) + { + nsize++; + } + } + + printf("Namespace size for thingy: %i\n", nsize); } diff --git a/src/vm/src/is.c b/src/vm/src/is.c @@ -16,6 +16,7 @@ void get_opcode(byte_t byte, bc_cont* ins) { ins->op = byte; ins->mdata = INS_MDATA[byte]; + //ins->adata = INS_ADATA[byte]; } /* Fills in metadata in @param byte_t. diff --git a/src/vm/src/main.c b/src/vm/src/main.c @@ -2,18 +2,20 @@ #include "proc.h" #include "rt.h" +#include "is.h" #include "ins_def.h" -#include "ins_mdata.h" +#include "ins_adata.h" #include "helper.h" int main(int argc, char** argv) { - ASSERT(argc < 0, "C'mon, man! Gimme some args\n"); + ASSERT(argc > 1, "C'mon, man! Gimme some args\n"); init_mdata(); // Initalize the instruction definitions + init_adata(); init_ins_def(); - rt_t* runtime = proc_init(argv[0]); // Initalize process + rt_t* runtime = proc_init(argv[1]); // Initalize process proc_run(runtime); // Execute runtime diff --git a/src/vm/src/pc.c b/src/vm/src/pc.c @@ -48,24 +48,6 @@ void pc_inc(pc_t* pc, pc_addr addr) pc->address = pc->address + addr; } -int pc_safe(pc_t* pc) -{ - N_ASSERT(pc); - - int rv = 0; - - if (pc->address >= pc->root->real_addr) - { - rv = 0; - } else - if (pc->address < pc->root->real_addr) - { - rv = 1; - } - - return rv; -} - void pc_branch(pc_t* pc, pc_addr addr) { N_ASSERT(pc); diff --git a/src/vm/src/proc.c b/src/vm/src/proc.c @@ -29,11 +29,16 @@ rt_t* proc_init(char* fname) void proc_run(rt_t* ctx) { N_ASSERT(ctx); + + int n; - for (pc_branch(ctx->pc, 0); pc_safe(ctx->pc); pc_update(ctx->pc)) + for (n = 0; ctx->pc->line->next != NULL; pc_update(ctx->pc)) { - ins_def_is_valid(ctx->pc->line); - INS_DEF[ctx->pc->line->op](ctx, ctx->pc->line->args); + printf("%i: %x\n", n, ctx->pc->line->op); + + INS_DEF[ctx->pc->line->op](ctx, ctx->pc->line); + + n++; } } diff --git a/src/vm/src/rt.c b/src/vm/src/rt.c @@ -43,7 +43,7 @@ void rt_ctx_del(rt_t* ctx) N_ASSERT(ctx->vars); ns_del(ctx->vars); - + N_ASSERT(ctx->pc); pc_del(ctx->pc); } @@ -66,7 +66,7 @@ void *rt_worker_run(void* ctx) rt_worker* c; c = (rt_worker*)ctx; - //TODO actually make this run the function that runs opcodes n' what not + //TODO this. return 0; } diff --git a/src/vm/src/stk.c b/src/vm/src/stk.c @@ -8,20 +8,29 @@ stk_t* stk_new( void ) { stk_t* new = (stk_t*)malloc(sizeof(stk_t)); - ASSERT(new != NULL, "Could not allocate memory\n"); + M_ASSERT(new); + + new->data = var_new(VOID); + new->next = NULL; return new; } void stk_del(stk_t* root) { - if (root->next != NULL) + //N_ASSERT(root); + + var_cont* data; + + while ((data = stk_pop(&root)) != NULL) { - stk_del(root->next); + if (data != NULL) + { + var_del(data); + } } - if (root->data != NULL) - var_del(root->data); + var_del(root->data); free(root); } @@ -29,7 +38,7 @@ void stk_del(stk_t* root) var_cont* stk_pop(stk_t** root) { if ((*root)->next == NULL) - return 0; + return NULL; stk_t* new = (*root)->next; var_cont* data = (*root)->data; diff --git a/src/vm/src/var.c b/src/vm/src/var.c @@ -72,7 +72,7 @@ var_cont* var_new(b_type type) new->type = type; - new->data = var_data_alloc(type); + new->data = NULL; return new; } @@ -102,8 +102,7 @@ void var_data_free(void** data, b_type type) void var_del(var_cont* var) { - if (var == NULL) - return; + N_ASSERT(var); if (var->data != NULL) var_data_free(var->data, var->type);