Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * an attempt is done to construct smaller objects of larger
- * fields whenever it is possible.
- *
- * the vm_slot can contain any value.
- * the vm_slot_array can contain many.
- */
- typedef struct
- {
- uint64_t data;
- } vm_slot;
- typedef struct
- {
- size_t used;
- size_t size;
- vm_slot *slots;
- } vm_slot_array;
- /*
- * everything sitting in heap, accessible as value is an object.
- */
- typedef struct
- {
- uint64_t type;
- vm_slot interface;
- } vm_object;
- typedef enum
- {
- vm_t_object = 0,
- vm_t_constant,
- vm_t_string,
- vm_t_arraybuffer,
- vm_t_integer,
- vm_t_double = 8,
- vm_t_dict,
- vm_t_list,
- vm_t_indexing_iterator,
- vm_t_property,
- vm_t_upval,
- vm_t_string_stream,
- vm_t_file_stream,
- vm_t_descriptor,
- vm_t_closure,
- vm_t_stack,
- vm_t_greenlet,
- vm_t_context,
- vm_t_builtin
- } vm_object_type;
- /*
- * strings and arraybuffers have a lot in common.
- * both are buffers, devoid of pointers.
- */
- typedef struct
- {
- vm_object object;
- size_t length;
- char string[];
- } vm_string;
- typedef struct
- {
- vm_object object;
- size_t length;
- uint8_t data[];
- } vm_arraybuffer;
- /*
- * dictionaries and lists
- */
- typedef struct
- {
- vm_object object;
- vm_slot_array array;
- } vm_dict;
- typedef struct
- {
- vm_object object;
- vm_slot_array array;
- } vm_list;
- /*
- * everything that has +getitem and .length can be iterated using an indexing iterator.
- */
- typedef struct
- {
- vm_object object;
- vm_slot slot;
- size_t index;
- size_t length;
- } vm_indexing_iterator;
- /*
- * there are a lot of objects with property fields, so this is a builtin.
- */
- typedef struct
- {
- vm_object object;
- vm_slot get;
- vm_slot set;
- vm_slot call;
- } vm_property;
- /*
- * upvalues. they never see the stack.
- */
- typedef struct
- {
- vm_object object;
- vm_slot slot;
- } vm_upval;
- /*
- * lets say these two belong to posix.
- */
- typedef struct
- {
- vm_object object;
- vm_arraybuffer* buffer;
- int index;
- } vm_string_stream;
- typedef struct
- {
- vm_object object;
- int fd;
- } vm_file_stream;
- /*
- * virtual machine without functions.. what would it be?
- */
- struct vm_descriptor
- {
- vm_object object;
- size_t argc;
- size_t valc;
- size_t nupvalc; /* how many new upvalues? */
- vm_arraybuffer *upcopy; /* interpreted as uint16_t internally */
- vm_arraybuffer *program;
- vm_list *functions;
- vm_list *constants;
- };
- /*
- * should be immutable after created.
- */
- struct vm_closure
- {
- vm_object object;
- vm_descriptor *desc;
- size_t count;
- vm_upval *upvalues[];
- };
- /*
- */
- typedef struct
- {
- vm_closure *clos;
- vm_upval **upvalues;
- vm_slot self;
- int base;
- int top;
- size_t pc;
- /* alter soon, for C calls */
- } vm_frame;
- typedef struct
- {
- size_t used;
- size_t size;
- vm_frame *frames;
- } vm_frame_array;
- /*
- */
- typedef struct
- {
- int frame;
- int type;
- int base;
- size_t pc;
- } vm_except;
- typedef struct
- {
- size_t used;
- size_t size;
- vm_except *excepts;
- } vm_except_array;
- /*
- *
- */
- typedef struct vm_stack vm_stack;
- struct vm_stack
- {
- vm_object object;
- vm_stack* parent;
- vm_slot_array slots;
- vm_frame_array frames;
- vm_except_array excepts;
- };
- /*
- * whereas stack might be an active generator, greenlets are here for
- * async io without the ills.
- */
- typedef struct vm_greenlet vm_greenlet;
- struct vm_greenlet
- {
- vm_object object;
- vm_greenlet *parent;
- vm_stack *stack;
- };
- /*
- * ultimately we have a context.
- */
- typedef struct
- {
- vm_stack *stack;
- vm_greenlet *greenlet;
- jmp_buf exception_return;
- vm_slot exception_type;
- vm_slot exception_value;
- /* vm_list *exception_traceback; */
- } vm_context;
- /*
- */
- typedef struct
- {
- const char* name;
- void (*func)(vm_context* ctx);
- } vm_builtin;
- /*
- * might be deprecated, for the VM the nature of the object matters, not it's interface.
- struct vm_typespec
- {
- size_t size;
- vm_value interface;
- vm_value (*factory)();
- };
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement