path: root/parse/type.c
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-28Revert "Add a missing tysearch."Ori Bernstein
This reverts commit b31626248ea64c23d2020846e2cac1c751348b61.
2019-03-03Give traits the necessary env.Ori Bernstein
2019-02-16Clean up redundant code.Ori Bernstein
2019-02-10Pass the type envs through properly in delayed unification.Ori Bernstein
2019-02-09Work towards removing the streq check.Ori Bernstein
2019-02-06Fix indentation.Ori Bernstein
2019-02-05Add a missing tysearch.Ori Bernstein
2018-10-18Remove bogus assert.Ori Bernstein
2018-06-11Fix type env assertion.Ori Bernstein
If a subtype has args, it should introduce an env.
2018-01-21Cheap enums.Quentin Carbonneaux
2018-01-14Remove a global-global.Ori Bernstein
Now it's static.
2018-01-11Fix how we bind types.Ori Bernstein
Now we accept most valid programs, and reject most invalid ones.
2018-01-11Move to new trait syntax.Ori Bernstein
2017-08-26Make internal functions static.Ori Bernstein
2017-08-26...The line that fixes things should probably get committed.Ori Bernstein
2017-08-26It's not an lvalue.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-23Check constraints correctly on typarams.Ori Bernstein
2017-08-23Resolve types in match rank.Ori Bernstein
2017-08-20Fix trait shit.Ori Bernstein
2017-08-13Remove dead debug code.Ori Bernstein
2017-08-13Types are also equal with flipflopping.Ori Bernstein
If we have types a -> b -> ptr -> a, and b -> a -> ptr -> b, there are cases where the two types can end up on different branches, so we end up flipflopping between avisited and bvisited containing the type we want.
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-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
2017-07-06Cleaner/correcter version of the termination condition.Ori Bernstein
It isn't entirely equivalent, but the cases where it returns true should be the same. And it shouldn't return false early.
2017-07-06Fix up the type equality checking.Ori Bernstein
2017-07-06Remove double recursion.Ori Bernstein
2017-06-30Remove unused traitlist from Type structMichael Forney
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.
2016-08-11Error if we duplicate struct members.Ori Bernstein
2016-06-21Don't accidentally duck type unions.Ori Bernstein
std.option is not the same as any union with `Some x; `None.
2016-05-10Remove values from the visited set.Ori Bernstein
2016-05-09Avoid infinite recursion when priting bad types.Ori Bernstein
We sometimes error on bad types. Let's not crash when we do that.
2016-04-12Fix typo.Ori Bernstein
Search if search is set.
2016-02-28Don't recompute 'hasparams' over and over.Ori Bernstein
2016-02-27Fix up type generation a bit.Ori Bernstein
2016-02-27Add ability to deduplicate types.Ori Bernstein
2016-02-22Extract util functions into separate dir from parse/Ori Bernstein
2016-02-07Generic iterators now seem to work.Ori Bernstein
2016-01-31Add support for generic impls.Ori Bernstein
You can now implement generic shit like iterators.
2016-01-31Fix missing tysearch()Ori Bernstein
We were erronously saying that two types were not equal, even though we'd already unified them.
2016-01-30Give better errors on infinite types.Ori Bernstein
We used to miss some of them, and we used to givea a confusing error about incompatibility.
2016-01-29Clean up type inference a bit.Ori Bernstein
2016-01-24A pointer isn't an unsigned int...Ori Bernstein
2016-01-02Correctly check for decls without initializers.Ori Bernstein
This turns them into errors. Also fixes a couple that slipped into the code.
2016-01-03fix debug cruftOri Bernstein
2016-01-01Fix style.Ori Bernstein