Skip to content

Comments

SVCD::notify [NOT READY]#31

Open
samkumar wants to merge 11 commits intoUCB-IoET:masterfrom
samkumar:feature-svcd-notify
Open

SVCD::notify [NOT READY]#31
samkumar wants to merge 11 commits intoUCB-IoET:masterfrom
samkumar:feature-svcd-notify

Conversation

@samkumar
Copy link
Contributor

Leonard, Michael, and I have implemented SVCD.notify in C. Please give us suggestions and let us know if you find any bugs.

Should we also push our tests to GitHub?

natlib/svcd.c Outdated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use

int arr_as_str(lua_State *L);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is lua_pushnumber(L, arr_type_uint16) the correct code. I did the same thing but couldn't find out why its correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lua_pushnumber(L, ARR_TYPE_UINT16)
is the correct code. In Lua you would do
storm.array.create(1, storm.array.UINT16)
. What you're doing in the Lua code is calling storm.array.create with two arguments: the length of the array, and a constant to say how big each element is. So we push storm_array_create (the function), 1 (the length), ARR_TYPE_UINT16 (the constant that indicates the length), and then invoke lua_call.

So to answer your question, storm.array.UINT16 is a constant that tells the create function how big each element of the array should be. In C you can access that constant as ARR_TYPE_UINT16. Make sense?

@Michaelhobo
Copy link

Some comments would be nice... otherwise I don't see anything off about the code.
FantasticFour

natlib/svcd.c Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between a C closure and calling the function as a light function? I see that Michael does something similar in his init function and uses a pushlightfunction instead. Do you think there are advantages to using C closure calls rather than accessing it as a light function?
PB4J

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Michael uses the fact that storm.invokePeriodically takes in optional arguments that will be passed to the callback each time it is called. This way he can pass arguments in the current scope on to the anonymous function. In our case, cord.new just takes a function, so we need to use a closure so that the function can have access to values in our current scope such as svc_id

@NickFirmani
Copy link

Agreed on the number of comments, the notify function is devoid of them completely

@jenniferdai
Copy link

I know you explained this to me already, but for the rest of the class in case they were curious, what does
for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, lua_gettop(L) - 2))
do?

-birdpeople

@samkumar
Copy link
Contributor Author

samkumar commented Mar 1, 2015

for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, lua_gettop(L) - 2))

iterates over the key-value pairs in a table.
lua_next pops the value at the top of the stack and interprets it as a key in the table. It then pushes on the NEXT key in the iteration, and the value of that key. So the for loop first pushes nil (which is done so we get the first key when we do lua_next). Then in each iteration, it takes the value and performs the body of the for loop using that value. At the end of each iteration, it removes everything from the stack on top of the key whose value was being processed (we remove everything else from the stack by doing lua_pop(L, lua_gettop(L) - 2)). We terminate the loop when lua_next returns 0, at which point there are no more key-value pairs over which we must iterate.

@mschuldt
Copy link
Contributor

mschuldt commented Mar 1, 2015

Team Running With Scissors approves of this pull request.

@immesys immesys changed the title First pass at implementing SVCD.notify SVCD::notify Mar 2, 2015
@immesys immesys changed the title SVCD::notify SVCD::notify [OK] Mar 2, 2015
natlib/svcd.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait sorry this just hit me. You are calling cord.await? How did that even work? Did you test this?

You cannot call a function that yields - like cord.await. You need to use the deferred invocation framework with cord.nc, OR you can call invoke later directly and pass it a continuation

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, we did test this and it worked, but thinking about it it definitely breaks the yield across a c call rule.

I will look into the fix.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have a firestorm on me to test, but from reading it looks like I can use cord_wrap_nc on our closure when it's on the stack, then from inside the closure use nc_invoke_sleep, does that sound sane?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call stack is lost when we yield, so we're going to have to use nc_set_continuation... which is going to require quite a bit of restructuring. We'll have to make the next key in the table an upvalue of the function that we invoke next, meaning that we'll probably have to change the for loop to something else.

I'm really curious how our test managed to work despite this error; it seems like it should have printed an error after the notification completed. I don't have the firestorm on me so I can't make any bugfixes at the moment. We'll probably have to wait until tomorrow to fix this...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea having the next key as an upvalue makes sense, that way the continuation checks the current key and if lua_next returns nil then we've finished.

@immesys immesys changed the title SVCD::notify [OK] SVCD::notify [NOT READY] Mar 2, 2015
@leonardt
Copy link

leonardt commented Mar 2, 2015

Pushed an untested fix using a continuation, we will test it tomorrow morning before lab

@samkumar
Copy link
Contributor Author

samkumar commented Mar 3, 2015

All errors should be fixed now. Michael, please take another look at our code. Sorry for not having debugged this by yesterday night.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants