2026-05-17 15:33:44 +01:00
|
|
|
#include "compile-node.h"
|
|
|
|
|
|
2026-05-25 10:33:29 +01:00
|
|
|
#include <bshell/ast.h>
|
|
|
|
|
#include <bshell/compile.h>
|
|
|
|
|
#include <bshell/status.h>
|
2026-05-17 15:33:44 +01:00
|
|
|
|
|
|
|
|
extern enum bshell_status compile_node(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
|
|
|
|
switch (src->n_type) {
|
2026-05-25 10:33:29 +01:00
|
|
|
case BSHELL_AST_IF:
|
2026-05-17 15:33:44 +01:00
|
|
|
return compile_if(ctx, src);
|
2026-05-25 10:33:29 +01:00
|
|
|
case BSHELL_AST_BLOCK:
|
2026-05-17 15:33:44 +01:00
|
|
|
return compile_block_immediate(ctx, src);
|
|
|
|
|
default:
|
|
|
|
|
return compile_expression(ctx, src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum bshell_status bshell_compile(
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src,
|
2026-05-17 15:33:44 +01:00
|
|
|
bshell_scriptblock *dest)
|
|
|
|
|
{
|
|
|
|
|
struct compile_ctx ctx = {.c_block = dest};
|
|
|
|
|
|
|
|
|
|
enum bshell_status status = compile_node(&ctx, src);
|
|
|
|
|
if (status != BSHELL_SUCCESS) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = compile_resolve_labels(&ctx);
|
|
|
|
|
if (status != BSHELL_SUCCESS) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|