add number type and object
This commit is contained in:
2
Makefile
2
Makefile
@@ -25,7 +25,7 @@ native: $(CFILES) $(LEXER_C) $(LEXER_H)
|
|||||||
|
|
||||||
debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
gcc -g -O0 -o $(BINARY) $(CFILES) $(CFLAGS)
|
gcc -g -O3 -o $(BINARY) $(CFILES) $(CFLAGS)
|
||||||
|
|
||||||
full-debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
full-debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
|||||||
@@ -5,160 +5,187 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "number.h"
|
#include "number.h"
|
||||||
#include "../../lexer/token.h"
|
|
||||||
#include "../parser.h"
|
|
||||||
#include "../../memory.h"
|
#include "../../memory.h"
|
||||||
|
#include <ctype.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
// #include <stdio.h>
|
|
||||||
// #include <stdlib.h>
|
|
||||||
// #include <string.h>
|
|
||||||
// #include <ctype.h>
|
|
||||||
|
|
||||||
|
int parse_exponent(const char *exp_str, long *exp_val) {
|
||||||
|
char *endptr;
|
||||||
|
long val = strtol(exp_str, &endptr, 10);
|
||||||
|
if (*endptr != '\0') {
|
||||||
|
// exponent contains invalid chars or decimal point → reject
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*exp_val = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// int parse_exponent(const char *exp_str, long *exp_val) {
|
int mpq_set_decimal_str_exp(mpq_t r, const char *str) {
|
||||||
// char *endptr;
|
// Skip leading whitespace
|
||||||
// long val = strtol(exp_str, &endptr, 10);
|
while (isspace(*str))
|
||||||
// if (*endptr != '\0') {
|
str++;
|
||||||
// // exponent contains invalid chars or decimal point → reject
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// *exp_val = val;
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int mpq_set_decimal_str_exp(mpq_t r, const char *str) {
|
// Handle sign
|
||||||
// // Skip leading whitespace
|
int negative = 0;
|
||||||
// while (isspace(*str)) str++;
|
if (*str == '-') {
|
||||||
|
negative = 1;
|
||||||
|
str++;
|
||||||
|
} else if (*str == '+') {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
// // Handle sign
|
// Copy input to a buffer for manipulation
|
||||||
// int negative = 0;
|
size_t len = strlen(str);
|
||||||
// if (*str == '-') {
|
char *buf = malloc(len + 1);
|
||||||
// negative = 1;
|
if (!buf)
|
||||||
// str++;
|
return -1;
|
||||||
// } else if (*str == '+') {
|
strcpy(buf, str);
|
||||||
// str++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Copy input to a buffer for manipulation
|
// Find 'e' or 'E'
|
||||||
// size_t len = strlen(str);
|
char *e_ptr = strchr(buf, 'e');
|
||||||
// char *buf = malloc(len + 1);
|
if (!e_ptr)
|
||||||
// if (!buf) return -1;
|
e_ptr = strchr(buf, 'E');
|
||||||
// strcpy(buf, str);
|
|
||||||
|
|
||||||
// // Find 'e' or 'E'
|
char *exp_str = NULL;
|
||||||
// char *e_ptr = strchr(buf, 'e');
|
if (e_ptr) {
|
||||||
// if (!e_ptr) e_ptr = strchr(buf, 'E');
|
*e_ptr = '\0';
|
||||||
|
exp_str = e_ptr + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// char *exp_str = NULL;
|
// Validate decimal part (digits and one dot)
|
||||||
// if (e_ptr) {
|
int dot_count = 0;
|
||||||
// *e_ptr = '\0';
|
for (char *p = buf; *p; p++) {
|
||||||
// exp_str = e_ptr + 1;
|
if (*p == '.') {
|
||||||
// }
|
if (++dot_count > 1) {
|
||||||
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isdigit((unsigned char)*p)) {
|
||||||
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// // Validate decimal part (digits and one dot)
|
// Extract integer and fractional parts
|
||||||
// int dot_count = 0;
|
char *dot = strchr(buf, '.');
|
||||||
// for (char *p = buf; *p; p++) {
|
size_t int_len = dot ? (size_t)(dot - buf) : strlen(buf);
|
||||||
// if (*p == '.') {
|
size_t frac_len = dot ? strlen(dot + 1) : 0;
|
||||||
// if (++dot_count > 1) { free(buf); return -1; }
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (!isdigit((unsigned char)*p)) { free(buf); return -1; }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Extract integer and fractional parts
|
// Validate exponent if present
|
||||||
// char *dot = strchr(buf, '.');
|
int exp_negative = 0;
|
||||||
// size_t int_len = dot ? (size_t)(dot - buf) : strlen(buf);
|
long exp_val = 0;
|
||||||
// size_t frac_len = dot ? strlen(dot + 1) : 0;
|
if (exp_str) {
|
||||||
|
// Skip leading spaces in exponent (not in regex but safe)
|
||||||
|
while (isspace(*exp_str))
|
||||||
|
exp_str++;
|
||||||
|
|
||||||
// // Validate exponent if present
|
if (*exp_str == '-') {
|
||||||
// int exp_negative = 0;
|
exp_negative = 1;
|
||||||
// long exp_val = 0;
|
exp_str++;
|
||||||
// if (exp_str) {
|
} else if (*exp_str == '+') {
|
||||||
// // Skip leading spaces in exponent (not in regex but safe)
|
exp_str++;
|
||||||
// while (isspace(*exp_str)) exp_str++;
|
}
|
||||||
|
|
||||||
// if (*exp_str == '-') {
|
if (!isdigit((unsigned char)*exp_str)) {
|
||||||
// exp_negative = 1;
|
free(buf);
|
||||||
// exp_str++;
|
return -1;
|
||||||
// } else if (*exp_str == '+') {
|
}
|
||||||
// exp_str++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!isdigit((unsigned char)*exp_str)) {
|
char *endptr;
|
||||||
// free(buf);
|
exp_val = strtol(exp_str, &endptr, 10);
|
||||||
// return -1;
|
if (*endptr != '\0') {
|
||||||
// }
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (exp_negative)
|
||||||
|
exp_val = -exp_val;
|
||||||
|
}
|
||||||
|
|
||||||
// char *endptr;
|
// Build numerator string (integer part + fractional part)
|
||||||
// exp_val = strtol(exp_str, &endptr, 10);
|
size_t num_len = int_len + frac_len;
|
||||||
// if (*endptr != '\0') {
|
if (num_len == 0) {
|
||||||
// free(buf);
|
free(buf);
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
// if (exp_negative) exp_val = -exp_val;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Build numerator string (integer part + fractional part)
|
char *num_str = malloc(num_len + 1);
|
||||||
// size_t num_len = int_len + frac_len;
|
if (!num_str) {
|
||||||
// if (num_len == 0) { free(buf); return -1; }
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// char *num_str = malloc(num_len + 1);
|
if (int_len > 0)
|
||||||
// if (!num_str) { free(buf); return -1; }
|
memcpy(num_str, buf, int_len);
|
||||||
|
if (frac_len > 0)
|
||||||
|
memcpy(num_str + int_len, dot + 1, frac_len);
|
||||||
|
num_str[num_len] = '\0';
|
||||||
|
|
||||||
// if (int_len > 0) memcpy(num_str, buf, int_len);
|
// Calculate denominator exponent considering exponent part
|
||||||
// if (frac_len > 0) memcpy(num_str + int_len, dot + 1, frac_len);
|
long denom_exp = frac_len - exp_val;
|
||||||
// num_str[num_len] = '\0';
|
|
||||||
|
|
||||||
// // Calculate denominator exponent considering exponent part
|
mpz_t numerator, denominator;
|
||||||
// long denom_exp = frac_len - exp_val;
|
mpz_init(numerator);
|
||||||
|
mpz_init(denominator);
|
||||||
|
|
||||||
// mpz_t numerator, denominator;
|
if (mpz_set_str(numerator, num_str, 10) != 0) {
|
||||||
// mpz_init(numerator);
|
free(num_str);
|
||||||
// mpz_init(denominator);
|
free(buf);
|
||||||
|
mpz_clear(numerator);
|
||||||
|
mpz_clear(denominator);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(num_str);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
// if (mpz_set_str(numerator, num_str, 10) != 0) {
|
if (denom_exp >= 0) {
|
||||||
// free(num_str);
|
mpz_ui_pow_ui(denominator, 10, (unsigned long)denom_exp);
|
||||||
// free(buf);
|
} else {
|
||||||
// mpz_clear(numerator);
|
// denom_exp < 0 means multiply numerator by 10^(-denom_exp)
|
||||||
// mpz_clear(denominator);
|
mpz_ui_pow_ui(denominator, 10, 0);
|
||||||
// return -1;
|
mpz_ui_pow_ui(numerator, 10, (unsigned long)(-denom_exp));
|
||||||
// }
|
}
|
||||||
// free(num_str);
|
|
||||||
// free(buf);
|
|
||||||
|
|
||||||
// if (denom_exp >= 0) {
|
if (denom_exp < 0) {
|
||||||
// mpz_ui_pow_ui(denominator, 10, (unsigned long)denom_exp);
|
mpz_t temp;
|
||||||
// } else {
|
mpz_init(temp);
|
||||||
// // denom_exp < 0 means multiply numerator by 10^(-denom_exp)
|
mpz_ui_pow_ui(temp, 10, (unsigned long)(-denom_exp));
|
||||||
// mpz_ui_pow_ui(denominator, 10, 0);
|
mpz_mul(numerator, numerator, temp);
|
||||||
// mpz_ui_pow_ui(numerator, 10, (unsigned long)(-denom_exp));
|
mpz_clear(temp);
|
||||||
// }
|
mpz_set_ui(denominator, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// if (denom_exp < 0) {
|
mpq_set_num(r, numerator);
|
||||||
// mpz_t temp;
|
mpq_set_den(r, denominator);
|
||||||
// mpz_init(temp);
|
mpq_canonicalize(r);
|
||||||
// mpz_ui_pow_ui(temp, 10, (unsigned long)(-denom_exp));
|
|
||||||
// mpz_mul(numerator, numerator, temp);
|
|
||||||
// mpz_clear(temp);
|
|
||||||
// mpz_set_ui(denominator, 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mpq_set_num(r, numerator);
|
if (negative)
|
||||||
// mpq_set_den(r, denominator);
|
mpq_neg(r, r);
|
||||||
// mpq_canonicalize(r);
|
|
||||||
|
|
||||||
// if (negative) mpq_neg(r, r);
|
mpz_clear(numerator);
|
||||||
|
mpz_clear(denominator);
|
||||||
|
|
||||||
// mpz_clear(numerator);
|
return 0;
|
||||||
// mpz_clear(denominator);
|
}
|
||||||
|
|
||||||
// return 0;
|
ParsedValueReturn parse_number(Token *token, char*path) {
|
||||||
// }
|
|
||||||
|
|
||||||
ParsedValueReturn parse_number(Token *token) {
|
|
||||||
ParsedValue *parsedValue = checked_malloc(sizeof(ParsedValue));
|
ParsedValue *parsedValue = checked_malloc(sizeof(ParsedValue));
|
||||||
parsedValue->type = AST_NUMBER;
|
parsedValue->type = AST_NUMBER;
|
||||||
parsedValue->data = strdup(token->value);
|
mpq_t r;
|
||||||
|
mpq_init(r);
|
||||||
|
int err = mpq_set_decimal_str_exp(r, token->value);
|
||||||
|
if (err) {
|
||||||
|
free(parsedValue);
|
||||||
|
return (ParsedValueReturn){
|
||||||
|
create_err(token->length, token->column, token->length, path, "Parsing Error", "Unable to parse number"),
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
char *s = mpq_get_str(NULL, 62, r);
|
||||||
|
parsedValue->data = strdup(s);
|
||||||
return (ParsedValueReturn){no_err, parsedValue};
|
return (ParsedValueReturn){no_err, parsedValue};
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,6 @@
|
|||||||
#include "../../lexer/token.h" // for Token
|
#include "../../lexer/token.h" // for Token
|
||||||
|
|
||||||
// Function declaration for parsing an identifier
|
// Function declaration for parsing an identifier
|
||||||
ParsedValueReturn parse_number(Token *token);
|
ParsedValueReturn parse_number(Token *token, char*path);
|
||||||
|
|
||||||
#endif // NUMBER_H
|
#endif // NUMBER_H
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
#include "assignable/identifier/identifier.h"
|
#include "assignable/identifier/identifier.h"
|
||||||
#include "declaration/declaration.h"
|
#include "declaration/declaration.h"
|
||||||
#include "dictionary/dictionary.h"
|
#include "dictionary/dictionary.h"
|
||||||
#include "return/return.h"
|
|
||||||
#include "dowrap/dowrap.h"
|
#include "dowrap/dowrap.h"
|
||||||
#include "function/function.h"
|
#include "function/function.h"
|
||||||
#include "if/if.h"
|
#include "if/if.h"
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
#include "literals/literals.h"
|
#include "literals/literals.h"
|
||||||
#include "number/number.h"
|
#include "number/number.h"
|
||||||
#include "operations/operations.h"
|
#include "operations/operations.h"
|
||||||
|
#include "return/return.h"
|
||||||
#include "string/string.h"
|
#include "string/string.h"
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -30,9 +30,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
const char *ValueTypeNames[] = {
|
const char *ValueTypeNames[] = {
|
||||||
"string", "assign", "identifier", "number", "if statement",
|
"string", "assign", "identifier", "number",
|
||||||
"access", "call", "declaration", "null", "boolean",
|
"if statement", "access", "call", "declaration",
|
||||||
"do wrap", "operations", "list", "dictionary", "function", "return"};
|
"null", "boolean", "do wrap", "operations",
|
||||||
|
"list", "dictionary", "function", "return"};
|
||||||
|
|
||||||
ArErr error_if_finished(char *file, DArray *tokens, size_t *index) {
|
ArErr error_if_finished(char *file, DArray *tokens, size_t *index) {
|
||||||
if ((*index) >= tokens->size) {
|
if ((*index) >= tokens->size) {
|
||||||
@@ -117,7 +118,7 @@ ParsedValueReturn parse_token_full(char *file, DArray *tokens, size_t *index,
|
|||||||
break;
|
break;
|
||||||
case TOKEN_NUMBER:
|
case TOKEN_NUMBER:
|
||||||
(*index)++;
|
(*index)++;
|
||||||
output = parse_number(token);
|
output = parse_number(token, file);
|
||||||
break;
|
break;
|
||||||
case TOKEN_LET:
|
case TOKEN_LET:
|
||||||
output = parse_declaration(file, tokens, index);
|
output = parse_declaration(file, tokens, index);
|
||||||
@@ -132,10 +133,9 @@ ParsedValueReturn parse_token_full(char *file, DArray *tokens, size_t *index,
|
|||||||
output = parse_dictionary(file, tokens, index);
|
output = parse_dictionary(file, tokens, index);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return (ParsedValueReturn){create_err(token->line,
|
return (ParsedValueReturn){create_err(token->line, token->column,
|
||||||
token->column,
|
token->length, file, "Syntax Error",
|
||||||
token->length, file,
|
"unexpected token"),
|
||||||
"Syntax Error", "unexpected token"),
|
|
||||||
NULL};
|
NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
src/runtime/objects/number/number.c
Normal file
43
src/runtime/objects/number/number.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 William Bell
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "number.h"
|
||||||
|
#include "../string/string.h"
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "../functions/functions.h"
|
||||||
|
|
||||||
|
ArgonObject *ARGON_NUMBER_TYPE;
|
||||||
|
|
||||||
|
ArgonObject *ARGON_NUMBER_TYPE___string__(size_t argc, ArgonObject **argv,
|
||||||
|
ArErr *err, RuntimeState *state) {
|
||||||
|
(void)state;
|
||||||
|
if (argc != 1) {
|
||||||
|
*err = create_err(0, 0, 0, "", "Runtime Error",
|
||||||
|
"__string__ expects 1 arguments, got %" PRIu64, argc);
|
||||||
|
}
|
||||||
|
double val = mpq_get_d(argv[0]->value.as_number);
|
||||||
|
char buffer[64];
|
||||||
|
snprintf(buffer, sizeof(buffer), "%.15g", val);
|
||||||
|
return new_string_object_null_terminated(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_ARGON_NUMBER_TYPE() {
|
||||||
|
ARGON_NUMBER_TYPE = new_object();
|
||||||
|
add_field(ARGON_NUMBER_TYPE, "__name__",
|
||||||
|
new_string_object_null_terminated("number"));
|
||||||
|
add_field(ARGON_NUMBER_TYPE, "__string__",
|
||||||
|
create_argon_native_function("__string__", ARGON_NUMBER_TYPE___string__));
|
||||||
|
}
|
||||||
|
|
||||||
|
ArgonObject *new_number_object(char *data) {
|
||||||
|
ArgonObject *object = new_object();
|
||||||
|
add_field(object, "__class__", ARGON_NUMBER_TYPE);
|
||||||
|
object->type = TYPE_NUMBER;
|
||||||
|
mpq_init(object->value.as_number);
|
||||||
|
mpq_set_str(object->value.as_number, data, 62);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
17
src/runtime/objects/number/number.h
Normal file
17
src/runtime/objects/number/number.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 William Bell
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RUNTIME_NUMBER_H
|
||||||
|
#define RUNTIME_NUMBER_H
|
||||||
|
#include "../object.h"
|
||||||
|
|
||||||
|
extern ArgonObject *ARGON_NUMBER_TYPE;
|
||||||
|
|
||||||
|
void create_ARGON_NUMBER_TYPE();
|
||||||
|
|
||||||
|
ArgonObject *new_number_object(char *data);
|
||||||
|
|
||||||
|
#endif // RUNTIME_NUMBER_H
|
||||||
@@ -20,6 +20,7 @@ ArgonObject *new_object() {
|
|||||||
object->type = TYPE_OBJECT;
|
object->type = TYPE_OBJECT;
|
||||||
object->dict = createHashmap_GC();
|
object->dict = createHashmap_GC();
|
||||||
add_field(object, "__class__", ARGON_TYPE_TYPE);
|
add_field(object, "__class__", ARGON_TYPE_TYPE);
|
||||||
|
add_field(object, "__base__", BASE_CLASS);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "objects/string/string.h"
|
#include "objects/string/string.h"
|
||||||
#include "objects/term/term.h"
|
#include "objects/term/term.h"
|
||||||
#include "objects/type/type.h"
|
#include "objects/type/type.h"
|
||||||
|
#include "objects/number/number.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <gc/gc.h>
|
#include <gc/gc.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -122,10 +123,14 @@ ArgonObject *BASE_CLASS___string__(size_t argc, ArgonObject **argv, ArErr *err,
|
|||||||
get_field(argv[0], "__class__", false, false), "__name__", NULL);
|
get_field(argv[0], "__class__", false, false), "__name__", NULL);
|
||||||
|
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
|
if (class_name && object_name)
|
||||||
snprintf(buffer, sizeof(buffer), "<%.*s %.*s at %p>",
|
snprintf(buffer, sizeof(buffer), "<%.*s %.*s at %p>",
|
||||||
(int)class_name->value.as_str.length, class_name->value.as_str.data,
|
(int)class_name->value.as_str.length,
|
||||||
|
class_name->value.as_str.data,
|
||||||
(int)object_name->value.as_str.length,
|
(int)object_name->value.as_str.length,
|
||||||
object_name->value.as_str.data, argv[0]);
|
object_name->value.as_str.data, argv[0]);
|
||||||
|
else
|
||||||
|
snprintf(buffer, sizeof(buffer), "<object at %p>", argv[0]);
|
||||||
return new_string_object_null_terminated(buffer);
|
return new_string_object_null_terminated(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +227,8 @@ void bootstrap_types() {
|
|||||||
ARGON_NULL = new_object();
|
ARGON_NULL = new_object();
|
||||||
add_field(ARGON_NULL, "__class__", ARGON_NULL_TYPE);
|
add_field(ARGON_NULL, "__class__", ARGON_NULL_TYPE);
|
||||||
|
|
||||||
add_field(BASE_CLASS, "__base__", ARGON_NULL);
|
add_field(BASE_CLASS, "__base__", NULL);
|
||||||
|
add_field(BASE_CLASS, "__class__", ARGON_TYPE_TYPE);
|
||||||
|
|
||||||
ARGON_BOOL_TYPE = new_object();
|
ARGON_BOOL_TYPE = new_object();
|
||||||
add_field(ARGON_BOOL_TYPE, "__base__", BASE_CLASS);
|
add_field(ARGON_BOOL_TYPE, "__base__", BASE_CLASS);
|
||||||
@@ -254,6 +260,7 @@ void bootstrap_types() {
|
|||||||
add_field(ARGON_METHOD_TYPE, "__base__", BASE_CLASS);
|
add_field(ARGON_METHOD_TYPE, "__base__", BASE_CLASS);
|
||||||
add_field(ARGON_METHOD_TYPE, "__name__",
|
add_field(ARGON_METHOD_TYPE, "__name__",
|
||||||
new_string_object_null_terminated("method"));
|
new_string_object_null_terminated("method"));
|
||||||
|
create_ARGON_NUMBER_TYPE();
|
||||||
|
|
||||||
add_field(BASE_CLASS, "__new__",
|
add_field(BASE_CLASS, "__new__",
|
||||||
create_argon_native_function("__new__", BASE_CLASS___new__));
|
create_argon_native_function("__new__", BASE_CLASS___new__));
|
||||||
@@ -331,6 +338,8 @@ void load_const(Translated *translated, RuntimeState *state) {
|
|||||||
case TYPE_OP_STRING:
|
case TYPE_OP_STRING:
|
||||||
object = new_string_object(data, length);
|
object = new_string_object(data, length);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_OP_NUMBER:
|
||||||
|
object = new_number_object(data);
|
||||||
}
|
}
|
||||||
state->registers[to_register] = object;
|
state->registers[to_register] = object;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
size_t translate_parsed_number(Translated *translated, char *number_str, size_t to_register) {
|
size_t translate_parsed_number(Translated *translated, char *number_str, size_t to_register) {
|
||||||
size_t length = strlen(number_str);
|
size_t length = strlen(number_str)+1;
|
||||||
size_t number_pos = arena_push(&translated->constants, number_str, length);
|
size_t number_pos = arena_push(&translated->constants, number_str, length);
|
||||||
set_registers(translated, to_register+1);
|
set_registers(translated, to_register+1);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
let x = "hello"
|
|
||||||
if (x) term.log('bruh')
|
|
||||||
else term.log('not bruh')
|
|
||||||
Reference in New Issue
Block a user