Skip to content

Commit

Permalink
Fix #57
Browse files Browse the repository at this point in the history
  • Loading branch information
refi64 committed Nov 27, 2015
1 parent b2f9343 commit 12867b5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions o.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ ST rst=0; //root stack
typedef enum{TD,TS,TA,TCB}OT; //decimal,string,array,codeblock
typedef struct{OT t;union{F d;struct{S s;L z;}s;ST a;};}OB;typedef OB*O; //type:type flag,value{decimal,{string,len},array}(NOTE:code blocks use string struct to store their code!)
S tos(O o){
S r,t;L z;switch(o->t){
S r,t;L z,i;switch(o->t){
case TD:r=alc(BZ)/*hope this is big enough!*/;sprintf(r,"%f",o->d);z=strlen(r)-1;while(r[z]=='0')r[z--]=0;if(r[z]=='.')r[z]=0;BK;
case TS:r=alc(o->s.z+1);memcpy(r,o->s.s,o->s.z);r[o->s.z]=0;BK;
case TA:r=alc(BZ)/*XXX:overflow potential here!again!*/;r[0]='[';r[1]=0;I l=len(o->a);if(l){I i;for(i=0;i<l;++i){
if(i)strcat(r,",");t=tos(o->a->st[i]);strcat(r,t);DL(t);
}}strcat(r,"]");BK;
case TA:r=alc(1);r[0]='[';z=1;for(i=0;i<len(o->a);++i){L l;if(i){r=rlc(r,z+1);r[z++]=',';}t=tos(o->a->st[i]);l=strlen(t);r=rlc(r,z+l);memcpy(r+z,t,l);z+=l;DL(t);}r=rlc(r,z+2);r[z]=']';r[z+1]=0;BK;
case TCB:r=alc(o->s.z+3);r[0]='{';memcpy(r+1,o->s.s,o->s.z);memcpy(r+1+o->s.z,"}",2);BK;
}R r;
} //tostring (copies)
Expand Down

0 comments on commit 12867b5

Please sign in to comment.