Commit graph

212 commits

Author SHA1 Message Date
Leonardo de Moura
ff88c35fc1 refactor(library/init): move io and platform to system subdir 2019-07-25 17:29:33 -07:00
Leonardo de Moura
f6d3fc881d feat(library/init): add platform.cpp 2019-07-25 17:19:50 -07:00
Leonardo de Moura
27e0ad0d9e chore(library/init/lean/compiler/ir/emitcpp): remove constant registration 2019-07-19 10:52:18 -07:00
Leonardo de Moura
a8c36d4c29 feat(library/init/lean/syntax): remove MacroScopes
We are going to use a simpler approach to help users writing hygienic
macros. Suppose we have a syntax quotation such as
```
`(let x := %%a;
  ite x x %%b)
```
We will parse this quotation, and during elaboration, we must create
code (i.e., an `Expr`) such that given `a` and `b`, it constructs
a (new) syntax object, and we want to guarantee that there is no accidental name capture.
So, given the syntax object `S` representing the quotation above, we
first pre-resolve the identifiers in `S`. In this step, we annotate the
identifier `ite` with the global declaration `_root_.ite`.
Then, we create a fresh identifier for each identifier, but we would
preserve the pre-resolved information.
Assume the monadic action `mkFresh <id>` creates a fresh identifier with
prefix `<id>`, and `mkFreshWithPreresolved <id> <pre-list>` creates a
fresh identifier with prefix <id> and pre-resolved list `<pre-list>`.
Then, the quotation above would be transformed into:
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
`(let %%x := %%a;
 %%ite %%x %%x %%b)
```
Here, the new quotation is just syntax sugar for a sequence of `Syntax`
constructor applications. Now, whenever we want to create a syntax
object using the quotation above, we guarantee there is no accidental
name capture because we are creating a fresh identifier for all
identifiers in the quotation. Global references are preserved using the
field preresolved that we already have.
It is straightforward to implement the transformation above using a
mapping. Note that if we use the same mapping to elaborate two different
quotations, we are essentially saying they share the same scope.
For example, suppose we have
```
let c := `(ite x x %%b);
`(let x := %%a; %%c)
```
If we use the same mapping, we produce
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
`(let %%x := %%a; %%c)
```
If we create a new mapping when compiling each quotation, we get
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
let x1 := mkFresh `x;
`(let %%x1 := %%a; %%c)
```
which is probably not what the user wants.
We can provide a simple notation for users specifying which behavior
they want. The default may be super simple. Example: we have a new mapping (aka scope) per declaration.
The approach above is simple and efficient. It is also great for
users that want to create syntax objects during the elaboration phase
and want to avoid name capture.
2019-07-15 10:00:27 -07:00
Leonardo de Moura
295cabed2e chore(library/init): remove unnecessary notations 2019-07-11 10:27:16 -07:00
Leonardo de Moura
c00788a982 fix(library/init/lean/compiler/ir/emitcpp): header of big boxed functions 2019-07-08 21:52:01 -07:00
Leonardo de Moura
324a053f4c fix(library/init/lean/compiler/ir/resetreuse): bug at Dmain 2019-07-08 20:37:54 -07:00
Leonardo de Moura
1a81d60820 chore(frontends/lean/parser): simplify binder notation
The `<ident> : <expr>` now requires explicit brackets.
2019-07-08 08:54:19 -07:00
Leonardo de Moura
ea6eee516b chore(frontends/lean): use => instead of := in match-expressions
Motivation: use same separator used in lambda expressions as in
other programming languages.
2019-07-04 11:38:38 -07:00
Leonardo de Moura
92466272ed fix(library/init/lean/compiler/ir/emitcpp): incorrectly emitting unicode characters in the range [128, 255]
For example, "·" was being stored as `\xb7` which is not the valid UTF8.
2019-07-02 15:56:32 -07:00
Leonardo de Moura
a02443d23d chore(frontends/lean): fun x, e ==> fun x => e 2019-07-02 13:22:11 -07:00
Leonardo de Moura
6841e47aa4 chore(frontends/lean/builtin_exprs): remove support for (<infix>) and (<infix> <expr>) notations
In Lean 4, we will support the more general

`a + ·` ==> `fun x, a + x`
`· + b` ==> `fun x, x + b`
`· + ·` ==> `fun x y, x + y`
`f · y` ==> `fun x, f a y`
`g · · b` ==> `fun x y, g x y b`
2019-07-02 08:06:06 -07:00
Leonardo de Moura
91e1d30cf8 feat(frontends/lean/builtin_exprs): use ; in do-notation 2019-06-27 18:00:43 -07:00
Leonardo de Moura
ab487ea4ac feat(frontends/lean): allow ; instead of in in let-decls 2019-06-27 17:12:03 -07:00
Leonardo de Moura
235b4c02c1 feat(library/init/lean/compiler/specialize): implement specExtension in Lean 2019-06-27 09:58:19 -07:00
Leonardo de Moura
4bc0346c17 chore(library/init/lean/compiler): specializeattrs.lean ==> specialize.lean 2019-06-27 09:38:21 -07:00
Leonardo de Moura
f05df7c511 fix(library/init/lean/compiler/ir/simpcase): missing optimization 2019-06-26 19:07:07 -07:00
Leonardo de Moura
14f05d2001 feat(library/init/lean/compiler): register [implementedBy] attribute using new attribute manager 2019-06-26 15:55:51 -07:00
Leonardo de Moura
3a1aff1687 feat(library/init/lean/compiler): register [specialize] and [nospecialize] attributes using new attribute manager 2019-06-26 15:08:12 -07:00
Leonardo de Moura
e6e71a1f79 chore(init/lean/compiler): inline.lean ==> inlineattrs.lean 2019-06-26 14:10:00 -07:00
Leonardo de Moura
105ca4f76b feat(library/init/lean/compiler/inline): use EnumAttributes to declare inlining attributes 2019-06-26 14:01:30 -07:00
Leonardo de Moura
e00dc873a8 chore(library/pattern_attribute): [pattern] ==> [matchPattern] 2019-06-26 11:26:49 -07:00
Leonardo de Moura
5cfdd2452a chore(library/init/lean/compiler/externattr): remove unnecessary [export] annotations 2019-06-26 11:06:38 -07:00
Leonardo de Moura
16d423dab6 feat(frontends/lean): switch to [extern] implemented in Lean
This commit also changes how we represent attribute parameters as
Syntax objects.
2019-06-26 10:57:33 -07:00
Leonardo de Moura
64ee4e01a8 refactor(library/init/lean/attributes): split getParam into getParam and afterSet 2019-06-26 10:09:57 -07:00
Leonardo de Moura
be6ca5ba30 feat(library/init/lean/compiler/externattr): @[extern] attribute in Lean 2019-06-26 08:42:57 -07:00
Leonardo de Moura
7ca4607ef3 chore(library/init/lean): move name_mangling.lean to compiler directory 2019-06-26 07:05:23 -07:00
Leonardo de Moura
5148497e8c feat(library/init/lean/compiler/externattr): add mkExternAttr skeleton 2019-06-25 13:16:11 -07:00
Leonardo de Moura
5188eb2d3b feat(library/init/lean/compiler/externattr): decode [extern ...] parameters 2019-06-25 12:05:34 -07:00
Leonardo de Moura
aa111df0ec feat(library/init/lean/syntax): add Syntax.isIdOrAtom 2019-06-25 11:20:31 -07:00
Leonardo de Moura
2e01ac508a feat(library/init/lean/syntax): primitives for creating and testing string and nat literals 2019-06-25 10:39:23 -07:00
Leonardo de Moura
1ff6ee3155 feat(library/init/lean/attributes): allow getParam at ParametricAttribute registration to update environment 2019-06-25 09:15:55 -07:00
Leonardo de Moura
70a1589817 refactor(library/init/lean): move extern.lean to compiler subdirectory 2019-06-25 08:59:55 -07:00
Leonardo de Moura
45dc2cd49a feat(library/init/lean/compiler): [export] attribute in Lean 2019-06-24 15:48:12 -07:00
Leonardo de Moura
94bca2b9d8 chore(library/init): mimize use of notations 2019-06-24 15:48:11 -07:00
Leonardo de Moura
dda0e38802 chore(library/init): avoid local notation 2019-06-24 15:48:11 -07:00
Leonardo de Moura
bc9e460f62 fix(library/init/lean/compiler/ir): collectUsedDecls must take initialization functions into account
Move builtin parser level to its own directory
2019-06-21 13:34:42 -07:00
Leonardo de Moura
0b99a18f97 chore(library): use >> as notation for andthen
We have other plans for `;`.
2019-06-20 09:54:53 -07:00
Leonardo de Moura
697f69020f fix(library/init/lean/parser/parser): new registerBuiltinParserAttribute
It is still broken since we apply attributes before we compile code.

Recall that attributes such as `@[export]` and `@[extern]` must be applied before we
compile code.

On the other hand, any attribute `attrName`
```
@[attrName] def foo := ...
```
which creates auxiliary definitions that depend on `foo` must be applied
AFTER we generate code for `foo`. Otherwise, we will fail to compile the
auxiliary definition since we don't have code for `foo` yet.

I will fix the issue above by allowing attributes to specify when they
should be applied. I will start with only two options: before and after
code compilation. In the future, we may need more options (e.g., before
elaboration), but I don't see the need yet.

cc @kha
2019-06-19 09:52:56 -07:00
Leonardo de Moura
08cdb757b4 feat(library/init/lean/environment): add Environment.addAndCompile
To fix `BuiltinParserAttribute`, we need to be able to add auxiliary declarations programmatically.
2019-06-18 18:20:17 -07:00
Leonardo de Moura
0dfca42f6d chore(library/init/lean/compiler/initattr): remove unnecessary @[export] 2019-06-18 16:15:48 -07:00
Leonardo de Moura
6219a2277a fix(library/init/lean/compiler/initattr): getInitFnNameFor 2019-06-18 16:03:52 -07:00
Leonardo de Moura
696088cf2e feat(library/init/lean/compiler/initattr): @[init] attribute in Lean 2019-06-18 16:03:52 -07:00
Leonardo de Moura
a03c236380 feat(library/init/lean/compiler/initattr): new @[init] attribute validation 2019-06-18 15:40:16 -07:00
Leonardo de Moura
91821529c0 feat(library/init/lean/compiler/initattr): register new @[init] attributre using new attribute manager
This is just the basic skeleton for testing
2019-06-18 15:20:17 -07:00
Leonardo de Moura
f176a7963c feat(library/init/lean/compiler/ir/emitcpp): register arity 0 declarations 2019-06-07 17:15:16 -07:00
Leonardo de Moura
c3a7cc4617 feat(library/init/lean/compiler/ir/emitcpp): register functions 2019-06-07 15:34:55 -07:00
Leonardo de Moura
b292fc13cc chore(library/init/lean/compiler/inline): export typo 2019-06-06 15:28:20 -07:00
Leonardo de Moura
9b457cc77c feat(library/init/lean/compiler/inline): implement tester functions and export them 2019-06-06 15:07:08 -07:00
Leonardo de Moura
72290483e4 chore(library/init/lean/compiler): attributes.lean ==> inline.lean 2019-06-06 14:08:13 -07:00