Integrated with newest TracingHeap, refactoring for functions
This commit is contained in:
parent
dfd2f81f3d
commit
702bb6f850
5 changed files with 67 additions and 52 deletions
9
src/heap.h
Normal file
9
src/heap.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef FLUP_HEAP_H
|
||||
#define FLUP_HEAP_H
|
||||
|
||||
enum HeapDataKind {
|
||||
HEAPDATAKIND_OBJECT,
|
||||
HEAPDATAKIND_OBJECTTYPE,
|
||||
};
|
||||
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
#include "builtin-functions.h"
|
||||
#include "object-type.h"
|
||||
#include "error-message.h"
|
||||
#include "heap.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdalign.h>
|
||||
|
@ -306,7 +307,7 @@ int Interpreter_GetParenthesizedRange(Interpreter* self, CallFrame* top_frame, s
|
|||
Object* _Interpreter_MakeObject(Interpreter* self, ObjectType* otype)
|
||||
{
|
||||
size_t object_size = Object_AllocationSizeForType(otype);
|
||||
Object* new_object = TracingHeap_Allocate(&self->heap, object_size);
|
||||
Object* new_object = TracingHeap_Allocate(&self->heap, object_size, HEAPDATAKIND_OBJECT);
|
||||
|
||||
return new_object;
|
||||
}
|
||||
|
|
52
src/main.c
52
src/main.c
|
@ -26,63 +26,13 @@
|
|||
#include "interpreter.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
//Debug
|
||||
//Temp
|
||||
|
||||
void tokencontent_tostring(Token* token) {
|
||||
switch (token->type) {
|
||||
case TOKENTYPE_INTEGER:
|
||||
printf("%" PRIi64, token->get.integer);
|
||||
break;
|
||||
case TOKENTYPE_DOUBLE:
|
||||
printf("%f", token->get.decimal);
|
||||
break;
|
||||
case TOKENTYPE_IDENTIFIER:
|
||||
case TOKENTYPE_COMMENT:
|
||||
case TOKENTYPE_STRING:
|
||||
case TOKENTYPE_ERROR:
|
||||
printf("%s", token->get.identifier);
|
||||
break;
|
||||
case TOKENTYPE_NONE:
|
||||
case TOKENTYPE_LEFT_BRACE:
|
||||
case TOKENTYPE_RIGHT_BRACE:
|
||||
case TOKENTYPE_AMPERSAND:
|
||||
case TOKENTYPE_PLUS:
|
||||
case TOKENTYPE_MINUS:
|
||||
case TOKENTYPE_MULTIPLY:
|
||||
case TOKENTYPE_DIVIDE:
|
||||
case TOKENTYPE_PIPE:
|
||||
case TOKENTYPE_ARROW:
|
||||
case TOKENTYPE_COLON:
|
||||
case TOKENTYPE_SEMICOLON:
|
||||
case TOKENTYPE_EQUALITY:
|
||||
case TOKENTYPE_INEQUALITY:
|
||||
case TOKENTYPE_LESSTHAN:
|
||||
case TOKENTYPE_LESSEQUAL:
|
||||
case TOKENTYPE_GREATERTHAN:
|
||||
case TOKENTYPE_GREATEREQUAL:
|
||||
case TOKENTYPE_COMMA:
|
||||
case TOKENTYPE_BIND:
|
||||
case TOKENTYPE_AS:
|
||||
case TOKENTYPE_LEFT_PAREN:
|
||||
case TOKENTYPE_RIGHT_PAREN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void print_token(Token* token) {
|
||||
printf("Token: type: %s, TokenContent: ", TokenType_ToString(token->type));
|
||||
tokencontent_tostring(token);
|
||||
printf(" , contex: row: %i, col: %i\n", token->context.row, token->context.col);
|
||||
}
|
||||
|
||||
int tokenize_all(StringView source, DynamicArray* a)
|
||||
{
|
||||
TokenContext context = {.row = 1, .col = 1};
|
||||
Token t;
|
||||
while ((t = Tokenizer_NextToken(&source, &context)).type != TOKENTYPE_NONE) {
|
||||
//Debug
|
||||
print_token(&t);
|
||||
// Debug Token_Print(&t);
|
||||
int append_code = DynamicArray_Append(a, &t);
|
||||
if (append_code) return append_code;
|
||||
if (t.type == TOKENTYPE_ERROR) break;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "tokenizer.h"
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static StringView StringViewOfNumberTillNextNonDigit(StringView* source) {
|
||||
StringView stringViewOfNumber = StringView_Slice(*source, 0, 0);
|
||||
|
@ -310,3 +312,54 @@ const char* TokenType_ToString(enum TokenType type)
|
|||
|
||||
return "INVALID";
|
||||
}
|
||||
|
||||
void _TokenContent_Print(Token* token)
|
||||
{
|
||||
switch (token->type) {
|
||||
case TOKENTYPE_INTEGER:
|
||||
printf("%" PRIi64, token->get.integer);
|
||||
break;
|
||||
case TOKENTYPE_DOUBLE:
|
||||
printf("%f", token->get.decimal);
|
||||
break;
|
||||
case TOKENTYPE_IDENTIFIER:
|
||||
case TOKENTYPE_COMMENT:
|
||||
case TOKENTYPE_STRING:
|
||||
case TOKENTYPE_ERROR:
|
||||
printf("%s", token->get.identifier.source);
|
||||
break;
|
||||
case TOKENTYPE_NONE:
|
||||
case TOKENTYPE_LEFT_BRACE:
|
||||
case TOKENTYPE_RIGHT_BRACE:
|
||||
case TOKENTYPE_AMPERSAND:
|
||||
case TOKENTYPE_PLUS:
|
||||
case TOKENTYPE_MINUS:
|
||||
case TOKENTYPE_MULTIPLY:
|
||||
case TOKENTYPE_DIVIDE:
|
||||
case TOKENTYPE_PIPE:
|
||||
case TOKENTYPE_ARROW:
|
||||
case TOKENTYPE_COLON:
|
||||
case TOKENTYPE_SEMICOLON:
|
||||
case TOKENTYPE_EQUALITY:
|
||||
case TOKENTYPE_INEQUALITY:
|
||||
case TOKENTYPE_LESSTHAN:
|
||||
case TOKENTYPE_LESSEQUAL:
|
||||
case TOKENTYPE_GREATERTHAN:
|
||||
case TOKENTYPE_GREATEREQUAL:
|
||||
case TOKENTYPE_COMMA:
|
||||
case TOKENTYPE_BIND:
|
||||
case TOKENTYPE_AS:
|
||||
case TOKENTYPE_LEFT_PAREN:
|
||||
case TOKENTYPE_RIGHT_PAREN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Token_Print(Token* token)
|
||||
{
|
||||
printf("Token: type: %s, TokenContent: ", TokenType_ToString(token->type));
|
||||
_TokenContent_Print(token);
|
||||
printf(" , contex: row: %i, col: %i\n", token->context.row, token->context.col);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,4 +60,6 @@ typedef struct Token_s {
|
|||
Token Tokenizer_NextToken(StringView* source, TokenContext* context);
|
||||
const char* TokenType_ToString(enum TokenType type);
|
||||
|
||||
void Token_Print(Token* token);
|
||||
|
||||
#endif //header guard
|
||||
|
|
Loading…
Reference in a new issue