summaryrefslogtreecommitdiff
path: root/parse/dump.c
AgeCommit message (Collapse)Author
2019-02-26Accept that `file` isn't a node.Ori Bernstein
Shrink node sizes, simplify code a bit.
2019-02-26Add support for `__fini__` functions.Ori Bernstein
2018-01-26New auto operator.Quentin Carbonneaux
Summary: -------- During the Myrcon in September Ori suggested an 'auto' operator that would evaluate what it applies to, store the result in a temporary t, and call __dispose__(t) when the current block exits. This patch implements this idea under the form of a unary operator. This, for instance, allows to have: impl disposable regex# = __dispose__ = {r; regex.free(r)} ;; regex.exec(auto std.try(regex.compile("f..bar")), "foobar") Like before, it is guaranteed that __dispose__ is called in reverse order of auto appearance. Backward compatibility: ----------------------- Nope. Auto variables are now gone. This should not be a problem, simply rewrite: var auto x = foo() into: var x = auto foo() Implementation: --------------- It largely reuses the code I had written for 'auto' variables but needs a little finer grain tracking because we don't always want to call __dispose__ for *all* auto expression results when leaving a block (some might not be evaluated yet). For example: auto 1 if b -> void ;; auto 2 Only __dispose__(1) must be called when '-> void' is executed. If the block falls through, __dispose__(2) and __dispose__(1) will be called in sequence. TODO: ----- - Err when goto jumps in/out of a block that has auto expressions. - Support auto in patterns. match ... | `std.Some (auto x): ... is essentially rewritten to: match ... | `std.Some (auto x): auto x ... - Test edge cases (e.g., auto in loop condition) Actually, test. Cheers,
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-15Use type hashing instead of string hasing in tyenv.Ori Bernstein
Set the stage for stricter env lookups.
2017-07-15Type binding refactoring now compiles.Ori Bernstein
Still a bit sloppy on a few things, needs some dedup work, but it's working.
2017-07-09Style(9)-ify.Ori Bernstein
2016-02-22Extract util functions into separate dir from parse/Ori Bernstein
2015-12-14Initial support for void as an expression.Ori Bernstein
2015-11-17MEGAPATCH: Tabification.Ori Bernstein
Tabs > spaces. By 4 spaces, to be precise. Let's use them.
2015-09-24Put the closure at the function level.Ori Bernstein
2015-09-24Capture and dump function environments in parse.Ori Bernstein
We can now dump the closure of a function correctly. We still don't compile it, though.
2015-07-12Correctly dump out global symtabs.Ori Bernstein
Somehow during the namespace shuffle, we lost dumping namespaces.
2015-07-09Refactor namespaces.Ori Bernstein
We no longer store subnamespaces in the stab node; now they're a part of the file.
2015-05-08A few more fixes for dataflow checks.Ori Bernstein
2015-01-20Add missing stdarg.h includes.Ori Bernstein
2015-01-06Improve error messages.Ori Bernstein
This involved lots of table changes.
2014-12-20Improve error reporting.Ori Bernstein
Double declarations now say where they were double declared.
2014-12-18Get rid of the 'exports' stab.Ori Bernstein
This should simplify a number of chunks of code.
2014-12-13Add plan9 instruction formats.Ori Bernstein
Work towards a plan9 port. This commit also fixes a bug with strings that contain '\0'. The commits got tangled, and I'm too lazy to detangle them.
2014-10-07Keep track of source files as well as line numbers.Ori Bernstein
This makes our error messages better *AND* makes it easier to provide good debug info later.
2014-10-07Add support for storing file ids.Ori Bernstein
2014-10-07Print all decl bools.Ori Bernstein
For better debugging.
2014-10-07Work on trimming BBs and inseting Orets.Ori Bernstein
This is to enable work on checking BBs for missed returns. This seems to be working, but is overzealous, and will error out when we try to call terminating functions like die().
2014-10-04Start work of porting to Plan 9.Ori Bernstein
We're missing getopt, but everything else seems to work as far as compiling goes. Remaining work: - Converting assembly syntax - Invoking plan9 executables correctly
2014-09-28Fix premature unification in generics.Ori Bernstein
We used to unify generics prematurely, meaning that if we had a generic being used before the declaration was fully inferred, we would fix it's type at the first use. This would cause errors when we tried to use it with a different type. A demonstration of this bug is below: const main = { id("asdf") /* we decided that id (byte[:] -> $t) */ id(123) /* type error: (byte[:] -> $t) is not compatible with (intline -> $t) */ } generic id = {x : @a -> x }
2014-07-14Indent trace information.Ori Bernstein
2014-05-08Default the types correctly in specialized functions.Ori Bernstein
If we have @a::(numerical,integral), for example, in a function that is not unfied with any specific numerical,integral type, we need to default it to an int. This does that.
2014-02-26Add a back link for traits, instead of a bool.Ori Bernstein
This allows us to link the impls to the trait, look them up, and generate trait-local specialized names, instead of hoping that we can hack around the decl id and such when hashing.
2014-02-26Dump the 'istraitfn' variable.Ori Bernstein
2014-02-14Dump trait nodes for debugging.Ori Bernstein
2014-02-02Remove 'trait' node.Ori Bernstein
This should go in the types table, not in it's own AST node.
2014-02-01Stub in more code for trait/impl.Ori Bernstein
We now make Impl nodes, and then die when we try to use them.
2014-01-13Work towards parsing traits definitions.Ori Bernstein
2013-12-28Add parsing support for iter loopsOri Bernstein
'for expr in loop' syntax is now parsed, although we don't actually generate code for it.
2013-12-27Move towards automatically creating hidden exports.Ori Bernstein
Right now, this only works muse, since the probing is only done when generating usefiles. However, with a bit of work it should be usable for exporting symbols in assembly as well
2013-12-19Push and pop stabs correctly when loading usefiles.Ori Bernstein
2013-08-09More commenting.Ori Bernstein
2013-06-18Fix a bug in array size inference.Ori Bernstein
It's not a literal any more. Don't use fields from literals.
2013-06-18Move away from literal types that aren't actual compile time constants.Ori Bernstein
2013-06-17Fix const inference for compound literals.Ori Bernstein
2013-06-08Add indexed initializer tree support.Ori Bernstein
Needed to support indexed initialization of sequence literals.
2013-06-07Parses struct elements, but doesn't compile them.Ori Bernstein
2013-01-04Fix formatting of dumps.Ori Bernstein
The symtab was interspersed with the arguments. Oops.
2012-10-17Labels are now Lit values, not their own toplev nodes.Ori Bernstein
2012-10-03Duplicate types correctly.Ori Bernstein
We need to copy all of their members.
2012-08-23Print a string as a string, not as a node.Ori Bernstein
2012-08-14More comments and some code rearrangements.Ori Bernstein
2012-07-25Don't export symbols willy-nilly.Ori Bernstein
Only export things in the package section, or 'main'.
2012-07-16Move away from literals for tuples.Ori Bernstein