Visible compiler code in new repository.

11 views
Skip to first unread message

jon....@gmail.com

unread,
Feb 17, 2009, 5:03:42 PM2/17/09
to Applied Language Technologies Group, wsc...@gmail.com
Hi everyone,

I've created a new Mercurial repository at bitbucket.org for our
group, and pushed some code that demonstrates decomposing the SML/NJ
read-eval-print loop (REPL). In the work I'm doing on the extensible
front-end, I'm proposing reusing some form of this evaluator, both as
a macro processor, and as a compiler following source-to-source
translation.

If you are interested in getting the code, you can browse and/or get
tarballs at http://bitbucket.org/jriehl/altg/. To keep things
current, you'll need Mercurial. Once you're set up, you can get a
copy of the repository as follows:

$ hg clone http://bitbucket.org/jriehl/altg/ altg
$ cd altg/viscomp
$ sml
...
- use "sml_eval.sml";
...

Periodic updates can be had by doing a "hg pull -u" from your
repository subdirectory. If you are new to Mercurial, I recommend
reading the Bitbucket docs, and/or the Mercurial book at http://hgbook.red-bean.com/.

Please let me know if you want push access to the repository, or have
any questions or comments about what's already in there.

Thanks,
-Jon

Wonseok Chae

unread,
Feb 24, 2009, 3:10:41 AM2/24/09
to Applied Language Technologies Group
Hi everyone,
Jon challenged us to write a DSL using his transformer. That is what I
will do soon.
Jon, you did a good job.

Wonseok

p.s.
While I was running the code, I ran into the following error message:
-- Error: Compiler bug: UnpickMod: stub lookup failed

Anyone who sees this message would like to see the post at "http://
www.nabble.com/compiling-smlnj-td20765432.html". (Thanks Jon)

On Feb 17, 4:03 pm, jon.ri...@gmail.com wrote:
> Hi everyone,
>
> I've created a new Mercurial repository at bitbucket.org for our
> group, and pushed some code that demonstrates decomposing the SML/NJ
> read-eval-print loop (REPL).  In the work I'm doing on the extensible
> front-end, I'm proposing reusing some form of this evaluator, both as
> a macro processor, and as a compiler following source-to-source
> translation.
>
> If you are interested in getting the code, you can browse and/or get
> tarballs athttp://bitbucket.org/jriehl/altg/.  To keep things
> current, you'll need Mercurial.  Once you're set up, you can get a
> copy of the repository as follows:
>
> $ hg clonehttp://bitbucket.org/jriehl/altg/altg
> $ cd altg/viscomp
> $ sml
> ...
> - use "sml_eval.sml";
> ...
>
> Periodic updates can be had by doing a "hg pull -u" from your
> repository subdirectory.  If you are new to Mercurial, I recommend
> reading the Bitbucket docs, and/or the Mercurial book athttp://hgbook.red-bean.com/.

Wonseok Chae

unread,
Feb 26, 2009, 1:41:03 AM2/26/09
to Applied Language Technologies Group
Hi everyone,

I did some hack on Jon's code to provide the private interactive mode
running on the SML/NJ interactive mode.
( I failed to make it stand-alone. It can run alone, but I don't know
how to autoload libraries such as +)
It takes streams, parses them into ast, unparse ast back to a string,
then evaluates such a string to a value.

For example,

- Main.main ("",[""]);
Interactive Mode
# fun fact n = if n = 0 then 1 else n * fact (n-1)
val fact = fn : int -> int
# fact 5
val it = 120 : int

So what? For what reason do we need another SML/NJ interactive mode?
With this machinery, possibly, we can have ...

1. Nested interactive mode by chaining global environments...?
Currently, it is not nested. It globally shares the environment
with the native interactive mode.

2. Embedded interactive mode for a DSL by replacing
Parse.parseString.
We may implement Ast-to-Ast transformation.

It is getting interesting...:-)

p.s.

I am attaching some related code:

------------------------------------------------------------------------------------------------------------
structure Main : sig
val main : string * string list -> OS.Process.status
end = struct

fun evalString str = Backend.Interact.useStream (TextIO.openString
str);

fun main (self, args) =
let val _ = print "Interactive Mode\n"
fun run () =
let val _ = print "# "
val source = getOpt (T.inputLine T.stdIn, "")
val ast = Parse.parseString source
val source' = Parse.unparseAst ast
val _ = evalString source'
in run ()
end
handle e => (TextIO.output (TextIO.stdErr, General.exnMessage e
^ "\n");
run ())

in (run (); OS.Process.success)
end

end
------------------------------------------------------------------------------------------------------------

It calls unparseAst which is my version of ppAstDec:

------------------------------------------------------------------------------------------------------------
fun ppAstDec0 dec =
let val {static=statenv, ...} = getenv ()
fun printfn ppstrm dec = PPAst.ppDec (statenv, NONE) ppstrm
(dec, valOf Int.maxInt)
in PP.pp_to_string 0 printfn dec
end (* ppAstDe0 *)
------------------------------------------------------------------------------------------------------------

where the Parse Module looks like ...

------------------------------------------------------------------------------------------------------------
structure Parse : sig
val sourceFromStream : TextIO.instream -> Source.inputSource
val parseOneStream : TextIO.instream -> unit -> Ast.dec option
val parseOneString : string -> unit -> Ast.dec option
val parseStream : TextIO.instream -> Ast.dec
val parseString : string -> Ast.dec
val unparseAst : Ast.dec -> string (* ppAstDec0 *)
end = struct
...
end
------------------------------------------------------------------------------------------------------------



On Feb 24, 2:10 am, Wonseok Chae <wsc...@gmail.com> wrote:
> Hi everyone,
> Jon challenged us to write a DSL using his transformer. That is what I
> will do soon.
> Jon, you did a good job.
>
> Wonseok
>
> p.s.
> While I was running the code, I ran into the following error message:
> -- Error: Compiler bug: UnpickMod: stub lookup failed
>
> Anyone who sees this message would like to see the post at "http://www.nabble.com/compiling-smlnj-td20765432.html". (Thanks Jon)
Reply all
Reply to author
Forward
0 new messages