about summary refs log blame commit diff stats
path: root/arc/.traces/sleep-long
blob: 5a7d10e8b0b32e28c477bbb7beabb38eca2e1f57 (plain) (tree)

























































                                                                    
c{0: 0 (((sleep)) ((for-some-cycles literal)) ((20 literal))) -- nil
c{0: 1 (((1 integer)) <- ((copy)) ((0 literal))) -- nil
c{0: 2 (((1 integer)) <- ((copy)) ((0 literal))) -- nil
c{1: 0 ✓ (((sleep)) ((for-some-cycles literal)) ((20 literal)))
c{1: 1 ✓ (((1 integer)) <- ((copy)) ((0 literal)))
c{1: 2 ✓ (((1 integer)) <- ((copy)) ((0 literal)))
c{0: 0 (((2 integer)) <- ((copy)) ((0 literal))) -- nil
c{0: 1 (((2 integer)) <- ((copy)) ((0 literal))) -- nil
c{1: 0 ✓ (((2 integer)) <- ((copy)) ((0 literal)))
c{1: 1 ✓ (((2 integer)) <- ((copy)) ((0 literal)))
cn0: convert-names in f1
cn0: (((sleep)) ((for-some-cycles literal)) ((20 literal))) nil nil
cn0: checking arg ((for-some-cycles literal))
cn0: checking arg ((20 literal))
cn0: (((1 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((1 integer))
maybe-add: ((1 integer))
cn0: (((1 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((1 integer))
maybe-add: ((1 integer))
cn0: convert-names in f2
cn0: (((2 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn0: (((2 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn1: (((sleep)) ((for-some-cycles literal)) ((20 literal)))
cn1: (((1 integer)) <- ((copy)) ((0 literal)))
cn1: (((1 integer)) <- ((copy)) ((0 literal)))
cn1: (((2 integer)) <- ((copy)) ((0 literal)))
cn1: (((2 integer)) <- ((copy)) ((0 literal)))
schedule: f1
run: f1 0: (((sleep)) ((for-some-cycles literal)) ((20 literal)))
run: f1 0: sleeping until 21
schedule: pushing f1 to sleep queue
schedule: f2
run: f2 0: (((2 integer)) <- ((copy)) ((0 literal)))
run: f2 0: 0 => ((2 integer))
mem: ((2 integer)): 2 <= 0
run: f2 1: (((2 integer)) <- ((copy)) ((0 literal)))
run: f2 1: 0 => ((2 integer))
mem: ((2 integer)): 2 <= 0
schedule: done with routine nil
schedule: skipping to cycle 22
schedule: waking up f1
schedule: f1
run: f1 1: (((1 integer)) <- ((copy)) ((0 literal)))
run: f1 1: 0 => ((1 integer))
mem: ((1 integer)): 1 <= 0
run: f1 2: (((1 integer)) <- ((copy)) ((0 literal)))
run: f1 2: 0 => ((1 integer))
mem: ((1 integer)): 1 <= 0
schedule: done with routine nil
m">* Serial stream * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" #include "auxiliar.h" #include "socket.h" #include "options.h" #include "unix.h" #include <string.h> #include <sys/un.h> /* Reuses userdata definition from unix.h, since it is useful for all stream-like objects. If we stored the serial path for use in error messages or userdata printing, we might need our own userdata definition. Group usage is semi-inherited from unix.c, but unnecessary since we have only one object type. */ /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ static int global_create(lua_State *L); static int meth_send(lua_State *L); static int meth_receive(lua_State *L); static int meth_close(lua_State *L); static int meth_settimeout(lua_State *L); static int meth_getfd(lua_State *L); static int meth_setfd(lua_State *L); static int meth_dirty(lua_State *L); static int meth_getstats(lua_State *L); static int meth_setstats(lua_State *L); /* serial object methods */ static luaL_Reg serial_methods[] = { {"__gc", meth_close}, {"__tostring", auxiliar_tostring}, {"close", meth_close}, {"dirty", meth_dirty}, {"getfd", meth_getfd}, {"getstats", meth_getstats}, {"setstats", meth_setstats}, {"receive", meth_receive}, {"send", meth_send}, {"setfd", meth_setfd}, {"settimeout", meth_settimeout}, {NULL, NULL} }; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ LUASOCKET_API int luaopen_socket_serial(lua_State *L) { /* create classes */ auxiliar_newclass(L, "serial{client}", serial_methods); /* create class groups */ auxiliar_add2group(L, "serial{client}", "serial{any}"); lua_pushcfunction(L, global_create); return 1; } /*=========================================================================*\ * Lua methods \*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Just call buffered IO methods \*-------------------------------------------------------------------------*/ static int meth_send(lua_State *L) { p_unix un = (p_unix) auxiliar_checkclass(L, "serial{client}", 1); return buffer_meth_send(L, &un->buf); } static int meth_receive(lua_State *L) { p_unix un = (p_unix) auxiliar_checkclass(L, "serial{client}", 1); return buffer_meth_receive(L, &un->buf); } static int meth_getstats(lua_State *L) { p_unix un = (p_unix) auxiliar_checkclass(L, "serial{client}", 1); return buffer_meth_getstats(L, &un->buf); } static int meth_setstats(lua_State *L) { p_unix un = (p_unix) auxiliar_checkclass(L, "serial{client}", 1); return buffer_meth_setstats(L, &un->buf); } /*-------------------------------------------------------------------------*\ * Select support methods \*-------------------------------------------------------------------------*/ static int meth_getfd(lua_State *L) { p_unix un = (p_unix) auxiliar_checkgroup(L, "serial{any}", 1); lua_pushnumber(L, (int) un->sock); return 1; } /* this is very dangerous, but can be handy for those that are brave enough */ static int meth_setfd(lua_State *L) { p_unix un = (p_unix) auxiliar_checkgroup(L, "serial{any}", 1); un->sock = (t_socket) luaL_checknumber(L, 2); return 0; } static int meth_dirty(lua_State *L) { p_unix un = (p_unix) auxiliar_checkgroup(L, "serial{any}", 1); lua_pushboolean(L, !buffer_isempty(&un->buf)); return 1; } /*-------------------------------------------------------------------------*\ * Closes socket used by object \*-------------------------------------------------------------------------*/ static int meth_close(lua_State *L) { p_unix un = (p_unix) auxiliar_checkgroup(L, "serial{any}", 1); socket_destroy(&un->sock); lua_pushnumber(L, 1); return 1; } /*-------------------------------------------------------------------------*\ * Just call tm methods \*-------------------------------------------------------------------------*/ static int meth_settimeout(lua_State *L) { p_unix un = (p_unix) auxiliar_checkgroup(L, "serial{any}", 1); return timeout_meth_settimeout(L, &un->tm); } /*=========================================================================*\ * Library functions \*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Creates a serial object \*-------------------------------------------------------------------------*/ static int global_create(lua_State *L) { const char* path = luaL_checkstring(L, 1); /* allocate unix object */ p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); /* open serial device */ t_socket sock = open(path, O_NOCTTY|O_RDWR); /*printf("open %s on %d\n", path, sock);*/ if (sock < 0) { lua_pushnil(L); lua_pushstring(L, socket_strerror(errno)); lua_pushnumber(L, errno); return 3; } /* set its type as client object */ auxiliar_setclass(L, "serial{client}", -1); /* initialize remaining structure fields */ socket_setnonblocking(&sock); un->sock = sock; io_init(&un->io, (p_send) socket_write, (p_recv) socket_read, (p_error) socket_ioerror, &un->sock); timeout_init(&un->tm, -1, -1); buffer_init(&un->buf, &un->io, &un->tm); return 1; }