start supporting identifiers in bytecode
This commit is contained in:
15
src/translator/identifier/identifier.c
Normal file
15
src/translator/identifier/identifier.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../translator.h"
|
||||
#include "identifier.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
size_t translate_parsed_identifier(Translated *translated, char* identifier) {
|
||||
size_t length = strlen(identifier);
|
||||
size_t identifier_pos = arena_push(&translated->constants, identifier, length);
|
||||
set_registers(translated, 1);
|
||||
size_t start = push_instruction_byte(translated, OP_IDENTIFIER);
|
||||
push_instruction_code(translated,length);
|
||||
push_instruction_code(translated, identifier_pos);
|
||||
return start;
|
||||
}
|
||||
8
src/translator/identifier/identifier.h
Normal file
8
src/translator/identifier/identifier.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef BYTECODE_IDENTIFIER_H
|
||||
#define BYTECODE_IDENTIFIER_H
|
||||
#include "../translator.h"
|
||||
#include "../../parser/assignable/identifier/identifier.h"
|
||||
|
||||
size_t translate_parsed_identifier(Translated *translated, char* identifier);
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../hashmap/hashmap.h"
|
||||
#include "declaration/declaration.h"
|
||||
#include "function/function.h"
|
||||
#include "identifier/identifier.h"
|
||||
#include "number/number.h"
|
||||
#include "string/string.h"
|
||||
#include <stddef.h>
|
||||
@@ -122,6 +123,8 @@ size_t translate_parsed(Translated *translated, ParsedValue *parsedValue) {
|
||||
case AST_FUNCTION:
|
||||
return translate_parsed_function(translated,
|
||||
(ParsedFunction *)parsedValue->data);
|
||||
case AST_IDENTIFIER:
|
||||
return translate_parsed_identifier(translated, (char *)parsedValue->data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum { OP_LOAD_CONST, OP_DECLARE, OP_LOAD_NULL, OP_LOAD_FUNCTION } OperationType;
|
||||
typedef enum { OP_LOAD_CONST, OP_DECLARE, OP_LOAD_NULL, OP_LOAD_FUNCTION, OP_IDENTIFIER } OperationType;
|
||||
typedef enum { TYPE_OP_STRING, TYPE_OP_NUMBER } types;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user