Code Monkey home page Code Monkey logo

chimney's Introduction

chimney (C sHIM library)

There are certain things in C that either come up all the time, and either have a poor API (e.g. error handling in i/o operations) or require a lot of untyped code (e.g. dynamic arrays). This library is a collection of these things, as I run into them in my own work.

Inventory

  • static assert that you have a "normal" architecture
  • bits types (i.e. convert between signed, unsigned, and (where applicable) pointer types)
  • alignment arithmetic
  • alloc/: first-class allocation interfaces
    • unaligned: unaligned allocations
    • aligned: aligned allocations
    • tags: tagged pointer utilites
      • untyped native tagged pointers
      • polymorphic (tagged_ptr<type ptr_type>)
      • wider tags (set a tag width; would require aligned allocs)
      • polymorphic wider tags
    • polymorphic alloc
    • safe allocations: submit (programmer-controlled) size of object times (user-controlled) number of objects, detect overflows
  • buffer/: polymorphic growable buffers
    • forward (usual) buffer
    • backwards-growing buffer (for e.g. buffers of big-endian digits built little-endian)
    • monomorphize to byte buffers
    • monomorphize to void* buffers
    • polymorphic pointer buffers
  • memory slices
    • length + pointer
      • monomorphize to byte slices (lenstr)
      • monomorphise to void* slices
      • polymorphic pointer slices (lenarr)
    • original + offset + length
  • script that creates instantiations of polymorphic modules (so the documentation is better)
  • unicode utilities
    • a sentinel for char32_t
    • read utf8 from byte slice
    • create utf8 encoding for one character
  • other possibilities include (but I have not committed to)
    • sane i/o error reporting
    • list of blocks
    • decode binary-encoded integers from string/file (signed/unsigned 8,16,32,64-bit big/little-endian)
    • readline
  • runtime system utilites (these may go in here, or in an entirely separate library)
    • symbol table
    • garbage collector (simple and general object layout, generational, moving, single-threaded, some sort of inter-thread memory passing/sharing)
    • s-expressions
    • simple bigint library

Macro Trickery

Inline Functions

I want to write the body of an inline function exactly once, and emit exactly one copy. To do this, I've followed this advice.

  • Header files are included as normal. To support this, the header has the preprocessor sequence: #ifndef INLINE; #define INLINE inline; #endif Then, the function must be defined in that header file, preceded byINLINE. It may also declare the function, but this should be done either inline or INLINE.
  • Translation units must #define INLINE (i.e. define it as blank) before including their corresponding header. The translation unit does not itself define the inline function, since the ehader already defines it.

Polymorphism

This is where the real trickery happens.

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.