mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
file parser, file merge, callf command remove, SM fixes. todo: fix interpreter and analyzer with new algorithm
This commit is contained in:
parent
51381aea43
commit
343a21ee2d
8 changed files with 256 additions and 77 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include "parser.h"
|
||||
|
|
@ -35,7 +36,7 @@ enum class Cmd : int8_t {
|
|||
ARRAY,
|
||||
FAIL,
|
||||
LINE,
|
||||
CALLF,
|
||||
// CALLF,
|
||||
PATT,
|
||||
// NOTE: no longer used
|
||||
// Lread,
|
||||
|
|
@ -49,6 +50,8 @@ enum class Cmd : int8_t {
|
|||
|
||||
Bytefile *read_file(const char *fname);
|
||||
|
||||
Bytefile *merge_files(const std::vector<Bytefile> &bytefiles);
|
||||
|
||||
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile *bf);
|
||||
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile *bf,
|
||||
std::ostream &out);
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ static inline void **var_by_category(enum VarCategory category, size_t id) {
|
|||
// s.bf->global_area_size);
|
||||
}
|
||||
#endif
|
||||
var = s.stack + STACK_SIZE - 1 - id;
|
||||
var = s.bf->global_ptr + STACK_SIZE - 1 - id;
|
||||
break;
|
||||
case VAR_LOCAL:
|
||||
#ifndef WITH_CHECK
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ enum CMD_CTRLS {
|
|||
CMD_CTRL_ARRAY,
|
||||
CMD_CTRL_FAIL,
|
||||
CMD_CTRL_LINE,
|
||||
CMD_CTRL_CALLF,
|
||||
// CMD_CTRL_CALLF,
|
||||
};
|
||||
|
||||
enum CMD_PATTS {
|
||||
|
|
|
|||
|
|
@ -7,17 +7,24 @@
|
|||
#include "../../runtime/runtime.h"
|
||||
#include "../../runtime/runtime_common.h"
|
||||
|
||||
typedef struct {
|
||||
uint offset;
|
||||
char label[0];
|
||||
} Subst;
|
||||
|
||||
/* The unpacked representation of bytecode file */
|
||||
typedef struct {
|
||||
uint main_offset; /* offset of the function 'main' */
|
||||
char *string_ptr; /* A pointer to the beginning of the string table */
|
||||
int *imports_ptr; /* A pointer to the beginning of imports table */
|
||||
int *public_ptr; /* A pointer to the beginning of publics table */
|
||||
char *code_ptr; /* A pointer to the bytecode itself */
|
||||
int *global_ptr; /* A pointer to the global area */
|
||||
int code_size; /* The size (in bytes) of code */
|
||||
uint main_offset; /* offset of the function 'main' */
|
||||
char *string_ptr; /* A pointer to the beginning of the string table */
|
||||
int *imports_ptr; /* A pointer to the beginning of imports table */
|
||||
int *public_ptr; /* A pointer to the beginning of publics table */
|
||||
char *code_ptr; /* A pointer to the bytecode itself */
|
||||
void **global_ptr; /* A pointer to the global area */
|
||||
char *substs_ptr; /* A pointer to the substs area */
|
||||
int code_size; /* The size (in bytes) of code */
|
||||
uint stringtab_size; /* The size (in bytes) of the string table */
|
||||
uint global_area_size; /* The size (in words) of global area */
|
||||
uint substs_area_size; /* number of required address substitutions */
|
||||
uint imports_number; /* The number of imports */
|
||||
uint public_symbols_number; /* The number of public symbols */
|
||||
char buffer[0];
|
||||
|
|
@ -64,6 +71,10 @@ static inline size_t get_public_offset_unsafe(const Bytefile *bf, size_t i) {
|
|||
|
||||
// read from ip
|
||||
|
||||
static inline void ip_write_int_unsafe(char *ip, int32_t x) {
|
||||
*((int32_t *)ip) = x;
|
||||
}
|
||||
|
||||
static inline uint16_t ip_read_half_int_unsafe(char **ip) {
|
||||
*ip += sizeof(uint16_t);
|
||||
return *(uint16_t *)((*ip) - sizeof(uint16_t));
|
||||
|
|
@ -124,6 +135,13 @@ static inline size_t get_public_offset_safe(const Bytefile *f, size_t i) {
|
|||
|
||||
// read from ip
|
||||
|
||||
static inline void ip_write_int_safe(char *ip, int32_t x, const Bytefile *bf) {
|
||||
if (ip + sizeof(int32_t) > bf->code_ptr + bf->code_size) {
|
||||
failure("last command is invalid, int parameter can not be read\n");
|
||||
}
|
||||
ip_write_int_unsafe(ip, x);
|
||||
}
|
||||
|
||||
static inline uint16_t ip_read_half_int_safe(char **ip, const Bytefile *bf) {
|
||||
if (*ip + sizeof(uint16_t) > bf->code_ptr + bf->code_size) {
|
||||
failure("last command is invalid, int parameter can not be read\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue