GithubHelp home page GithubHelp logo

clnhlzmn / makina Goto Github PK

View Code? Open in Web Editor NEW
114.0 6.0 1.0 17.32 MB

A simple hierarchical state machine compiler that generates C.

License: MIT License

ANTLR 0.06% Kotlin 4.94% C 1.18% Java 93.71% Makefile 0.11%
state-machine hierarchical-states

makina's Issues

Add support for user specified context types

In the generated struct <machine> { ... } and struct <machine>_event { ... } there is a void *ctx. The user should be able to specify the type of ctx. Maybe it could be passed on the command line (java -jar makina-compiler --machine-context struct my_type input.mkna) or the generated files could use a macro for that variable's type which would have to be defined by the user.

Is generating unreachable code correct?

The generated C for this has unreachable code:

machine unreach;

initial state s {
    on TERMINATE -> .done;
    on I (guard_foo) clear_foo -> done;

    state done {}

    state s1 {
        on I -> done;

        state done {}
    }
}

state done {

}

like so:

static int unreach_s_s1_done(struct unreach *self, struct unreach_event *event) {
        if (!self || !event) return -1;
        switch (event->id) {
        case unreach_event_I:
                if (1) {
                        self->state = NULL;
                        self->state = unreach_s_s1_done;
                        break;
                }
                if (guard_foo(self, event)) {
                        self->state = NULL;
                        clear_foo(self, event);
                        self->state = unreach_s_done;
                        break;
                }
                break;

The if (guard_foo) is unreachable and the C compiler complains about it.

Please suppress redundant "self->state = NULL" assignments.

I'd like to use this for very small 8 bit MCUs like STM8 and Pauduk with the SDCC compiler. Unfortunately SDCC does not optimize away the dead assignments, which bloats the generated code considerably.

If I were greedy, I'd also ask for an option to declare the type of the state variable so I could use uint8_t instead of int.

BTW, I really like the description language and the generated code, so clear and clean.

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.