language

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

commit 2a7d35da30a50d524edbea346756d3dfeeab80f4
parent 196b9fcd340b1b8c19946d90bf5e609f9e146eb5
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Thu Feb 25 13:39:14 2016

Updated SPECIFICATION, ins_mdata, rt.h, test.sh, STARTED to outline ins_def.(h|c)

Diffstat:
 doc/SPECIFICATION          | 22 +++++++++++-----------
 src/vm/inc/ins_def.h       | 15 +++++++++++++++
 src/vm/inc/ins_mdata.h     |  2 ++
 src/vm/inc/rt.h            | 15 ++++++++++++---
 src/vm/src/ins_def.c       | 12 ++++++++++++
 src/vm/tests/tools/test.sh |  3 +++
 6 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/doc/SPECIFICATION b/doc/SPECIFICATION @@ -106,9 +106,9 @@ be assigned or re-assigned to variables. Keywords: TOS - 'Top Of Stack' The top element - S<[variable]> - Static Arguement. Default 1 byte. + S<[variable]> - Static Arguement. (1 byte) A<[variable]> - Address Arguement. Address width will vary on file size, - decided on compile time. + decided on compile time. (for now, a word) D<[variable]> - Dynamic bytecode arguement. Arguements terminated with NULL byte. ------------------------------------------------------------------------------- @@ -121,10 +121,10 @@ Keywords: ------------------------------------------------------------------------------- 2 - Variable management ------------------------------------------------------------------------------- -20 DEC S<scope> S<type> D<ref> - declare variable of type -21 LOV S<scope> D<ref> - loads reference variable on to stack -22 STV S<scope> D<ref> - stores TOS to reference variable -23 LOC S<scope> D<ref> D<data> - loads constant into variable +20 DEC S<scope> S<type> A<ref> - declare variable of type +21 LOV S<scope> A<ref> - loads reference variable on to stack +22 STV S<scope> A<ref> - stores TOS to reference variable +23 LOC S<scope> A<ref> D<data> - loads constant into variable 24 CTS D<data> - loads constant into stack ------------------------------------------------------------------------------- 3 - Type management @@ -181,7 +181,7 @@ to TOS ------------------------------------------------------------------------------- 70 GOTO A<addr> - Goes to address 71 JUMPF S<n> - Goes forward <n> lines -7F CALL D<ref> - Calls function, pushes return value on to STACK. +7F CALL A<ref> - Calls function, pushes return value on to STACK. ------------------------------------------------------------------------------- 8 - Manipulating High-order Object Variables @@ -196,19 +196,19 @@ to TOS 82 GET - Gets key, TOS must be a keyed datastructure, and TOS1 must be a string that is a key in TOS. -83 GETP D<ref> - Get property of <ref> in object contained in TOS. pushes +83 GETP A<ref> - Get property of <ref> in object contained in TOS. pushes to stack -84 CALLM D<ref> - Call method of <ref> in object contained in TOS. Uses +84 CALLM A<ref> - Call method of <ref> in object contained in TOS. Uses arguement stack ------------------------------------------------------------------------------- F - Functions/classes ------------------------------------------------------------------------------- -FF DEFUN D<ref> S<type> D<args> - Un-funs everything. no, no- it defines a +FF DEFUN A<ref> S<type> D<args> - Un-funs everything. no, no- it defines a function. D<ref> is its name, S<type> is the return value, D<args> is the args. -FE DECLASS D<ref> D<args> - Defines a class. +FE DECLASS A<ref> D<args> - Defines a class. ------------------------------------------------------------------------------- 0 - SPECIAL BYTES ------------------------------------------------------------------------------- diff --git a/src/vm/inc/ins_def.h b/src/vm/inc/ins_def.h @@ -0,0 +1,15 @@ +/* `INS_DEF` provides instruction definitons + */ + +#ifndef INS_DEF_H +#define INS_DEF_H + +#include <stdlib.h> +#include <stdio.h> + +#include "rt.h" +#include "helper.h" + +void _ins_def_INSTRUCTIONNAME(rt_worker*, rt_context*); + +#endif INS_DEF_H diff --git a/src/vm/inc/ins_mdata.h b/src/vm/inc/ins_mdata.h @@ -1,6 +1,8 @@ #ifndef INS_MDATA_H #define INS_MDATA_H +#include "ins_def.h" + #define INS_MDATA_DEF() \ /* NULL */ INS_MDATA[0x00] = encode(0, A_NULL, A_NULL, A_NULL); \ /* POP */ INS_MDATA[0x10] = encode(1, A_BYTE, A_NULL, A_NULL); \ diff --git a/src/vm/inc/rt.h b/src/vm/inc/rt.h @@ -1,6 +1,9 @@ /* `rt.h` handles runtime management */ +#ifndef RT_H +#define RT_H + #include <stdlib.h> #include <stdio.h> @@ -19,13 +22,17 @@ typedef struct rt_info { typedef struct rt_worker { thrd_state state; + thread_t* thread_ctx; +} rt_worker + +typedef struct rt_context { stk_t* stack; + stk_t* argstk; ns_t* vars; ns_addr func; - thread_t* thread_ctx; -} rt_worker +} rt_context; -/* Initializes runtime environment, spawns main thread and +/* Initializes runtime environment, spawns main thread and * */ rt_info* rt_init(char); @@ -37,3 +44,5 @@ rt_worker* rt_spawnthread(rt_info*, ns_addr); void rt_runthread(rt_info*, rt_worker*); void* rt_workerfun(void*); + +#endif // RT_H diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -0,0 +1,12 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "ins_def.h" +#include "rt.h" +#include "helper.h" + +void _ins_def_INSTRUCTIONNAME(rt_worker* thread, rt_context* ctx) +{ + +} + diff --git a/src/vm/tests/tools/test.sh b/src/vm/tests/tools/test.sh @@ -1,5 +1,7 @@ #!/bin/bash +SEPARATOR="--------------------------------------------------------------------------------" + dir=$(ls) for i in $dir @@ -13,6 +15,7 @@ do printf "\n" ./test bytecode | diff /dev/stdin expected_output + printf "\n$SEPARATOR\n" cd .. fi done