summary refs log tree commit diff stats
path: root/compiler/semtempl.nim
Commit message (Expand)AuthorAgeFilesLines
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-1/+1
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-3/+3
* views: yet another bugfix (#15447)Andreas Rumpf2020-10-011-5/+0
* Fix forward declarations in shadow scope contexts (#15386)Clyybber2020-09-221-2/+2
* Big compiler Cleanup (#14777)Clyybber2020-08-281-1/+0
* Fix forward declaration issues in template/macro context (#15091)Clyybber2020-07-291-22/+5
* fix codegen bug due to changing existing symbol declaration in template (#14666)jcosborn2020-06-151-1/+1
* fixes #12885 [backport] (#12895)Andreas Rumpf2019-12-131-0/+4
* Fixes #12832 (#12842) [backport]Neelesh Chandola2019-12-081-0/+5
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-159/+155
* fixes #12193 (#12199)Andreas Rumpf2019-09-161-2/+1
* Small ast.nim cleanup (#12156)Clyybber2019-09-091-20/+20
* fixes yet another gensym regression (#12145)Andreas Rumpf2019-09-061-3/+3
* fixes #12121 (#12126)Andreas Rumpf2019-09-051-9/+24
* improvement for 'unused import' warningsAraq2019-09-021-0/+1
* new gensym handling (#11985)Andreas Rumpf2019-08-231-19/+43
* [refactoring] compiler: simplified markUsedAndreas Rumpf2019-08-081-1/+1
* [feature] detect unused importsAraq2019-07-171-1/+1
* Allow void macro result (#11286)Arne Döring2019-05-211-5/+0
* Fixes #9365 : let with exportC pragma in template. (#11235)Aditya Siram2019-05-141-0/+6
* rename tyExpr/tyStmt to tyUntyped/tyTyped (#11227)Arne Döring2019-05-111-5/+5
* Replace countup(x, y) with x .. yClyybber2019-05-071-4/+4
* Replace countup(x, y-1) with x ..< yClyybber2019-05-071-14/+14
* Fix loop tuple unpacking in templates (#11174)nc-x2019-05-051-1/+5
* callsite lineinfe for stackTrace template (#10785)Arne Döring2019-04-181-3/+5
* more destructor based changes (#10885)Andreas Rumpf2019-03-231-1/+1
* it's spelt callsiteAndreas Rumpf2019-02-221-2/+3
* 32 bit fixes (#10608)Arne Döring2019-02-131-0/+4
* compiler/sem*: improve lineinfo for qualified and generic procs (#10427)alaviss2019-01-231-6/+7
* nimfind: improvementsAndreas Rumpf2018-11-151-0/+2
* added first version of a nimfind tool for the poor souls that don't have a go...Andreas Rumpf2018-11-141-8/+12
* fixes regressionsAraq2018-10-301-10/+8
* fixes unexpected transforming of runnableExamples (#9158)Steve Kellock2018-10-091-1/+3
* fixes #8052Araq2018-08-311-1/+1
* code cleanup: remove newScopeForIf switchAndreas Rumpf2018-07-041-2/+1
* implements a --nep1:on switch to make the compiler enforce the naming convent...Andreas Rumpf2018-06-131-4/+4
* refactoring: remove idents.legacy global variable and pass the IdentCache aro...Andreas Rumpf2018-05-271-7/+7
* remove more global variables in the Nim compilerAndreas Rumpf2018-05-271-2/+2
* more modules compile againAndreas Rumpf2018-05-121-37/+40
* Implement custom annotations (#6987)cooldome2018-01-091-1/+4
* first steps in adding template/macro calls to stack tracesAraq2017-12-211-2/+2
* minor breaking change: for loop bodies now get their own scopeAndreas Rumpf2017-11-051-0/+2
* remove old implementation of the roof operator; make tests green again; close...Andreas Rumpf2017-10-291-18/+0
* deprecated unary '<'Andreas Rumpf2017-10-291-4/+4
* first implementation of the 'func' keywordAndreas Rumpf2017-09-231-0/+2
* Remove expr/stmt (#5857)Arne Döring2017-07-251-2/+2
* fixes #5478Araq2017-03-061-4/+4
* make tests green againAndreas Rumpf2017-03-021-0/+4
* Merge branch 'devel' into faster-nimsuggestAndreas Rumpf2017-02-241-5/+7
|\
| * fixes #5417Andreas Rumpf2017-02-241-5/+7


                      
 



                             
 










                                                             


                                                            


             
 



                                                            


                                                   

                 


                                                    
             


                                                                                


                                      


                                                                    
                                         


                                                              

                             


                                                            
                                      
             
                      


                                                              






                                   
 
struct bytebuffer {
  char *buf;
  int len;
  int cap;
};

static void bytebuffer_reserve(struct bytebuffer *b, int cap) {
  if (b->cap >= cap) {
    return;
  }

  // prefer doubling capacity
  if (b->cap * 2 >= cap) {
    cap = b->cap * 2;
  }

  char *newbuf = malloc(cap);
  if (b->len > 0) {
    // copy what was there, b->len > 0 assumes b->buf != null
    memcpy(newbuf, b->buf, b->len);
  }
  if (b->buf) {
    // in case there was an allocated buffer, free it
    free(b->buf);
  }
  b->buf = newbuf;
  b->cap = cap;
}

static void bytebuffer_init(struct bytebuffer *b, int cap) {
  b->cap = 0;
  b->len = 0;
  b->buf = 0;

  if (cap > 0) {
    b->cap = cap;
    b->buf = malloc(cap); // just assume malloc works always
  }
}

static void bytebuffer_free(struct bytebuffer *b) {
  if (b->buf)
    free(b->buf);
}

static void bytebuffer_clear(struct bytebuffer *b) {
  b->len = 0;
}

static void bytebuffer_append(struct bytebuffer *b, const char *data, int len) {
  bytebuffer_reserve(b, b->len + len);
  memcpy(b->buf + b->len, data, len);
  b->len += len;
}

static void bytebuffer_puts(struct bytebuffer *b, const char *str) {
  bytebuffer_append(b, str, strlen(str));
}

static void bytebuffer_resize(struct bytebuffer *b, int len) {
  bytebuffer_reserve(b, len);
  b->len = len;
}

static void bytebuffer_flush(struct bytebuffer *b, int fd) {
  int yyy = write(fd, b->buf, b->len);
  (void) yyy;
  bytebuffer_clear(b);
}

static void bytebuffer_truncate(struct bytebuffer *b, int n) {
  if (n <= 0)
    return;
  if (n > b->len)
    n = b->len;
  const int nmove = b->len - n;
  memmove(b->buf, b->buf+n, nmove);
  b->len -= n;
}