eudoxia0 / cmacro

Lisp macros for C
881 stars 29 forks source link

Macros that write macros #12

Open porky11 opened 8 years ago

porky11 commented 8 years ago

I'd like to create some templates similar to c++

template mover <T N> {
  T[N] pos;
  T[N] vel;
}

I don't know how I would write a macro for this, that replaces T and N in the body. But the I'd need to create a macro that writes a macro like the first one in following example

macro mover {
  case {
    match {
      < $(type) $(length) >
    }
    template {
      {
        $(type) [$(length)] pos;
        $(type) [$(length)] vel;
      }
    }
  }
}

struct mover <int 2> x;

This will cmc to following c-code

struct {
  int [2] pos;
  int [2] vel;
} x;

Another problem is, that macros written by macros don't get expanded by cmc, I have to run cmc multiple times.

ib00 commented 1 year ago

I think what's missing is an 'escape' operator. It would be nice to have.

eudoxia0 commented 1 year ago

This is an 8-year-old unmaintained project.

albuspiroglu commented 1 year ago

I haven’t done anything on this project but apparently subscribed to these messages. So please take this as a humble opinion and i wish one day i would have the motive to work on this project. So my thoughts is, since this is Common Lisp, if something was working last decade, it should work the next decade too ;) Thus even if this project is unmaintained, it’s good to put ideas about improvement. We don’t know maybe someone will want to add the requested feature :)