summaryrefslogtreecommitdiff
path: root/parse/gram.y
AgeCommit message (Collapse)Author
2020-04-30Allow optional eol after the commas of function parametersMura Li
So we can break long parameters into lines without '\'. For example, ``` const foo = {a : byte[:], \ b : int } ``` becomes ``` const foo = {a : byte[:], b : int } ```
2019-03-14Get a bit better at wrangling type bindings.Ori Bernstein
2019-03-03Don't set the env on typedef psuedodecls.Ori Bernstein
We want to specialize the args in the parent env.
2019-03-03Merge envs correctly.Ori Bernstein
Still a couple of straggling issues, but almost there.
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-02-09Work towards removing the streq check.Ori Bernstein
2019-01-07Change indexed array literal syntax.Ori Bernstein
2018-07-19Support direct tuple access operators "tuple.N"Quentin Carbonneaux
This patch adds tuple access expressions. If t is a tuple, its N-th component can be retrieved with the syntax t.N. Of course, the components are zero indexed. I believe the code also works if 't' is a pointer to a tuple (but I have not checked this).
2018-07-14Push down named unions types into union tagsOri Bernstein
Currently, union tags are given the type of their enclosing union, by default: type u = union `Foo ;; var x = `Foo will currently infer the variable 'x' as having type 'union `Foo ;;'. To make the type of 'x' infer as 'foo', the code needs to force 'x' to unify with something that is explicitly declared as a 'u'. This change makes it so that union tags declared in the manner above will default to type 'u', instead. This is a special case, but it makes the behavior less surprising.
2018-06-09Consistently and corretly add Oundef.Ori Bernstein
2018-03-13Merge branch 'autoexpr' into libmathS. Gilles
2018-03-06Add ternary operator.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,
2018-01-14Update language spec for new trait syntax.Ori Bernstein
2018-01-11Try harder to specialize. Still some bugs.Ori Bernstein
2018-01-11Move to new trait syntax.Ori Bernstein
2017-12-31Fix up grammar.Ori Bernstein
We had reduce/reduce conflicts.
2017-12-05Be able to split long lines in commasLucas Gabriel Vuotto
Signed-off-by: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
2017-09-22Remove 'in' token.Ori Bernstein
It's now available as a variable name.
2017-09-02Unjank trait resolution.Ori Bernstein
2017-09-02'in' is now a warning.Ori Bernstein
2017-08-20Fix trait shit.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-26Be stricter about declarations in function types.Ori Bernstein
stupid shit like: const foo : (bar : baz, blah, here -> void) should not miscompile any more.
2017-07-26Whitespace fixes.Quentin Carbonneaux
2017-07-25Remove spandrels.Ori Bernstein
Match patterns can't be null. They haven't been nullable for ages. And even if they could be nullable, $2 isn't the match statement any more.
2017-07-19Only use the filename itself for __init__Ori Bernstein
This sucks, but it's *extremely* unlikely that a file will share a namespace, filename, and __init__. This makes builds directory-independent, so that linking the same file compiled with a different compiler cwd will work.
2017-07-17Start migrating code to use `for x : iterable`.Ori Bernstein
`in` is too good of a variable name to waste on a loop iterator specifier.
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-05Add some discipline to type bindings.Ori Bernstein
We actually now do it in terms of scopes. It's still hacky, but...
2017-07-03Add impl(type, name) to retrieve a particular implementation of a trait declMichael Forney
This avoids having to create a temporary variable when you know what implementation your want for a generic constant or function with generic return value. Re-use the impl keyword for this expression to avoid invalidating existing programs.
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-03-10Fix labels in nested functions.Ori Bernstein
We used to keep a list of labels seen in a function so we could transfer them to the function scope when we finished parsing. This was incorrect because nested functions would collect all the labels from the enclosing scope. We now keep a stack.
2017-02-17Set loc when parsing decllistMichael Forney
Otherwise, the .use file gets a garbage line value, causing builds to be unreproducible.
2017-02-14Remove unused token type.Ori Bernstein
2017-02-13Clean up warnings about ambiguous grammar.Ori Bernstein
2017-02-04Ucons are now prefix expressions.Ori Bernstein
It's just what it looks like. This cleans up taking the address of union literals.
2017-02-01Revert mistaken cleanups.Ori Bernstein
These cleanups don't work. Oops.
2017-02-01Update the grammar.Ori Bernstein
2017-01-17Clean up grammar a little.Ori Bernstein
Remove dead and obsolete constructs.
2017-01-14Whitespace fixes.Ori Bernstein
The spaces were annoying me.
2016-12-10Trait members are global.Ori Bernstein
We were capturing them and not specializing. This fixes one issue.
2016-10-28merge consecutive string literalsandrewc
2016-05-17New syntax for casts.Ori Bernstein
2016-05-09Only allow one level of namespace in a name.Ori Bernstein
Fixes #113
2016-02-26Fix some generated asm for plan9.Ori Bernstein
2016-02-25Fix forward labels in nested blocks.Ori Bernstein
Fixes #91
2016-02-22Extract util functions into separate dir from parse/Ori Bernstein