Compare commits
4 Commits
| 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_runtime_push_scope(rt, p->f_block);
|
||||||
bshell_variable *item = bshell_runtime_define_var(rt, "_");
|
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);
|
fx_value out = bshell_runtime_eval(rt);
|
||||||
bshell_runtime_pop_scope(rt);
|
bshell_runtime_pop_scope(rt);
|
||||||
fx_value_unset(&in);
|
fx_value_unset(&in);
|
||||||
|
|||||||
@@ -56,11 +56,7 @@ static enum bshell_status process_record(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bshell_verb_ref(verb);
|
bshell_pipeline_write_value(pipeline, *v, false);
|
||||||
bshell_pipeline_write_value(
|
|
||||||
pipeline,
|
|
||||||
fx_value_ref_copy_return(v),
|
|
||||||
false);
|
|
||||||
break;
|
break;
|
||||||
} while (1);
|
} 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(
|
void print_instruction(
|
||||||
size_t offset,
|
size_t offset,
|
||||||
bshell_instruction instr,
|
bshell_instruction instr,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DEBUG_H_
|
#ifndef DEBUG_H_
|
||||||
#define DEBUG_H_
|
#define DEBUG_H_
|
||||||
|
|
||||||
|
#include <bshell/command/function.h>
|
||||||
#include <bshell/runtime/opcode.h>
|
#include <bshell/runtime/opcode.h>
|
||||||
#include <bshell/runtime/script-block.h>
|
#include <bshell/runtime/script-block.h>
|
||||||
#include <stdbool.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(struct bshell_ast_node *node);
|
||||||
extern void print_ast_node_recursive(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_scriptblock(bshell_scriptblock *block, size_t depth);
|
||||||
|
extern void print_function(bshell_function *func);
|
||||||
extern void print_instruction(
|
extern void print_instruction(
|
||||||
size_t offset,
|
size_t offset,
|
||||||
bshell_instruction instr,
|
bshell_instruction instr,
|
||||||
|
|||||||
@@ -107,6 +107,17 @@ int main(int argc, const char **argv)
|
|||||||
printf("----\n");
|
printf("----\n");
|
||||||
|
|
||||||
bshell_scriptblock_clear_text(block);
|
bshell_scriptblock_clear_text(block);
|
||||||
|
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);
|
bshell_compile(node, block);
|
||||||
print_scriptblock(block, 0);
|
print_scriptblock(block, 0);
|
||||||
|
|
||||||
@@ -114,7 +125,15 @@ int main(int argc, const char **argv)
|
|||||||
if (result.v_type != NULL) {
|
if (result.v_type != NULL) {
|
||||||
format_value_default(&result, fx_stdout);
|
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_parse_ctx_cleanup(&parse);
|
||||||
bshell_lex_ctx_cleanup(&lex);
|
bshell_lex_ctx_cleanup(&lex);
|
||||||
@@ -129,5 +148,7 @@ int main(int argc, const char **argv)
|
|||||||
bshell_file_close(file);
|
bshell_file_close(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bshell_cleanup_all_verbs();
|
||||||
|
|
||||||
return 0;
|
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