forked from NeoFlock/noom
:<
This commit is contained in:
@@ -30,7 +30,9 @@
|
||||
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
|
||||
typedef struct noomC_LocalInfo {
|
||||
enum { NOOMC_GLOBAL, NOOMC_LOCAL, NOOMC_UPVAL } type;
|
||||
enum { NOOMC_GLOBAL,
|
||||
NOOMC_LOCAL,
|
||||
NOOMC_UPVAL } type;
|
||||
unsigned int idx;
|
||||
} noomC_LocalInfo;
|
||||
|
||||
@@ -165,8 +167,7 @@ static noom_Exit noomC_compile_expr(
|
||||
noomV_Function* func,
|
||||
const noomP_Node* node,
|
||||
// retc of -1 means all values!!!!!!!!!!!
|
||||
int retc
|
||||
) {
|
||||
int retc) {
|
||||
noom_Exit result;
|
||||
if (node->type == NOOMP_NODE_NILLITERAL) {
|
||||
compiler->curstack++;
|
||||
|
||||
@@ -82,8 +82,7 @@ noom_uint_t noom_format_error(const noomP_Parser* parser, const char* program_na
|
||||
if (parser->code[i] == '\n') {
|
||||
row++;
|
||||
column = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
column++;
|
||||
}
|
||||
}
|
||||
@@ -127,8 +126,7 @@ noom_uint_t noom_format_error(const noomP_Parser* parser, const char* program_na
|
||||
|
||||
if (row == 0) {
|
||||
num_buf[num_len++] = '0';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
noom_uint_t temp = row;
|
||||
noom_uint_t divisor = 1;
|
||||
while (temp / divisor >= 10) divisor *= 10;
|
||||
|
||||
35
src/helper.c
35
src/helper.c
@@ -13,7 +13,7 @@ double noom_strtod(const char* s, const char** endptr, int* error) {
|
||||
s++;
|
||||
|
||||
if (!noomL_isnumber(s[*s == '.'])) goto fuck;
|
||||
|
||||
|
||||
if (*s == '0' && noomL_lower(s[1]) == 'x') {
|
||||
s += 2;
|
||||
// if the string starts with "0x" but does not contain digits it's invalid
|
||||
@@ -22,14 +22,14 @@ double noom_strtod(const char* s, const char** endptr, int* error) {
|
||||
int digit;
|
||||
if (noomL_isnumber(*s)) digit = *s - '0';
|
||||
else digit = noomL_lower(*s) - 'a' + 10;
|
||||
|
||||
|
||||
num = num * 16.0 + digit;
|
||||
are_we_cooked = 0;
|
||||
s++;
|
||||
}
|
||||
|
||||
|
||||
if (are_we_cooked) goto fuck;
|
||||
|
||||
|
||||
if (noomL_lower(*s) == 'p') {
|
||||
// damn then
|
||||
s++;
|
||||
@@ -37,18 +37,17 @@ double noom_strtod(const char* s, const char** endptr, int* error) {
|
||||
const noom_bool_t exponent_negative = *s == '-';
|
||||
if (*s == '-' || *s == '+')
|
||||
s++;
|
||||
|
||||
|
||||
if (!noomL_isnumber(*s)) goto fuck;
|
||||
|
||||
|
||||
while (noomL_isnumber(*s)) {
|
||||
exponent = exponent * 10 + (*s - '0');
|
||||
s++;
|
||||
}
|
||||
|
||||
|
||||
num *= noom_pow(2.0, exponent_negative ? -exponent : exponent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
noom_bool_t are_we_cooked = 1;
|
||||
while (noomL_isnumber(*s)) {
|
||||
num = num * 10.0 + (*s - '0');
|
||||
@@ -57,7 +56,7 @@ double noom_strtod(const char* s, const char** endptr, int* error) {
|
||||
}
|
||||
if (*s == '.') {
|
||||
s++;
|
||||
|
||||
|
||||
double fraction_divisor = 10.0;
|
||||
while (noomL_isnumber(*s)) {
|
||||
are_we_cooked = 0;
|
||||
@@ -67,21 +66,21 @@ double noom_strtod(const char* s, const char** endptr, int* error) {
|
||||
}
|
||||
}
|
||||
if (are_we_cooked) goto fuck;
|
||||
|
||||
|
||||
if (noomL_lower(*s) == 'e') {
|
||||
s++;
|
||||
int exponent = 0;
|
||||
const noom_bool_t exponent_negative = *s == '-';
|
||||
if (*s == '-' || *s == '+')
|
||||
s++;
|
||||
|
||||
|
||||
if (!noomL_isnumber(*s)) goto fuck;
|
||||
|
||||
|
||||
while (noomL_isnumber(*s)) {
|
||||
exponent = exponent * 10 + (*s - '0');
|
||||
s++;
|
||||
}
|
||||
|
||||
|
||||
num *= noom_pow(10.0, exponent_negative ? -exponent : exponent);
|
||||
}
|
||||
}
|
||||
@@ -99,16 +98,16 @@ double noom_pow(double x, int y) {
|
||||
return 1;
|
||||
|
||||
const double temp = noom_pow(x, y / 2);
|
||||
|
||||
|
||||
if (y % 2 == 0) {
|
||||
return temp * temp;
|
||||
}
|
||||
|
||||
|
||||
if (y > 0)
|
||||
return x * temp * temp;
|
||||
|
||||
|
||||
return temp * temp / x;
|
||||
}
|
||||
}
|
||||
|
||||
int noom_startswith(const char* str, const char* compare) {
|
||||
#ifdef __has_builtin
|
||||
|
||||
35
src/main.c
35
src/main.c
@@ -39,7 +39,7 @@ void print_node(const noomP_Node* node, noom_uint_t depth) {
|
||||
int execute(const char* code, noom_LuaVersion version, const char* program_name, const char* filename) {
|
||||
noomP_Parser parser;
|
||||
noomP_Node* program;
|
||||
|
||||
|
||||
// goodbye "shitass" you will be missed
|
||||
int success = noomP_parse(code, filename, version, &program, &parser);
|
||||
if (success == 0) {
|
||||
@@ -84,15 +84,14 @@ int execute(const char* code, noom_LuaVersion version, const char* program_name,
|
||||
puts("\x1b[0m");
|
||||
puts("PARSE OUTPUT:");
|
||||
print_node(program, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
noom_uint_t bleh = noom_format_error(&parser, program_name, NULL, 0);
|
||||
char* buf = noom_alloc(bleh);
|
||||
noom_format_error(&parser, program_name, buf, bleh);
|
||||
fputs(buf, stdout);
|
||||
noom_free(buf);
|
||||
}
|
||||
|
||||
|
||||
// freeing time
|
||||
noomP_Node* last_node = parser.last_node;
|
||||
while (last_node) {
|
||||
@@ -102,7 +101,7 @@ int execute(const char* code, noom_LuaVersion version, const char* program_name,
|
||||
noom_free(last_node);
|
||||
last_node = next;
|
||||
}
|
||||
|
||||
|
||||
if (success) {
|
||||
noom_LuaVM* vm = noom_createVM(version);
|
||||
noomV_Value peak;
|
||||
@@ -138,7 +137,7 @@ int execute(const char* code, noom_LuaVersion version, const char* program_name,
|
||||
}
|
||||
noom_destroyVM(vm);
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -264,19 +263,18 @@ int main(int argc, char** argv) {
|
||||
params.script_exec = argv[i];
|
||||
params.do_i_already_know_what_to_do = 1;
|
||||
}
|
||||
|
||||
|
||||
if (argv[i][1] == 'l') {
|
||||
const char* version_string = 0;
|
||||
if (argv[i][2] != '\0') {
|
||||
version_string = argv[i] + 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (++i >= argc) {
|
||||
err = "-l needs an argument";
|
||||
goto die;
|
||||
}
|
||||
version_string = argv[i];
|
||||
}
|
||||
}
|
||||
if (noom_strcmp(version_string, "51") == 0) params.lua_version = NOOM_VERSION_51;
|
||||
else if (noom_strcmp(version_string, "52") == 0) params.lua_version = NOOM_VERSION_52;
|
||||
else if (noom_strcmp(version_string, "53") == 0) params.lua_version = NOOM_VERSION_53;
|
||||
@@ -314,7 +312,8 @@ int main(int argc, char** argv) {
|
||||
char* code = read_file(params.script_path);
|
||||
if (code == 0) return 1;
|
||||
int offset = 0;
|
||||
if (code[0] == '#' && code[1] == '!') for (offset = 2; code[offset] && code[offset] != '\n'; offset++);
|
||||
if (code[0] == '#' && code[1] == '!')
|
||||
for (offset = 2; code[offset] && code[offset] != '\n'; offset++);
|
||||
const int e = execute(code + offset, params.lua_version, argv[0], params.script_path);
|
||||
noom_free(code);
|
||||
return e;
|
||||
@@ -336,12 +335,12 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
die:
|
||||
fprintf(stderr, "%s: %s\n"
|
||||
"usage: %s [options] [script [args]]\n"
|
||||
"Available options are:\n"
|
||||
" - execute stdin\n"
|
||||
" -e stat execute string 'stat'\n"
|
||||
" -v show version\n"
|
||||
" -l [51|52|53|54] select lua version\n",
|
||||
argv[0], err, argv[0]);
|
||||
"usage: %s [options] [script [args]]\n"
|
||||
"Available options are:\n"
|
||||
" - execute stdin\n"
|
||||
" -e stat execute string 'stat'\n"
|
||||
" -v show version\n"
|
||||
" -l [51|52|53|54] select lua version\n",
|
||||
argv[0], err, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user