path: root/parse/tok.c
AgeCommit message (Collapse)Author
2018-12-20Ignore shebang lines in the compiler.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-03-06Add ternary operator.Ori Bernstein
2017-09-22Remove 'in' token.Ori Bernstein
It's now available as a variable name.
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-09Style(9)-ify.Ori Bernstein
2017-02-14Remove unused token type.Ori Bernstein
2017-01-17Clean up grammar a little.Ori Bernstein
Remove dead and obsolete constructs.
2016-10-29Add support for exponential notation for floats.Ori Bernstein
2016-02-22Extract util functions into separate dir from parse/Ori Bernstein
2016-01-26Remove the '$' shorthand for end of array.Ori Bernstein
2016-01-09Start of parsing files.Ori Bernstein
2016-01-03fix debug cruftOri Bernstein
2016-01-01Fix style.Ori Bernstein
2015-12-19Add // comments.Ori Bernstein
2015-12-14Initial support for void as an expression.Ori Bernstein
2015-12-04Fix code formatting.Ori Bernstein
2015-11-17MEGAPATCH: Tabification.Ori Bernstein
Tabs > spaces. By 4 spaces, to be precise. Let's use them.
2015-11-06Add support for '$' operator.Ori Bernstein
2015-07-05Add proper support for a 'gap' variable.Ori Bernstein
'_' is now a reserved token.
2015-06-26Fix a few misc memory bugs.Ori Bernstein
2015-04-19Add support for 'dep=' in mbld genOri Bernstein
This means that mbld code will regenerate generated targets if the inputs aren't up to date.
2015-01-20Add missing stdarg.h includes.Ori Bernstein
2015-01-04Fix this extra arg in lfatal bug again.Ori Bernstein
lfatal had an extra arg that was causing it to crash. Hosed mercurial repositories meant I lost this commit.
2014-12-29Fix a buggy usage of lfatal()Ori Bernstein
we were passing a null string. oshit.
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-07Generalize grammar: specific attrs ar now lists.Ori Bernstein
2014-10-07Whitespace consistency fixes.Ori Bernstein
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-23Shut up Clang's static analyzer a bit.Ori Bernstein
Remove dead store, assert e != null
2014-09-17Add support for 'pkglocal' keyword.Ori Bernstein
pkglocal makes the export only available within the package.
2014-09-17Float formatting finally implemented.Ori Bernstein
2014-09-16Track line number correctly in tokenizerOri Bernstein
When we had a '\' escaping a newline, this would skip counting the escaped newline.
2014-06-16Truncate the message in the right place.Ori Bernstein
2014-06-10Strip out '_' from what we pass to strtol() and friends.Ori Bernstein
2014-06-06Remove unused keyword.Ori Bernstein
Yes. we have no bananas.
2014-06-03Allow integer parsing to work with large integers.Ori Bernstein
We used to fail when we were out of the range of strtol. strtoull is what we want to use, since the integer format is guaranteed to be unsigned. Unary '-' is applied elsewhere, as are range checks.
2014-01-22Add single digit division, and make bigint output use it.Ori Bernstein
2014-01-14Add support for break/continue in loops.Ori Bernstein
Yeah, I resisted until now. Oh well.
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-28Fix hex escape sequences.Ori Bernstein
2013-12-27Add support for \u{...} escape sequences.Ori Bernstein
2013-12-26Fix escape characters for strings.Ori Bernstein
I buggered it up. Oops.
2013-12-19Abort on overly long character constants.Ori Bernstein
2013-12-18Support utf8 character values.Ori Bernstein
2013-11-12More range checking.Ori Bernstein
Make sure that we're not adding bad hex values to integers.
2013-07-23Allow splitting lines.Ori Bernstein