Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add an internal_pmc/context as the code path for contexts.

  • Loading branch information...
commit 7fd870d93d44065f66bc47728f46294a9ae697dd 1 parent a99e827
Jon Gentle authored
9 Makefile
View
@@ -1,6 +1,11 @@
PERL = perl
-HEADERS = config.h lorito.h microcode.h interp.h loader.h pmc.h internal_pmc.h pmc_func.h
-COMPILED = main.o interp.o core.o loader.o pmc.o internal_pmc.o pmc_func.o
+
+INTERNAL_PMC_HEADERS = internal_pmc/context.h
+HEADERS = $(INTERNAL_PMC_HEADERS) config.h lorito.h microcode.h interp.h loader.h pmc.h internal_pmc.h pmc_func.h
+
+INTERNAL_PMC_COMPILED = internal_pmc/context.o
+COMPILED = $(INTERNAL_PMC_COMPILED) main.o interp.o core.o loader.o pmc.o internal_pmc.o pmc_func.o
+
TEST_FILES = $(wildcard t/*.t)
COMPILED_TESTS = $(patsubst %.t,%.ito,$(TEST_FILES))
9 internal_pmc.c
View
@@ -4,6 +4,7 @@
#include "pmc.h"
#include "internal_pmc.h"
#include "interp.h"
+#include "internal_pmc/context.h"
/*
Lorito_PMC *
@@ -136,8 +137,8 @@ lorito_datadef_block_new(Lorito_Interp *interp, char *name, int length)
void *data = (void *) malloc(sizeof(Lorito_Opcode) * length);
Lorito_Datadefseg *result = (Lorito_Datadefseg *) malloc(sizeof(Lorito_Datadefseg));
- result->pmc.size = 0;
- result->pmc.internal_type = CONST_BLOCK;
+ result->pmc.size = length;
+ result->pmc.internal_type = DATA_BLOCK;
result->name = name;
result->length = length * sizeof(Lorito_Opcode);
result->data = data;
@@ -165,11 +166,13 @@ lorito_ctx_new(Lorito_Interp *interp, Lorito_Ctx *next_ctx, Lorito_PMC *codeseg)
result->next_ctx = next_ctx;
result->pc = 0;
result->current_codeseg = codeseg;
- result->current_file = NULL;
+ result->current_file = null;
result->args_cnt = 0;
result->rets_cnt = 0;
+ result->pmc.lookup = (Lorito_PMC *) lorito_c_method_new(interp, lorito_internal_pmc_context_lookup);
+
// We are going to blank out $S0 and $P0, but the rest may still cause
// a seg fault. TODO
result->regs.regs_s[0] = lorito_string(interp, 0, "");
78 internal_pmc/context.c
View
@@ -0,0 +1,78 @@
+// This will drive the context pmc logic
+
+#include "lorito.h"
+#include "pmc.h"
+#include "interp.h"
+#include "internal_pmc.h"
+#include "internal_pmc/context.h"
+
+void
+lorito_internal_pmc_context_lookup(Lorito_Interp *interp, Lorito_Ctx *ctx)
+{
+ Lorito_PMC *inkey = lorito_pop_arg(interp, ctx);
+ if (!IS_BOX_STR(inkey))
+ {
+ lorito_push_arg(interp, ctx, null);
+ return;
+ }
+ Lorito_Str *key = ((Lorito_BoxStr *) inkey)->data;
+
+ Lorito_PMC *vtable = lorito_pop_arg(interp, ctx);
+ lorito_clr_arg(interp, ctx);
+
+ if (key == lorito_string(interp, 0, "GET_DATASEG"))
+ {
+ lorito_push_arg(interp, ctx, (Lorito_PMC *) lorito_c_method_new(interp, lorito_internal_pmc_context_get_dataseg));
+ return;
+ }
+ lorito_push_arg(interp, ctx, null);
+ return;
+}
+
+void
+lorito_internal_pmc_context_get_dataseg(Lorito_Interp *interp, Lorito_Ctx *ctx)
+{
+ Lorito_PMC *self = lorito_pop_arg(interp, ctx);
+ Lorito_PMC *box_name = lorito_pop_arg(interp, ctx);
+ Lorito_Str *name;
+ lorito_clr_arg(interp, ctx);
+
+ printf("%d\n", self->internal_type);
+
+ if (!IS_CONTEXT(self))
+ {
+ //Bah.
+ printf("2\n");
+ return;
+ }
+ printf("3\n");
+ Lorito_Ctx *self_ctx = (Lorito_Ctx *) self;
+
+ printf("4\n");
+ if (IS_BOX_STR(box_name))
+ {
+ name = ((Lorito_BoxStr *) box_name)->data;
+ }
+ else
+ {
+ name = lorito_string(interp, 0, self_ctx->current_constseg->name);
+ }
+ printf("%s\n", name);
+
+ Lorito_File *file = self_ctx->current_file;
+
+ int i;
+ printf("5\n");
+ for (i = 0; i < file->datadefseg_count; i++)
+ {
+ if (lorito_string(interp, 0, file->datadefsegs[i]->name) == name)
+ {
+ lorito_push_arg(interp, ctx, PMC file->datadefsegs[i]);
+ printf("6\n");
+ break;
+ }
+ }
+ printf("7\n");
+
+ return;
+}
12 internal_pmc/context.h
View
@@ -0,0 +1,12 @@
+#include "lorito.h"
+
+#ifndef LORITO_INTERNAL_PMC_CONTEXT_H_GUARD
+#define LORITO_INTERNAL_PMC_CONTEXT_H_GUARD
+
+void
+lorito_internal_pmc_context_lookup(Lorito_Interp *interp, Lorito_Ctx *ctx);
+
+void
+lorito_internal_pmc_context_get_dataseg(Lorito_Interp *interp, Lorito_Ctx *ctx);
+
+#endif /* LORITO_INTERNAL_PMC_CONTEXT_H_GUARD */
Please sign in to comment.
Something went wrong with that request. Please try again.