Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change how constants are stored

Use a similar strategy as the callframe storage, store each constant as either
a uint64_t or a pointer to something larger. This gives integer & floating
point constants value semantics and strings pointer semantics.

This allows the c implementation to pass all tests using a single deref call
instead of the double deref previously required for constants with value
semantics.
  • Loading branch information...
commit 6a75a09a24d410b01ac68eb6ca0765a30a899e0c 1 parent 780e12a
@nbrown nbrown authored
View
4 src/m0/c/include/m0_mob_structures.h
@@ -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;
View
2  src/m0/c/m0_interp.c
@@ -133,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] );
}
View
14 src/m0/c/m0_mob.c
@@ -217,8 +217,9 @@ parse_mob_constants_segment( M0_Interp *interp, FILE *stream ) {
unsigned long i = 0;
M0_Constants_Segment *segment =
malloc( sizeof( M0_Constants_Segment ) );
- segment->consts = malloc( sizeof ( char * ) * const_count );
- segment->count = const_count;
+ segment->consts = calloc(const_count, sizeof ( uint64_t ));
+ segment->pointers = calloc(const_count, sizeof ( unsigned int));
+ segment->count = const_count;
UNUSED( byte_count );
@@ -230,10 +231,15 @@ parse_mob_constants_segment( M0_Interp *interp, FILE *stream ) {
if (encoding == 0) {
constant = (char *) &(constant[8]);
}
+ if (constant) {
+ segment->consts[i] = (uint64_t)constant;
+ segment->pointers[i] = 1;
+ }
+ } else {
+ if (constant)
+ segment->consts[i] = *(uint64_t*)constant;
}
- if (constant)
- segment->consts[i] = constant;
}
return segment;

0 comments on commit 6a75a09

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