summaryrefslogtreecommitdiff
path: root/mi
AgeCommit message (Collapse)Author
2017-08-26Let's get happy little rvalues.Ori Bernstein
2017-08-13Give a better error message about incomparable types.Ori Bernstein
2017-07-29Automatic variablesOri Bernstein
Hello, I wrote this patch to start a conversation about resource management in Myrddin. ~ Introduction ~~~~~~~~~~~~~~ The patch attached provides a hopefully life-improving and surely non-invasive mechanism to handle resources that have block-limited lifetimes: automatic variables. This resource-management scheme can be found in multiple languages today. For example, C++ calls destructors automatically at the end of the scope of a variable; similarly, Rust automatically calls user-defined code when a variable's scope ends; finally, also related is Go's defer statement which ensures that resource-releasing code is called at the end of a function. ~ Description ~~~~~~~~~~~~~ The idea is that every "binder" of the language (var/const/ fn args/match) offers the possibility to mark the variables it binds as "automatic" using the 'auto' keyword. An automatic variable must be of a type that implements the new builtin 'disposable' trait below. When the scope of a variable 'v' marked as automatic ends, '__dispose__(v)' is called. That's it. trait disposable @a = __dispose__ : (val : @a -> void) ;; ~ Example Programs ~~~~~~~~~~~~~~~~~~ The language modification is shown in action in the program below. use std impl disposable int = __dispose__ = {x std.put("__dispose__({})\n", x) } ;; const g = {auto x -> x++ - 1 } const main = { var auto i, auto j = 42 for i = 1; i < 6; i=i+1 var auto z : int = 2*i if i == 3 std.put("z = {} -- cont\n", z) continue ;; std.put("z = {}\n", z) if i/2 == 2 var auto inner : int = 1234 break ;; ;; i = g(321) } The output of the previous test program is: 1: z = 2 2: __dispose__(2) 3: z = 4 4: __dispose__(4) 5: z = 6 -- cont 6: __dispose__(6) 7: z = 8 8: __dispose__(1234) 9: __dispose__(8) 10: __dispose__(322) 11: __dispose__(42) 12: __dispose__(320) Some important remarks: * Unlike Go, __dispose__ is called as soon as the scope of a variable ends, not at the end of the function. In particular, the variable 'z' in the example is always disposed of before starting the next iteration. (An iteration ends the loop body block.) * __dispose__ is called in reverse order of declaration This allows variables to depend on resources of variables already in scope. * Regardless of how a block is exited (fallthrough, break, continue, return), variables of the blocks left are disposed of in reverse order and exactly once. * As line 10 of the output shows, the __dispose__ calls happen "after" the return statement of the function. (It happens after the post-increment, so x's value when it is disposed of is 322.) The following example shows that, using an ad hoc type, it is possible to execute arbitrary code at the end of a scope. type defer = (-> void) impl disposable defer = __dispose__ = {f: defer; f()} ;; const foobar = {... const auto _dummy = ({ std.put("Bye!\n") }: defer) ... } ~ Discussion ~~~~~~~~~~~~ Multiple alternatives exist for resource management, and hopefully this mail starts an interesting debate. According to me, here are the pros and cons of the current proposal: - PROS - * Opt-in * Backward compatible * Simple * The spirit of C's original auto * It has an implementation - CONS - * No safety guarantees/compiler checks whatsoever * Syntactic pollution: 'auto' keyword, 'disposable' trait Finally, note that the current patch does not implement auto support for variables bound in match statements. This will come in a followup patch if there is sufficient interest. Also, the patch does not provide proper support (or proper errors) for gotos and labels.
2017-07-10Clean up conditions in trait satisfaction.Ori Bernstein
2017-07-09Style(9)-ify.Ori Bernstein
2017-07-08Break up overly long statements.Ori Bernstein
A monster function declaration and if condition.
2017-07-08Allow matching of empty structs and arraysS. Gilles
2017-06-28Remove unused memb from Trait and rename funcs -> protoMichael Forney
These are prototype declarations that must be implemented by the impl (not necessarily functions), so proto seems like a better name.
2017-06-24Miscellaneous typo/formatting fixesMichael Forney
2017-01-28Describe lvalues and rvalues.Ori Bernstein
2017-01-23Fix decrement in while loop.Ori Bernstein
Fixes #70
2016-12-06Reduce memory usage.Ori Bernstein
2016-10-09Fix bug with postinc returns.Ori Bernstein
We were draining the postinc queue before the rval. Oops.
2016-08-21Fix handling of pointers in match.Ori Bernstein
2016-08-13Don't generate loops in trees.Ori Bernstein
We only want to append to last if we're actaully expanding the match frontier. It's a bug to add it if it's unused.
2016-04-04Fix matching.Ori Bernstein
TODO: understand why. The appending of the start state shoudl be a bug.
2016-03-07Fix missing null terminator.Ori Bernstein
Fixes #108
2016-02-26Fix some generated asm for plan9.Ori Bernstein
2016-02-26Fix compile of C codeOri Bernstein
2016-02-24Fix destructuring of nested tuples.Ori Bernstein
Fixes #92
2016-02-22Fix uniniitalized variable use.Ori Bernstein
2016-02-22Extract util functions into separate dir from parse/Ori Bernstein
2016-02-22Remove comments.Ori Bernstein
2016-02-20Move more operators to flatten.Ori Bernstein
preinc, predec, comparison conversions.
2016-02-20Move more code to flatten.cOri Bernstein
2016-02-20Start refactoringOri Bernstein
Split flattening and lowering.
2016-01-30Error on unmatchable types.Ori Bernstein
2016-01-29Functions act as basic types.Ori Bernstein
Fixes #65
2016-01-24Only walk pointer patterns that walk pointers.Ori Bernstein
2016-01-24Handle the other branch for pointers.Ori Bernstein
2016-01-24Add pointer match syntax.Ori Bernstein
2016-01-20Add a distinction between label values and names.Ori Bernstein
This allows us to have labels work across scopes in assembly source.
2016-01-09Don't attach wildcards *AFTER* accept nodes.Ori Bernstein
2016-01-03Update mkfiles for code shuffleOri Bernstein
2016-01-02Don't double label BBs.Ori Bernstein
If we've already got a BB with a specific label, don't add that label again. Fixes #28
2016-01-01Actually check array sizes when inferring.Ori Bernstein
2015-12-30Don't double-infer nodes.Ori Bernstein
This was leading to us deciding that variables double declared.
2015-12-30Missing a cast to fold to the right type.Ori Bernstein
The length of an array should always be converted to the type used for indexing. Fixes #31
2015-12-18Don't introduce loops in the match trie.Ori Bernstein
2015-12-15Fix wildcards for void.Ori Bernstein
Void acts like a primitive here.
2015-12-15Allow matching a single void.Ori Bernstein
Void has 1 constructor, not 0.
2015-12-14Initial support for void as an expression.Ori Bernstein
2015-12-13Initialize ret() to 0.Ori Bernstein
Fix scan-build warning.
2015-12-13Don't generate useless assignments.Ori Bernstein
We never generate them...
2015-12-13Fix a couple of segfaults.Ori Bernstein
We should actually use valid values when generating errors.
2015-12-11Fix code to disallow use before definition.Ori Bernstein
At least in some cases.
2015-11-17MEGAPATCH: Tabification.Ori Bernstein
Tabs > spaces. By 4 spaces, to be precise. Let's use them.
2015-11-06Fix patterns with multiple sequential wildcardsOri Bernstein
(a, b) was an invalid pattern, since we would never generate the jump to the pattern check for b.
2015-11-06Rewrite pattern matching code.Ori Bernstein
Much cleaner, and more efficient.
2015-11-06Shuffle around functions.Ori Bernstein
Move some code into the frontend so the middle end can call it.