start working on runtime oop
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
for i in range(10000):
|
for i in range(10000000):
|
||||||
sys.stdout.write("\"")
|
sys.stdout.write("\"hello world\"\n")
|
||||||
sys.stdout.write(str(random.random()))
|
|
||||||
sys.stdout.write("\"\n")
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
#ifndef AROBJECT_H
|
#ifndef AROBJECT_H
|
||||||
#define AROBJECT_H
|
#define AROBJECT_H
|
||||||
|
|
||||||
#include <gmp.h>
|
|
||||||
#include "runtime/internals/dynamic_array_armem/darray_armem.h"
|
#include "runtime/internals/dynamic_array_armem/darray_armem.h"
|
||||||
#include "runtime/internals/hashmap/hashmap.h"
|
#include "runtime/internals/hashmap/hashmap.h"
|
||||||
|
#include <gmp.h>
|
||||||
|
|
||||||
typedef struct ArgonObject ArgonObject; // forward declaration
|
typedef struct ArgonObject ArgonObject; // forward declaration
|
||||||
|
|
||||||
typedef enum ArgonType {
|
typedef enum ArgonType {
|
||||||
TYPE_NULL,
|
TYPE_NULL,
|
||||||
@@ -40,13 +40,12 @@ struct argon_function_struct {
|
|||||||
char **parameters;
|
char **parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// full definition of ArgonObject (no typedef again!)
|
// full definition of ArgonObject (no typedef again!)
|
||||||
struct ArgonObject {
|
struct ArgonObject {
|
||||||
ArgonType type;
|
ArgonType type;
|
||||||
char *name;
|
struct hashmap_GC *dict;
|
||||||
ArgonObject *self;
|
|
||||||
ArgonObject *baseObject;
|
|
||||||
struct hashmap_GC *fields;
|
|
||||||
union {
|
union {
|
||||||
mpq_t as_number;
|
mpq_t as_number;
|
||||||
bool as_bool;
|
bool as_bool;
|
||||||
|
|||||||
@@ -8,17 +8,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "../memory.h"
|
||||||
|
|
||||||
void darray_init(DArray *arr, size_t element_size) {
|
void darray_init(DArray *arr, size_t element_size) {
|
||||||
arr->element_size = element_size;
|
arr->element_size = element_size;
|
||||||
arr->size = 0;
|
arr->size = 0;
|
||||||
arr->capacity = CHUNK_SIZE;
|
arr->capacity = CHUNK_SIZE / element_size;
|
||||||
arr->data = malloc(CHUNK_SIZE * element_size);
|
arr->data = checked_malloc(CHUNK_SIZE); // fixed byte allocation
|
||||||
arr->resizable = true;
|
arr->resizable = true;
|
||||||
if (!arr->data) {
|
|
||||||
fprintf(stderr, "darray_init: allocation failed\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void darray_resize(DArray *arr, size_t new_size) {
|
void darray_resize(DArray *arr, size_t new_size) {
|
||||||
@@ -26,9 +23,17 @@ void darray_resize(DArray *arr, size_t new_size) {
|
|||||||
fprintf(stderr, "darray_resize: unresizable darray\n");
|
fprintf(stderr, "darray_resize: unresizable darray\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
size_t new_capacity = ((new_size + CHUNK_SIZE) / CHUNK_SIZE) * CHUNK_SIZE;
|
|
||||||
|
// Determine number of full chunks needed to store new_size elements
|
||||||
|
size_t required_bytes = new_size * arr->element_size;
|
||||||
|
size_t new_capacity_bytes = ((required_bytes + CHUNK_SIZE - 1) / CHUNK_SIZE) * CHUNK_SIZE;
|
||||||
|
size_t new_capacity = new_capacity_bytes / arr->element_size;
|
||||||
|
if (!new_capacity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (new_capacity != arr->capacity) {
|
if (new_capacity != arr->capacity) {
|
||||||
void *new_data = realloc(arr->data, new_capacity * arr->element_size);
|
void *new_data = realloc(arr->data, new_capacity_bytes);
|
||||||
if (!new_data) {
|
if (!new_data) {
|
||||||
fprintf(stderr, "darray_resize: reallocation failed\n");
|
fprintf(stderr, "darray_resize: reallocation failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
|
|
||||||
#define CHUNK_SIZE 1048576
|
#define CHUNK_SIZE 4096
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *data;
|
void *data;
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void output_err(ArErr err) {
|
|||||||
fprintf(stderr, " ");
|
fprintf(stderr, " ");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "|\n");
|
fprintf(stderr, "|\n");
|
||||||
for (size_t i = 0;i<len;i++) {
|
for (ssize_t i = 0;i<len;i++) {
|
||||||
if (buffer[i] == '\n') {
|
if (buffer[i] == '\n') {
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ void ar_memory_init() {
|
|||||||
|
|
||||||
void *ar_alloc(size_t size) { return GC_MALLOC(size); }
|
void *ar_alloc(size_t size) { return GC_MALLOC(size); }
|
||||||
|
|
||||||
|
void *ar_realloc(void * old,size_t size) { return GC_REALLOC(old, size); }
|
||||||
|
|
||||||
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
||||||
GC_finalization_proc *old_fn, void **old_client_data) {
|
GC_finalization_proc *old_fn, void **old_client_data) {
|
||||||
return GC_register_finalizer_no_order(obj, fn, client_data, old_fn, old_client_data);
|
return GC_register_finalizer_no_order(obj, fn, client_data, old_fn, old_client_data);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
||||||
GC_finalization_proc *old_fn, void **old_client_data);
|
GC_finalization_proc *old_fn, void **old_client_data);
|
||||||
void *ar_alloc(size_t size);
|
void *ar_alloc(size_t size);
|
||||||
|
void *ar_realloc(void * old,size_t size);
|
||||||
void *ar_alloc_atomic(size_t size);
|
void *ar_alloc_atomic(size_t size);
|
||||||
char *ar_strdup(const char *str);
|
char *ar_strdup(const char *str);
|
||||||
|
|
||||||
|
|||||||
0
src/runtime/call/call.c
Normal file
0
src/runtime/call/call.c
Normal file
0
src/runtime/call/call.h
Normal file
0
src/runtime/call/call.h
Normal file
@@ -19,6 +19,7 @@ ArErr runtime_declaration(Translated *translated, RuntimeState *state,
|
|||||||
SourceLocation *source_location = darray_get(&translated->source_locations, source_location_index);
|
SourceLocation *source_location = darray_get(&translated->source_locations, source_location_index);
|
||||||
return create_err(source_location->line, source_location->column, source_location->length, state->path, "Runtime Error", "Identifier '%.*s' has already been declared in the current scope", length, arena_get(&translated->constants, offset));
|
return create_err(source_location->line, source_location->column, source_location->length, state->path, "Runtime Error", "Identifier '%.*s' has already been declared in the current scope", length, arena_get(&translated->constants, offset));
|
||||||
}
|
}
|
||||||
hashmap_insert_GC(stack->scope, hash, arena_get(&translated->constants, offset), state->registers[from_register], 0);
|
ArgonObject * key = init_string_object(arena_get(&translated->constants, offset), length);
|
||||||
|
hashmap_insert_GC(stack->scope, hash, key, state->registers[from_register], 0);
|
||||||
return no_err;
|
return no_err;
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#ifndef runtime_declaration_H
|
#ifndef runtime_declaration_H
|
||||||
#define runtime_declaration_H
|
#define runtime_declaration_H
|
||||||
#include "../runtime.h"
|
#include "../runtime.h"
|
||||||
|
#include "../objects/string/string.h"
|
||||||
|
|
||||||
ArErr runtime_declaration(Translated *translated, RuntimeState *state,
|
ArErr runtime_declaration(Translated *translated, RuntimeState *state,
|
||||||
struct Stack *stack);
|
struct Stack *stack);
|
||||||
|
|||||||
@@ -12,11 +12,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void darray_armem_init(darray_armem *arr, size_t element_size) {
|
void darray_armem_init(darray_armem *arr, size_t element_size) {
|
||||||
|
if (element_size > CHUNK_SIZE) {
|
||||||
|
fprintf(stderr, "darray_armem_init: element size larger than chunk size\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
arr->element_size = element_size;
|
arr->element_size = element_size;
|
||||||
arr->size = 0;
|
arr->size = 0;
|
||||||
arr->capacity = CHUNK_SIZE;
|
arr->capacity = CHUNK_SIZE / element_size;
|
||||||
arr->data = ar_alloc(CHUNK_SIZE * element_size);
|
arr->data = ar_alloc(CHUNK_SIZE); // fixed-size byte allocation
|
||||||
arr->resizable = true;
|
arr->resizable = true;
|
||||||
|
|
||||||
if (!arr->data) {
|
if (!arr->data) {
|
||||||
fprintf(stderr, "darray_armem_init: allocation failed\n");
|
fprintf(stderr, "darray_armem_init: allocation failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -28,15 +34,23 @@ void darray_armem_resize(darray_armem *arr, size_t new_size) {
|
|||||||
fprintf(stderr, "darray_armem_resize: unresizable darray_armem\n");
|
fprintf(stderr, "darray_armem_resize: unresizable darray_armem\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
size_t new_capacity = ((new_size + CHUNK_SIZE) / CHUNK_SIZE) * CHUNK_SIZE;
|
|
||||||
|
size_t required_bytes = new_size * arr->element_size;
|
||||||
|
size_t new_capacity_bytes =
|
||||||
|
((required_bytes + CHUNK_SIZE - 1) / CHUNK_SIZE) * CHUNK_SIZE;
|
||||||
|
size_t new_capacity = new_capacity_bytes / arr->element_size;
|
||||||
|
|
||||||
|
if (!new_capacity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (new_capacity != arr->capacity) {
|
if (new_capacity != arr->capacity) {
|
||||||
void *new_data = ar_alloc(new_capacity * arr->element_size);
|
printf("%zu\n", new_capacity_bytes);
|
||||||
memccpy(new_data,arr->data, arr->element_size, arr->capacity);
|
arr->data = ar_realloc(arr->data, new_capacity_bytes);
|
||||||
if (!new_data) {
|
if (!arr->data) {
|
||||||
fprintf(stderr, "darray_armem_resize: reallocation failed\n");
|
fprintf(stderr, "darray_armem_resize: reallocation failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
arr->data = new_data;
|
|
||||||
arr->capacity = new_capacity;
|
arr->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +81,11 @@ void darray_armem_pop(darray_armem *arr, void (*free_data)(void *)) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (free_data) {
|
if (free_data) {
|
||||||
void *target = (char *)arr->data + (arr->size-1) * arr->element_size;
|
void *target = (char *)arr->data + (arr->size - 1) * arr->element_size;
|
||||||
free_data(target);
|
free_data(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
darray_armem_resize(arr, arr->size-1);
|
darray_armem_resize(arr, arr->size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *darray_armem_get(darray_armem *arr, size_t index) {
|
void *darray_armem_get(darray_armem *arr, size_t index) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
|
|
||||||
#define CHUNK_SIZE 1048576
|
#define CHUNK_SIZE 4096
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *data;
|
void *data;
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ ArgonObject *init_argon_class(char *name) {
|
|||||||
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
|
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
|
||||||
object->name = name;
|
object->name = name;
|
||||||
object->type = TYPE_OBJECT;
|
object->type = TYPE_OBJECT;
|
||||||
object->self = NULL;
|
object->self = object;
|
||||||
object->baseObject = ARGON_TYPE;
|
object->classObject = ;
|
||||||
|
object->baseObject = BASE_CLASS;
|
||||||
object->fields = createHashmap_GC();
|
object->fields = createHashmap_GC();
|
||||||
memset(&object->value, 0, sizeof(object->value));
|
memset(&object->value, 0, sizeof(object->value));
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
@@ -23,14 +23,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
uint64_t bytes_to_uint64(const uint8_t bytes[8]) {
|
|
||||||
uint64_t value = 0;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
value |= ((uint64_t)bytes[i]) << (i * 8);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_types() {
|
void init_types() {
|
||||||
BASE_CLASS = init_argon_class("BASE_CLASS");
|
BASE_CLASS = init_argon_class("BASE_CLASS");
|
||||||
|
|
||||||
@@ -40,6 +32,13 @@ void init_types() {
|
|||||||
init_string_type();
|
init_string_type();
|
||||||
|
|
||||||
init_base_field();
|
init_base_field();
|
||||||
|
BASE_CLASS->baseObject = ARGON_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int compare_by_order(const void *a, const void *b) {
|
||||||
|
const struct node_GC *itemA = (const struct node_GC *)a;
|
||||||
|
const struct node_GC *itemB = (const struct node_GC *)b;
|
||||||
|
return itemA->order - itemB->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t pop_byte(Translated *translated, RuntimeState *state) {
|
uint8_t pop_byte(Translated *translated, RuntimeState *state) {
|
||||||
@@ -47,11 +46,11 @@ uint8_t pop_byte(Translated *translated, RuntimeState *state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t pop_bytecode(Translated *translated, RuntimeState *state) {
|
uint64_t pop_bytecode(Translated *translated, RuntimeState *state) {
|
||||||
uint8_t bytes[8];
|
uint64_t value = 0;
|
||||||
for (size_t i = 0; i < sizeof(bytes); i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
bytes[i] = *((uint8_t *)darray_get(&translated->bytecode, state->head++));
|
value |= ((uint64_t)pop_byte(translated, state)) << (i * 8);
|
||||||
}
|
}
|
||||||
return bytes_to_uint64(bytes);
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_const(Translated *translated, RuntimeState *state) {
|
void load_const(Translated *translated, RuntimeState *state) {
|
||||||
@@ -147,7 +146,28 @@ ArErr run_instruction(Translated *translated, RuntimeState *state,
|
|||||||
case OP_NEW_SCOPE:
|
case OP_NEW_SCOPE:
|
||||||
*stack = create_scope(*stack);
|
*stack = create_scope(*stack);
|
||||||
break;
|
break;
|
||||||
case OP_POP_SCOPE:
|
case OP_POP_SCOPE:;
|
||||||
|
// struct node_GC *array =
|
||||||
|
// checked_malloc(sizeof(struct node_GC) * (*stack)->scope->count);
|
||||||
|
// size_t j = 0;
|
||||||
|
// for (size_t i = 0; i < (*stack)->scope->size; i++) {
|
||||||
|
// struct node_GC *temp = (*stack)->scope->list[i];
|
||||||
|
// while (temp) {
|
||||||
|
// array[j++] = *temp;
|
||||||
|
// temp = temp->next;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// qsort(array, (*stack)->scope->count, sizeof(struct node_GC),
|
||||||
|
// compare_by_order);
|
||||||
|
// for (size_t i = 0; i < (*stack)->scope->count; i++) {
|
||||||
|
// struct node_GC temp = array[i];
|
||||||
|
// printf("%.*s = %.*s\n",
|
||||||
|
// (int)((ArgonObject *)temp.key)->value.as_str.length,
|
||||||
|
// ((ArgonObject *)temp.key)->value.as_str.data,
|
||||||
|
// (int)((ArgonObject *)temp.val)->value.as_str.length,
|
||||||
|
// ((ArgonObject *)temp.val)->value.as_str.data);
|
||||||
|
// }
|
||||||
|
// free(array);
|
||||||
*stack = (*stack)->prev;
|
*stack = (*stack)->prev;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -160,7 +180,7 @@ ArErr run_instruction(Translated *translated, RuntimeState *state,
|
|||||||
RuntimeState init_runtime_state(Translated translated, char *path) {
|
RuntimeState init_runtime_state(Translated translated, char *path) {
|
||||||
return (RuntimeState){
|
return (RuntimeState){
|
||||||
checked_malloc(translated.registerCount * sizeof(ArgonObject *)), 0, path,
|
checked_malloc(translated.registerCount * sizeof(ArgonObject *)), 0, path,
|
||||||
ARGON_NULL};
|
ARGON_NULL, NULL, NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
Stack *create_scope(Stack *prev) {
|
Stack *create_scope(Stack *prev) {
|
||||||
@@ -172,11 +192,21 @@ Stack *create_scope(Stack *prev) {
|
|||||||
|
|
||||||
ArErr runtime(Translated translated, RuntimeState state, Stack *stack) {
|
ArErr runtime(Translated translated, RuntimeState state, Stack *stack) {
|
||||||
state.head = 0;
|
state.head = 0;
|
||||||
while (state.head < translated.bytecode.size) {
|
StackFrame *currentStackFrame = checked_malloc(sizeof(StackFrame));
|
||||||
ArErr err = run_instruction(&translated, &state, &stack);
|
*currentStackFrame = (StackFrame){translated, state, stack, NULL};
|
||||||
if (err.exists) {
|
state.currentStackFramePointer = ¤tStackFrame;
|
||||||
return err;
|
ArErr err = no_err;
|
||||||
|
while (currentStackFrame) {
|
||||||
|
while (currentStackFrame->state.head <
|
||||||
|
currentStackFrame->translated.bytecode.size &&
|
||||||
|
!err.exists) {
|
||||||
|
err =
|
||||||
|
run_instruction(¤tStackFrame->translated,
|
||||||
|
¤tStackFrame->state, ¤tStackFrame->stack);
|
||||||
}
|
}
|
||||||
|
StackFrame *tempStackFrame = currentStackFrame;
|
||||||
|
currentStackFrame = currentStackFrame->previousStackFrame;
|
||||||
|
free(tempStackFrame);
|
||||||
}
|
}
|
||||||
return no_err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -6,20 +6,35 @@
|
|||||||
|
|
||||||
#ifndef RUNTIME_H
|
#ifndef RUNTIME_H
|
||||||
#define RUNTIME_H
|
#define RUNTIME_H
|
||||||
|
#include "../returnTypes.h"
|
||||||
#include "../translator/translator.h"
|
#include "../translator/translator.h"
|
||||||
#include "internals/hashmap/hashmap.h"
|
#include "internals/hashmap/hashmap.h"
|
||||||
#include "../returnTypes.h"
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct StackFrame StackFrame;
|
||||||
|
typedef struct RuntimeState RuntimeState;
|
||||||
|
|
||||||
|
typedef ArErr (*error_result)(ArErr, Translated *translated,
|
||||||
|
RuntimeState *state, struct Stack **stack);
|
||||||
|
|
||||||
|
typedef struct RuntimeState {
|
||||||
ArgonObject **registers;
|
ArgonObject **registers;
|
||||||
size_t head;
|
size_t head;
|
||||||
char*path;
|
char *path;
|
||||||
ArgonObject * return_value;
|
ArgonObject *return_value;
|
||||||
|
StackFrame **currentStackFramePointer;
|
||||||
|
error_result result;
|
||||||
} RuntimeState;
|
} RuntimeState;
|
||||||
|
|
||||||
|
typedef struct StackFrame {
|
||||||
|
Translated translated;
|
||||||
|
RuntimeState state;
|
||||||
|
Stack *stack;
|
||||||
|
StackFrame *previousStackFrame;
|
||||||
|
} StackFrame;
|
||||||
|
|
||||||
void init_types();
|
void init_types();
|
||||||
|
|
||||||
extern struct hashmap * runtime_hash_table;
|
extern struct hashmap *runtime_hash_table;
|
||||||
|
|
||||||
uint64_t runtime_hash(const void *data, size_t len, uint64_t prehash);
|
uint64_t runtime_hash(const void *data, size_t len, uint64_t prehash);
|
||||||
|
|
||||||
|
|||||||
9
test.py
9
test.py
@@ -10,7 +10,7 @@ def generate_names(max_width, skip_keywords=None):
|
|||||||
if skip_keywords is None:
|
if skip_keywords is None:
|
||||||
skip_keywords = {"if", "else", "while", "forever", "for", "break", "continue",
|
skip_keywords = {"if", "else", "while", "forever", "for", "break", "continue",
|
||||||
"return", "let", "import", "from", "do", "true", "false", "null",
|
"return", "let", "import", "from", "do", "true", "false", "null",
|
||||||
"delete", "not", "try", "catch", "in"}
|
"delete", "not", "try", "catch", "in", "or", "and", "elif"}
|
||||||
else:
|
else:
|
||||||
skip_keywords = set(skip_keywords)
|
skip_keywords = set(skip_keywords)
|
||||||
|
|
||||||
@@ -25,15 +25,14 @@ def generate_names(max_width, skip_keywords=None):
|
|||||||
name = ''.join(p)
|
name = ''.join(p)
|
||||||
if name in skip_keywords:
|
if name in skip_keywords:
|
||||||
continue
|
continue
|
||||||
if not first:
|
write('let ')
|
||||||
write('\n')
|
|
||||||
write(name)
|
write(name)
|
||||||
|
write(' = null\n')
|
||||||
first = False
|
first = False
|
||||||
if i>10000000:
|
if i>10000000:
|
||||||
break
|
break
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
max_width = 15
|
max_width = 5
|
||||||
# sys.stdout.write("let ")
|
|
||||||
generate_names(max_width)
|
generate_names(max_width)
|
||||||
|
|||||||
19
testing.ar
19
testing.ar
@@ -1,11 +1,16 @@
|
|||||||
# SPDX-FileCopyrightText: 2025 William Bell
|
# SPDX-FileCopyrightText: 2025 William Bell
|
||||||
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
do
|
||||||
let y = 1
|
let x = "hello world"
|
||||||
|
let i = "hell"
|
||||||
let x = do
|
|
||||||
do
|
do
|
||||||
return y
|
let x = "hello world"
|
||||||
x
|
let i = "hell"
|
||||||
let z = x
|
let z = "hello world"
|
||||||
|
let a = "hello world"
|
||||||
|
let b = "hello world"
|
||||||
|
x
|
||||||
|
let z = "hello world"
|
||||||
|
let a = "hello world"
|
||||||
|
let b = "hello world"
|
||||||
Reference in New Issue
Block a user