turn access into a function to be ran at runtime
This commit is contained in:
32
src/translator/access/access.c
Normal file
32
src/translator/access/access.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 William Bell
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
#include "access.h"
|
||||
|
||||
size_t translate_access(Translated *translated, ParsedAccess *access,
|
||||
ArErr *err) {
|
||||
set_registers(translated, 1);
|
||||
uint64_t first = push_instruction_byte(translated, OP_LOAD_ACCESS_FUNCTION);
|
||||
push_instruction_byte(translated, OP_INIT_CALL);
|
||||
push_instruction_code(translated, 3);
|
||||
|
||||
translate_parsed(translated, &access->to_access, err);
|
||||
push_instruction_byte(translated, OP_INSERT_ARG);
|
||||
push_instruction_code(translated, 0);
|
||||
translate_parsed(translated, darray_get(&access->access, 0), err);
|
||||
push_instruction_byte(translated, OP_INSERT_ARG);
|
||||
push_instruction_code(translated, 1);
|
||||
|
||||
push_instruction_byte(translated, OP_LOAD_BOOL);
|
||||
push_instruction_byte(translated, access->access_fields);
|
||||
push_instruction_byte(translated, OP_INSERT_ARG);
|
||||
push_instruction_code(translated, 2);
|
||||
push_instruction_byte(translated, OP_SOURCE_LOCATION);
|
||||
push_instruction_code(translated, access->line);
|
||||
push_instruction_code(translated, access->column);
|
||||
push_instruction_code(translated, access->length);
|
||||
push_instruction_byte(translated, OP_CALL);
|
||||
return first;
|
||||
}
|
||||
15
src/translator/access/access.h
Normal file
15
src/translator/access/access.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 William Bell
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef translator_access_H
|
||||
#define translator_access_H
|
||||
#include "../../parser/assignable/access/access.h"
|
||||
#include "../translator.h"
|
||||
|
||||
size_t translate_access(Translated *translated, ParsedAccess *access,
|
||||
ArErr *err);
|
||||
|
||||
#endif // translator_access_H
|
||||
@@ -109,6 +109,16 @@ sets the source location onto the runtime
|
||||
4. the column
|
||||
5. the length
|
||||
|
||||
## OP_LOAD_ACCESS_FUNCTION
|
||||
|
||||
loads the access function into register 1
|
||||
|
||||
## OP_LOAD_BOOL
|
||||
|
||||
loads a boolean into register 1
|
||||
|
||||
1. byte representing true or false (1 or 0) *
|
||||
|
||||
## OP_SWAP_REGISTERS
|
||||
|
||||
swap the contents in two registers
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "number/number.h"
|
||||
#include "string/string.h"
|
||||
#include "return/return.h"
|
||||
#include "access/access.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -146,6 +147,8 @@ size_t translate_parsed(Translated *translated, ParsedValue *parsedValue, ArErr*
|
||||
return translate_parsed_return(translated, (ParsedReturn *)parsedValue->data, err);
|
||||
case AST_CALL:
|
||||
return translate_parsed_call(translated, (ParsedCall*)parsedValue->data, err);
|
||||
case AST_ACCESS:
|
||||
return translate_access(translated,(ParsedAccess*)parsedValue->data, err);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,13 +8,30 @@
|
||||
#define TRANSLATOR_H
|
||||
|
||||
#include "../dynamic_array/darray.h"
|
||||
#include "../hashmap/hashmap.h"
|
||||
#include "../memory.h"
|
||||
#include "../parser/parser.h"
|
||||
#include "../hashmap/hashmap.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum { OP_LOAD_CONST, OP_DECLARE, OP_LOAD_NULL, OP_LOAD_FUNCTION, OP_IDENTIFIER, OP_BOOL, OP_JUMP_IF_FALSE, OP_JUMP, OP_NEW_SCOPE, OP_POP_SCOPE, OP_INIT_CALL, OP_INSERT_ARG, OP_CALL, OP_SOURCE_LOCATION } OperationType;
|
||||
typedef enum {
|
||||
OP_LOAD_CONST,
|
||||
OP_DECLARE,
|
||||
OP_LOAD_NULL,
|
||||
OP_LOAD_FUNCTION,
|
||||
OP_IDENTIFIER,
|
||||
OP_BOOL,
|
||||
OP_JUMP_IF_FALSE,
|
||||
OP_JUMP,
|
||||
OP_NEW_SCOPE,
|
||||
OP_POP_SCOPE,
|
||||
OP_INIT_CALL,
|
||||
OP_INSERT_ARG,
|
||||
OP_CALL,
|
||||
OP_SOURCE_LOCATION,
|
||||
OP_LOAD_ACCESS_FUNCTION,
|
||||
OP_LOAD_BOOL
|
||||
} OperationType;
|
||||
typedef enum { TYPE_OP_STRING, TYPE_OP_NUMBER } types;
|
||||
|
||||
void arena_resize(ConstantArena *arena, size_t new_size);
|
||||
@@ -33,9 +50,10 @@ void set_instruction_code(Translated *translator, size_t index, uint64_t code);
|
||||
|
||||
void set_registers(Translated *translator, uint8_t count);
|
||||
|
||||
Translated init_translator(char* path);
|
||||
Translated init_translator(char *path);
|
||||
|
||||
size_t translate_parsed(Translated *translated, ParsedValue *parsedValue, ArErr*err);
|
||||
size_t translate_parsed(Translated *translated, ParsedValue *parsedValue,
|
||||
ArErr *err);
|
||||
|
||||
ArErr translate(Translated *translated, DArray *ast);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user