mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Reorganize object types. Sort alphabetically.
This commit is contained in:
24
src/main.c
24
src/main.c
@ -43,27 +43,3 @@ int main(int argc, const char * argv[])
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
/*
|
||||
static void dumpTokens(Buffer* buffer, Token* token)
|
||||
{
|
||||
while (token)
|
||||
{
|
||||
switch (token->type)
|
||||
{
|
||||
case TOKEN_LINE: printf("(line)"); break;
|
||||
case TOKEN_ERROR: printf("(error)"); break;
|
||||
case TOKEN_EOF: printf("(eof)"); break;
|
||||
default:
|
||||
printf("⊏");
|
||||
for (int i = token->start; i < token->end; i++)
|
||||
{
|
||||
putchar(buffer->bytes[i]);
|
||||
}
|
||||
printf("⊐");
|
||||
}
|
||||
token = token->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
*/
|
||||
|
||||
30
src/vm.c
30
src/vm.c
@ -62,6 +62,14 @@ void freeVM(VM* vm)
|
||||
free(vm);
|
||||
}
|
||||
|
||||
ObjBlock* makeBlock()
|
||||
{
|
||||
ObjBlock* block = malloc(sizeof(ObjBlock));
|
||||
block->obj.type = OBJ_BLOCK;
|
||||
block->obj.flags = 0;
|
||||
return block;
|
||||
}
|
||||
|
||||
ObjClass* makeSingleClass()
|
||||
{
|
||||
ObjClass* obj = malloc(sizeof(ObjClass));
|
||||
@ -87,12 +95,14 @@ ObjClass* makeClass()
|
||||
return classObj;
|
||||
}
|
||||
|
||||
ObjBlock* makeBlock()
|
||||
ObjInstance* makeInstance(ObjClass* classObj)
|
||||
{
|
||||
ObjBlock* block = malloc(sizeof(ObjBlock));
|
||||
block->obj.type = OBJ_BLOCK;
|
||||
block->obj.flags = 0;
|
||||
return block;
|
||||
ObjInstance* instance = malloc(sizeof(ObjInstance));
|
||||
instance->obj.type = OBJ_INSTANCE;
|
||||
instance->obj.flags = 0;
|
||||
instance->classObj = classObj;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
ObjNum* makeNum(double number)
|
||||
@ -113,16 +123,6 @@ ObjString* makeString(const char* text)
|
||||
return string;
|
||||
}
|
||||
|
||||
ObjInstance* makeInstance(ObjClass* classObj)
|
||||
{
|
||||
ObjInstance* instance = malloc(sizeof(ObjInstance));
|
||||
instance->obj.type = OBJ_INSTANCE;
|
||||
instance->obj.flags = 0;
|
||||
instance->classObj = classObj;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void initSymbolTable(SymbolTable* symbols)
|
||||
{
|
||||
symbols->count = 0;
|
||||
|
||||
44
src/vm.h
44
src/vm.h
@ -7,11 +7,11 @@
|
||||
#define MAX_SYMBOLS 256
|
||||
|
||||
typedef enum {
|
||||
OBJ_NUM,
|
||||
OBJ_STRING,
|
||||
OBJ_BLOCK,
|
||||
OBJ_CLASS,
|
||||
OBJ_INSTANCE
|
||||
OBJ_INSTANCE,
|
||||
OBJ_NUM,
|
||||
OBJ_STRING
|
||||
} ObjType;
|
||||
|
||||
typedef enum
|
||||
@ -28,17 +28,7 @@ typedef struct
|
||||
|
||||
typedef Obj* Value;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Obj obj;
|
||||
double value;
|
||||
} ObjNum;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Obj obj;
|
||||
const char* value;
|
||||
} ObjString;
|
||||
typedef Value (*Primitive)(Value* args, int numArgs);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -49,8 +39,6 @@ typedef struct
|
||||
int numLocals;
|
||||
} ObjBlock;
|
||||
|
||||
typedef Value (*Primitive)(Value* args, int numArgs);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
METHOD_NONE,
|
||||
@ -84,6 +72,18 @@ typedef struct
|
||||
// TODO(bob): Fields.
|
||||
} ObjInstance;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Obj obj;
|
||||
double value;
|
||||
} ObjNum;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Obj obj;
|
||||
const char* value;
|
||||
} ObjString;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// Load the constant at index [arg].
|
||||
@ -156,13 +156,21 @@ typedef struct
|
||||
VM* newVM();
|
||||
void freeVM(VM* vm);
|
||||
|
||||
ObjClass* makeClass();
|
||||
// Creates a new block object. Assumes the compiler will fill it in with
|
||||
// bytecode, constants, etc.
|
||||
ObjBlock* makeBlock();
|
||||
|
||||
// Creates a new class object.
|
||||
ObjClass* makeClass();
|
||||
|
||||
// Creates a new instance of the given [classObj].
|
||||
ObjInstance* makeInstance(ObjClass* classObj);
|
||||
|
||||
// Creates a new number object.
|
||||
ObjNum* makeNum(double number);
|
||||
|
||||
// Creates a new string object. Does not copy text.
|
||||
ObjString* makeString(const char* text);
|
||||
ObjInstance* makeInstance(ObjClass* classObj);
|
||||
|
||||
// Initializes the symbol table.
|
||||
void initSymbolTable(SymbolTable* symbols);
|
||||
|
||||
Reference in New Issue
Block a user