44 lines
803 B
C
44 lines
803 B
C
#include "../compile.h"
|
|
|
|
#include "../ast/ast.h"
|
|
#include "../debug.h"
|
|
#include "../status.h"
|
|
#include "compile-node.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
extern enum bshell_status compile_node(
|
|
struct compile_ctx *ctx,
|
|
struct ast_node *src)
|
|
{
|
|
switch (src->n_type) {
|
|
case AST_IF:
|
|
return compile_if(ctx, src);
|
|
case AST_BLOCK:
|
|
return compile_block_immediate(ctx, src);
|
|
default:
|
|
return compile_expression(ctx, src);
|
|
}
|
|
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
enum bshell_status bshell_compile(
|
|
struct ast_node *src,
|
|
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;
|
|
}
|