summaryrefslogtreecommitdiff
path: root/parse/parse.h
AgeCommit message (Collapse)Author
2019-04-28Fix float conversions in casts.Ori Bernstein
We were dropping the intness, and didn't registerize the args to comisd.
2019-04-12Rename traits correctly.Ori Bernstein
2019-03-03Give traits the necessary env.Ori Bernstein
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
2019-01-28Bump ABI version.Ori Bernstein
Fixes bug for slices in varargs.
2018-10-15Disallow negative array sizes. And do some cleanup.Ori Bernstein
2018-05-29Retroactively update the ABI version.Ori Bernstein
Auto expressions changed the usefile layout, but we forgot to bump ABI.
2018-04-18Merge remote-tracking branch 'ori/master' into HEADS. Gilles
2018-04-08Add support for `-T` option to compile in test mode.Ori Bernstein
Tests can now access hidden declarations.
2018-03-13Merge branch 'autoexpr' into libmathS. Gilles
2018-03-12Bump ABI retroactively.Ori Bernstein
Forgot to do it when adding ternary operator.
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,
2018-01-21Cheap enums.Quentin Carbonneaux
2018-01-17Hack in seqaux.Ori Bernstein
It's not perfect, and the right solution would be to keep a trait->aux mapping, but for now it works good enough.
2018-01-17Infer after generating init functions.Ori Bernstein
Pull out the usefile loading, so we can call it separately from inference. Then shuffle the infer() call to after we generate init().
2018-01-14Remove a global-global.Ori Bernstein
Now it's static.
2018-01-14Fix serializing trait specs in usefiles.Ori Bernstein
2018-01-11Fix how we bind types.Ori Bernstein
Now we accept most valid programs, and reject most invalid ones.
2018-01-11Try harder to specialize. Still some bugs.Ori Bernstein
2018-01-11Move to new trait syntax.Ori Bernstein
2017-11-05Accept the globalness of file.Ori Bernstein
2017-10-29Fix traits when exported cross-namespaces.Ori Bernstein
2017-09-02Unjank trait resolution.Ori Bernstein
2017-08-26Add monotonically increasing equality check.Ori Bernstein
Because unlike the bit sets, nothing gets removed from here, we should either converge on equality, or error out.
2017-08-22Clean up usefile cruft.Ori Bernstein
2017-08-20Fix trait shit.Ori Bernstein
2017-08-19File is already global.Ori Bernstein
Let's use it.
2017-08-08Bring back enforced namespaces.Ori Bernstein
It turns out that people actually like being forced to type the full names. Go figure. It does have the benefit of adding pressure to keep package names short. Eventually, we'll probably grow the ability to alias a package at import. We'll see how that goes. This reverts commit c5245eaa80064b77186fa286f8e5e8bca73309ab.
2017-07-30Add hook into frontend for sizeof() folding.Ori Bernstein
Before, code like: const f = { var buf: byte[sizeof(int)] } would crash us, because `sizeof` would not get folded. A slightly subtle point: muse doens't install a hook here, but since it's already handling processed usefiles, the array sizes should already be prefolded for its viewing pleasure.
2017-07-29Finally do a by-scope comparison of generic types.Ori Bernstein
This should clear the way for better deduplication.
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-28Fix error message for generics in non-generic decls.Ori Bernstein
2017-07-27std.change std.name std.lookup std.rules.Ori Bernstein
std.no std.on std.every std.name std.you std.use. The rules for an un-namespaced name now are as follows: 1) Attempt to look up a name in the current file. 2) Check all namespaces for a unique name. If the name is not globally unique, give an error.
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-12Add support for -O in 6m.Ori Bernstein
First step to not polluting source dirs.
2017-07-10Remove unused enum.Ori Bernstein
2017-07-09Mark things as static.Ori Bernstein
2017-07-05Add some discipline to type bindings.Ori Bernstein
We actually now do it in terms of scopes. It's still hacky, but...
2017-07-03Actually mark void arg lists as void.Ori Bernstein
2017-07-03Clean up indentation of comments.Ori Bernstein
2017-07-03Specialize impl declarations on impl type in addition to decl typeMichael Forney
This allows multiple specializations of a declarations with a concrete type, which can be selected with the new impl expression if it can't be deduced by its type alone. For example trait hasname @t = Name: byte[:] ;; impl hasname void = Name = "somename" ;; impl hasname bool = Name = "othername" ;; const boolname = impl(Name, void) To do this, pass the param type through to genericname and specializedcl. Since we now need the type parameter to look up trait decls, make sure n->expr.param gets the necessary treatment in typesub, specializenode, pickle, and unpickle. We also need to tag the param types for export.
2017-06-30Remove unused traitlist from Type structMichael Forney
2017-06-28Update ABI version.Ori Bernstein
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-28Remove unused trait structure in NodeMichael Forney
2017-02-17Search for usefiles relative to the output.Ori Bernstein
For most uses, this is equivalent to compiler cwd, but supports out of tree builds better. It also means that builds behave the same way regardless of the directory that the compiler is run from, which is convenient for testing. This also drops support for `.use` suffixes on local uses.
2017-02-14Fold Utags on union literals.Ori Bernstein
2017-01-02Fix clang warnings.Ori Bernstein
Apparently enums getting promoted to ints in va_start() is undefined behavior. This is stupid.
2016-10-08Don't infer things multiple times.Ori Bernstein
In addition to installing variables repeatedly, it's just kind of inefficient.