Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeg committed May 5, 2003
1 parent 1f64777 commit e02f861
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
63 changes: 60 additions & 3 deletions lib/claw/HISTORY
Expand Up @@ -15,7 +15,7 @@ The compiler's basic specification is to take a Core Erlang program as
input and return an equivalent Lisp program as output.

----------------------------------------
Phase 1, circa March 2003:
Circa March 2003:

Rough goal: Run the factorial program.

Expand Down Expand Up @@ -45,7 +45,7 @@ Notable features:


----------------------------------------
Phase 2, April 2003:
April 2003:

Rough goal: Add a parser, then compile and execute the "real"
factorial program generated by erlc.
Expand Down Expand Up @@ -175,7 +175,7 @@ Notable features:
expression, and BODY is only executed if the guard is true.

----------------------------------------
Phase 3, April 2003
April 2003

Rough goal: make the generated code more readable.

Expand Down Expand Up @@ -239,3 +239,60 @@ Notables:
- The current program is 595 lines of code, excluding the lex/yacc
clones that I downloaded.


----------------------------------------
4th of May, 2003

Started trying to compile lists.erl from stdlib, which flushed out a
bunch of bugs straight away. Now it compiles without warnings, and
some functions are working fine:

* (|lists|:|map/2| #'1+ '(1 2 3))
(2 3 4)
* (|lists|:|foreach/2| #'print '(1 2 3))
1
2
3
ATOM::|ok|

though runtime support is obviously lacking in various other cases:

* (|lists|:|flatmap/2| #'list '(1 2 3))
Error in KERNEL:%COERCE-TO-FUNCTION: the function ++ is undefined.

I also have CLAW generating actual Lisp source files, and slightly
tweaked the pretty printing. Here's the transformations of the
standard lists:foreach/2 function, first in Erlang:

foreach(F, [Hd|Tail]) ->
F(Hd),
foreach(F, Tail);
foreach(_, []) -> ok.

then Core Erlang:

'foreach'/2 =
fun (_cor1,_cor0) ->
case <_cor1,_cor0> of
<F,[Hd|Tail]> when 'true' ->
do apply F
(Hd)
apply 'foreach'/2
(F, Tail)
<_cor4,[]> when 'true' ->
'ok'
<_cor3,_cor2> when 'true' ->
primop 'match_fail'
({'function_clause',_cor3,_cor2})
end

and into Lisp:

(defun |foreach/2| ($_cor1 $_cor0)
(match-case (values $_cor1 $_cor0)
(($F ($Hd . $Tail)) @true
(progn (funcall $F $Hd) (|foreach/2| $F $Tail)))
(($_cor4 nil) @true @ok)
(($_cor3 $_cor2) @true
(primop "match_fail" #(@function_clause $_cor3 $_cor2)))))

19 changes: 19 additions & 0 deletions lib/claw/src/test.lisp
@@ -0,0 +1,19 @@
;; Simple test script: compiles and loads CLAW, then uses it to
;; compile and run the factorial program.
;;
;; Works in CMUCL. In the Lisp shell, type: (load "test")
;; After this has run, the file "fact.cl" contains the compiled program.
;;
;; It can take a very long time to compile the code generated for the
;; parser. I'd like to improve this somehow. Meanwhile, a workaround
;; for this script is to compile CLAW to bytecode instead of native
;; code. Then it compiles about 10x faster, but bytecode isn't as nice
;; to work with (e.g. in the Lisp debugger.)

(compile-file "clex" :load t) ; lexer generator
(compile-file "lalr" :load t) ; parser generator
(compile-file "claw" :load t :byte-compile t)

(claw:file "fact" :load t)
(format t "~%The factorial of 100 is ~s" (|fact|:|fact/1| 100)))

0 comments on commit e02f861

Please sign in to comment.