~ ncgutil: generate interface thunks for local classes too ~ nld: during the first pass, we rewrite the nodes that load captured variables, except for nodes marked with the new flag loadnf_captured_param = pdecobj, symdef: factored out tobjectdef.register_implemented_interface + pexpr: access to captured variables from expressions; nameless routine declarations + symconst: new flags for tprocoption (po_nameless, po_has_closure) and tobjectoption (oo_is_nameless) ~ symdef: mangled name generator is now aware of local classes and interfaces + symsym: new field tabstractnormalvarsym.captured_into holds a reference to a new location for the captured variable

git-svn-id: http://svn.freepascal.org/svn/fpc/branches/blaise/closures/compiler@20138 3ad0048d-3df7-0310-abae-a5850022a9f2
+ defcmp: structural equivalence for COM interfaces ~ pdecobj, pdecsub: parsing mode for routines: normal, class method, nameless routine, method reference = pdecsub: factored out parse_proc_parameter_dec(); code simplifications + symdef: tprocdef.add_to_procsym() + ptype, tokens: new UDT -- method reference

git-svn-id: http://svn.freepascal.org/svn/fpc/branches/blaise/closures/compiler@20212 3ad0048d-3df7-0310-abae-a5850022a9f2
Fix compilation. Implementation will be fixed in the future.
Construct frame object. Return interface-reference as parsing result for anonymous function.

Now we are able to generate assembler code. But it crashes :)
1. Interface variables are not initialized.
2. Something wrong with frame object interfaces. Even initialization of frame object by hand doesn't help.
3. Compiler crashes if put anonymous function inside other function (currently only example have anonymous functin inside main)
Generate frame object's initialization code in right place.

Now compiler parses anonymous functin not only inside PascalMain.

TODO:
Resulting programms crash. This is because compiler does not generat interface wrappers.
Inherit created interfaces xfrom IUnknown.

Current problems:
 -interface variables isn't initialized by 0s(probably because I used localvarsym instead of staticvarsym in pascalmain;
 -intf wrappers (again) is not generated. But now virtual tables are ok;
 -didn't check call of anonymous function
Fixed generation of intf wrappers. Now vtbl for frame object is ok. Intf wrappers are ok.

Problem: compiler generate intf wrappers for frame object only if closure defined inside PascalMain.
Cause: during creation of tprocdef it adds itself into module defs and into top symtable defs(look into one of inherited constructors of tprocdef). Since class definition inside procedure is forbidden all class definitions was inside
current_module.localsymtable. And code which generates wrappers didn't look into nested symtables.
Fix: walk through nested symtables during creation of intf wrappers.

Current state:
+ it's possible to assign closure to variable and call it
+ looks like parameters passing works ok
- variables capturing doesn't work
- compiler doesn't check types during assignment of closure to variable
- it's magic that something works, didn't perform proper(and even not proper) testing
Simple tests. Little refactoring.

To run tests
1) build compiler by lazarus(or change path to compiler executable in devtest/test.sh)
2) cd ./devtest
3) sh test.sh
Fix parser to eat semicolon after all nested functions.

Problem: parser doesn't eat semicolon after closure's nested function.
Simple typecheck.

Currently closure is an interface(objectdef) with magic boolean flag "Is closure". It should contain single method which is used to call closure. Compare return types of closure and parametes type. If parameter types are equal then all is good.

TODO: Consider situatin
A < B (A inherited from B)

var
  pa: reference to procedure(arg: A);
  pb: reference to procedure(arg: B);
begin
  pa := pb;

In theory we can allow such assignment since all arguments of pa will be valid for pb.
Better error messages in case of typecheck errors.

Now closure implementaion and closure reference are represented as tobjectdef with flag isClosure. To make nice error messages we hardcoded into few places printing of "reference to procedure" instead of class name.
TODO: Better to refactor this in the future.
Allow to call closure-variable using procvar(arg1, arg2, arg3, ...) or procvar; syntax. Fix error messages. Add more tests.
Write proper internal errors. Fix few comments. Remove code which was marked as redutant before.
Fix coding style.