Coder Social home page Coder Social logo

Why use C macros? about v86 HOT 8 CLOSED

copy avatar copy commented on May 13, 2024
Why use C macros?

from v86.

Comments (8)

copy avatar copy commented on May 13, 2024

When I started the project, parts of the code were a bit more complex and I think introducing macros back then made sense. Right now they're not necessary, but still used in places to avoid code duplication, especially to define opcodes:

op(0xA0, {
    // mov
    var data = safe_read8(read_moffs());
    reg8[reg_al] = data;
});

Macros rarely improve speed. It's of a more convenience, for example the fact that you can pass a block of code to a macro. I have to admit that I went too far in at least one place, but I'll refactor that soon.

from v86.

h8liu avatar h8liu commented on May 13, 2024

The reason I asked this question is that I might try to refactor the code especially the macro part, also as a way to get familiar with the code, but I am not sure if you would like it.

from v86.

copy avatar copy commented on May 13, 2024

Feel free to ask before refactoring larger parts of the code. Right now I'm okay with the use of macros, but a second opinion on this could be interesting. too.

from v86.

haneefmubarak avatar haneefmubarak commented on May 13, 2024

Well, I'm not really involved at all in this project, but if I may say, I think that refactoring the macro portions of the code would be a good idea.

from v86.

copy avatar copy commented on May 13, 2024

I changed my mind, using macros wasn't a great idea. I'll look into refactoring the code to work without macros.

from v86.

h8liu avatar h8liu commented on May 13, 2024

Very glad to hear this. I wish I can help but I don't have much time lately. Also, it takes some time for a non-author like me to understand the code even to start any refactoring. But still, look forward for that to happen.

I have recently been thinking about writing complex programming projects with small modularized files (<200 lines each) that have no circular dependencies among files, so that it could be more easily understood by a new programmer/reader. But that might be just asking too much, and I am not sure if my methodology would really help a newcomer to understand the code after all. This is really another topic.

from v86.

ZaDarkSide avatar ZaDarkSide commented on May 13, 2024

Can we remove the C preprocessor dependency altogether including all macros associated with building the library? It's useless dependency now, all the code generated from macros can be used in source and later refactored if needed.

from v86.

copy avatar copy commented on May 13, 2024

Most macros should be refactored to functions, so that code isn't repeated too much. Doing that part later will be a pain. It shouldn't be too hard, I just haven't found the time to do it yet.

from v86.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.