Skip to content
This repository
Browse code

borrow Regs struct from parrot, break M0 test now

  • Loading branch information...
commit 3c62ec93858f9708018d35ff5f19cb7be034c401 1 parent 076d7e6
authored
2  docs/pdds/draft/pdd32_m0.pod
Source Rendered
@@ -175,7 +175,7 @@ of M0 ops.
175 175
 
176 176
 In descriptions, C<$1> refers to the value of the first argument to an op,
177 177
 C<$2> to the second and C<$3> to the third.  Any op can operate on any
178  
-register; types are only by convention.  As far as an M0 VM is conerned, the
  178
+register; types are only by convention.  As far as an M0 VM is concerned, the
179 179
 256 ops are nothing more than an array of 256 int32-sized chunks of data.
180 180
 
181 181
 Note that this documentation uses a C-like syntax to differentiate between a
14  src/m0/c/include/m0_interp_structures.h
@@ -13,8 +13,20 @@ typedef struct {
13 13
     M0_Chunk       *last_chunk;
14 14
 } M0_Interp;
15 15
 
  16
+typedef union {
  17
+    void        *p[128];
  18
+    char        *s[128];
  19
+} Regs_ps;
  20
+
  21
+typedef union {
  22
+    double       n[128];
  23
+    long         i[128];
  24
+} Regs_ni;
  25
+
16 26
 typedef struct {
17  
-    uint64_t registers[256];
  27
+    uint64_t registers[12];
  28
+    Regs_ni  regs_ni;
  29
+    Regs_ps  regs_ps;
18 30
 } M0_CallFrame;
19 31
 
20 32
 enum CF_NAMED_REGS {
35  src/m0/c/m0_ops.c
@@ -14,7 +14,7 @@ Copyright (C) 2011-2012, Parrot Foundation.
14 14
 static void
15 15
 m0_op_set_imm( M0_CallFrame *frame, const unsigned char *ops  )
16 16
 {
17  
-    frame->registers[ops[1]] = ops[2] * 256 + ops[3];
  17
+    frame->regs_ni.i[ops[1]] = ops[2] * 256 + ops[3];
18 18
 }
19 19
 
20 20
 static void
@@ -23,15 +23,16 @@ m0_op_deref( M0_CallFrame *frame, const unsigned char *ops )
23 23
     unsigned char ref = ops[2];
24 24
 
25 25
     switch (ref) {
26  
-        case CONSTS:
  26
+        case CONST:
27 27
         {
28 28
             M0_Constants_Segment *consts =
29 29
                 (M0_Constants_Segment *)frame->registers[ ref ];
30 30
             unsigned long         offset = frame->registers[ ops[3] ];
31 31
 
32  
-            frame->registers[ ops[1] ]   = (uint64_t)consts->consts[ offset ];
  32
+            frame->regs_ni.n[ ops[1] ]   = (uint64_t)consts->consts[ offset ];
33 33
             break;
34 34
         }
  35
+
35 36
         default:
36 37
             /* XXX: the rest of the system has non-uniform array handling */
37 38
             break;
@@ -49,50 +50,42 @@ static void
49 50
 m0_op_print_i( M0_CallFrame *frame, const unsigned char *ops )
50 51
 {
51 52
     /* note the lack of filehandle selection (ops[1]) for output */
52  
-    fprintf( stdout, "%d", *(int *)frame->registers[ ops[2] ] );
  53
+    fprintf( stdout, "%d", frame->regs_ni.i[ ops[2] ] );
53 54
 }
54 55
 
55 56
 static void
56 57
 m0_op_print_n( M0_CallFrame *frame, const unsigned char *ops )
57 58
 {
58 59
     /* note the lack of filehandle selection (ops[1]) for output */
59  
-    fprintf( stdout, "%.15g", *(double *)frame->registers[ ops[2] ] );
  60
+    fprintf( stdout, "%.15g", frame->regs_ni.n[ ops[2] ] );
60 61
 }
61 62
 
62 63
 static void
63 64
 m0_op_add_i( M0_CallFrame *frame, const unsigned char *ops )
64 65
 {
65  
-    const uint64_t result = *(uint64_t *) frame->registers[ops[2]] +
66  
-       *(uint64_t *)frame->registers[ops[3]];
67  
-
68  
-    frame->registers[ops[1]] = &result;
  66
+    frame->regs_ni.i[ops[1]] = frame->regs_ni.i[ops[2]] +
  67
+       frame->regs_ni.i[ops[3]];
69 68
 }
70 69
 
71 70
 static void
72 71
 m0_op_add_n( M0_CallFrame *frame, const unsigned char *ops )
73 72
 {
74  
-    const double result = *(double *) frame->registers[ops[2]] +
75  
-       *(double *)frame->registers[ops[3]];
76  
-
77  
-    frame->registers[ops[1]] = &result;
  73
+    frame->regs_ni.n[ops[1]] = frame->regs_ni.n[ops[2]] +
  74
+       frame->regs_ni.n[ops[3]];
78 75
 }
79 76
 
80 77
 static void
81 78
 m0_op_sub_i( M0_CallFrame *frame, const unsigned char *ops )
82 79
 {
83  
-    const uint64_t result = *(uint64_t *) frame->registers[ops[2]] +
84  
-       *(uint64_t *)frame->registers[ops[3]];
85  
-
86  
-    frame->registers[ops[1]] = &result;
  80
+    frame->regs_ni.i[ops[1]] = frame->regs_ni.i[ops[2]] -
  81
+       frame->regs_ni.i[ops[3]];
87 82
 }
88 83
 
89 84
 static void
90 85
 m0_op_sub_n( M0_CallFrame *frame, const unsigned char *ops )
91 86
 {
92  
-    const double result = *(double *) frame->registers[ops[2]] -
93  
-       *(double *)frame->registers[ops[3]];
94  
-
95  
-    frame->registers[ops[1]] = &result;
  87
+    frame->regs_ni.n[ops[1]] = frame->regs_ni.n[ops[2]] -
  88
+       frame->regs_ni.n[ops[3]];
96 89
 }
97 90
 
98 91
 static void

0 notes on commit 3c62ec9

Please sign in to comment.
Something went wrong with that request. Please try again.