return (UwUVMValue) {
.type = VT_INT,
.value = {
- .int_value = value,
+ .int_value = value,
},
};
}
.value = {
.nat_value = {
.type = &uwunil_type,
- .data = NULL,
+ .data = NULL,
}
- }
+ }
};
}
UwUVMNativeType uwunil_type = {
.copy = &uwunil_copy,
.delete = &uwunil_delete,
- .print = &uwunil_print,
+ .print = &uwunil_print,
};
return (UwUVMValue) {
.type = VT_STR,
.value = {
- .str_value = strdup(value),
+ .str_value = strdup(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)
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));
fibo(sub($0, 2))
)))
-
print
if(smaller($0, 0), "",
:str:cat(
} 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
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) {
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++)
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:
default:
break;
- }
+ }
free(parse_expr);
}
if (! dlerror())
found = true;
-
+
free(symbol);
}
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)
free(prog_dirname);
free(api_path);
-
+
state.program.main_function = require_function(&state, require_module(&state, strdup(modname)), "main");
while (true) {
if (module->handle.ast.functions)
free(module->handle.ast.functions);
}
-
+
free(module);
}
#ifndef _EXPRESSION_H_
#define _EXPRESSION_H_
-typedef enum
+typedef enum
{
EX_UNINIT,
EX_INTLIT,
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);
}
buffer_append(state, '\0');
char *buffer = state->buffer;
-
+
state->buffer = NULL;
state->buffer_size = 0;
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);
static bool continue_arg(ParseState *state, char c)
{
DBG(__FUNCTION__)
-
+
if (c == ',')
start_arg(state);
else if (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)
}
static bool parse_expression_finish(ParseState *state, char c)
-{
+{
DBG(__FUNCTION__)
if (state->expression->type == EX_ARGNUM && state->buffer_size == 0)
}
static bool parse_expression(ParseState *state, char c)
-{
+{
DBG(__FUNCTION__)
return state->expression->type == EX_UNINIT
}
static bool parse_character(ParseState *state, char c)
-{
+{
#if DEBUG
printf("\nparse_character ");
printf("\n");
#endif
-
+
return state->expression
? parse_expression(state, c)
: parse_function(state, c);
.buffer = NULL,
.expression = NULL,
};
-
+
int lines = 1;
FILE *f = fopen(filename, "r");
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);
}
typedef struct
{
AbstractSyntaxTree tree;
-
+
size_t buffer_size;
char *buffer;
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);
}
free_expression(function->value.plain);
free(function->value.plain);
}
-
+
free(function);
}
for (size_t i = 1; i < args->num; i++)
if (get_bool_arg(args, i) != value)
return uwubool_create(false);
-
+
return uwubool_create(true);
}
{
if (args->num != 0)
error("error: :bool:true does not take any arguments\n");
-
+
return uwubool_create(true);
}
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);
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)
}
UwUVMValue uwu_equal(UwUVMArgs *args)
-{
+{
if (args->num < 2)
error("error: :int:equal requires at least 2 arguments\n");