Permalink
Browse files

Merge remote-tracking branch 'nbrown/m0-c-single-deref' into m0

  • Loading branch information...
2 parents 0e5c911 + 2f1e85a commit 9bde02013fe12d81c15c0264277390bfd276a7be @cotto cotto committed Apr 29, 2012
@@ -140,16 +140,15 @@ Execution Environments" [TBC].
=head2 Scope of This Document
This document only covers M0 and the minimum VM necessary to support it.
-Anything beyond that, e.g. the meta-object model or in-memory layout of call
-frames, is beyond its scope.
+Anything beyond that, e.g. the meta-object model, is beyond its scope.
=head2 Call Frames
This is the central data structure at the M0 level. The call frame graph
contains most of the state that is needed to execute M0 bytecode. A pointer to
the current call frame will be passed to each op as the implicit first
argument, though this pointer (or equivalent) will not be stored in bytecode.
-It layout is described in detail in the C<Register Types and Call Frame
+It layout is described in detail in the L<Register Types and Call Frame
Structure> section.
Call frames were previously referred to as contexts. The name "call frame" was
@@ -793,14 +792,16 @@ are not require to have any defined semantics.
0x1D set_ref
0x1E set_byte
0x1F get_byte
- 0x20 csym
- 0x21 ccall_arg
- 0x22 ccall_ret
- 0x23 ccall
- 0x24 print_s
- 0x25 print_i
- 0x25 print_n
- 0x26 exit
+ 0x20 set_word
+ 0x21 get_word
+ 0x22 csym
+ 0x23 ccall_arg
+ 0x24 ccall_ret
+ 0x25 ccall
+ 0x26 print_s
+ 0x27 print_i
+ 0x28 print_n
+ 0x29 exit
=head2 Chunk Name Constants and Bytecode Loading
@@ -892,7 +893,7 @@ runloop does need to accomplish the following:
=item * execute the instruction
-=item * increment the pc, if needed
+=item * increment the pc by one, if needed
=back
@@ -1045,10 +1046,11 @@ data.
0 OP_FUNCS array of functions that implement ops
1 CHUNKS array of all loaded chunks
2 CHUNK_INFO array of chunk metadata (currently just names)
- 3 CALL_FRAMES array of all initial call frames
- 4 CONFIG static global config data
- 5 ARGC number of elements in ARGV
- 6 ARGV array of command-line arguments passed to the m0 program
+ 3 CHUNK_MAP
+ 4 CALL_FRAMES array of all initial call frames
+ 5 CONFIG static global config data
+ 6 ARGC number of elements in ARGV
+ 7 ARGV array of command-line arguments passed to the m0 program
C<CONFIG> should have at least the following values:
View
@@ -7,3 +7,6 @@
# define M0_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -8,3 +8,6 @@
# define M0_COMPILER_DEFINES_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -7,3 +7,6 @@
# define M0_CONSTANTS_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -4,3 +4,6 @@
# define M0_INTERP_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -2,21 +2,14 @@
# include "m0_mob_structures.h"
# include <stdint.h>
-typedef struct {
- unsigned short mob_version;
- unsigned short ireg_size;
- unsigned short nreg_size;
- unsigned short opcode_t_size;
- unsigned short pointer_size;
- unsigned short endianness;
- M0_Chunk *first_chunk;
- M0_Chunk *last_chunk;
-} M0_Interp;
+typedef uint64_t M0_Config[8];
typedef struct {
uint64_t registers[256];
} M0_CallFrame;
+typedef uint64_t M0_Interp[8];
+
enum CF_NAMED_REGS {
CF,
PCF,
@@ -32,5 +25,41 @@ enum CF_NAMED_REGS {
SPILLCF
};
+enum M0_INTERP_DATA {
+ OP_FUNCS,
+ CHUNKS,
+ CHUNK_INFO,
+ CHUNK_MAP,
+ CALL_FRAMES,
+ CONFIG,
+ ARGC,
+ ARGV
+};
+
+enum M0_CONFIG_DATA {
+ CFG_M0V,
+ CFG_REGSZ,
+ CFG_CFSZ,
+ CFG_IREGSZ,
+ CFG_NREGSZ,
+ CFG_OPCODESZ,
+ CFG_PTRSZ,
+ CFG_ENDIANNESS
+};
+
+typedef enum {
+ INVALID,
+ NAMED,
+ INTEGER,
+ NUMBER,
+ STRING,
+ POINTER
+} M0_RegisterType;
+
+
+
# define M0_INTERP_STRUCTURES_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -7,3 +7,6 @@ int load_mob_file( M0_Interp *interp, const char *filename );
# define M0_MOB_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -1,7 +1,9 @@
#ifndef M0_MOB_STRUCTURES_H
+# include <stdint.h>
typedef struct M0_Constants_Segment {
- const char **consts;
+ uint64_t *consts;
+ unsigned int *pointers;
unsigned long count;
} M0_Constants_Segment;
@@ -33,3 +35,6 @@ typedef struct M0_Chunk {
# define M0_MOB_STRUCTURES_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
@@ -52,3 +52,6 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf );
# define M0_OPS_H 1
#endif
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
View
@@ -39,6 +39,9 @@ main( int argc, const char *argv[]) {
if (!interp)
exit(1);
+ (*interp)[ARGC] = argc - 1;
+ (*interp)[ARGV] = (uint64_t)&(argv[1]);
+
if (argc < 2) {
fprintf( stderr, "Usage: m0 <filename.mob>\n" );
interp_free( interp );
@@ -63,17 +66,28 @@ main( int argc, const char *argv[]) {
M0_Interp *
new_interp() {
- return calloc( 1, sizeof (M0_Interp) );
+ M0_Interp *interp = calloc( 1, sizeof (M0_Interp) );
+ M0_Config *config = calloc( 1, sizeof (M0_Config) );
+ (*config)[CFG_REGSZ] = 8;
+ (*config)[CFG_CFSZ] = sizeof( M0_CallFrame );
+
+ (*interp)[CONFIG] = (uint64_t)config;
+ return interp;
}
M0_CallFrame *
new_call_frame( M0_Interp *interp ) {
M0_CallFrame *frame = malloc( sizeof (M0_CallFrame) );
+ unsigned int i;
+ for(i = 0; i < 256; i++)
+ frame->registers[i] = (uint64_t)0;
/* this is a silly minimal hack for now */
- frame->registers[CHUNK] = (uint64_t)interp->first_chunk;
+ frame->registers[CHUNK] = (uint64_t)(*interp)[CHUNKS];
frame->registers[PC] = (uint64_t)0;
- frame->registers[CONSTS] = (uint64_t)interp->first_chunk->constants;
+ frame->registers[CONSTS] = (uint64_t)((M0_Chunk*) ((*interp)[CHUNKS]))->constants;
+ frame->registers[CF] = (uint64_t)frame;
+ frame->registers[INTERP] = (uint64_t)interp;
return frame;
}
@@ -86,14 +100,14 @@ call_frame_free( M0_Interp *interp, M0_CallFrame *cf ) {
void
interp_free( M0_Interp *interp ) {
- M0_Chunk *chunk = interp->first_chunk;
+ M0_Chunk *chunk = (M0_Chunk*)((*interp)[CHUNKS]);
while (chunk) {
M0_Chunk *next = chunk->next;
m0_chunk_free( chunk );
chunk = next;
}
-
+ free( ((void *)(*interp)[CONFIG]) );
free( interp );
}
@@ -119,7 +133,7 @@ m0_chunk_free_constants( M0_Constants_Segment *constants )
unsigned long i = 0;
for (i = 0; i < count; i++) {
- if ( constants->consts[i] )
+ if ( constants->consts[i] && constants->pointers[i])
free( (void *)constants->consts[i] );
}
@@ -150,3 +164,6 @@ m0_chunk_free_bytecode( M0_Bytecode_Segment *bytecode )
free( bytecode );
}
+
+/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+*/
Oops, something went wrong.

0 comments on commit 9bde020

Please sign in to comment.