Skip to content

Commit

Permalink
refs #232: added the code for packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Mar 30, 2021
1 parent 6ea4e8c commit da97cf8
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 40 deletions.
3 changes: 2 additions & 1 deletion include/kinx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ typedef struct kx_lexinfo_ {
int is_trim;
kx_lexinner_t inner;
kx_yyin_t in;
int tempbuf[16];
const char *pkgkey;
const int *restart;
int tempbuf[16];
} kx_lexinfo_t;
kvec_init_t(kx_lexinfo_t);

Expand Down
1 change: 1 addition & 0 deletions include/kxastobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern kx_object_t *kx_gen_str_object_pos(name_t name);
extern const char *kx_gen_constant_string(const char *name);
extern const char *kx_check_the_name(kx_object_t *obj);
extern kx_object_t *kx_gen_stmtlist(kx_object_t *lhs, kx_object_t *rhs);
extern kx_object_t *kx_gen_exprlist(kx_object_t *lhs, kx_object_t *rhs);
extern kx_object_t *kx_gen_range_object(kx_object_t *start, kx_object_t *end, int include_end);
extern kx_object_t *kx_gen_case_when_object(kx_object_t *decl, kx_object_t *expr, kx_object_t *modifier);
extern kx_object_t *kx_gen_forin_object(kx_object_t *var, kx_object_t *range, kx_object_t *stmt, int is_decl);
Expand Down
9 changes: 9 additions & 0 deletions include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

#include <stdint.h>
#include <kinx.h>
#include <khash.h>

typedef struct package_t_ {
const char *vers;
struct package_t_ *next;
} package_t;
KHASH_MAP_INIT_STR(package, package_t *)

typedef struct name_t_ {
const char *name;
int line;
int pos1;
int pos2;
} name_t;

typedef struct arytype_t_ {
int type;
int depth;
const char *name; /* class name */
} arytype_t;

typedef struct named_stmt_ {
const char *name; /* class name */
kx_object_t *stmt;
Expand Down
3 changes: 2 additions & 1 deletion src/ast_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,8 @@ LOOP_HEAD:;
case KXST_EXPRSEQ: /* lhs: expr1: rhs: expr2 */
case KXST_EXPRLIST: /* lhs: expr1: rhs: expr2 */
analyze_ast(ctx, node->lhs, actx);
analyze_ast(ctx, node->rhs, actx);
node = node->rhs;
if (node) goto LOOP_HEAD;
break;
case KXST_STMTLIST: /* lhs: stmt2: rhs: stmt1 */
analyze_ast(ctx, node->lhs, actx);
Expand Down
3 changes: 2 additions & 1 deletion src/ast_defdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ LOOP_HEAD:;
break;
case KXST_EXPRLIST: /* lhs: expr1: rhs: expr2 */
display_def_ast(dctx, node->lhs, lvalue);
display_def_ast(dctx, node->rhs, lvalue);
node = node->rhs;
if (node) goto LOOP_HEAD;
break;
case KXST_STMTLIST: /* lhs: stmt1: rhs: stmt2 */
display_def_ast(dctx, node->lhs, lvalue);
Expand Down
3 changes: 2 additions & 1 deletion src/ast_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ LOOP_HEAD:;
break;
case KXST_EXPRLIST: /* lhs: expr1: rhs: expr2 */
display_ast(node->lhs, indent, lvalue);
display_ast(node->rhs, indent, lvalue);
node = node->rhs;
if (node) goto LOOP_HEAD;
break;
case KXST_STMTLIST: /* lhs: stmt1: rhs: stmt2 */
display_ast(node->lhs, indent, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/ast_gencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ static void gencode_ast(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana,
}

LOOP_HEAD:;
// printf("%s:%d, node->type = %d (%s:%d)\n", __FILE__, __LINE__, node->type, node->file, node->line);
kx_module_t *module = ana->module;
switch (node->type) {
case KXVL_UNKNOWN:
Expand Down Expand Up @@ -1994,9 +1995,8 @@ LOOP_HEAD:;
}
case KXST_EXPRLIST: { /* lhs: expr1: rhs: expr2 */
gencode_ast_hook(ctx, node->lhs, ana, 0);
if (node->rhs) {
gencode_ast_hook(ctx, node->rhs, ana, 0);
}
node = node->rhs;
if (node) goto LOOP_HEAD;
break;
}
case KXST_STMTLIST: { /* lhs: stmt1: rhs: stmt2 */
Expand Down
19 changes: 16 additions & 3 deletions src/ast_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ kx_object_t *kx_gen_stmtlist(kx_object_t *lhs, kx_object_t *rhs)
return lhs;
}

kx_object_t *kx_gen_exprlist(kx_object_t *lhs, kx_object_t *rhs)
{
if (!lhs) {
return rhs;
}
if (lhs->type != KXST_EXPRLIST) {
return kx_gen_bexpr_object(KXST_EXPRLIST, lhs, rhs);
}
kx_object_t *node = lhs->ex ? lhs->ex : lhs;
while (node->rhs && node->rhs->type == KXST_EXPRLIST) {
node = node->rhs;
}
lhs->ex = node->rhs = kx_gen_bexpr_object(KXST_EXPRLIST, node->rhs, rhs);
return lhs;
}

kx_object_t *kx_gen_range_object(kx_object_t *lhs, kx_object_t *end, int exclude_end)
{
return kx_gen_obj(KXOP_MKRANGE, exclude_end, lhs, end, NULL);
Expand Down Expand Up @@ -690,9 +706,6 @@ static kx_object_t *kx_gen_func_object_impl(int type, int optional, arytype_t *r
}
}
kx_object_t *obj = kx_gen_obj(type, (type != KXST_NATIVE) ? optional : KXFT_ANONYMOUS, lhs, rhs, ex);
if (inherit) {
obj->typename = inherit;
}
obj->line2 = obj->line;
if (line > 0) {
obj->line = line;
Expand Down
4 changes: 4 additions & 0 deletions src/global.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <dbg.h>
#include <kinx.h>
#include <khash.h>
#include <kxthread.h>
#define KX_NO_INCLUDE_PARSER_TAB_H
#include <parser.h>

/* used in parsing, parsing phase is not reentrant. */
kx_lexinfo_t kx_lexinfo = {0};
Expand All @@ -10,6 +13,7 @@ kx_object_t *kx_ast_root = NULL;
int g_yyerror = 0;
int g_yywarning = 0;
kx_context_t *g_parse_ctx = NULL;
khash_t(package) *g_packages;

/* used in runtime. */
volatile int g_terminated = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/kinx.y
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ AssignExpressionObjList

KeyValueList
: KeyValue
| KeyValueList ',' KeyValue { $$ = kx_gen_bexpr_object(KXST_EXPRLIST, $1, $3); }
| KeyValueList ',' KeyValue { $$ = kx_gen_exprlist($1, $3); }
;

KeyValue
Expand Down Expand Up @@ -1034,9 +1034,9 @@ Inherit_Opt
.name = kx_check_the_name($3),
.stmt =
kx_gen_bexpr_object(KXST_STMTLIST,
kx_gen_bexpr_object(KXOP_DECL, kx_gen_var_object_line("this", KX_UNKNOWN_T, $2),
kx_gen_bexpr_object(KXOP_DECL, kx_gen_var_object_line("this", KX_OBJ_T, $2),
kx_gen_bexpr_object(KXOP_CALL, kx_gen_bexpr_object(KXOP_IDX, $3, kx_gen_str_object("create")), $4)),
kx_gen_bexpr_object(KXOP_DECL, kx_gen_var_object_line("super", KX_UNKNOWN_T, $2),
kx_gen_bexpr_object(KXOP_DECL, kx_gen_var_object_line("super", KX_OBJ_T, $2),
kx_gen_bexpr_object(KXOP_CALL, kx_gen_bexpr_object(KXOP_IDX, kx_gen_var_object("System", KX_UNKNOWN_T), kx_gen_str_object("makeSuper")), kx_gen_var_object("this", KX_UNKNOWN_T)))
),
};
Expand Down
Loading

0 comments on commit da97cf8

Please sign in to comment.