view test/hoge.c @ 725:3f1f6c0610c1

goto with enviornment syntax changed.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 20 Aug 2009 16:39:02 +0900
parents 6b7372e17970
children c2c709727221
line wrap: on
line source

#include <stdio.h>
// #include "hoge.h"
// #include "task.h"

struct task;

typedef
struct pkt {
    int val;
    __code (*next)(struct pkt *,struct task *);
} Pkt, *PktPtr;


typedef
struct task {
    int val;
    __code (*next)(struct pkt *,struct task *);
} Task, *TaskPtr;

int count = 5;

void *env;
__code (*exit0)(int,void*);

__code scheduler(PktPtr pkt, TaskPtr task)
{
    if (count-->0)
	goto pkt->next(pkt,task);
    goto exit0(0,env);
}

__code modulo(PktPtr pkt, TaskPtr current_task);

__code increment(PktPtr pkt, TaskPtr current_task)
{
    pkt->val++;
    printf("inc: %d\n", pkt->val);
    pkt->next = modulo;
    goto scheduler(pkt, current_task);
}

__code modulo(PktPtr pkt, TaskPtr current_task)
{
    pkt->val %= 10;
    pkt->val = pkt->val % 10;
    printf("mod: %d\n", pkt->val);
    pkt->next = increment;
    goto scheduler(pkt, current_task);
}

static Pkt pkt;
static Task task;

int
main()
{
    exit0 = __return;
    env = __environment;
    goto increment(&pkt,&task);
}