]> git.lizzy.rs Git - uwu-lang.git/commitdiff
Code format
authorElias Fleckenstein <eliasfleckenstein@web.de>
Thu, 30 Dec 2021 13:28:19 +0000 (14:28 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Thu, 30 Dec 2021 13:28:19 +0000 (14:28 +0100)
12 files changed:
api/int.c
api/nil.c
api/str.c
api/vm.c
example/fibo.uwu
src/collect.c
src/expression.h
src/parse.c
src/parse.h
src/vm.c
std/bool.c
std/int.c

index aea8e26d0ad3038ece66a5e9dc4d6b8e168c3058..49463cf0792a962dde9dd03f33184e532db44595 100644 (file)
--- a/api/int.c
+++ b/api/int.c
@@ -5,7 +5,7 @@ UwUVMValue uwuint_create(int value)
        return (UwUVMValue) {
                .type = VT_INT,
                .value = {
-                       .int_value = value,     
+                       .int_value = value,
                },
        };
 }
index a9c54cca55a96394372bc3a02e685b5c59eed87b..bbd1eb82534488cc8db5b9a6159fc82da269cbd9 100644 (file)
--- a/api/nil.c
+++ b/api/nil.c
@@ -8,9 +8,9 @@ UwUVMValue uwunil_create()
                .value = {
                        .nat_value = {
                                .type = &uwunil_type,
-                               .data = NULL,   
+                               .data = NULL,
                        }
-               }       
+               }
        };
 }
 
@@ -33,5 +33,5 @@ static char *uwunil_print(void *data)
 UwUVMNativeType uwunil_type = {
        .copy = &uwunil_copy,
        .delete = &uwunil_delete,
-       .print = &uwunil_print, 
+       .print = &uwunil_print,
 };
index c634fc24def2753e2debddea6d9b0f257a80978e..37b8e7015ca5b97b641f1b0b843002effcbd072b 100644 (file)
--- a/api/str.c
+++ b/api/str.c
@@ -7,7 +7,7 @@ UwUVMValue uwustr_create(const char *value)
        return (UwUVMValue) {
                .type = VT_STR,
                .value = {
-                       .str_value = strdup(value),     
+                       .str_value = strdup(value),
                },
        };
 }
@@ -23,7 +23,7 @@ char *uwustr_get(UwUVMValue vm_value)
 
                case VT_REF:
                        return asprintf_wrapper("[Function reference: %p]", vm_value.value.ref_value);
-               
+
                case VT_NAT:
                        return vm_value.value.nat_value.type->print
                                ? vm_value.value.nat_value.type->print(vm_value.value.nat_value.data)
index 547805cee896766809c11492f52d3869bc3b4c95..c33c32e0689a9c0a8dc4e8decf0adee1a45b4149 100644 (file)
--- a/api/vm.c
+++ b/api/vm.c
@@ -67,7 +67,7 @@ UwUVMValue uwuvm_evaluate_expression(UwUVMExpression *expression, UwUVMArgs *arg
                        return uwustr_create(expression->value.str_value);
 
                case EX_ARGNUM:
-                       if ((size_t) expression->value.int_value >= args->num) 
+                       if ((size_t) expression->value.int_value >= args->num)
                                error("error: not enough arguments (accessed argument $%d, but only %lu arguments were passed)\n", expression->value.int_value, args->num);
 
                        return uwuvm_copy_value(uwuvm_get_arg(args, expression->value.int_value));
index d3126a1e444eedd50902d7f10ffee528720f5b1a..48851c54ff05fc04952b6a8f1b4fd7ab31bb2646 100644 (file)
@@ -15,7 +15,6 @@ fibo
                fibo(sub($0, 2))
        )))
 
-
 print
        if(smaller($0, 0), "",
        :str:cat(
index fadb9d10129026496782d805d8fd212b2d96f3e9..ae155131fd23e73860dfbefa092c9f1e14195769 100644 (file)
@@ -72,11 +72,11 @@ typedef struct
        } handle;
 } Module;
 
-typedef struct 
+typedef struct
 {
        Module   **modules;                     // loaded modules
        size_t num_modules;                     // count for modules
-       
+
        char *std_path;                         // path to standard library
 
        UwUVMProgram program;                   // the result program
@@ -169,7 +169,7 @@ static UwUVMFunction *require_function(CollectorState *state, Module *module, co
        ref->type = module->type;
 
        state->program.functions = realloc(state->program.functions, sizeof *state->program.functions * ++state->program.num_functions);
-       state->program.functions[state->program.num_functions - 1] = ref;       
+       state->program.functions[state->program.num_functions - 1] = ref;
 
        module->functions = realloc(module->functions, sizeof *module->functions * ++module->num_functions);
        module->functions[module->num_functions - 1] = (FunctionLink) {
@@ -207,7 +207,7 @@ static UwUVMFunction *resolve_function(CollectorState *state, Module *caller_mod
                        callee_name++;
                }
 
-               size_t path_len = fnname - callee_name; 
+               size_t path_len = fnname - callee_name;
                char callee_path[path_len];
 
                for (size_t i = 0; i < path_len; i++)
@@ -229,7 +229,7 @@ static void translate_expression(CollectorState *state, Module *module, UwUVMExp
                vm_function = resolve_function(state, module, parse_expr->value.str_value);
                free(parse_expr->value.str_value);
        }
-       
+
        switch (vm_expr->type = parse_expr->type) {
                case EX_INTLIT:
                case EX_ARGNUM:
@@ -258,7 +258,7 @@ static void translate_expression(CollectorState *state, Module *module, UwUVMExp
 
                default:
                        break;
-       }               
+       }
 
        free(parse_expr);
 }
@@ -299,7 +299,7 @@ static void load_functions(CollectorState *state, Module *module)
 
                        if (! dlerror())
                                found = true;
-       
+
                        free(symbol);
                }
 
@@ -321,7 +321,7 @@ static void free_expression(ParseExpression *expr)
        if (expr->type != EX_INTLIT && expr->type != EX_ARGNUM)
                free(expr->value.str_value);
 
-       free(expr);     
+       free(expr);
 }
 
 UwUVMProgram create_program(const char *progname, const char *modname)
@@ -345,7 +345,7 @@ UwUVMProgram create_program(const char *progname, const char *modname)
 
        free(prog_dirname);
        free(api_path);
-       
+
        state.program.main_function = require_function(&state, require_module(&state, strdup(modname)), "main");
 
        while (true) {
@@ -396,7 +396,7 @@ UwUVMProgram create_program(const char *progname, const char *modname)
                        if (module->handle.ast.functions)
                                free(module->handle.ast.functions);
                }
-               
+
                free(module);
        }
 
index da74620ae1e4cbe747fbc93eefa6968808e3e943..55d10f7b9cfec6f6d231caf5494e9d2e5e518255 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _EXPRESSION_H_
 #define _EXPRESSION_H_
 
-typedef enum 
+typedef enum
 {
        EX_UNINIT,
        EX_INTLIT,
index be0ee98de181eacdb5e2781ee8de38dca13cf983..c8b430d4963f52698b6f38caa62c77d6c3d48c11 100644 (file)
@@ -45,7 +45,7 @@ static void print_ast(AbstractSyntaxTree tree)
 
        for (size_t f = 0; f < tree.num_functions; f++) {
                ParseFunction *function = tree.functions[f];
-       
+
                printf("function %s\n", function->name);
                print_expression(function->expression, 1);
        }
@@ -63,7 +63,7 @@ static char *buffer_terminate(ParseState *state)
        buffer_append(state, '\0');
 
        char *buffer = state->buffer;
-       
+
        state->buffer = NULL;
        state->buffer_size = 0;
 
@@ -73,7 +73,7 @@ static char *buffer_terminate(ParseState *state)
 static void start_arg(ParseState *state)
 {
        DBG(__FUNCTION__)
-       
+
        ParseExpression *parent = state->expression;
        parent->children = realloc(parent->children, sizeof *parent->children * ++parent->num_children);
        ParseExpression *child = parent->children[parent->num_children - 1] = malloc(sizeof *child);
@@ -87,7 +87,7 @@ static void start_arg(ParseState *state)
 static bool continue_arg(ParseState *state, char c)
 {
        DBG(__FUNCTION__)
-                       
+
        if (c == ',')
                start_arg(state);
        else if (c == ')')
@@ -98,8 +98,8 @@ static bool continue_arg(ParseState *state, char c)
        return true;
 }
 
-static bool finish_arg(ParseState *state, char c) 
-{      
+static bool finish_arg(ParseState *state, char c)
+{
        state->expression = state->expression->parent;
 
        if (state->expression)
@@ -147,7 +147,7 @@ static bool parse_expression_init(ParseState *state, char c)
 }
 
 static bool parse_expression_finish(ParseState *state, char c)
-{      
+{
        DBG(__FUNCTION__)
 
        if (state->expression->type == EX_ARGNUM && state->buffer_size == 0)
@@ -210,7 +210,7 @@ static bool parse_expression_continue(ParseState *state, char c)
 }
 
 static bool parse_expression(ParseState *state, char c)
-{      
+{
        DBG(__FUNCTION__)
 
        return state->expression->type == EX_UNINIT
@@ -251,7 +251,7 @@ static bool parse_function(ParseState *state, char c)
 }
 
 static bool parse_character(ParseState *state, char c)
-{      
+{
 #if DEBUG
        printf("\nparse_character ");
 
@@ -262,7 +262,7 @@ static bool parse_character(ParseState *state, char c)
 
         printf("\n");
 #endif
-       
+
        return state->expression
                ? parse_expression(state, c)
                : parse_function(state, c);
@@ -279,7 +279,7 @@ AbstractSyntaxTree parse_file(const char *filename)
                .buffer = NULL,
                .expression = NULL,
        };
-       
+
        int lines = 1;
 
        FILE *f = fopen(filename, "r");
@@ -307,7 +307,7 @@ AbstractSyntaxTree parse_file(const char *filename)
                if (c == '\n')
                        printf("\n[Line %d]\n", lines);
 #endif
-               
+
                if (! parse_character(&state, c))
                        error("%s: syntax error in line %d\n", filename, lines);
        }
index 861ad1c95db9de196ef5f0d8c1ecff1d885d213c..7aca6afb03c8581bef0f245c27b8655f8df43eeb 100644 (file)
@@ -33,7 +33,7 @@ typedef struct
 typedef struct
 {
        AbstractSyntaxTree tree;
-       
+
        size_t buffer_size;
        char *buffer;
 
index 7f0db998ba8a34cd5a8470eb6675f431d367f608..335eb48d5b8aa261e4e89cbe72d38b7482fdc15b 100644 (file)
--- a/src/vm.c
+++ b/src/vm.c
@@ -9,7 +9,7 @@ static void free_expression(UwUVMExpression *expr)
        if (expr->type == EX_FNCALL) {
                for (size_t i = 0; i < expr->value.cll_value.num_args; i++)
                        free_expression(&expr->value.cll_value.args[i]);
-       
+
                free(expr->value.cll_value.args);
        }
 
@@ -36,7 +36,7 @@ void vm_run_file(const char *progname, const char *modname)
                        free_expression(function->value.plain);
                        free(function->value.plain);
                }
-                       
+
                free(function);
        }
 
index cb4082b6116e5efc7fb7d92f146753729bcb6f9c..80aade57218093906e535189bcb6c8b70171d24b 100644 (file)
@@ -55,7 +55,7 @@ UwUVMValue uwu_equal(UwUVMArgs *args)
        for (size_t i = 1; i < args->num; i++)
                if (get_bool_arg(args, i) != value)
                        return uwubool_create(false);
-       
+
        return uwubool_create(true);
 }
 
@@ -71,7 +71,7 @@ UwUVMValue uwu_true(UwUVMArgs *args)
 {
        if (args->num != 0)
                error("error: :bool:true does not take any arguments\n");
-       
+
        return uwubool_create(true);
 }
 
index a8d2c6de56d90639e035e318a845cd7d3fbfa55f..48c808b18fcec473d78b7b16608ddc6cb40ad6c3 100644 (file)
--- a/std/int.c
+++ b/std/int.c
@@ -56,7 +56,7 @@ static int reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, int result)
 
        for (size_t i = 0; i < args->num; i++) {
                UwUVMValue value = uwuvm_get_arg(args, i);
-       
+
                if (value.type != VT_INT)
                        error("error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i);
 
@@ -90,7 +90,7 @@ UwUVMValue uwu_sub(UwUVMArgs *args)
 
 UwUVMValue uwu_mul(UwUVMArgs *args)
 {
-       return uwuint_create(reduce(":int:mul", args, ROP_MUL, 1));     
+       return uwuint_create(reduce(":int:mul", args, ROP_MUL, 1));
 }
 
 UwUVMValue uwu_div(UwUVMArgs *args)
@@ -114,7 +114,7 @@ UwUVMValue uwu_greater(UwUVMArgs *args)
 }
 
 UwUVMValue uwu_equal(UwUVMArgs *args)
-{      
+{
        if (args->num < 2)
                error("error: :int:equal requires at least 2 arguments\n");