GithubHelp home page GithubHelp logo

copse's Introduction

Continuation-passing-style (CPS) in C

This library provides an interface for writing continuation-passing-style (CPS) code in C. Each continuation is represented by an instance of struct cps_cont, which contains a function pointer. To invoke the continuation, we call the function pointer. The function takes in two continuation parameters: the first is the continuation being invoked, and the second is the continuation that the function should pass control to when it's done.

The continuation function doesn't allow any other parameters; information can only be passed between continuations by embedding the struct cps_cont instance in some larger struct, which should also contain any additional state that must be passed into the continuation.

Since C isn't an inherently CPS-based language, we have to make the distinction being regions of code that are using CPS, and regions that aren't. “Normal” C code can transfer control to CPS code by calling the cps_run function. This takes in a continuation object, which will be invoked, passing in an appropriate next continuation to cause the cps_run function to return when the continuation has finished.

Conversely, CPS code can return control the most recent “normal” C code region by simply returning from the continuation function. It can return a simple integer status code, which can be used for basic error reporting. When using a compiler that implements sibling/tail-call optimizations, each region of CPS code will only occupy one frame on the call stack.

copse's People

Watchers

 avatar

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.