Bitwise » Forums » New Homework? (+ Suggestion)
mathk
8 posts
#14872 New Homework? (+ Suggestion)
3 months, 1 week ago Edited by mathk on April 8, 2018, 4:57 p.m.

Hey there.

Is there new homework on the horizon?

I personally would love it if there was at least one bit of homework per week available. Some people might like to "code along" but to me that feels a little too open ended to get myself to do it on the regular. I like the focused homework assignments because I feel they deliver more learning/hour even if there is (in absolute terms) more to learn by coding along. The latter feels like too much of a time investment for me.

Of course this is just a suggestion, I very much enjoy this project either way :-)

Edit:
I was just having a quick think about this. The problem with following along for me is that weeks, months or years down the road there will likely be large stretches in which I don't have the time/energy/whatever to follow the project. Afterwards I would be sitting there with a codebase that's far behind Per's and it would take quite a lot just to catch up. I think I'm not the only one for whom this would be a certainty were they to follow along.

Now, my idea is:
Maybe you could from time to time (or however often you like, of course) create the homework in a way in which you take the bitwise codebase but strip out whatever is the object of the exercise. Be it an algorithm, a specialized datastructure, a whole subsystem etc. People who are following along could still do the exercise in their own codebase.
pervognsen
Per Vognsen
49 posts / 1 project
#14882 New Homework? (+ Suggestion)
3 months, 1 week ago

Thanks for the reminder. I'll start thinking about some new assignments.
Maykeye
19 posts
#14976 New Homework? (+ Suggestion)
2 months, 4 weeks ago

Finished defers today (I didn't forbid assignments, only declarations, breaks and continue).

Continuing with the idea of assignments(from `if`s and `while`s),
I've added "initializer" to defer so it's possible to capture values manually:

1
2
mem := malloc(10);  defer(p:=mem) {free(p);}
mem = malloc(100);  defer(p:=mem) {free(p);}


Compare to

1
2
mem := malloc(10);  defer {free(mem);}
mem = malloc(100);  defer  {free(mem);}


where program would double free the same pointer

Idea is to have automatic captures someday and it's a scaffold for it which can be used manually for now. (On C side it just creates variable name, based on which p is used).

From other things. I've added a new modifier - @essential. A function is essential, if its return value can't be ignored. It's like __attribute__((warn_unused_result)) in gcc, only not a warning, but an error.

And asserts now work more or less and can print ast(that was used before c codegen) and values of expressions if something goes wrong or you just ask it to print everything. They support only integers now though, but still now I can test compiler using it itself
which I'll probably do more in a future. Testing from inside of C is pain and suffering.
pervognsen
Per Vognsen
49 posts / 1 project
#14984 New Homework? (+ Suggestion)
2 months, 4 weeks ago Edited by Per Vognsen on April 18, 2018, 5:41 a.m.

Nice! I like the capture idea.

It's cool to see all the work you're doing on your parallel implementation.

I'll add asserts today since you reminded me. I was planning on piggybacking on # notes since those take expression arguments syntactically. So #assert(x >= 0) and so on. Right now I only support # notes as top-level decls but the plan is to add them at statement level as well. Regarding the printing, if AST nodes have full start/end string pointer ranges into the stream, you can do a verbatim string copy. I'm only tracking the start right now, but this is a good excuse to fix that.