Permalink
Browse files

Add internal_pmc/file as the code base for the file PMCs

  • Loading branch information...
1 parent 8c2a2d7 commit 8f0e31f0ba0b0966b68d3822471bf2ed5fae65b2 @atrodo committed Feb 9, 2011
Showing with 82 additions and 2 deletions.
  1. +2 −2 Makefile
  2. +3 −0 internal_pmc.c
  3. +68 −0 internal_pmc/file.c
  4. +9 −0 internal_pmc/file.h
View
4 Makefile
@@ -1,9 +1,9 @@
PERL = perl
-INTERNAL_PMC_HEADERS = internal_pmc/context.h
+INTERNAL_PMC_HEADERS = internal_pmc/context.h internal_pmc/file.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
+INTERNAL_PMC_COMPILED = internal_pmc/context.o internal_pmc/file.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)
View
3 internal_pmc.c
@@ -5,6 +5,7 @@
#include "internal_pmc.h"
#include "interp.h"
#include "internal_pmc/context.h"
+#include "internal_pmc/file.h"
/*
Lorito_PMC *
@@ -96,6 +97,8 @@ lorito_file_new(Lorito_Interp *interp, Lorito_Str *name)
lorito_pmc_init(interp, (Lorito_PMC *) result);
+ result->pmc.lookup = (Lorito_PMC *) lorito_c_method_new(interp, lorito_internal_pmc_file_lookup);
+
return result;
}
View
68 internal_pmc/file.c
@@ -0,0 +1,68 @@
+// This will drive the context pmc logic
+
+#include "lorito.h"
+#include "pmc.h"
+#include "interp.h"
+#include "internal_pmc.h"
+#include "internal_pmc/file.h"
+
+void
+lorito_internal_pmc_file_get_method(Lorito_Interp *interp, Lorito_Ctx *ctx)
+{
+ Lorito_PMC *inkey = lorito_pop_arg(interp, ctx);
+ Lorito_PMC *inself = lorito_pop_arg(interp, ctx);
+ lorito_clr_arg(interp, ctx);
+
+ printf("1\n");
+ if (!IS_BOX_STR(inkey))
+ {
+ lorito_push_arg(interp, ctx, null);
+ return;
+ }
+ printf("2\n");
+ if (!IS_FILE_BLOCK(inself))
+ {
+ //Bah.
+ lorito_push_arg(interp, ctx, null);
+ return;
+ }
+
+ Lorito_File *self = (Lorito_Ctx *) inself;
+ Lorito_Str *key = ((Lorito_BoxStr *) inkey)->data;
+ Lorito_PMC *result = null;
+
+ int i;
+ for (i=0; i < self->codeseg_count; i++)
+ {
+ printf("%s\n", self->codesegs[i]->name);
+ if (self->codesegs[i]->name == key)
+ {
+ lorito_push_arg(interp, ctx, PMC self->codesegs[i]);
+ return;
+ }
+ }
+}
+
+
+void
+lorito_internal_pmc_file_lookup(Lorito_Interp *interp, Lorito_Ctx *ctx)
+{
+ Lorito_PMC *inkey = lorito_pop_arg(interp, ctx);
+ Lorito_PMC *vtable = lorito_pop_arg(interp, ctx);
+ lorito_clr_arg(interp, ctx);
+
+ if (!IS_BOX_STR(inkey))
+ {
+ lorito_push_arg(interp, ctx, null);
+ return;
+ }
+ Lorito_Str *key = ((Lorito_BoxStr *) inkey)->data;
+
+ if (key == lorito_string(interp, 0, "GET_METHOD"))
+ {
+ lorito_push_arg(interp, ctx, (Lorito_PMC *) lorito_c_method_new(interp, lorito_internal_pmc_file_get_method));
+ return;
+ }
+ lorito_push_arg(interp, ctx, null);
+ return;
+}
View
9 internal_pmc/file.h
@@ -0,0 +1,9 @@
+#include "lorito.h"
+
+#ifndef LORITO_INTERNAL_PMC_FILE_H_GUARD
+#define LORITO_INTERNAL_PMC_FILE_H_GUARD
+
+void
+lorito_internal_pmc_file_lookup(Lorito_Interp *interp, Lorito_Ctx *ctx);
+
+#endif /* LORITO_INTERNAL_PMC_FILE_H_GUARD */

0 comments on commit 8f0e31f

Please sign in to comment.