Compare commits
4 Commits
1710f705e9
...
afab5343c4
| Author | SHA1 | Date | |
|---|---|---|---|
| afab5343c4 | |||
| 0697d889c5 | |||
| 28abb4d2d3 | |||
| 531191ab52 |
@@ -50,7 +50,7 @@ static enum bshell_status process_record(
|
||||
|
||||
bshell_runtime_push_scope(rt, p->f_block);
|
||||
bshell_variable *item = bshell_runtime_define_var(rt, "_");
|
||||
bshell_variable_set_value(item, &in);
|
||||
bshell_variable_set_value(item, in);
|
||||
fx_value out = bshell_runtime_eval(rt);
|
||||
bshell_runtime_pop_scope(rt);
|
||||
fx_value_unset(&in);
|
||||
|
||||
@@ -56,11 +56,7 @@ static enum bshell_status process_record(
|
||||
continue;
|
||||
}
|
||||
|
||||
bshell_verb_ref(verb);
|
||||
bshell_pipeline_write_value(
|
||||
pipeline,
|
||||
fx_value_ref_copy_return(v),
|
||||
false);
|
||||
bshell_pipeline_write_value(pipeline, *v, false);
|
||||
break;
|
||||
} while (1);
|
||||
|
||||
|
||||
@@ -171,6 +171,32 @@ void print_scriptblock(bshell_scriptblock *block, size_t depth)
|
||||
}
|
||||
}
|
||||
|
||||
void print_function(bshell_function *func)
|
||||
{
|
||||
const char *name = bshell_function_get_name(func);
|
||||
const fx_array *params
|
||||
= bshell_function_get_positional_parameters(func);
|
||||
bshell_scriptblock *body = bshell_function_get_body(func);
|
||||
printf("%s(", name);
|
||||
|
||||
size_t i = 0;
|
||||
const fx_iterator *it = fx_iterator_begin(params);
|
||||
fx_foreach(v, it)
|
||||
{
|
||||
if (i > 0) {
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
printf("$");
|
||||
fx_value_to_string(v, fx_stdout, NULL);
|
||||
i++;
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
printf("):\n");
|
||||
print_scriptblock(body, 1);
|
||||
}
|
||||
|
||||
void print_instruction(
|
||||
size_t offset,
|
||||
bshell_instruction instr,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef DEBUG_H_
|
||||
#define DEBUG_H_
|
||||
|
||||
#include <bshell/command/function.h>
|
||||
#include <bshell/runtime/opcode.h>
|
||||
#include <bshell/runtime/script-block.h>
|
||||
#include <stdbool.h>
|
||||
@@ -12,6 +13,7 @@ extern void print_lex_token(struct bshell_lex_token *tok);
|
||||
extern void print_ast_node(struct bshell_ast_node *node);
|
||||
extern void print_ast_node_recursive(struct bshell_ast_node *node);
|
||||
extern void print_scriptblock(bshell_scriptblock *block, size_t depth);
|
||||
extern void print_function(bshell_function *func);
|
||||
extern void print_instruction(
|
||||
size_t offset,
|
||||
bshell_instruction instr,
|
||||
|
||||
+27
-6
@@ -107,15 +107,34 @@ int main(int argc, const char **argv)
|
||||
printf("----\n");
|
||||
|
||||
bshell_scriptblock_clear_text(block);
|
||||
bshell_compile(node, block);
|
||||
print_scriptblock(block, 0);
|
||||
|
||||
fx_value result = bshell_runtime_eval_global(rt, block);
|
||||
if (result.v_type != NULL) {
|
||||
format_value_default(&result, fx_stdout);
|
||||
switch (node->n_type) {
|
||||
case BSHELL_AST_FUNC: {
|
||||
bshell_function *func = NULL;
|
||||
bshell_compile_function(node, &func);
|
||||
print_function(func);
|
||||
bshell_runtime_define_function(rt, func);
|
||||
bshell_function_unref(func);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
bshell_compile(node, block);
|
||||
print_scriptblock(block, 0);
|
||||
|
||||
fx_value result = bshell_runtime_eval_global(rt, block);
|
||||
if (result.v_type != NULL) {
|
||||
format_value_default(&result, fx_stdout);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bshell_ast_node_destroy(node);
|
||||
}
|
||||
|
||||
bshell_runtime_destroy(rt);
|
||||
bshell_scriptblock_unref(block);
|
||||
|
||||
bshell_parse_ctx_cleanup(&parse);
|
||||
bshell_lex_ctx_cleanup(&lex);
|
||||
|
||||
@@ -129,5 +148,7 @@ int main(int argc, const char **argv)
|
||||
bshell_file_close(file);
|
||||
}
|
||||
|
||||
bshell_cleanup_all_verbs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
func test-function($name) {
|
||||
echo "Hello, $name!"
|
||||
}
|
||||
|
||||
$x = "Jonh"
|
||||
test-function $x
|
||||
Reference in New Issue
Block a user