mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
fixes, some checks, made working on part of simple tests (functions, arrays, operations, read, write, loops)
This commit is contained in:
parent
da050c082c
commit
1e38ffaefb
11 changed files with 333 additions and 220 deletions
|
|
@ -99,9 +99,9 @@ void *Belem(void *p, aint i);
|
|||
void *LmakeArray(aint length);
|
||||
void *LmakeString(aint length);
|
||||
|
||||
void *Bstring(aint *args /*void *p*/);
|
||||
void *Lstringcat(aint *args /* void* p */);
|
||||
void *Lstring(aint *args /* void *p */);
|
||||
void *Bstring(aint *p);
|
||||
void *Lstringcat(aint *p);
|
||||
void *Lstring(aint *p);
|
||||
|
||||
void *Bclosure(aint *args, aint bn);
|
||||
void *Barray(aint *args, aint bn);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@
|
|||
|
||||
#include "stdlib.h"
|
||||
|
||||
void **s_top(struct State *s);
|
||||
bool s_is_empty(struct State *s);
|
||||
void **s_peek(struct State *s);
|
||||
aint *s_peek_i(struct State *s);
|
||||
|
||||
void s_push(struct State *s, void *val);
|
||||
void s_push_i(struct State *s, aint val);
|
||||
void s_push_nil(struct State *s);
|
||||
|
|
@ -24,8 +29,7 @@ void s_popn(struct State *s, size_t n);
|
|||
//
|
||||
// where |> defines corresponding frame pointer, | is stack pointer
|
||||
// location before / after new frame added
|
||||
void s_enter_f(struct State *s, char *func_ip, auint params_sz,
|
||||
auint locals_sz);
|
||||
void s_enter_f(struct State *s, char *rp, auint args_sz, auint locals_sz);
|
||||
|
||||
void s_exit_f(struct State *s);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,24 +7,26 @@
|
|||
|
||||
// ------ General ------
|
||||
|
||||
enum Type {
|
||||
STR_T = STRING_TAG,
|
||||
ARRAY_T = ARRAY_TAG,
|
||||
SEXP_T = SEXP_TAG,
|
||||
CLOJURE_T = CLOSURE_TAG,
|
||||
};
|
||||
// enum Type {
|
||||
// STR_T = STRING_TAG,
|
||||
// ARRAY_T = ARRAY_TAG,
|
||||
// SEXP_T = SEXP_TAG,
|
||||
// CLOJURE_T = CLOSURE_TAG,
|
||||
// };
|
||||
|
||||
#define STACK_SIZE 100000
|
||||
|
||||
static const size_t MAX_ARRAY_SIZE = 0x11111110;
|
||||
|
||||
// ------ Frame ------
|
||||
|
||||
struct Frame {
|
||||
void *ret; // store returned value [gc pointer]
|
||||
char *rp; // ret instruction pointer [not gc pointer]
|
||||
aint to_prev_fp_box; // ret function frame pointer [boxed value, not gc
|
||||
// pointer]
|
||||
aint args_sz_box; // store arguments [boxed value, not gc pointer]
|
||||
aint locals_sz_box; // store locals [boxed value, not gc pointer]
|
||||
void *ret; // store returned value [gc pointer]
|
||||
char *rp; // ret instruction pointer [not gc pointer]
|
||||
void **prev_fp; // ret function frame pointer [boxed value, not gc
|
||||
// pointer]
|
||||
aint args_sz_box; // store arguments [boxed value, not gc pointer]
|
||||
aint locals_sz_box; // store locals [boxed value, not gc pointer]
|
||||
};
|
||||
|
||||
auint frame_sz();
|
||||
|
|
@ -37,12 +39,13 @@ void **f_args(struct Frame *fp);
|
|||
// ------ State ------
|
||||
|
||||
struct State {
|
||||
void **stack; // vaid**
|
||||
void **stack;
|
||||
void **sp; // stack pointer
|
||||
struct Frame *fp; // function frame pointer
|
||||
bytefile *bf;
|
||||
|
||||
char *ip; // instruction pointer
|
||||
char *prev_ip; // prev instruction pointer (to remember jmp locations)
|
||||
char *call_ip; // prev instruction pointer (to remember jmp locations)
|
||||
};
|
||||
|
||||
struct State init_state(bytefile *bf);
|
||||
|
|
@ -58,3 +61,5 @@ enum VarCategory {
|
|||
};
|
||||
|
||||
enum VarCategory to_var_category(uint8_t category);
|
||||
|
||||
void print_stack(struct State *s);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../runtime/runtime_common.h"
|
||||
|
||||
/* The unpacked representation of bytecode file */
|
||||
typedef struct {
|
||||
|
|
@ -15,12 +19,12 @@ typedef struct {
|
|||
} bytefile;
|
||||
|
||||
/* Gets a string from a string table by an index */
|
||||
char *get_string(bytefile *f, int pos);
|
||||
char *get_string(bytefile *f, size_t pos);
|
||||
|
||||
/* Gets a name for a public symbol */
|
||||
char *get_public_name(bytefile *f, int i);
|
||||
char *get_public_name(bytefile *f, size_t i);
|
||||
|
||||
/* Gets an offset for a public symbol */
|
||||
int get_public_offset(bytefile *f, int i);
|
||||
size_t get_public_offset(bytefile *f, size_t i);
|
||||
|
||||
// ---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue