edfb3e24a3
bshell: the front-end binary bshell.runtime: contains the parser, compiler, and classes needed to run bshell scripts bshell.core: contains the builtin commandlets and aliases
188 lines
5.3 KiB
C
188 lines
5.3 KiB
C
#ifndef COMPILE_COMPILE_NODE_H_
|
|
#define COMPILE_COMPILE_NODE_H_
|
|
|
|
#include <bshell/ast.h>
|
|
#include <bshell/parse/token.h>
|
|
#include <bshell/runtime/operator.h>
|
|
#include <bshell/runtime/script-block.h>
|
|
#include <bshell/status.h>
|
|
#include <fx/queue.h>
|
|
#include <fx/vector.h>
|
|
|
|
#define COMPILE_OK(flags) \
|
|
((struct compile_result) {.r_status = BSHELL_SUCCESS, \
|
|
.r_flags = (flags)})
|
|
#define COMPILE_ERR(status) ((struct compile_result) {.r_status = (status)})
|
|
|
|
struct compile_ctx;
|
|
struct compile_value;
|
|
|
|
struct compile_result {
|
|
enum bshell_status r_status;
|
|
enum {
|
|
COMPILE_REPEAT_NODE = 0x00u,
|
|
} r_flags;
|
|
};
|
|
|
|
typedef struct compile_result (*compile_begin_impl)(struct compile_ctx *);
|
|
typedef struct compile_result (*compile_end_impl)(struct compile_ctx *);
|
|
typedef struct compile_result (
|
|
*compile_node_impl)(struct compile_ctx *, struct bshell_ast_node *);
|
|
|
|
enum compile_state_type_id {
|
|
COMPILE_NORMAL = 0,
|
|
COMPILE_FSTRING,
|
|
};
|
|
|
|
struct compile_value_type {
|
|
enum bshell_status (
|
|
*v_load)(struct compile_ctx *, struct compile_value *);
|
|
enum bshell_status (
|
|
*v_store)(struct compile_ctx *, struct compile_value *);
|
|
};
|
|
|
|
struct compile_value {
|
|
const struct compile_value_type *v_type;
|
|
enum bshell_operator_id v_op;
|
|
struct compile_value *v_left, *v_right;
|
|
struct compile_value **v_args;
|
|
size_t v_nr_args;
|
|
struct bshell_ast_node *v_node;
|
|
unsigned long v_pool;
|
|
fx_queue_entry v_entry;
|
|
};
|
|
|
|
struct compile_label {
|
|
size_t l_ip;
|
|
};
|
|
|
|
struct compile_label_ref {
|
|
fx_queue_entry ref_entry;
|
|
size_t ref_offset;
|
|
size_t ref_label_id;
|
|
};
|
|
|
|
struct compile_ctx {
|
|
fx_queue c_state, c_stack;
|
|
bshell_scriptblock *c_block;
|
|
FX_VECTOR_DECLARE(struct compile_label, c_labels);
|
|
fx_queue c_label_refs;
|
|
size_t c_depth;
|
|
};
|
|
|
|
struct compile_state_type {
|
|
size_t s_size;
|
|
compile_begin_impl s_compile_begin;
|
|
compile_end_impl s_compile_end;
|
|
const compile_node_impl *s_compile_node;
|
|
compile_node_impl s_compile_node_generic;
|
|
size_t s_nr_compile_node;
|
|
};
|
|
|
|
struct compile_state {
|
|
const struct compile_state_type *s_type;
|
|
fx_queue_entry s_entry;
|
|
size_t s_depth;
|
|
};
|
|
|
|
extern struct compile_state *compile_push_state(
|
|
struct compile_ctx *ctx,
|
|
enum compile_state_type_id state_type);
|
|
extern void compile_pop_state(struct compile_ctx *ctx);
|
|
extern struct compile_state *compile_get_state(const struct compile_ctx *ctx);
|
|
|
|
extern enum bshell_status compile_push_value(
|
|
struct compile_ctx *ctx,
|
|
const struct compile_value_type *type,
|
|
struct bshell_ast_node *node);
|
|
extern enum bshell_status compile_push_value_array(
|
|
struct compile_ctx *ctx,
|
|
const struct compile_value_type *type,
|
|
struct bshell_ast_node *node,
|
|
struct compile_value **values,
|
|
size_t nr_values);
|
|
extern enum bshell_status compile_push_pool_value(
|
|
struct compile_ctx *ctx,
|
|
const struct compile_value_type *type,
|
|
unsigned long pool_slot);
|
|
extern enum bshell_status compile_push_op(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *node,
|
|
const struct compile_value_type *type,
|
|
enum bshell_operator_id op,
|
|
struct compile_value *left,
|
|
struct compile_value *right);
|
|
extern struct compile_value *compile_pop_value(struct compile_ctx *ctx);
|
|
extern void compile_value_load(
|
|
struct compile_ctx *ctx,
|
|
struct compile_value *item);
|
|
extern void compile_value_store(
|
|
struct compile_ctx *ctx,
|
|
struct compile_value *item);
|
|
extern void compile_value_destroy(struct compile_value *item);
|
|
|
|
extern size_t compile_declare_label(struct compile_ctx *ctx);
|
|
extern void compile_define_label(struct compile_ctx *ctx, size_t label_id);
|
|
extern void compile_ref_label(struct compile_ctx *ctx, size_t label_id);
|
|
extern enum bshell_status compile_resolve_labels(struct compile_ctx *ctx);
|
|
|
|
extern struct compile_result compile_int(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_double(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_string(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_word(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_op(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_var(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern struct compile_result compile_fstring(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_array(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_hashtable_item(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_hashtable(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern struct compile_result compile_block(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern struct compile_result compile_cmdcall(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern struct compile_result compile_pipeline(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern enum bshell_status compile_if(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern enum bshell_status compile_block_immediate(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
extern enum bshell_status compile_expression(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
extern enum bshell_status compile_node(
|
|
struct compile_ctx *ctx,
|
|
struct bshell_ast_node *src);
|
|
|
|
#endif
|