freenode/#sicl - IRC Chatlog
Search
8:56:48
beach
This is looking good. I can turn ENCLOSE into FUNCALL of ENCLOSE, and after closure conversion, I can turn MAKE-CELL into a FUNCALL of CONS, FETCH into AREF, READ-CELL into CAR and write-cell into RPLACA.
8:57:52
beach
I need to centralize information about what the static environment always contains, in addition to the code object.
9:09:31
beach
So by eliminating those instructions at the end of AST-to-HIR, The elimination code can be tested when I do HIR-to-CL and thus run the boot procedure. Plus, there will be much less code in HIR-to-MIR, which was also a goal.
11:24:00
beach
I just had some major insight, and it will influence what I do now and what I am working on next. I'll take some time and document it here...
11:25:18
beach
So source code contains constants that can be arbitrarily complicated. And it can also contain MAKE-LOAD-FORM forms that can contain any code.
11:27:24
beach
For example, if the file compiler is applied to source code that contains a standard object, then a "similar" object must be built at load time.
11:30:39
beach
So, ultimately, at load time, some code needs to be executed that does what the MAKE-LOAD-FORM requires, and that builds constants that need to be built at load time.
11:32:43
beach
And heisig has been working on a module that moves the code that needs to be executed at load time so that all this code is present at the outermost level. This is necessary because code in nested functions will be turned into binary, and binary code does not understand about constants. It has to find them somewhere, put there by this load-time code.
11:34:07
beach
So anything that can be written using PRINT and read using READ can be handled "directly' by SICL.
11:36:01
beach
So the AST has this top-level function that is turned into HIR and that top-level function will be invoked in order to "tie" the compiled code to a particular first-class global environment.
11:36:43
beach
The top-level function has a single parameter, namely a function-cell-finder function.
11:37:18
beach
Given a constant function name, it returns a function cell for that function in the environment to which the code will be tied.
11:38:49
beach
When SICL code is executed in the host, I turn HIR into host Common Lisp which is compiled and then executed by the host compiler.
11:39:59
beach
So let's use "residual constants" to mean constants that do not need to be constructed at load time because they were constructed by READ when the AST (or the source code as it might be) was read.
11:40:37
beach
For HIR-to-CL, I could have left all residual constants as constant inputs to HIR instructions.
11:41:13
beach
Then HIR-to-CL would gust generate a constant in the host Common Lisp code, and the host compiler would know how to handle those.
11:42:35
beach
But I wanted to make the process as close as possible to what the native SICL compiler will do, especially since, during the boot procedure, at some point I need to generate both host Common Lisp code and native code for SICL simultaneously.
11:44:28
beach
So the idea was to transform the HIR code as much as possible the way it needs to be transformed for native code generation, but only as much as the host Common Lisp can then handle. These transformations would then be common to both host and native execution, thereby avoiding duplication.
11:46:49
beach
So what I have done, and what heisig has been working on is to turn residual constant into CONSTANT-INPUTs at the top level, and to turn FDEFINITIONs into FUNCALL-INSTRUCTIONs to the function-cell-finder function, again with residual CONSTANT-INPUTs as its inputs.
11:47:44
beach
When this transformed code is turned into Common Lisp by HIR-to-CL for execution in the host, again, those constants pose no problem to the host compiler.
11:49:35
beach
But, and here is the catch, what do I do with these top-level HIR instructions containing CONSTANT-INPUTs in the ultimate SICL system, i.e., not during bootstrapping in the host, but when some code is compiled in the final SICL system by the SICL compiler?
11:51:00
beach
I can't use the trick that is used by the host, because I would get into an infinite computation, hosting constants over and over again, with no end.
11:51:08
beach
I swept this issue under the rug, thinking I would probably need a HIR interpreter for the top-level HIR instructions.
11:56:24
beach
For one thing, it would contain some of the same information that HIR-to-MIR and MIR-to-LIR must contain, like argument passing with an arbitrary number of arguments. etc.
11:58:14
beach
I think it would be better to treat the top-level function, i.e. the one to be executed to "tie" the code to an environment, just like the rest of the code.
11:58:45
beach
The only problem with that is that we need to know what to do with those famous residual constants.
11:59:05
beach
I think the solution is that we stick them in the static environment of the top-level function.
12:00:40
beach
So, we collect all those residual constants. Where they have been inputs, we add accesses to the static environment, just as we do with constants in nested functions.
12:01:13
beach
Then the entire top-level function and all the nested functions can be turned into MIR, then LIR, etc.
12:02:17
beach
To "tie", then, we build a closure with the resulting code of the top-level function and an environment that contains all those residual constants. And finally, we invoke the resulting closure as an ordinary function.
12:07:50
beach
I should change the translation suite so that at some point, I obtain a top-level function containing no CONSTANT-INPUTs, but only IMMEDIATE-INPUTs, i.e. constants that I know can be turned into immediate constants in native code.
12:08:54
beach
Other residual constants should be collected outside the top-level function for use when the top-level function is turned into a closure.
12:10:44
beach
HIR-to-MIR can then also be applied to the entire top-level function, including the top-level forms to be executed at load time, which was not possible before.
12:23:09
beach
For the work done by heisig, we tentatively decided that all constant inputs be hoisted, and we would be left with a lexical location in the using code. But we also said that this lexical location could be a subclass of the standard one, and the subclass would have a type, presumably (EQL <the-constant>).
12:24:02
beach
At some later pass, some implementation-specific and backend-specific code could decide whether to use the lexical variable or turn the type into an immediate input.
14:37:41
scymtym
beach: i worked on other issues and forgot about it, sorry. i'm re-reading our discussion now. i'll try to get to it today
14:40:39
beach
The Eclector thing? I plan to replace the modified SICL reader currently in Second Climacs by Eclector.
14:41:32
scymtym
the iterate issue got me sidetracked into "extensible quasiquotation" and i made this to investigate whether/how a hash-table literal that works like a vector literal could be implemented: https://techfak.de/~jmoringe/hash-table-literal-test.lisp
14:43:42
scymtym
reading our final conclusion, it doesn't seem to much work (famous last words) and i'm almost done with the essential backquote-related changes
15:46:33
scymtym
what i'm planning to commit for eclector will do `#'(lambda () ,(random 10)) |- Unquote is illegal in the function reader macro
15:51:05
beach
That is interesting. If I weren't so tired, I could probably deduce how it must be implemented.
15:53:05
scymtym
it reads (quasiquote (function (unquote *foo*))) and the rest is macroexpansion, i think
15:55:43
scymtym
i guess quasiquote depth should be reset to 0 by SHARPSIGN-DOT to get a good error message
15:57:13
scymtym
maybe i should distribute pre-built versions of the style-check thing and let people attempt to break it in order find bugs in eclector and the syntax library
17:21:56
scymtym
beach: i made a prototypical READ-MAYBE-NOTHING function: https://github.com/robert-strandh/Eclector/tree/read-maybe-nothing . if this works for you, i can clean it up and push to master tomorrow
18:17:13
beach
Great, thank! I'll study it tomorrow. Now i must go spend time with my (admittedly small) family.