by Marko Mikuličić, Cesanta Software, for LD2015 Pisa
Implicit data structures
O(1) compacting collector
Interpreter
VM
StdLib
GC
Parser
Compiler
Heap
User C code
Implicit data structures are data structures with negligible space overhead; auxiliary information is mostly represented by permuting the elements cleverly
typedef val_t double; /* IEEE 745 NaN packing */
struct v7_property {
struct v7_property *next; /* Linkage in struct v7_object::properties */
unsigned int attributes;
val_t name; /* Property name (a string) */
val_t value; /* Property value */
};
struct v7_object {
struct v7_property *properties;
struct v7_object *prototype;
uint8_t attributes;
};
#include <v7.h>
int main() {
struct v7 *v7 = v7_create();
v7_val_t res;
v7_exec(v7, "function random() { return 42; }", NULL);
v7_exec(v7, "function msg() { return 'foo'; }", NULL);
v7_exec(v7, "random()", &res);
printf("random number (really): %lg\n", v7_to_number(res));
v7_exec(v7, "msg()", &res);
printf("msg: %s\n", v7_to_cstring(res));
v7_destroy(v7);
return 0;
}
struct Value {
union {
int boolean;
double number;
String *str;
Object *object;
/* more */
} u;
char type; /* type tag */
/* padding */
};
Challenges: