Reformat ParseStatement.CC

This commit is contained in:
TomAwezome 2020-07-26 17:46:51 -05:00 committed by VoidNV
parent 1b380ef95d
commit bb497eca7c
3 changed files with 932 additions and 789 deletions

View file

@ -3,7 +3,8 @@ CHashClass *ParseClass(CCompCtrl *cc,I64 keyword,I64 fsp_flags,Bool is_extern)
CHashClass *tmpc, *base_class; CHashClass *tmpc, *base_class;
if (cc->token != TK_IDENT) if (cc->token != TK_IDENT)
LexExcept(cc, "Expecting identifier at "); LexExcept(cc, "Expecting identifier at ");
if (is_extern) { if (is_extern)
{
tmpc = ParseClassNew; tmpc = ParseClassNew;
tmpc->str = cc->cur_str; tmpc->str = cc->cur_str;
cc->cur_str = NULL; cc->cur_str = NULL;
@ -11,23 +12,29 @@ CHashClass *ParseClass(CCompCtrl *cc,I64 keyword,I64 fsp_flags,Bool is_extern)
LBts(&tmpc->flags, Cf_EXTERN); LBts(&tmpc->flags, Cf_EXTERN);
HashSrcFileSet(cc, tmpc); HashSrcFileSet(cc, tmpc);
Lex(cc); Lex(cc);
} else { }
else
{
if (cc->flags & CCF_AOT_COMPILE) if (cc->flags & CCF_AOT_COMPILE)
tmpc = HashFind(cc->cur_str, cc->htc.global_hash_table, HTT_CLASS); tmpc = HashFind(cc->cur_str, cc->htc.global_hash_table, HTT_CLASS);
else else
tmpc = HashSingleTableFind(cc->cur_str, cc->htc.global_hash_table, HTT_CLASS); tmpc = HashSingleTableFind(cc->cur_str, cc->htc.global_hash_table, HTT_CLASS);
if (tmpc) { if (tmpc)
{
if (!Bt(&tmpc->flags, Cf_EXTERN)) if (!Bt(&tmpc->flags, Cf_EXTERN))
tmpc = NULL; tmpc = NULL;
else if (tmpc->use_count < 3) else if (tmpc->use_count < 3)
UnusedExternWarning(cc, tmpc); UnusedExternWarning(cc, tmpc);
} }
if (tmpc) { if (tmpc)
{
Free(tmpc->src_link); Free(tmpc->src_link);
tmpc->src_link = NULL; tmpc->src_link = NULL;
Free(tmpc->idx); Free(tmpc->idx);
tmpc->idx = NULL; tmpc->idx = NULL;
} else { }
else
{
tmpc = ParseClassNew; tmpc = ParseClassNew;
tmpc->str = cc->cur_str; tmpc->str = cc->cur_str;
cc->cur_str = NULL; cc->cur_str = NULL;
@ -41,9 +48,9 @@ CHashClass *ParseClass(CCompCtrl *cc,I64 keyword,I64 fsp_flags,Bool is_extern)
HashSrcFileSet(cc, tmpc, -1); HashSrcFileSet(cc, tmpc, -1);
else else
HashSrcFileSet(cc, tmpc,0); HashSrcFileSet(cc, tmpc,0);
if (Lex(cc)==':') { if (Lex(cc) == ':')
if (Lex(cc)!=TK_IDENT || !(base_class=cc->hash_entry) || {
!(base_class->type&HTT_CLASS)) if (Lex(cc) != TK_IDENT || !(base_class = cc->hash_entry) || !(base_class->type & HTT_CLASS))
LexExcept(cc, "Invalid class at "); LexExcept(cc, "Invalid class at ");
if (Lex(cc) == ',') if (Lex(cc) == ',')
LexExcept(cc, "Only one base class allowed at this time at "); LexExcept(cc, "Only one base class allowed at this time at ");
@ -59,28 +66,30 @@ CHashClass *ParseClass(CCompCtrl *cc,I64 keyword,I64 fsp_flags,Bool is_extern)
return tmpc; return tmpc;
} }
CHashFun *ParseFunJoin(CCompCtrl *cc,CHashClass *tmp_return, CHashFun *ParseFunJoin(CCompCtrl *cc, CHashClass *tmp_return, U8 *name, I64 fsp_flags)
U8 *name,I64 fsp_flags)
{ {
CMemberList *tmpm, *header_list; CMemberList *tmpm, *header_list;
CAOTCtrl *aotc = cc->aotc; CAOTCtrl *aotc = cc->aotc;
CHashClass *header_return; CHashClass *header_return;
CHashFun *tmpf; CHashFun *tmpf;
I64 header_arg_count; I64 header_arg_count;
if (name) {//if not fun_ptr if (name)
if (cc->flags&CCF_AOT_COMPILE) { {//if not fun_ptr
if ((tmpf=HashFind(name,cc->htc.global_hash_table,HTT_FUN)) && if (cc->flags & CCF_AOT_COMPILE)
tmpf->type & HTF_IMPORT) {
if ((tmpf = HashFind(name, cc->htc.global_hash_table, HTT_FUN)) && tmpf->type & HTF_IMPORT)
tmpf=NULL; tmpf=NULL;
} else }
if ((tmpf=HashSingleTableFind(name,cc->htc.global_hash_table,HTT_FUN)) && else
!Bt(&tmpf->flags,Cf_EXTERN)) if ((tmpf = HashSingleTableFind(name, cc->htc.global_hash_table, HTT_FUN)) && !Bt(&tmpf->flags, Cf_EXTERN))
tmpf = NULL; tmpf = NULL;
if (tmpf && tmpf->use_count < 3) if (tmpf && tmpf->use_count < 3)
UnusedExternWarning(cc, tmpf); UnusedExternWarning(cc, tmpf);
} else }
else
tmpf = NULL; tmpf = NULL;
if (tmpf) { if (tmpf)
{
tmpf->used_reg_mask = REGG_CLOBBERED + REGG_SAVED + REGG_STACK_TMP; tmpf->used_reg_mask = REGG_CLOBBERED + REGG_SAVED + REGG_STACK_TMP;
Free(tmpf->src_link); Free(tmpf->src_link);
tmpf->src_link = NULL; tmpf->src_link = NULL;
@ -92,7 +101,9 @@ CHashFun *ParseFunJoin(CCompCtrl *cc,CHashClass *tmp_return,
header_return = tmpf->return_class; header_return = tmpf->return_class;
tmpf->member_list_and_root = NULL; tmpf->member_list_and_root = NULL;
ClassMemberListDel(tmpf); ClassMemberListDel(tmpf);
} else { }
else
{
tmpf = ParseFunNew; tmpf = ParseFunNew;
header_return = NULL; header_return = NULL;
tmpf->used_reg_mask = REGG_CLOBBERED + REGG_SAVED + REGG_STACK_TMP; tmpf->used_reg_mask = REGG_CLOBBERED + REGG_SAVED + REGG_STACK_TMP;
@ -116,18 +127,23 @@ CHashFun *ParseFunJoin(CCompCtrl *cc,CHashClass *tmp_return,
if (0 < tmpf->arg_count << 3 <= I16_MAX && !Bt(&tmpf->flags, Ff_DOT_DOT_DOT)) if (0 < tmpf->arg_count << 3 <= I16_MAX && !Bt(&tmpf->flags, Ff_DOT_DOT_DOT))
LBts(&tmpf->flags, Ff_RET1); LBts(&tmpf->flags, Ff_RET1);
tmpm = tmpf->member_list_and_root; tmpm = tmpf->member_list_and_root;
while (tmpm) { while (tmpm)
{
tmpm->offset += 16; //RBP+RETURN tmpm->offset += 16; //RBP+RETURN
tmpm = tmpm->next; tmpm = tmpm->next;
} }
tmpf->size = 0; tmpf->size = 0;
if (header_return) { if (header_return)
if (OptionGet(OPTf_WARN_HEADER_MISMATCH)) { {
if (tmpf->return_class!=header_return) { if (OptionGet(OPTf_WARN_HEADER_MISMATCH))
{
if (tmpf->return_class != header_return)
{
PrintWarn("Fun Header return mismatch '%s'\n", tmpf->str); PrintWarn("Fun Header return mismatch '%s'\n", tmpf->str);
cc->warning_count++; cc->warning_count++;
} }
if (!MemberListCmp(tmpf->member_list_and_root,header_list,header_arg_count)) { if (!MemberListCmp(tmpf->member_list_and_root, header_list, header_arg_count))
{
PrintWarn("Fun header args mismatch '%s'\n", tmpf->str); PrintWarn("Fun header args mismatch '%s'\n", tmpf->str);
cc->warning_count++; cc->warning_count++;
} }
@ -168,21 +184,25 @@ U0 ParseFun(CCompCtrl *cc,CHashClass *tmp_return,U8 *name,I64 fsp_flags)
cc->lb_leave = saved_leave_label; cc->lb_leave = saved_leave_label;
ICAdd(cc, IC_LEAVE, 0, cc->htc.fun->return_class); ICAdd(cc, IC_LEAVE, 0, cc->htc.fun->return_class);
cc->htc.fun->size &= ~7; cc->htc.fun->size &= ~7;
if (cc->flags&CCF_AOT_COMPILE) { if (cc->flags & CCF_AOT_COMPILE)
{
cc->htc.fun->exe_addr = cc->aotc->rip; cc->htc.fun->exe_addr = cc->aotc->rip;
cc->htc.fun->type |= HTF_EXPORT | HTF_RESOLVE; cc->htc.fun->type |= HTF_EXPORT | HTF_RESOLVE;
r = COCCompile(cc, &size, &cc->htc.fun->debug_info, NULL); r = COCCompile(cc, &size, &cc->htc.fun->debug_info, NULL);
if (r) { if (r)
{
j = (size + 7) >> 3; j = (size + 7) >> 3;
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
AOTStoreCodeU64(cc, r[i]); AOTStoreCodeU64(cc, r[i]);
Free(r); Free(r);
} }
} else { }
else
{
old_trace = Btr(&cc->opts, OPTf_TRACE); old_trace = Btr(&cc->opts, OPTf_TRACE);
cc->htc.fun->exe_addr=COCCompile( cc->htc.fun->exe_addr = COCCompile(cc, &size, &cc->htc.fun->debug_info, NULL);
cc,&size,&cc->htc.fun->debug_info,NULL); if (old_trace)
if (old_trace) { {
Bts(&cc->opts, OPTf_TRACE); Bts(&cc->opts, OPTf_TRACE);
Un(cc->htc.fun->exe_addr, size, 64); Un(cc->htc.fun->exe_addr, size, 64);
} }
@ -191,23 +211,23 @@ U0 ParseFun(CCompCtrl *cc,CHashClass *tmp_return,U8 *name,I64 fsp_flags)
LBtr(&cc->htc.fun->flags, Cf_EXTERN); LBtr(&cc->htc.fun->flags, Cf_EXTERN);
COCPop(cc); COCPop(cc);
tmpm = cc->htc.fun->member_list_and_root; tmpm = cc->htc.fun->member_list_and_root;
while (tmpm) { while (tmpm)
if (tmpm->flags & MLF_NO_UNUSED_WARN) { {
if (tmpm->flags & MLF_NO_UNUSED_WARN)
{
if (tmpm->use_count > 1 && StrCompare(tmpm->str, "_anon_")) if (tmpm->use_count > 1 && StrCompare(tmpm->str, "_anon_"))
PrintWarn("Unneeded no_warn\n $$LK,\"FL:%s,%d\"$$ '%s' in '%s'\n", PrintWarn("Unneeded no_warn\n $$LK,\"FL:%s,%d\"$$ '%s' in '%s'\n",
cc->lex_include_stack->full_name,cc->lex_include_stack->line_num, cc->lex_include_stack->full_name, cc->lex_include_stack->line_num, tmpm->str, cc->htc.fun->str);
tmpm->str,cc->htc.fun->str); }
} else if (!tmpm->use_count && OptionGet(OPTf_WARN_UNUSED_VAR)) else if (!tmpm->use_count && OptionGet(OPTf_WARN_UNUSED_VAR))
PrintWarn("Unused var\n $$LK,\"FL:%s,%d\"$$ '%s' in '%s'\n", PrintWarn("Unused var\n $$LK,\"FL:%s,%d\"$$ '%s' in '%s'\n",
cc->lex_include_stack->full_name,cc->lex_include_stack->line_num, cc->lex_include_stack->full_name, cc->lex_include_stack->line_num, tmpm->str, cc->htc.fun->str);
tmpm->str,cc->htc.fun->str);
tmpm = tmpm->next; tmpm = tmpm->next;
} }
cc->htc.local_var_list = cc->htc.fun=cc->fun_lex_file = NULL; cc->htc.local_var_list = cc->htc.fun=cc->fun_lex_file = NULL;
} }
U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc, U0 ParseGlobalVarList(CCompCtrl *cc, I64 saved_mode, CHashClass *saved_tmpc, I64 saved_val, I64 fsp_flags)
I64 saved_val,I64 fsp_flags)
{ {
I64 i, j, mode, k, val; I64 i, j, mode, k, val;
U8 *st; U8 *st;
@ -219,28 +239,33 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
CHashFun *tmpf, *tmpf_fun_ptr; CHashFun *tmpf, *tmpf_fun_ptr;
CArrayDim tmpad; CArrayDim tmpad;
Bool has_alias, undef_array_size, is_array; Bool has_alias, undef_array_size, is_array;
while (TRUE) { while (TRUE)
tmpc=ParseType(cc,&saved_tmpc,&saved_mode,NULL,&st, {
&tmpf_fun_ptr,&tmpex,&tmpad,fsp_flags); tmpc = ParseType(cc, &saved_tmpc, &saved_mode, NULL, &st, &tmpf_fun_ptr, &tmpex, &tmpad, fsp_flags);
if (!st) return; if (!st)
return;
if (tmpad.next) if (tmpad.next)
is_array = TRUE; is_array = TRUE;
else if (tmpad.total_count<0) { else if (tmpad.total_count < 0)
{
is_array = TRUE; is_array = TRUE;
tmpc--; tmpc--;
} else }
else
is_array = FALSE; is_array = FALSE;
val = saved_val; val = saved_val;
mode = saved_mode; mode = saved_mode;
if (tmpex && mode&255==PRS0_EXTERN && !(cc->flags&CCF_AOT_COMPILE) && if (tmpex && mode & 255 == PRS0_EXTERN && !(cc->flags & CCF_AOT_COMPILE) && tmpex->type & HTT_EXPORT_SYS_SYM)
tmpex->type&HTT_EXPORT_SYS_SYM) { {
val = tmpex->val; val = tmpex->val;
mode = PRS0__EXTERN | PRS1_NOT_REALLY__EXTERN; mode = PRS0__EXTERN | PRS1_NOT_REALLY__EXTERN;
} }
if (cc->token=='(') { if (cc->token == '(')
switch (mode&255) { {
switch (mode & 255)
{
case PRS0__INTERN: case PRS0__INTERN:
tmpf = ParseFunJoin(cc, tmpc, st, fsp_flags); tmpf = ParseFunJoin(cc, tmpc, st, fsp_flags);
tmpf->exe_addr = val; tmpf->exe_addr = val;
@ -268,7 +293,8 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
case PRS0_IMPORT: case PRS0_IMPORT:
if (!(cc->flags & CCF_AOT_COMPILE)) if (!(cc->flags & CCF_AOT_COMPILE))
LexExcept(cc, "import not needed at "); LexExcept(cc, "import not needed at ");
else { else
{
tmpf = ParseFunJoin(cc, tmpc, st, fsp_flags); tmpf = ParseFunJoin(cc, tmpc, st, fsp_flags);
tmpf->type |= HTF_IMPORT; tmpf->type |= HTF_IMPORT;
if (mode & 255 == PRS0__IMPORT) if (mode & 255 == PRS0__IMPORT)
@ -281,11 +307,16 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
ParseFun(cc, tmpc, st, fsp_flags); ParseFun(cc, tmpc, st, fsp_flags);
return; return;
} }
} else { }
if (tmpad.total_count<0) { else
{
if (tmpad.total_count < 0)
{
i = 0; i = 0;
undef_array_size = TRUE; undef_array_size = TRUE;
} else { }
else
{
i = tmpad.total_count; i = tmpad.total_count;
undef_array_size = FALSE; undef_array_size = FALSE;
} }
@ -296,13 +327,17 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
j *= i; j *= i;
has_alias = FALSE; has_alias = FALSE;
tmphg = NULL; tmphg = NULL;
switch (mode&255) { switch (mode & 255)
{
case PRS0__EXTERN: case PRS0__EXTERN:
if (cc->flags&CCF_AOT_COMPILE) { if (cc->flags & CCF_AOT_COMPILE)
{
tmpg = CAlloc(sizeof(CHashGlobalVar)); tmpg = CAlloc(sizeof(CHashGlobalVar));
tmpg->data_addr_rip = val; tmpg->data_addr_rip = val;
tmpg->type = HTT_GLOBAL_VAR | HTF_EXPORT; tmpg->type = HTT_GLOBAL_VAR | HTF_EXPORT;
} else { }
else
{
tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap); tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap);
tmpg->data_addr = val; tmpg->data_addr = val;
tmpg->type = HTT_GLOBAL_VAR; tmpg->type = HTT_GLOBAL_VAR;
@ -313,7 +348,8 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
case PRS0_IMPORT: case PRS0_IMPORT:
if (!(cc->flags & CCF_AOT_COMPILE)) if (!(cc->flags & CCF_AOT_COMPILE))
LexExcept(cc, "import not needed at "); LexExcept(cc, "import not needed at ");
else { else
{
tmpg = CAlloc(sizeof(CHashGlobalVar)); tmpg = CAlloc(sizeof(CHashGlobalVar));
tmpg->type = HTT_GLOBAL_VAR | HTF_IMPORT; tmpg->type = HTT_GLOBAL_VAR | HTF_IMPORT;
if (mode & 255 == PRS0__IMPORT) if (mode & 255 == PRS0__IMPORT)
@ -323,16 +359,20 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
} }
break; break;
case PRS0_EXTERN: case PRS0_EXTERN:
if (cc->flags&CCF_AOT_COMPILE) { if (cc->flags & CCF_AOT_COMPILE)
{
tmpg = CAlloc(sizeof(CHashGlobalVar)); tmpg = CAlloc(sizeof(CHashGlobalVar));
tmpg->type = HTT_GLOBAL_VAR; tmpg->type = HTT_GLOBAL_VAR;
} else { }
else
{
tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap); tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap);
tmpg->type = HTT_GLOBAL_VAR | HTF_UNRESOLVED; tmpg->type = HTT_GLOBAL_VAR | HTF_UNRESOLVED;
} }
break; break;
default: default:
if (cc->flags&CCF_AOT_COMPILE) { if (cc->flags & CCF_AOT_COMPILE)
{
if (Bt(&cc->opts, OPTf_GLOBALS_ON_DATA_HEAP)) { if (Bt(&cc->opts, OPTf_GLOBALS_ON_DATA_HEAP)) {
if (cc->token == '=') if (cc->token == '=')
LexExcept(cc, "Can't init global var on data heap in AOT module "); LexExcept(cc, "Can't init global var on data heap in AOT module ");
@ -346,7 +386,9 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
tmpg->type = HTT_GLOBAL_VAR; //TODO: HTF_EXPORT tmpg->type = HTT_GLOBAL_VAR; //TODO: HTF_EXPORT
if (tmpex && tmpex->type & HTT_GLOBAL_VAR) //TODO!! extern if (tmpex && tmpex->type & HTT_GLOBAL_VAR) //TODO!! extern
LexExcept(cc, "Feature not implemented "); LexExcept(cc, "Feature not implemented ");
} else { }
else
{
tmpg = CAlloc(sizeof(CHashGlobalVar)); tmpg = CAlloc(sizeof(CHashGlobalVar));
if (cc->token == '=') if (cc->token == '=')
tmpg->data_addr = CAlloc(j); tmpg->data_addr = CAlloc(j);
@ -366,18 +408,22 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
for (k = 0; k < j; k++) for (k = 0; k < j; k++)
AOTStoreCodeU8(cc, 0); //Init AOT global to zero. AOTStoreCodeU8(cc, 0); //Init AOT global to zero.
} }
} else { }
if (Bt(&cc->opts,OPTf_GLOBALS_ON_DATA_HEAP)) { else
{
if (Bt(&cc->opts, OPTf_GLOBALS_ON_DATA_HEAP))
{
tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap); tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap);
tmpg->data_addr = MAlloc(j); tmpg->data_addr = MAlloc(j);
tmpg->flags = GVF_DATA_HEAP; tmpg->flags = GVF_DATA_HEAP;
} else { }
else
{
tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap); tmpg = CAlloc(sizeof(CHashGlobalVar), Fs->code_heap);
tmpg->data_addr = MAlloc(j, Fs->code_heap); tmpg->data_addr = MAlloc(j, Fs->code_heap);
} }
tmpg->type = HTT_GLOBAL_VAR; tmpg->type = HTT_GLOBAL_VAR;
if (tmpex && tmpex->type&HTT_GLOBAL_VAR && if (tmpex && tmpex->type & HTT_GLOBAL_VAR && tmpex->type & HTF_UNRESOLVED &&
tmpex->type&HTF_UNRESOLVED &&
MHeapCtrl(tmpex) == MHeapCtrl(tmpg)) MHeapCtrl(tmpex) == MHeapCtrl(tmpg))
has_alias = TRUE; has_alias = TRUE;
if (sys_var_init_flag) if (sys_var_init_flag)
@ -400,7 +446,8 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
tmpg->flags |= GVF_IMPORT; tmpg->flags |= GVF_IMPORT;
if (mode & 255 == PRS0_EXTERN) if (mode & 255 == PRS0_EXTERN)
tmpg->flags |= GVF_EXTERN; tmpg->flags |= GVF_EXTERN;
if (tmpf_fun_ptr) { if (tmpf_fun_ptr)
{
tmpg->fun_ptr = tmpf_fun_ptr; tmpg->fun_ptr = tmpf_fun_ptr;
tmpg->flags |= GVF_FUN; tmpg->flags |= GVF_FUN;
} }
@ -409,8 +456,10 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
HashAdd(tmpg, cc->htc.global_hash_table); HashAdd(tmpg, cc->htc.global_hash_table);
if (!(cc->flags & CCF_AOT_COMPILE) && !(tmpg->flags & GVF_EXTERN)) if (!(cc->flags & CCF_AOT_COMPILE) && !(tmpg->flags & GVF_EXTERN))
SysSymImportsResolve(tmpg->str); SysSymImportsResolve(tmpg->str);
if (cc->token=='=') { if (cc->token == '=')
if (undef_array_size) { {
if (undef_array_size)
{
LexPush(cc); LexPush(cc);
LexPush(cc); LexPush(cc);
Lex(cc); Lex(cc);
@ -435,8 +484,10 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
AOTStoreCodeU8At(cc, tmpg->data_addr_rip + k, tmpg->data_addr[k]); AOTStoreCodeU8At(cc, tmpg->data_addr_rip + k, tmpg->data_addr[k]);
LexPopNoRestore(cc); LexPopNoRestore(cc);
} }
if (has_alias) { if (has_alias)
if (tmpex(CHashGlobalVar *)->use_count<2) { {
if (tmpex(CHashGlobalVar *)->use_count < 2)
{
PrintWarn("Unused extern '%s'\n", tmpex(CHashGlobalVar *)->str); PrintWarn("Unused extern '%s'\n", tmpex(CHashGlobalVar *)->str);
cc->warning_count++; cc->warning_count++;
} }
@ -446,7 +497,8 @@ U0 ParseGlobalVarList(CCompCtrl *cc,I64 saved_mode,CHashClass *saved_tmpc,
} }
if (cc->token == ',') if (cc->token == ',')
Lex(cc); Lex(cc);
else { else
{
if (cc->token != ';') if (cc->token != ';')
LexExcept(cc, "Missing ';' at"); LexExcept(cc, "Missing ';' at");
Lex(cc); Lex(cc);
@ -472,14 +524,16 @@ U0 ParseIf(CCompCtrl *cc,I64 try_count,CCodeMisc *lb_break)
ICAdd(cc, IC_BR_ZERO, lb, 0); ICAdd(cc, IC_BR_ZERO, lb, 0);
ParseStatement(cc, try_count, lb_break); ParseStatement(cc, try_count, lb_break);
k = ParseKeyWord(cc); k = ParseKeyWord(cc);
if (k==KW_ELSE) { if (k == KW_ELSE)
{
Lex(cc); Lex(cc);
lb1 = COCMiscNew(cc, CMT_LABEL); lb1 = COCMiscNew(cc, CMT_LABEL);
ICAdd(cc, IC_JMP, lb1, 0); ICAdd(cc, IC_JMP, lb1, 0);
ICAdd(cc, IC_LABEL, lb, 0); ICAdd(cc, IC_LABEL, lb, 0);
ParseStatement(cc, try_count, lb_break); ParseStatement(cc, try_count, lb_break);
ICAdd(cc, IC_LABEL, lb1, 0); ICAdd(cc, IC_LABEL, lb1, 0);
} else }
else
ICAdd(cc, IC_LABEL, lb, 0); ICAdd(cc, IC_LABEL, lb, 0);
} }
@ -563,12 +617,14 @@ U0 ParseFor(CCompCtrl *cc,I64 try_count)
ICAdd(cc, IC_LABEL, lb_done, 0); ICAdd(cc, IC_LABEL, lb_done, 0);
} }
class CSubSwitch { class CSubSwitch
{
CSubSwitch *next, *last; CSubSwitch *next, *last;
CCodeMisc *lb_start, *lb_break; CCodeMisc *lb_start, *lb_break;
}; };
class CSwitchCase { class CSwitchCase
{
CSwitchCase *next; CSwitchCase *next;
CCodeMisc *label; CCodeMisc *label;
I64 val; I64 val;
@ -605,11 +661,14 @@ U0 ParseSwitch(CCompCtrl *cc,I64 try_count)
tmpi_sub = ICAdd(cc, IC_IMM_I64, 0, cmp.internal_types[RT_I64]); tmpi_sub = ICAdd(cc, IC_IMM_I64, 0, cmp.internal_types[RT_I64]);
ICAdd(cc, IC_SUB, 0, cmp.internal_types[RT_I64]); ICAdd(cc, IC_SUB, 0, cmp.internal_types[RT_I64]);
tmpi_cmp = ICAdd(cc, IC_IMM_I64, 0, cmp.internal_types[RT_I64]); tmpi_cmp = ICAdd(cc, IC_IMM_I64, 0, cmp.internal_types[RT_I64]);
if (nobound) { if (nobound)
{
ICAdd(cc, IC_NOBOUND_SWITCH, mc_jt, 0); ICAdd(cc, IC_NOBOUND_SWITCH, mc_jt, 0);
if (cc->token != ']') if (cc->token != ']')
LexExcept(cc, "Missing ']' at "); LexExcept(cc, "Missing ']' at ");
} else { }
else
{
ICAdd(cc, IC_SWITCH, mc_jt, 0); ICAdd(cc, IC_SWITCH, mc_jt, 0);
if (cc->token != ')') if (cc->token != ')')
LexExcept(cc, "Missing ')' at "); LexExcept(cc, "Missing ')' at ");
@ -618,10 +677,13 @@ U0 ParseSwitch(CCompCtrl *cc,I64 try_count)
LexExcept(cc, "Expecting '{' at "); LexExcept(cc, "Expecting '{' at ");
Lex(cc); Lex(cc);
ICAdd(cc, IC_LABEL, mc_jt->begin, 0); ICAdd(cc, IC_LABEL, mc_jt->begin, 0);
while (TRUE) { while (TRUE)
while (cc->token && cc->token!='}') { {
while (cc->token && cc->token != '}')
{
sw_cont: sw_cont:
switch (ParseKeyWord(cc)) { switch (ParseKeyWord(cc))
{
case KW_END: case KW_END:
goto sw_sub_end; goto sw_sub_end;
case KW_START: case KW_START:
@ -638,18 +700,23 @@ sw_cont:
tmpss->lb_start = COCMiscNew(cc, CMT_LABEL); tmpss->lb_start = COCMiscNew(cc, CMT_LABEL);
tmpi_start = ICAdd(cc, IC_LABEL, tmpss->lb_start, 0); tmpi_start = ICAdd(cc, IC_LABEL, tmpss->lb_start, 0);
while (cc->token && cc->token!='}') { while (cc->token && cc->token != '}')
switch (ParseKeyWord(cc)) { {
switch (ParseKeyWord(cc))
{
case KW_END: case KW_END:
OptFree(tmpi_jmp); OptFree(tmpi_jmp);
goto sw_sub_end; goto sw_sub_end;
case KW_START: case KW_START:
case KW_CASE: case KW_CASE:
case KW_DEFAULT: case KW_DEFAULT:
if (cc->coc.coc_head.last==tmpi_start) { if (cc->coc.coc_head.last == tmpi_start)
{
OptFree(tmpi_jmp); OptFree(tmpi_jmp);
tmpss->lb_start = NULL; tmpss->lb_start = NULL;
} else { }
else
{
ICAdd(cc, IC_RET, 0, 0); ICAdd(cc, IC_RET, 0, 0);
ICAdd(cc, IC_LABEL, lb_fwd_case, 0); ICAdd(cc, IC_LABEL, lb_fwd_case, 0);
ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0);//In case fall-thru ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0);//In case fall-thru
@ -661,7 +728,8 @@ sw_cont:
} }
break; break;
case KW_CASE: case KW_CASE:
if (head.next!=&head) { if (head.next != &head)
{
lb_fwd_case = COCMiscNew(cc, CMT_LABEL); lb_fwd_case = COCMiscNew(cc, CMT_LABEL);
tmpi_jmp = ICAdd(cc, IC_JMP, lb_fwd_case, 0);//In case fall-thru tmpi_jmp = ICAdd(cc, IC_JMP, lb_fwd_case, 0);//In case fall-thru
} }
@ -669,41 +737,54 @@ sw_cont:
lb_entry = COCMiscNew(cc, CMT_LABEL); lb_entry = COCMiscNew(cc, CMT_LABEL);
ICAdd(cc, IC_LABEL, lb_entry, 0); ICAdd(cc, IC_LABEL, lb_entry, 0);
lb_entry->use_count++; lb_entry->use_count++;
if (head.next!=&head) { if (head.next != &head)
{
tmpss = head.next; tmpss = head.next;
while (tmpss!=&head) { while (tmpss != &head)
{
if (tmpss->lb_start) if (tmpss->lb_start)
ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0); ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0);
tmpss = tmpss->next; tmpss = tmpss->next;
} }
ICAdd(cc, IC_LABEL, lb_fwd_case, 0); ICAdd(cc, IC_LABEL, lb_fwd_case, 0);
} }
if (cc->token==':') { if (cc->token == ':')
{
if (k_start == I64_MIN) if (k_start == I64_MIN)
k_start = 0; k_start = 0;
else else
k_start++; k_start++;
} else }
else
k_start = LexExpressionI64(cc); k_start = LexExpressionI64(cc);
if (k_start<lo) lo=k_start; if (k_start < lo)
if (k_start>hi) hi=k_start; lo = k_start;
if (cc->token==':') { if (k_start > hi)
hi = k_start;
if (cc->token == ':')
{
Lex(cc); Lex(cc);
tmps = MAlloc(sizeof(CSwitchCase)); tmps = MAlloc(sizeof(CSwitchCase));
tmps->label = lb_entry; tmps->label = lb_entry;
tmps->val = k_start; tmps->val = k_start;
tmps->next = header; tmps->next = header;
header = tmps; header = tmps;
} else if (cc->token==TK_ELLIPSIS) { }
else if (cc->token == TK_ELLIPSIS)
{
Lex(cc); Lex(cc);
k_end = LexExpressionI64(cc); k_end = LexExpressionI64(cc);
if (cc->token==':') { if (cc->token == ':')
{
Lex(cc); Lex(cc);
if (k_end<lo) lo=k_end; if (k_end < lo)
if (k_end>hi) hi=k_end; lo = k_end;
if (k_end > hi)
hi = k_end;
if (k_start > k_end) if (k_start > k_end)
SwapI64(&k_start, &k_end); SwapI64(&k_start, &k_end);
for (i=k_start;i<=k_end;i++) { for (i = k_start; i <= k_end; i++)
{
tmps = MAlloc(sizeof(CSwitchCase)); tmps = MAlloc(sizeof(CSwitchCase));
tmps->label = lb_entry; tmps->label = lb_entry;
tmps->val = i; tmps->val = i;
@ -711,13 +792,16 @@ sw_cont:
header = tmps; header = tmps;
} }
k_start = k_end; k_start = k_end;
} else }
else
LexExcept(cc, "Expecting ':' at "); LexExcept(cc, "Expecting ':' at ");
} else }
else
LexExcept(cc, "Expecting ':' at "); LexExcept(cc, "Expecting ':' at ");
break; break;
case KW_DEFAULT: case KW_DEFAULT:
if (head.next!=&head) { if (head.next != &head)
{
lb_fwd_case = COCMiscNew(cc, CMT_LABEL); lb_fwd_case = COCMiscNew(cc, CMT_LABEL);
tmpi_jmp = ICAdd(cc, IC_JMP, lb_fwd_case, 0);//In case fall-thru tmpi_jmp = ICAdd(cc, IC_JMP, lb_fwd_case, 0);//In case fall-thru
} }
@ -727,9 +811,11 @@ sw_cont:
Lex(cc); Lex(cc);
else else
LexExcept(cc, "Expecting ':' at "); LexExcept(cc, "Expecting ':' at ");
if (head.next!=&head) { if (head.next != &head)
{
tmpss = head.next; tmpss = head.next;
while (tmpss!=&head) { while (tmpss != &head)
{
if (tmpss->lb_start) if (tmpss->lb_start)
ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0); ICAdd(cc, IC_SUB_CALL, tmpss->lb_start, 0);
tmpss = tmpss->next; tmpss = tmpss->next;
@ -745,12 +831,15 @@ sw_cont:
sw_sub_end: sw_sub_end:
tmpss = head.last; tmpss = head.last;
ICAdd(cc, IC_LABEL, tmpss->lb_break, 0); ICAdd(cc, IC_LABEL, tmpss->lb_break, 0);
if (tmpss==&head) { if (tmpss == &head)
{
if (cc->token != '}') if (cc->token != '}')
LexExcept(cc, "Missing '}' at "); LexExcept(cc, "Missing '}' at ");
Lex(cc); Lex(cc);
break; break;
} else { }
else
{
QueueRemove(tmpss); QueueRemove(tmpss);
Free(tmpss); Free(tmpss);
if (ParseKeyWord(cc) != KW_END) if (ParseKeyWord(cc) != KW_END)
@ -774,7 +863,8 @@ sw_sub_end:
tmpi_sub->ic_data = lo; tmpi_sub->ic_data = lo;
tmpi_cmp->ic_data = range; tmpi_cmp->ic_data = range;
tmps = header; tmps = header;
while (tmps) { while (tmps)
{
tmps1 = tmps->next; tmps1 = tmps->next;
if (jmp_table[tmps->val - lo] != lb_default) if (jmp_table[tmps->val - lo] != lb_default)
LexExcept(cc, "Duplicate case at "); LexExcept(cc, "Duplicate case at ");
@ -791,7 +881,8 @@ sw_sub_end:
U0 ParseNoWarn(CCompCtrl *cc) U0 ParseNoWarn(CCompCtrl *cc)
{ {
CMemberList *tmpm; CMemberList *tmpm;
while (cc->token==TK_IDENT) { while (cc->token == TK_IDENT)
{
if (!(tmpm = cc->local_var_entry)) if (!(tmpm = cc->local_var_entry))
LexExcept(cc, "Expecting local var at "); LexExcept(cc, "Expecting local var at ");
tmpm->flags |= MLF_NO_UNUSED_WARN; tmpm->flags |= MLF_NO_UNUSED_WARN;
@ -826,8 +917,7 @@ U0 ParseStreamBlk(CCompCtrl *cc)
ExeCmdLine(cc); ExeCmdLine(cc);
MemCopy(&cc->htc, htc, sizeof(CLexHashTableContext)); MemCopy(&cc->htc, htc, sizeof(CLexHashTableContext));
cc->flags=cc->flags&~CCF_EXE_BLK | cc->flags = cc->flags & ~CCF_EXE_BLK | htc->old_flags & (CCF_ASM_EXPRESSIONS | CCF_EXE_BLK | CCF_AOT_COMPILE);
htc->old_flags & (CCF_ASM_EXPRESSIONS|CCF_EXE_BLK|CCF_AOT_COMPILE);
Free(htc); Free(htc);
COCPop(cc); COCPop(cc);
QueueRemove(tmpe); QueueRemove(tmpe);
@ -858,16 +948,17 @@ U0 ParseTryBlk(CCompCtrl *cc,I64 try_count)
ICAdd(cc, IC_CALL_START, 0, 0); ICAdd(cc, IC_CALL_START, 0, 0);
ICAdd(cc, IC_GET_LABEL, lb_untry, tmpc, ICF_PUSH_RES); ICAdd(cc, IC_GET_LABEL, lb_untry, tmpc, ICF_PUSH_RES);
ICAdd(cc, IC_GET_LABEL, lb_catch, tmpc, ICF_PUSH_RES); ICAdd(cc, IC_GET_LABEL, lb_catch, tmpc, ICF_PUSH_RES);
if (Bt(&tmp_try->flags,Cf_EXTERN)) { if (Bt(&tmp_try->flags, Cf_EXTERN))
{
cc->abs_counts.externs++; cc->abs_counts.externs++;
if (cc->flags & CCF_AOT_COMPILE) if (cc->flags & CCF_AOT_COMPILE)
ICAdd(cc, IC_CALL_IMPORT, tmp_try, tmpc); ICAdd(cc, IC_CALL_IMPORT, tmp_try, tmpc);
else else
ICAdd(cc, IC_CALL_INDIRECT2, &tmp_try->exe_addr, tmpc); ICAdd(cc, IC_CALL_INDIRECT2, &tmp_try->exe_addr, tmpc);
} else }
else
ICAdd(cc, IC_CALL, tmp_try->exe_addr, tmpc); ICAdd(cc, IC_CALL, tmp_try->exe_addr, tmpc);
if ((Bt(&tmp_try->flags,Ff_RET1) || if ((Bt(&tmp_try->flags, Ff_RET1) || Bt(&tmp_try->flags, Ff_ARGPOP)) && !Bt(&tmp_try->flags, Ff_NOARGPOP))
Bt(&tmp_try->flags,Ff_ARGPOP)) && !Bt(&tmp_try->flags,Ff_NOARGPOP))
ICAdd(cc, IC_ADD_RSP1, 16, tmpc); ICAdd(cc, IC_ADD_RSP1, 16, tmpc);
else else
ICAdd(cc, IC_ADD_RSP, 16, tmpc); ICAdd(cc, IC_ADD_RSP, 16, tmpc);
@ -878,13 +969,15 @@ U0 ParseTryBlk(CCompCtrl *cc,I64 try_count)
ICAdd(cc, IC_LABEL, lb_untry, 0); ICAdd(cc, IC_LABEL, lb_untry, 0);
ICAdd(cc, IC_CALL_START, 0, 0); ICAdd(cc, IC_CALL_START, 0, 0);
if (Bt(&tmp_untry->flags,Cf_EXTERN)) { if (Bt(&tmp_untry->flags, Cf_EXTERN))
{
cc->abs_counts.externs++; cc->abs_counts.externs++;
if (cc->flags & CCF_AOT_COMPILE) if (cc->flags & CCF_AOT_COMPILE)
ICAdd(cc, IC_CALL_IMPORT, tmp_untry, tmpc); ICAdd(cc, IC_CALL_IMPORT, tmp_untry, tmpc);
else else
ICAdd(cc, IC_CALL_INDIRECT2, &tmp_untry->exe_addr, tmpc); ICAdd(cc, IC_CALL_INDIRECT2, &tmp_untry->exe_addr, tmpc);
} else }
else
ICAdd(cc, IC_CALL, tmp_untry->exe_addr, tmpc); ICAdd(cc, IC_CALL, tmp_untry->exe_addr, tmpc);
ICAdd(cc, IC_CALL_END, 0, tmpc); ICAdd(cc, IC_CALL_END, 0, tmpc);
ICAdd(cc, IC_END_EXP, 0, 0, ICF_RES_NOT_USED); ICAdd(cc, IC_END_EXP, 0, 0, ICF_RES_NOT_USED);
@ -901,8 +994,7 @@ U0 ParseTryBlk(CCompCtrl *cc,I64 try_count)
ICAdd(cc, IC_LABEL, lb_done, 0); ICAdd(cc, IC_LABEL, lb_done, 0);
} }
Bool ParseStatement(CCompCtrl *cc,I64 try_count=0, Bool ParseStatement(CCompCtrl *cc, I64 try_count=0, CCodeMisc *lb_break=NULL, I64 comp_flags=CMPF_PRS_SEMICOLON)
CCodeMisc *lb_break=NULL,I64 comp_flags=CMPF_PRS_SEMICOLON)
{ {
I64 i, fsp_flags = 0; I64 i, fsp_flags = 0;
CHashExport *tmpex; CHashExport *tmpex;
@ -910,49 +1002,69 @@ Bool ParseStatement(CCompCtrl *cc,I64 try_count=0,
U8 *import_name; U8 *import_name;
CHashFun *tmp_untry; CHashFun *tmp_untry;
CAOT *tmpaot; CAOT *tmpaot;
if (comp_flags&CMPF_ONE_ASM_INS) { if (comp_flags & CMPF_ONE_ASM_INS)
{
if (cc->flags & CCF_AOT_COMPILE || cc->aot_depth) if (cc->flags & CCF_AOT_COMPILE || cc->aot_depth)
ParseAsmBlk(cc, CMPF_ONE_ASM_INS); ParseAsmBlk(cc, CMPF_ONE_ASM_INS);
else if (tmpaot = CompJoin(cc, CMPF_ASM_BLK | CMPF_ONE_ASM_INS)) else if (tmpaot = CompJoin(cc, CMPF_ASM_BLK | CMPF_ONE_ASM_INS))
CompFixUpJITAsm(cc, tmpaot); CompFixUpJITAsm(cc, tmpaot);
fsp_flags = FSF_ASM; fsp_flags = FSF_ASM;
} else }
while (TRUE) { else
while (TRUE)
{
while (cc->token == ',') while (cc->token == ',')
Lex(cc); Lex(cc);
if (cc->token=='{') { if (cc->token == '{')
{
Lex(cc); Lex(cc);
while (cc->token != '}' && cc->token != TK_EOF) while (cc->token != '}' && cc->token != TK_EOF)
ParseStatement(cc, try_count, lb_break); ParseStatement(cc, try_count, lb_break);
if (cc->lex_include_stack == cc->fun_lex_file) if (cc->lex_include_stack == cc->fun_lex_file)
cc->max_line = cc->lex_include_stack->line_num; cc->max_line = cc->lex_include_stack->line_num;
if (Lex(cc)!=',') goto sm_done; if (Lex(cc) != ',')
} else if (cc->token==';') { goto sm_done;
}
else if (cc->token == ';')
{
if (comp_flags & CMPF_PRS_SEMICOLON) if (comp_flags & CMPF_PRS_SEMICOLON)
Lex(cc); Lex(cc);
if (cc->token!=',') goto sm_done; if (cc->token != ',')
} else { goto sm_done;
if (cc->token==TK_IDENT) { }
if (tmpex=cc->hash_entry) { else
if (tmpex->type & HTT_KEYWORD) { {
if (cc->token == TK_IDENT)
{
if (tmpex = cc->hash_entry)
{
if (tmpex->type & HTT_KEYWORD)
{
i = tmpex(CHashGeneric *)->user_data0; i = tmpex(CHashGeneric *)->user_data0;
switch [i] { switch [i]
{
case KW_KWS_NUM - 1: //nobound switch case KW_KWS_NUM - 1: //nobound switch
default: //A keyword that is not valid here is just a symbol. default: //A keyword that is not valid here is just a symbol.
goto sm_not_keyword_afterall; goto sm_not_keyword_afterall;
start: start:
case KW_ASM: case KW_ASM:
if (cc->htc.fun) { if (cc->htc.fun)
{
if (tmpaot = CompJoin(cc, CMPF_ASM_BLK)) if (tmpaot = CompJoin(cc, CMPF_ASM_BLK))
ICAdd(cc, IC_ASM, tmpaot, 0); ICAdd(cc, IC_ASM, tmpaot, 0);
Lex(cc); //Skip '}' of asm{} Lex(cc); //Skip '}' of asm{}
} else { }
if (cc->flags&CCF_AOT_COMPILE || cc->aot_depth) { else
{
if (cc->flags & CCF_AOT_COMPILE || cc->aot_depth)
{
Lex(cc); Lex(cc);
ParseAsmBlk(cc, 0); ParseAsmBlk(cc, 0);
if (cc->flags & CCF_AOT_COMPILE && cc->aot_depth == 1) if (cc->flags & CCF_AOT_COMPILE && cc->aot_depth == 1)
Lex(cc); //Skip '}' of asm{} Lex(cc); //Skip '}' of asm{}
} else { }
else
{
if (tmpaot = CompJoin(cc, CMPF_ASM_BLK)) if (tmpaot = CompJoin(cc, CMPF_ASM_BLK))
CompFixUpJITAsm(cc, tmpaot); CompFixUpJITAsm(cc, tmpaot);
Lex(cc); //Skip '}' of asm{} Lex(cc); //Skip '}' of asm{}
@ -987,7 +1099,8 @@ Bool ParseStatement(CCompCtrl *cc,I64 try_count=0,
break; break;
end: end:
end: end:
if (cc->token!=',') goto sm_done; if (cc->token != ',')
goto sm_done;
break; break;
start: start:
if (cc->htc.fun) if (cc->htc.fun)
@ -1021,8 +1134,7 @@ sm_underscore_import:
!(tmpex->type & (HTT_CLASS | HTT_INTERNAL_TYPE))) !(tmpex->type & (HTT_CLASS | HTT_INTERNAL_TYPE)))
LexExcept(cc, "Expecting type at "); LexExcept(cc, "Expecting type at ");
Lex(cc); Lex(cc);
ParseGlobalVarList(cc,PRS0__IMPORT|PRS1_NULL,tmpex, ParseGlobalVarList(cc, PRS0__IMPORT | PRS1_NULL, tmpex, import_name, fsp_flags);
import_name,fsp_flags);
Free(import_name); Free(import_name);
break; break;
case KW_EXTERN: case KW_EXTERN:
@ -1030,14 +1142,14 @@ sm_underscore_import:
LexExcept(cc, "Expecting type at "); LexExcept(cc, "Expecting type at ");
tmpex = cc->hash_entry; tmpex = cc->hash_entry;
i = ParseKeyWord(cc); i = ParseKeyWord(cc);
if (i==KW_CLASS||i==KW_UNION) { if (i == KW_CLASS || i == KW_UNION)
{
Lex(cc); Lex(cc);
ParseClass(cc, i, fsp_flags, TRUE); ParseClass(cc, i, fsp_flags, TRUE);
fsp_flags &= FSF_ASM; fsp_flags &= FSF_ASM;
goto sm_semicolon; goto sm_semicolon;
} }
if (!tmpex || if (!tmpex || !(tmpex->type & (HTT_CLASS | HTT_INTERNAL_TYPE)))
!(tmpex->type & (HTT_CLASS|HTT_INTERNAL_TYPE)))
LexExcept(cc, "Expecting type at "); LexExcept(cc, "Expecting type at ");
if (Bt(&cc->opts, OPTf_EXTERNS_TO_IMPORTS)) if (Bt(&cc->opts, OPTf_EXTERNS_TO_IMPORTS))
goto sm_import; goto sm_import;
@ -1068,8 +1180,7 @@ sm_import:
fsp_flags = FSF_STATIC | fsp_flags & FSF_ASM; fsp_flags = FSF_STATIC | fsp_flags & FSF_ASM;
break; break;
case KW_INTERRUPT: case KW_INTERRUPT:
fsp_flags=FSF_INTERRUPT|FSF_NOARGPOP| fsp_flags = FSF_INTERRUPT | FSF_NOARGPOP | fsp_flags & (FSG_FUN_FLAGS2 | FSF_ASM);
fsp_flags&(FSG_FUN_FLAGS2|FSF_ASM);
break; break;
case KW_HASERRCODE: case KW_HASERRCODE:
fsp_flags = FSF_HASERRCODE | fsp_flags & (FSG_FUN_FLAGS2 | FSF_ASM); fsp_flags = FSF_HASERRCODE | fsp_flags & (FSG_FUN_FLAGS2 | FSF_ASM);
@ -1089,39 +1200,42 @@ sm_import:
case KW_RETURN: case KW_RETURN:
if (!cc->htc.fun) if (!cc->htc.fun)
LexExcept(cc, "Not in fun. Can't return a val "); LexExcept(cc, "Not in fun. Can't return a val ");
if (try_count) { if (try_count)
tmp_untry=HashFind("SysUntry", {
cc->htc.hash_table_list,HTT_FUN); tmp_untry = HashFind("SysUntry", cc->htc.hash_table_list, HTT_FUN);
for (i=0;i<try_count;i++) { for (i = 0; i < try_count; i++)
if (Bt(&tmp_untry->flags,Cf_EXTERN)) { {
if (Bt(&tmp_untry->flags, Cf_EXTERN))
{
cc->abs_counts.externs++; cc->abs_counts.externs++;
if (cc->flags & CCF_AOT_COMPILE) if (cc->flags & CCF_AOT_COMPILE)
ICAdd(cc,IC_CALL_IMPORT, ICAdd(cc, IC_CALL_IMPORT, tmp_untry, cmp.internal_types[RT_PTR]);
tmp_untry,cmp.internal_types[RT_PTR]);
else else
ICAdd(cc,IC_CALL_INDIRECT2, ICAdd(cc, IC_CALL_INDIRECT2, &tmp_untry->exe_addr,
&tmp_untry->exe_addr,
cmp.internal_types[RT_PTR]);
} else
ICAdd(cc,IC_CALL,tmp_untry->exe_addr,
cmp.internal_types[RT_PTR]); cmp.internal_types[RT_PTR]);
} }
else
ICAdd(cc, IC_CALL, tmp_untry->exe_addr, cmp.internal_types[RT_PTR]);
} }
if (Lex(cc)!=';') { }
if (Lex(cc) != ';')
{
if (!cc->htc.fun->return_class->size) if (!cc->htc.fun->return_class->size)
LexWarn(cc, "Function should NOT return val "); LexWarn(cc, "Function should NOT return val ");
if (!ParseExpression(cc, NULL, FALSE)) if (!ParseExpression(cc, NULL, FALSE))
throw('Compiler'); throw('Compiler');
ICAdd(cc, IC_RETURN_VAL, 0, cc->htc.fun->return_class); ICAdd(cc, IC_RETURN_VAL, 0, cc->htc.fun->return_class);
cc->flags |= CCF_HAS_RETURN; cc->flags |= CCF_HAS_RETURN;
} else if (cc->htc.fun->return_class->size) }
else if (cc->htc.fun->return_class->size)
LexWarn(cc, "Function should return val "); LexWarn(cc, "Function should return val ");
ICAdd(cc, IC_JMP, cc->lb_leave, 0); ICAdd(cc, IC_JMP, cc->lb_leave, 0);
goto sm_semicolon; goto sm_semicolon;
case KW_GOTO: case KW_GOTO:
if (Lex(cc) != TK_IDENT) if (Lex(cc) != TK_IDENT)
LexExcept(cc, "Expecting identifier at "); LexExcept(cc, "Expecting identifier at ");
if (!(g_lb=COCGoToLabelFind(cc,cc->cur_str))) { if (!(g_lb = COCGoToLabelFind(cc, cc->cur_str)))
{
g_lb = COCMiscNew(cc, CMT_GOTO_LABEL); g_lb = COCMiscNew(cc, CMT_GOTO_LABEL);
g_lb->str = cc->cur_str; g_lb->str = cc->cur_str;
cc->cur_str = NULL; cc->cur_str = NULL;
@ -1148,45 +1262,65 @@ sm_import:
ParseGlobalVarList(cc, PRS0_NULL | PRS1_NULL, tmpex, 0, fsp_flags); ParseGlobalVarList(cc, PRS0_NULL | PRS1_NULL, tmpex, 0, fsp_flags);
fsp_flags &= FSF_ASM; fsp_flags &= FSF_ASM;
break; break;
} else { }
else
{
fsp_flags &= FSF_ASM; fsp_flags &= FSF_ASM;
goto sm_semicolon; goto sm_semicolon;
} }
} }
} else {//Ident, found in hash table, not keyword }
else
{//Ident, found in hash table, not keyword
sm_not_keyword_afterall: sm_not_keyword_afterall:
if (tmpex->type & (HTT_CLASS|HTT_INTERNAL_TYPE)) { if (tmpex->type & (HTT_CLASS | HTT_INTERNAL_TYPE))
if (cc->htc.fun) { {
if (cc->htc.fun)
{
if (fsp_flags & FSF_STATIC) if (fsp_flags & FSF_STATIC)
ParseVarList(cc, cc->htc.fun, PRS0_NULL | PRS1_STATIC_LOCAL_VAR); ParseVarList(cc, cc->htc.fun, PRS0_NULL | PRS1_STATIC_LOCAL_VAR);
else else
ParseVarList(cc, cc->htc.fun, PRS0_NULL | PRS1_LOCAL_VAR); ParseVarList(cc, cc->htc.fun, PRS0_NULL | PRS1_LOCAL_VAR);
if (cc->token=='}') goto sm_done; if (cc->token == '}')
} else { goto sm_done;
}
else
{
Lex(cc); Lex(cc);
ParseGlobalVarList(cc, PRS0_NULL | PRS1_NULL, tmpex, 0, fsp_flags); ParseGlobalVarList(cc, PRS0_NULL | PRS1_NULL, tmpex, 0, fsp_flags);
} }
} else { }
if (tmpex->type & (HTT_OPCODE|HTT_ASM_KEYWORD)) { else
if (cc->htc.fun) { {
if (tmpex->type & (HTT_OPCODE | HTT_ASM_KEYWORD))
{
if (cc->htc.fun)
{
if (tmpaot = CompJoin(cc, CMPF_ASM_BLK | CMPF_ONE_ASM_INS)) if (tmpaot = CompJoin(cc, CMPF_ASM_BLK | CMPF_ONE_ASM_INS))
ICAdd(cc, IC_ASM, tmpaot, 0); ICAdd(cc, IC_ASM, tmpaot, 0);
} else }
else
LexExcept(cc, "Use Asm Blk at "); LexExcept(cc, "Use Asm Blk at ");
if (cc->token!=',') goto sm_done; if (cc->token != ',')
} else goto sm_done;
}
else
goto sm_parse_exp; goto sm_parse_exp;
} }
fsp_flags &= FSF_ASM; fsp_flags &= FSF_ASM;
} }
} else {//Ident, not in hash table }
else
{//Ident, not in hash table
if (cc->local_var_entry) if (cc->local_var_entry)
goto sm_parse_exp; goto sm_parse_exp;
if (!(g_lb=COCGoToLabelFind(cc,cc->cur_str))) { if (!(g_lb = COCGoToLabelFind(cc, cc->cur_str)))
{
g_lb = COCMiscNew(cc, CMT_GOTO_LABEL); g_lb = COCMiscNew(cc, CMT_GOTO_LABEL);
g_lb->str = cc->cur_str; g_lb->str = cc->cur_str;
cc->cur_str = NULL; cc->cur_str = NULL;
} else if (g_lb->flags&CMF_DEFINED) }
else if (g_lb->flags & CMF_DEFINED)
LexExcept(cc, "Duplicate goto label at "); LexExcept(cc, "Duplicate goto label at ");
g_lb->flags |= CMF_DEFINED; g_lb->flags |= CMF_DEFINED;
ICAdd(cc, IC_LABEL, g_lb, 0); ICAdd(cc, IC_LABEL, g_lb, 0);
@ -1196,24 +1330,32 @@ sm_not_keyword_afterall:
LexExcept(cc, "Undefined identifier at "); LexExcept(cc, "Undefined identifier at ");
if (!cc->htc.fun) if (!cc->htc.fun)
LexExcept(cc, "No global labels at "); LexExcept(cc, "No global labels at ");
if (cc->token!=',') goto sm_done; if (cc->token != ',')
goto sm_done;
} }
} else if (cc->token==TK_STR||cc->token==TK_CHAR_CONST) { }
else if (cc->token == TK_STR || cc->token == TK_CHAR_CONST)
{
ParseFunCall(cc, NULL, FALSE, NULL); ParseFunCall(cc, NULL, FALSE, NULL);
goto sm_semicolon; goto sm_semicolon;
} else if (cc->token!=TK_EOF) {//Non-cur_str symbol, num or something }
else if (cc->token != TK_EOF)
{//Non-cur_str symbol, num or something
sm_parse_exp: sm_parse_exp:
if (!ParseExpression(cc, NULL, TRUE)) if (!ParseExpression(cc, NULL, TRUE))
throw('Compiler'); throw('Compiler');
sm_semicolon: sm_semicolon:
if (comp_flags&CMPF_PRS_SEMICOLON) { if (comp_flags & CMPF_PRS_SEMICOLON)
{
if (cc->token == ';') if (cc->token == ';')
Lex(cc); Lex(cc);
else if (cc->token != ',') else if (cc->token != ',')
LexExcept(cc, "Missing ';' at"); LexExcept(cc, "Missing ';' at");
} }
if (cc->token!=',') goto sm_done; if (cc->token != ',')
} else goto sm_done;
}
else
goto sm_done; //TK_EOF goto sm_done; //TK_EOF
} }
} }

View file

@ -64,6 +64,7 @@ StartOS.CC
OptPass789A.CC OptPass789A.CC
ParseExp.CC ParseExp.CC
ParseLib.CC ParseLib.CC
ParseStatement.CC
Templates.CC Templates.CC
OpCodes.DD OpCodes.DD
CompilerA.HH CompilerA.HH