~m15o/15f

e8dba58eb42117846d65a837a5742ba7a5e58be5 — m15o 6 months ago 8bd4cce
adding jmp
6 files changed, 26 insertions(+), 4 deletions(-)

M src/const.h
M src/interpret.c
M src/interpret.h
M src/parse.c
M src/runtime.c
M src/runtime.h
M src/const.h => src/const.h +1 -0
@@ 34,6 34,7 @@ typedef enum opcodes {
	COM,
	ALO,
	HER,
	JMP,
  LEN
} opcode;


M src/interpret.c => src/interpret.c +9 -3
@@ 7,7 7,7 @@

errc exec(Ctx *ctx, opcode op);

errc address_interpreter(Ctx *ctx, int n) {
errc address_interpreter(Ctx *ctx, int ptr) {
  opcode op;
  errc e;
  int *m_ptr = &ctx->m_ptr;


@@ 15,7 15,7 @@ errc address_interpreter(Ctx *ctx, int n) {
  if ((e = stack_push(&ctx->rstack, *m_ptr)) != SUCCESS)
    return e;

  *m_ptr = ctx->dict.entries[n].ptr;
  *m_ptr = ptr;

  while ((op = ctx->dict.mem.data[(*m_ptr)++]) != EXT) {
    if ((e = exec(ctx, op)) != SUCCESS)


@@ 28,6 28,8 @@ errc address_interpreter(Ctx *ctx, int n) {
/* exec: attempt to execute opcode */
errc exec(Ctx *ctx, opcode op) {
  int n;
	errc e;
	cell adr;

  switch (op) {
  case PSH:


@@ 70,9 72,13 @@ errc exec(Ctx *ctx, opcode op) {
    return run_alo(ctx);
  case HER:
    return run_her(ctx);
  case JMP:
		if ((e = stack_pop(&ctx->pstack, &adr)) != SUCCESS)
			return e;
		return address_interpreter(ctx, adr);
  default:
    if ((n = op - LEN) >= 0 && n <= ctx->dict.top) {
      return address_interpreter(ctx, n);
      return address_interpreter(ctx, ctx->dict.entries[n].ptr);
    }
    break;
  }

M src/interpret.h => src/interpret.h +1 -1
@@ 4,6 4,6 @@
#include "ctx.h"

errc interpret(Ctx *ctx);
errc address_interpreter(Ctx *ctx, int n);
errc address_interpreter(Ctx *ctx, int ptr);

#endif

M src/parse.c => src/parse.c +3 -0
@@ 74,6 74,9 @@ errc parse_op(Ctx *ctx, opcode *op, char *token) {
  } else if (strcmp(token, "here") == 0) {
    *op = HER;
    return SUCCESS;
  } else if (strcmp(token, "jmp") == 0) {
    *op = JMP;
    return SUCCESS;
	}

  /* check in dictionary */

M src/runtime.c => src/runtime.c +11 -0
@@ 1,4 1,5 @@
#include "runtime.h"
/* #include "interpret.h" */
#include "const.h"
#include "parse.h"
#include "screen.h"


@@ 359,3 360,13 @@ errc run_alo(Ctx *ctx) { /* ( n -- ) */
  m->top += n;
  return SUCCESS;
}

/* errc run_jmp(Ctx *ctx) { /\* ( adr -- ) *\/ */
/* 	cell adr; */
/* 	errc e; */

/*   if ((e = stack_pop(&ctx->pstack, &adr)) != SUCCESS) */
/*     return e; */

/* 	return SUCCESS; */
/* } */

M src/runtime.h => src/runtime.h +1 -0
@@ 12,6 12,7 @@ errc run_lod(Ctx *ctx); /* ( addr -- val ) */
errc run_sto(Ctx *ctx); /* ( n addr -- ) */
errc run_emt(Ctx *ctx); /* ( c -- ) */
errc run_clr(Ctx *ctx); /* ( r g b -- ) */
/* errc run_jmp(Ctx *ctx); /\* ( adr -- ) *\/ */

/* stack manipulation */
errc run_swp(Ctx *ctx); /* ( n1 n2 -- n2 n1 ) */