This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from gek169/seabass
-
Notifications
You must be signed in to change notification settings - Fork 1
/
metaprogramming.h
115 lines (94 loc) · 3.4 KB
/
metaprogramming.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef METAPROGRAMMING_H
#define METAPROGRAMMING_H
#include "parser.h"
#include "data.h"
/*
Header for metaprogramming features of Seabass.
*/
/*
This is the struct visible to the code from __builtin_get_ast().
Notice that it's all pointers, which means that it's just a multiple of 8 in size (64 bit pointers)
*/
typedef struct{
typedecl** type_table;
symdecl*** symbol_table;
typedecl_oop_metadata** oop_metadata;
scope*** scopestack;
stmt*** loopstack;
uint64_t* active_function;
uint64_t* ntypedecls;
uint64_t* nsymbols;
uint64_t* nscopes;
uint64_t* nloops; /*Needed for identifying the parent loop.*/
uint64_t target_word;
uint64_t signed_target_word;
uint64_t target_max_float;
}seabass_builtin_ast;
/*
Functions accessible from the compiletime metaprogramming runtime.
*/
int impl_builtin_getargc(); //DONE
char** impl_builtin_getargv(); //DONE
void* impl_builtin_malloc(uint64_t sz); //DONE
void* impl_builtin_realloc(char* p, uint64_t sz); //DONE
void impl_builtin_memset(char* p, unsigned char val, uint64_t sz);
uint64_t impl_builtin_type_getsz(char* p_in); //DONE
uint64_t impl_builtin_struct_metadata(uint64_t which); //DONE
char* impl_builtin_strdup(char* s); //DONE
void impl_builtin_free(char* p); //DONE
void impl_builtin_exit(int32_t errcode); //DONE
seabass_builtin_ast* impl_builtin_get_ast(); //DONE
strll* impl_builtin_peek(); //DONE
void* impl_builtin_getnext();
void impl_builtin_puts(char* s); //DONE
void impl_builtin_gets(char* s, uint64_t sz); //DONE
int impl_builtin_open_ofile(char* fname); //DONE
char* impl_builtin_read_file(char* fname, char* zz);
void impl_builtin_close_ofile(); //DONE
strll* impl_builtin_consume(); //DONE
uint64_t impl_builtin_emit(char* data, uint64_t sz); //DONE
void impl_builtin_validate_function(char* p_in); //DONE
void impl_builtin_memcpy(char* a, char* b, uint64_t sz); //DONE
/* Saturday, February 11th: the blessed saturday, praise the Lord!
functions to implement...
*/
void impl_builtin_utoa(char* buf, uint64_t v); //DONE
void impl_builtin_itoa(char* buf, int64_t v); //DONE
void impl_builtin_ftoa(char* buf, double v); //DONE
uint64_t impl_builtin_atou(char* buf); //DONE
double impl_builtin_atof(char* buf); //DONE
int64_t impl_builtin_atoi(char* buf); //DONE
/* AST manipulation functions.
*/
int32_t impl_builtin_peek_is_fname(); //TODO
int32_t impl_builtin_str_is_fname(char *s); //TODO
void impl_builtin_scopestack_push(char* scopeptr);
void impl_builtin_scopestack_pop();
void impl_builtin_loopstack_push(char* stmtptr);
void impl_builtin_loopstack_pop();
char* impl_builtin_parser_push_statement();
unsigned char* impl_builtin_retrieve_sym_ptr(char* name);
unsigned char* impl_builtin_strll_dupe(unsigned char* this);
unsigned char* impl_builtin_strll_dupell(unsigned char* this);
void impl_builtin_parse_global();
size_t is_builtin_name(char* s);
uint64_t get_builtin_nargs(char* s);
enum{
BUILTIN_PROTO_VOID=0,
BUILTIN_PROTO_U8_PTR=1,
BUILTIN_PROTO_U8_PTR2=2,
BUILTIN_PROTO_U64_PTR=3,
BUILTIN_PROTO_U64=4,
BUILTIN_PROTO_I32=5,
BUILTIN_PROTO_DOUBLE=6,
BUILTIN_PROTO_I64=7,
};
uint64_t get_builtin_retval(char* s);
uint64_t get_builtin_arg1_type(char* s);
uint64_t get_builtin_arg2_type(char* s);
uint64_t get_builtin_arg3_type(char* s);
/*
TODO: push built-in struct types onto the list of typedecls,
for the compiletime execution environment to access.
*/
#endif