develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33442 - in trunk: . compilers/pirc/new

From:
kjs
Date:
December 2, 2008 08:26
Subject:
[svn:parrot] r33442 - in trunk: . compilers/pirc/new
Message ID:
20081202162620.8E217CB9AF@x12.develooper.com
Author: kjs
Date: Tue Dec  2 08:26:19 2008
New Revision: 33442

Added:
   trunk/compilers/pirc/new/bcgen.c   (contents, props changed)
   trunk/compilers/pirc/new/bcgen.h   (contents, props changed)
Modified:
   trunk/MANIFEST

Log:
[pirc] add files for bytecode generator. some data structures are defined, but details will be filled in later. Long term goal is to create a separate library for these files, which is why they should not have any dependencies on pirc data structures/resources.
+ update MANIFEST.

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	(original)
+++ trunk/MANIFEST	Tue Dec  2 08:26:19 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools\dev\mk_manifest_and_skip.pl Tue Dec  2 10:07:56 2008 UT
+# generated by tools\dev\mk_manifest_and_skip.pl Tue Dec  2 16:24:22 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -174,6 +174,8 @@
 compilers/pirc/macro/macrolexer.h                           []
 compilers/pirc/macro/macroparser.c                          []
 compilers/pirc/macro/macroparser.h                          []
+compilers/pirc/new/bcgen.c                                  []
+compilers/pirc/new/bcgen.h                                  []
 compilers/pirc/new/hdocprep.c                               []
 compilers/pirc/new/hdocprep.l                               []
 compilers/pirc/new/main.c                                   []

Added: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- (empty file)
+++ trunk/compilers/pirc/new/bcgen.c	Tue Dec  2 08:26:19 2008
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ * Copyright (C) 2008, The Perl Foundation.
+ */
+
+#include "bcgen.h"
+
+/* private bits of the bytecode generator */
+
+typedef enum bc_const_types {
+    BC_INT_CONST_TYPE,
+    BC_NUM_CONST_TYPE,
+    BC_STR_CONST_TYPE,
+    BC_PMC_CONST_TYPE
+
+} bc_type;
+
+typedef union const_value {
+    INTVAL  ival;
+    NUMVAL  nval;
+    STRING *sval;
+    PMC    *pval;
+
+} const_value;
+
+typedef struct bc_const {
+    bc_type           type;  /* type of constant */
+    int               index; /* index into constant table */
+    const_value       value; /* this constant's value */
+
+    struct bc_const * next;  /* linked list */
+
+} bc_const;
+
+
+/* Note that typedef of struct bytecode is already done in the header file */
+
+struct bytecode {
+    int          num_constants;
+    bc_const    *constants;
+
+};
+
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Added: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- (empty file)
+++ trunk/compilers/pirc/new/bcgen.h	Tue Dec  2 08:26:19 2008
@@ -0,0 +1,82 @@
+/*
+ * $Id$
+ * Copyright (C) 2008, The Perl Foundation.
+ */
+
+#ifndef PARROT_BCGEN_H_GUARD
+#define PARROT_BCGEN_H_GUARD
+
+/* temporary */
+#define INTVAL  int
+#define NUMVAL  double
+#define STRING  char
+#define PMC     void
+
+/* the type name is exported, but not its private bits */
+struct bytecode;
+
+typedef struct bytecode bytecode;
+
+
+
+bytecode *new_bytecode(void);
+
+/* call this to write the PBC file */
+void write_pbc_file(bytecode * const bc);
+
+
+/* emitting ops */
+
+void emit_opcode(bytecode * const bc, int opcode);
+
+/* does a look-up of the op by name, then emit that bytecode */
+void emit_op_by_name(bytecode * const bc, char const * const name);
+
+
+/* emitting operands */
+
+void emit_int_arg(bytecode * const bc, int argvalue);
+
+void emit_pmc_arg(bytecode * const bc, int pmc_const_index);
+
+void emit_num_arg(bytecode * const bc, int num_const_index);
+
+void emit_string_arg(bytecode * const bc, int string_const_index);
+
+
+/* for adding constants */
+
+/* returns the id in the constant table */
+int add_pmc_const(bytecode * const bc);
+
+int add_string_const(bytecode * const bc, STRING *s);
+
+int add_num_const(bytecode * const bc, NUMVAL f);
+
+int add_int_const(bytecode * const bc, INTVAL i);
+
+
+/* some functions to update constants */
+
+void update_pmc_const(bytecode * const bc, int pmc_const_index
+/* what kind of value arg? */);
+
+void update_string_const(bytecode * const bc, int str_const_index, STRING *s);
+/* XXX and other types... */
+
+/* XXX todo: define some API functions for finding values, etc. like this: */
+int get_string_const_index(bytecode * const bc, STRING *s);
+/* retrieves the index of s in the constant table */
+
+/* for sake of completeness.. */
+void remove_const(bytecode * const bc, int const_index);
+/* removes constant in slot C<const_index> from constant table */
+
+#endif /* PARROT_BCGEN_H_GUARD */
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About