acces via vec_at
This commit is contained in:
parent
8358859423
commit
452221d7eb
2
lex.c
2
lex.c
|
@ -67,7 +67,6 @@ void lex_string(Lexer*lex,char*s)
|
|||
* - Finalize current token lexing and set state to LNONE
|
||||
* keepch bool will we retain this character in the token string?
|
||||
*****/
|
||||
//&((Tok*)lex->tokens.buffer)[lex->tokens.size-1].str
|
||||
#define modeterminate(keepch) do{lex->mode=LNONE;if(keepch)--i;str_assign(&(vec_at(&lex->tokens,lex->tokens.size-1,Tok*)->str),tmpstr.buffer);vec_at(&lex->tokens,lex->tokens.size-1,Tok*)->line=current_line;ch[0]=s[i];str_append(&tmpstr,ch);}while(0)
|
||||
|
||||
/*****
|
||||
|
@ -97,7 +96,6 @@ void lex_string(Lexer*lex,char*s)
|
|||
// Extra step: turn identifiers into keywords
|
||||
if(lex->tokens.size>1)
|
||||
{
|
||||
//Tok*lasttok=&((Tok*)lex->tokens.buffer)[lex->tokens.size-2];
|
||||
Tok*lasttok=vec_at(&lex->tokens,lex->tokens.size-2,Tok*);
|
||||
if(lasttok->type==LIDENTIFIER)
|
||||
{
|
||||
|
|
8
main.c
8
main.c
|
@ -141,17 +141,17 @@ int main(int argc,char**argv)
|
|||
{
|
||||
state=state_new();
|
||||
|
||||
state.infile=fopen(((const char**)args.buffer)[i],"r");
|
||||
state.infile=fopen(*vec_at(&args,i,const char**),"r");
|
||||
if(!state.infile)
|
||||
{
|
||||
err_log("failed to open infile '%s'",((const char**)args.buffer)[i]);
|
||||
err_log("failed to open infile '%s'",*vec_at(&args,i,const char**));
|
||||
cleanquit(1);
|
||||
}
|
||||
|
||||
// Read input file into buffer
|
||||
if(state.infile)
|
||||
{
|
||||
state.infilename=((char**)args.buffer)[i];
|
||||
state.infilename=(char*)*vec_at(&args,i,const char**);
|
||||
char file_buffer[1024]={0};
|
||||
size_t count=0;
|
||||
|
||||
|
@ -186,7 +186,7 @@ int main(int argc,char**argv)
|
|||
// Generate code
|
||||
if(generate)
|
||||
{
|
||||
state_set_outfile(&state,((char**)args.buffer)[i],setoutfile,setoutfile_name,buildarch);
|
||||
state_set_outfile(&state,(char*)*vec_at(&args,i,const char**),setoutfile,setoutfile_name,buildarch);
|
||||
|
||||
// Generate code based on buildarch
|
||||
switch(buildarch)
|
||||
|
|
4
pnode.c
4
pnode.c
|
@ -92,7 +92,7 @@ void pnode_print(PNode*n,size_t lvl)
|
|||
n->pnodes.capacity,
|
||||
n->tokens.size,
|
||||
n->tokens.capacity,
|
||||
(n->tokens.size>0)?(((Tok*)n->tokens.buffer)[0].line):(0)
|
||||
(n->tokens.size>0)?(vec_at(&n->tokens,0,const Tok*)->line):(0)
|
||||
);
|
||||
|
||||
// Print tokens
|
||||
|
@ -101,7 +101,7 @@ void pnode_print(PNode*n,size_t lvl)
|
|||
{
|
||||
if(usecolor)
|
||||
printf("'%s%s%s'",
|
||||
lextype_colors[((Tok*)n->tokens.buffer)[i].type],
|
||||
lextype_colors[vec_at(&n->tokens,i,const Tok*)->type],
|
||||
vec_at(&n->tokens,i,Tok*)->str.buffer,
|
||||
"\033[0m"
|
||||
);
|
||||
|
|
18
reg.c
18
reg.c
|
@ -74,8 +74,7 @@ void reg_match2(Reg*r,char*p,char*s)
|
|||
|
||||
else
|
||||
{
|
||||
((Match*)r->matches.buffer)[r->matches.size-1]
|
||||
.length++;
|
||||
vec_at(&r->matches,r->matches.size-1,Match*)->length++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,8 +107,7 @@ void reg_match2(Reg*r,char*p,char*s)
|
|||
|
||||
else
|
||||
{
|
||||
((Match*)r->matches.buffer)[r->matches.size-1]
|
||||
.length++;
|
||||
vec_at(&r->matches,r->matches.size-1,Match*)->length++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +128,7 @@ void reg_match2(Reg*r,char*p,char*s)
|
|||
else
|
||||
{
|
||||
if(s[string_idx]==p[pat_idx])
|
||||
((Match*)r->matches.buffer)[r->matches.size-1]
|
||||
.length++;
|
||||
vec_at(&r->matches,r->matches.size-1,Match*)->length++;
|
||||
else
|
||||
{
|
||||
if(found)
|
||||
|
@ -157,12 +154,9 @@ void reg_print(Reg*r)
|
|||
printf("%p [",&r->matches);
|
||||
for(size_t i=0;i<r->matches.size;++i)
|
||||
{
|
||||
Match*m=((Match*)r->matches.buffer)+i;
|
||||
//char*string=m->str;
|
||||
|
||||
printf("(%lu'",m->length);
|
||||
for(size_t j=0;j<m->length;++j)
|
||||
printf("%c",m->str[j]);
|
||||
printf("(%lu'",vec_at(&r->matches,i,Match*)->length);
|
||||
for(size_t j=0;j<vec_at(&r->matches,i,Match*)->length;++j)
|
||||
printf("%c",vec_at(&r->matches,i,Match*)->str[j]);
|
||||
printf("')");
|
||||
if(i<r->matches.size-1)
|
||||
printf(", ");
|
||||
|
|
10
vec.c
10
vec.c
|
@ -24,18 +24,18 @@ void vec_print(Vec*v,const char*fmt)
|
|||
if(v->isfloat)
|
||||
{
|
||||
if(v->unitsize==4)
|
||||
printf(fmt,((float*)v->buffer)[i]);
|
||||
printf(fmt,*vec_at(v,i,float*));
|
||||
else if(v->unitsize==8)
|
||||
printf(fmt,((double*)v->buffer)[i]);
|
||||
printf(fmt,*vec_at(v,i,double*));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(v->unitsize==1)
|
||||
printf(fmt,((uint8_t*)v->buffer)[i]);
|
||||
printf(fmt,*vec_at(v,i,uint8_t*));
|
||||
else if(v->unitsize==4)
|
||||
printf(fmt,((uint32_t*)v->buffer)[i]);
|
||||
printf(fmt,*vec_at(v,i,uint32_t*));
|
||||
else if(v->unitsize==8)
|
||||
printf(fmt,((uint64_t*)v->buffer)[i]);
|
||||
printf(fmt,*vec_at(v,i,uint64_t*));
|
||||
}
|
||||
|
||||
if(i<v->size-1)
|
||||
|
|
5
x86_64.c
5
x86_64.c
|
@ -403,13 +403,10 @@ Vec gen_x86_64_i2r(const Vec*tokens)
|
|||
// Convert to infix, then evaluate
|
||||
void gen_x86_64_eval(Gen*gen,const PNode*pn,FILE*file)
|
||||
{
|
||||
const Vec*tokens=NULL;
|
||||
Vec rpn_stack={0};
|
||||
Vec stack=vec_new(sizeof(int));
|
||||
|
||||
tokens=&(pn->tokens);
|
||||
|
||||
rpn_stack=gen_x86_64_i2r(tokens);
|
||||
rpn_stack=gen_x86_64_i2r(&pn->tokens);
|
||||
|
||||
// Evaluate RPN
|
||||
if(rpn_stack.buffer&&rpn_stack.size>0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user