caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocamlmktop and includes
@ 2001-04-28 14:54 Patrick M Doane
  2001-05-01  1:05 ` Jacques Garrigue
  0 siblings, 1 reply; 9+ messages in thread
From: Patrick M Doane @ 2001-04-28 14:54 UTC (permalink / raw)
  To: caml-list

Is there any way to transfer the -I directives from the ocamlmktop command
to the toplevel system that is created?

For example:

  ocamlmktop -I dir1 -I dir2 -o mytoplevel foo.cmo bar.cmo 

Then

  ./mytoplevel

would produce the same behavior as this does currently:

  ./mytoplevel -I dir1 -I dir2

Alternatively, it would be really nice to make stand-alone byte code
interpreters which have the .cmo files builtin.

Any ideas?

Patrick


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-04-28 14:54 [Caml-list] ocamlmktop and includes Patrick M Doane
@ 2001-05-01  1:05 ` Jacques Garrigue
  2001-05-01  3:39   ` John Gerard Malecki
  0 siblings, 1 reply; 9+ messages in thread
From: Jacques Garrigue @ 2001-05-01  1:05 UTC (permalink / raw)
  To: patrick; +Cc: caml-list

From: Patrick M Doane <patrick@watson.org>

> Alternatively, it would be really nice to make stand-alone byte code
> interpreters which have the .cmo files builtin.

If you just need a custome bytecode interpreter, that's not (too)
difficult.
The idea is to use the Dynlink module:
Just build a custom executable, including all the libraries you need,
and registering the modules you want to use with
Dynlink.add_available_units. This function takes the unit name, and a
CRC (in fact a MD5) for the .cmi, which you can get with
lib/ocaml/extract_crc. This way you don't need neither the .cma nor
the .cmi's for your libraries.
The your program will load all .cmo or .cma given on the command line,
using Dynlink.loadfile.
I join an exemple of such a bytecode interpreter including plenty of
libraries. (The CRC's are not up to date)

Cute, no?
There is a small pitfall: you can only make available an interface
when there is an implementation. So if you have pure interfaces (a .cmi
but no .cmo), you have to copy the the .mli to .ml, and compile it,
to get an empty implementation matching the .cmi.

Hope this helps,

Jacques Garrigue

(* Link with everything. Compile with:
   ocamlc -I +labltk -o ocamlloader -linkall dynlink.cma unix.cma dbm.cma \
       str.cma nums.cma labltk.cma stdclass.cma crcs.ml
   To get all crcs in one directory:
	extract_crc `\ls *.cmi | sed "s/.cmi//" | capitalize`
*)

let crc_unit_list = [
  "Arg",
    "\132\241\139\095\018\209\141\180\176\082\093\079\208\235\049\083";
  "Arith_status",
    "\089\253\033\080\043\135\175\127\166\158\179\030\223\236\054\166";
  "Array",
    "\146\022\203\069\253\093\134\037\233\194\070\176\050\248\097\172";
  "Big_int",
    "\243\042\214\129\099\114\179\135\162\146\175\227\015\202\143\160";
  "Callback",
    "\213\119\018\062\250\024\055\143\129\161\094\222\057\023\146\248";
  "Char",
    "\184\168\151\226\206\081\149\197\060\011\054\064\207\150\178\138";
  "Dbm",
    "\224\114\137\160\060\165\253\220\099\067\179\255\250\145\095\153";
  "Digest",
    "\132\054\239\158\106\045\248\017\082\204\225\229\020\063\091\254";
  "Dynlink",
    "\135\180\176\101\073\127\073\073\127\151\142\161\067\053\021\073";
  "Filename",
    "\097\078\243\010\046\199\169\212\199\183\242\067\050\043\255\112";
  "Format",
    "\255\061\006\074\141\083\248\109\242\099\050\153\088\097\166\055";
  "Gc",
    "\089\227\107\050\058\044\003\036\239\188\130\047\116\033\090\028";
  "Genlex",
    "\179\252\157\000\199\039\171\234\006\063\191\135\168\067\016\174";
  "Graphics",
    "\205\233\013\180\028\114\139\004\004\109\049\042\182\126\001\137";
  "Hashtbl",
    "\069\196\160\110\103\090\223\223\129\219\190\170\014\091\012\007";
  "Lazy",
    "\079\216\032\236\211\038\005\010\162\001\239\179\109\114\117\147";
  "Lexing",
    "\182\088\003\040\254\005\244\149\087\093\237\123\178\173\001\112";
  "List",
    "\034\235\035\108\154\120\077\156\180\011\013\141\063\152\055\055";
  "Map",
    "\112\213\080\192\236\152\247\119\049\174\106\154\198\248\038\243";
  "Marshal",
    "\212\185\081\165\100\136\097\073\164\142\082\147\055\242\088\149";
  "Nat",
    "\015\202\018\039\135\054\224\200\222\013\194\080\165\243\250\146";
  "Num",
    "\243\243\021\151\036\013\082\157\233\216\151\178\043\006\159\056";
  "Obj",
    "\194\237\101\179\047\114\046\161\072\117\212\196\008\083\213\072";
  "Oformat",
    "\040\190\172\213\155\053\141\220\205\093\073\042\228\252\159\179";
  "Ogenlex",
    "\248\206\017\001\181\044\188\030\052\115\066\169\211\058\231\051";
  "Ohashtbl",
    "\211\072\131\214\164\212\100\103\164\246\170\106\196\007\157\180";
  "Omap",
    "\052\094\138\008\100\038\194\008\000\094\175\065\019\178\109\103";
  "Omapping",
    "\225\081\091\064\046\201\022\178\088\089\230\124\177\109\178\248";
  "Oo",
    "\253\246\076\227\151\115\217\141\048\042\155\159\061\051\168\158";
  "Oqueue",
    "\147\020\229\095\046\075\213\196\181\031\216\209\074\236\217\075";
  "Oset",
    "\056\213\244\036\127\109\042\098\080\098\130\063\120\114\043\084";
  "Ostack",
    "\173\008\203\219\123\041\247\255\037\148\016\143\155\023\020\021";
  "Ostream",
    "\105\211\112\045\064\001\225\086\221\013\086\221\012\174\011\188";
  "Parsing",
    "\238\091\167\164\087\104\115\231\007\133\009\041\001\020\238\217";
  "Pervasives",
    "\081\190\153\116\206\164\208\178\173\067\134\249\076\133\233\089";
  "Printexc",
    "\068\225\231\087\144\035\057\101\195\150\166\074\076\076\191\093";
  "Printf",
    "\114\086\103\091\204\204\191\201\249\027\107\015\067\094\248\184";
  "Profiling",
    "\124\209\206\043\202\119\097\026\229\151\251\185\190\080\244\189";
  "Queue",
    "\106\035\239\245\185\045\075\131\162\053\038\054\070\007\103\098";
  "Random",
    "\225\240\003\163\080\059\165\202\076\018\224\180\160\191\100\140";
  "Ratio",
    "\176\030\022\221\242\249\175\107\233\038\141\239\208\245\187\163";
  "Set",
    "\241\198\021\016\215\179\209\129\251\204\237\117\232\142\136\012";
  "Sort",
    "\042\013\126\242\024\204\017\183\155\004\123\201\200\197\152\248";
  "Stack",
    "\035\108\042\081\047\041\088\231\118\222\233\248\184\053\215\118";
  "Std_exit",
    "\167\124\048\151\124\056\054\043\214\131\251\242\175\132\166\243";
  "Str",
    "\135\231\101\157\048\245\001\093\024\242\163\178\065\016\157\020";
  "Stream",
    "\068\127\097\226\098\205\064\112\082\037\105\079\236\126\121\046";
  "String",
    "\013\045\050\104\222\055\220\090\092\179\113\181\072\212\082\012";
  "Sys",
    "\041\089\246\208\014\005\096\240\061\077\000\157\239\193\241\111";
  "Topdirs",
    "\164\224\058\210\062\157\159\029\044\254\058\220\097\244\177\215";
  "Toploop",
    "\038\007\001\223\104\189\070\057\057\062\213\241\225\121\132\111";
  "Unix",
    "\100\176\025\054\154\219\152\081\252\126\095\147\016\069\153\070";
  "Weak",
    "\180\180\008\001\065\221\239\201\173\053\038\214\000\202\187\083";
  "Balloon",
    "\064\130\212\209\166\007\028\236\137\067\132\239\066\078\240\172";
  "Bell",
    "\017\183\096\172\169\146\009\071\065\080\067\231\011\088\184\145";
  "Button",
    "\228\106\173\140\076\048\063\055\228\010\106\073\000\157\054\103";
  "Canvas",
    "\018\123\213\204\031\021\012\106\218\240\020\003\047\011\035\087";
  "Checkbutton",
    "\082\050\250\035\240\200\013\191\168\107\238\089\104\206\068\016";
  "Clipboard",
    "\090\120\177\182\099\141\025\169\233\251\040\153\164\102\200\130";
  "Dialog",
    "\215\111\103\076\009\164\108\208\046\222\025\113\144\254\041\203";
  "Entry",
    "\090\241\159\056\214\250\171\107\145\014\042\143\189\248\093\132";
  "Fileevent",
    "\213\136\118\001\080\039\117\214\196\120\102\112\248\216\253\214";
  "Fileselect",
    "\016\042\091\024\048\222\255\072\189\205\042\141\195\173\019\025";
  "Focus",
    "\079\179\218\046\103\199\007\028\007\246\146\207\009\087\240\231";
  "Frame",
    "\067\222\053\008\203\055\121\013\189\206\219\142\169\160\211\056";
  "Grab",
    "\217\048\223\133\044\123\178\056\118\115\241\142\119\238\094\049";
  "Grid",
    "\123\214\154\096\213\037\019\209\194\242\049\062\059\087\089\127";
  "Imagebitmap",
    "\205\003\180\038\057\077\191\153\202\132\122\003\161\154\245\180";
  "Imagephoto",
    "\132\186\156\150\254\168\050\097\146\249\159\173\214\194\163\248";
  "Label",
    "\030\162\169\108\217\134\207\143\097\007\015\088\009\047\168\112";
  "Listbox",
    "\255\091\065\145\151\247\020\103\234\034\115\204\014\247\202\243";
  "Menu",
    "\133\213\100\249\249\029\073\255\154\030\187\015\067\024\214\010";
  "Menubutton",
    "\215\155\194\167\196\152\066\013\148\035\062\095\181\076\152\042";
  "Message",
    "\137\228\064\194\061\220\048\156\177\194\193\218\153\105\245\029";
  "Option",
    "\002\048\023\081\052\014\221\032\078\004\079\127\008\153\241\127";
  "Optionmenu",
    "\132\032\144\168\045\172\052\110\234\147\145\036\125\098\105\014";
  "Pack",
    "\007\057\162\105\211\180\208\132\037\061\148\070\011\171\207\128";
  "Palette",
    "\014\068\206\100\061\249\187\150\248\168\052\127\235\171\003\030";
  "Place",
    "\074\007\070\132\132\124\203\041\177\117\118\129\064\169\207\006";
  "Protocol",
    "\044\093\149\050\026\194\067\214\011\224\026\017\085\193\231\100";
  "Radiobutton",
    "\128\129\131\210\169\194\242\058\141\128\163\033\133\192\094\120";
  "Scale",
    "\227\078\017\132\154\090\007\086\144\195\166\055\233\180\183\131";
  "Scrollbar",
    "\177\242\191\174\051\150\159\225\108\101\233\010\112\084\057\216";
  "Selection",
    "\173\172\218\213\029\036\130\012\033\235\031\238\076\067\219\017";
  "Support",
    "\159\177\172\212\190\133\232\032\192\082\170\250\049\082\063\184";
  "Text",
    "\027\143\132\012\023\218\179\073\003\002\081\199\183\010\107\161";
  "Textvariable",
    "\172\029\217\109\207\144\254\185\068\049\028\090\224\087\177\139";
  "Timer",
    "\168\141\189\094\081\187\049\026\012\239\025\071\220\014\024\188";
  "Tk",
    "\155\008\032\103\156\245\158\235\161\052\121\080\091\119\211\242";
  "Tkwait",
    "\221\238\138\104\160\070\189\107\092\058\048\098\052\137\127\153";
  "Toplevel",
    "\091\097\016\210\132\101\149\002\036\075\240\001\240\192\132\178";
  "Widget",
    "\049\215\061\172\124\063\244\113\107\137\123\208\197\169\136\037";
  "Winfo",
    "\020\023\187\002\192\057\213\009\192\237\092\046\228\130\021\142";
  "Wm",
    "\169\231\071\215\217\053\030\124\162\209\103\160\145\052\110\120"
]

open Dynlink

let _ =
  init ();
  add_available_units crc_unit_list;
  allow_unsafe_modules true;
  try
    for i = 1 to Array.length Sys.argv - 1 do
      loadfile Sys.argv.(i)
    done
  with
    Error err -> prerr_endline (error_message err)
  | exn -> Printexc.catch raise exn
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-05-01  1:05 ` Jacques Garrigue
@ 2001-05-01  3:39   ` John Gerard Malecki
  0 siblings, 0 replies; 9+ messages in thread
From: John Gerard Malecki @ 2001-05-01  3:39 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: patrick, caml-list

Jacques Garrigue wrote (2001-05-01T10:05:37+0900):
 >    To get all crcs in one directory:
 > 	extract_crc `\ls *.cmi | sed "s/.cmi//" | capitalize`

Capitalize not posix and hence available on some but not all machines.
The ocaml team recognized this and allows uncased module names as in

 > 	extract_crc `\ls *.cmi | sed "s/.cmi//"`

Within a makefile the following works for me:

 extract_crc := $(shell ocamlc -where)/extract_crc

 crcs.ml: $(INTF)
	$(extract_crc) $< > \#$@
	mv \#$@ $@

where INTF may be something like

 INTF := $(patsubst %.mli,%.cmi,$(wildcard *.mli))

-cheers
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-05-01  1:27 David Gurr
@ 2001-05-01  2:57 ` Patrick M Doane
  0 siblings, 0 replies; 9+ messages in thread
From: Patrick M Doane @ 2001-05-01  2:57 UTC (permalink / raw)
  To: David Gurr; +Cc: garrigue, caml-list

Hi Jacques,

David's clarification is correct.  At first, I thought I was getting error
messages because .cmo files were not being linked into the toplevel.  Now
I understand the problem was with the .cmi files.  The Dynlink features
are quite nice but don't seem to be quite the right match. 

Patrick


On Mon, 30 Apr 2001, David Gurr wrote:

> Hi,  That is what I though at first.  But I think this is not fully
> what he wishes.  Dynlink.add_available_units makes digests available to
> the dynlinker but it does not make the persistent structures (cmi's)
> available to the compiler in the toplevel environment.  One could argue
> that ocmalmktop should embed both the cmo's and their cmi's  in such a
> way that the cmi's would be added to the initial env of the custom
> toplevel.  -D
> 
> > From owner-caml-list@pauillac.inria.fr Mon Apr 30 18:11:29 2001
> > From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
> > To: patrick@watson.org
> > Cc: caml-list@inria.fr
> > X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f
> > Subject: Re: [Caml-list] ocamlmktop and includes
> > Mime-Version: 1.0
> > Content-Transfer-Encoding: 7bit
> > Date: Tue, 01 May 2001 10:05:37 +0900
> > X-Dispatcher: imput version 20000228(IM140)
> > 
> > From: Patrick M Doane <patrick@watson.org>
> > 
> > > Alternatively, it would be really nice to make stand-alone byte code
> > > interpreters which have the .cmo files builtin.
> > 
> > If you just need a custome bytecode interpreter, that's not (too)
> > difficult.
> > The idea is to use the Dynlink module:
> > Just build a custom executable, including all the libraries you need,
> > and registering the modules you want to use with
> > Dynlink.add_available_units. This function takes the unit name, and a
> > CRC (in fact a MD5) for the .cmi, which you can get with
> > lib/ocaml/extract_crc. This way you don't need neither the .cma nor
> > the .cmi's for your libraries.
> > The your program will load all .cmo or .cma given on the command line,
> > using Dynlink.loadfile.
> > I join an exemple of such a bytecode interpreter including plenty of
> > libraries. (The CRC's are not up to date)
> > 
> > Cute, no?
> > There is a small pitfall: you can only make available an interface
> > when there is an implementation. So if you have pure interfaces (a .cmi
> > but no .cmo), you have to copy the the .mli to .ml, and compile it,
> > to get an empty implementation matching the .cmi.
> > 
> > Hope this helps,
> > 
> > Jacques Garrigue
> > 
> > (* Link with everything. Compile with:
> >    ocamlc -I +labltk -o ocamlloader -linkall dynlink.cma unix.cma dbm.cma \
> >        str.cma nums.cma labltk.cma stdclass.cma crcs.ml
> >    To get all crcs in one directory:
> > 	extract_crc `\ls *.cmi | sed "s/.cmi//" | capitalize`
> > *)
> > 
> > let crc_unit_list = [
> >   "Arg",
> >     "\132\241\139\095\018\209\141\180\176\082\093\079\208\235\049\083";
> >   "Arith_status",
> >     "\089\253\033\080\043\135\175\127\166\158\179\030\223\236\054\166";
> >   "Array",
> >     "\146\022\203\069\253\093\134\037\233\194\070\176\050\248\097\172";
> >   "Big_int",
> >     "\243\042\214\129\099\114\179\135\162\146\175\227\015\202\143\160";
> >   "Callback",
> >     "\213\119\018\062\250\024\055\143\129\161\094\222\057\023\146\248";
> >   "Char",
> >     "\184\168\151\226\206\081\149\197\060\011\054\064\207\150\178\138";
> >   "Dbm",
> >     "\224\114\137\160\060\165\253\220\099\067\179\255\250\145\095\153";
> >   "Digest",
> >     "\132\054\239\158\106\045\248\017\082\204\225\229\020\063\091\254";
> >   "Dynlink",
> >     "\135\180\176\101\073\127\073\073\127\151\142\161\067\053\021\073";
> >   "Filename",
> >     "\097\078\243\010\046\199\169\212\199\183\242\067\050\043\255\112";
> >   "Format",
> >     "\255\061\006\074\141\083\248\109\242\099\050\153\088\097\166\055";
> >   "Gc",
> >     "\089\227\107\050\058\044\003\036\239\188\130\047\116\033\090\028";
> >   "Genlex",
> >     "\179\252\157\000\199\039\171\234\006\063\191\135\168\067\016\174";
> >   "Graphics",
> >     "\205\233\013\180\028\114\139\004\004\109\049\042\182\126\001\137";
> >   "Hashtbl",
> >     "\069\196\160\110\103\090\223\223\129\219\190\170\014\091\012\007";
> >   "Lazy",
> >     "\079\216\032\236\211\038\005\010\162\001\239\179\109\114\117\147";
> >   "Lexing",
> >     "\182\088\003\040\254\005\244\149\087\093\237\123\178\173\001\112";
> >   "List",
> >     "\034\235\035\108\154\120\077\156\180\011\013\141\063\152\055\055";
> >   "Map",
> >     "\112\213\080\192\236\152\247\119\049\174\106\154\198\248\038\243";
> >   "Marshal",
> >     "\212\185\081\165\100\136\097\073\164\142\082\147\055\242\088\149";
> >   "Nat",
> >     "\015\202\018\039\135\054\224\200\222\013\194\080\165\243\250\146";
> >   "Num",
> >     "\243\243\021\151\036\013\082\157\233\216\151\178\043\006\159\056";
> >   "Obj",
> >     "\194\237\101\179\047\114\046\161\072\117\212\196\008\083\213\072";
> >   "Oformat",
> >     "\040\190\172\213\155\053\141\220\205\093\073\042\228\252\159\179";
> >   "Ogenlex",
> >     "\248\206\017\001\181\044\188\030\052\115\066\169\211\058\231\051";
> >   "Ohashtbl",
> >     "\211\072\131\214\164\212\100\103\164\246\170\106\196\007\157\180";
> >   "Omap",
> >     "\052\094\138\008\100\038\194\008\000\094\175\065\019\178\109\103";
> >   "Omapping",
> >     "\225\081\091\064\046\201\022\178\088\089\230\124\177\109\178\248";
> >   "Oo",
> >     "\253\246\076\227\151\115\217\141\048\042\155\159\061\051\168\158";
> >   "Oqueue",
> >     "\147\020\229\095\046\075\213\196\181\031\216\209\074\236\217\075";
> >   "Oset",
> >     "\056\213\244\036\127\109\042\098\080\098\130\063\120\114\043\084";
> >   "Ostack",
> >     "\173\008\203\219\123\041\247\255\037\148\016\143\155\023\020\021";
> >   "Ostream",
> >     "\105\211\112\045\064\001\225\086\221\013\086\221\012\174\011\188";
> >   "Parsing",
> >     "\238\091\167\164\087\104\115\231\007\133\009\041\001\020\238\217";
> >   "Pervasives",
> >     "\081\190\153\116\206\164\208\178\173\067\134\249\076\133\233\089";
> >   "Printexc",
> >     "\068\225\231\087\144\035\057\101\195\150\166\074\076\076\191\093";
> >   "Printf",
> >     "\114\086\103\091\204\204\191\201\249\027\107\015\067\094\248\184";
> >   "Profiling",
> >     "\124\209\206\043\202\119\097\026\229\151\251\185\190\080\244\189";
> >   "Queue",
> >     "\106\035\239\245\185\045\075\131\162\053\038\054\070\007\103\098";
> >   "Random",
> >     "\225\240\003\163\080\059\165\202\076\018\224\180\160\191\100\140";
> >   "Ratio",
> >     "\176\030\022\221\242\249\175\107\233\038\141\239\208\245\187\163";
> >   "Set",
> >     "\241\198\021\016\215\179\209\129\251\204\237\117\232\142\136\012";
> >   "Sort",
> >     "\042\013\126\242\024\204\017\183\155\004\123\201\200\197\152\248";
> >   "Stack",
> >     "\035\108\042\081\047\041\088\231\118\222\233\248\184\053\215\118";
> >   "Std_exit",
> >     "\167\124\048\151\124\056\054\043\214\131\251\242\175\132\166\243";
> >   "Str",
> >     "\135\231\101\157\048\245\001\093\024\242\163\178\065\016\157\020";
> >   "Stream",
> >     "\068\127\097\226\098\205\064\112\082\037\105\079\236\126\121\046";
> >   "String",
> >     "\013\045\050\104\222\055\220\090\092\179\113\181\072\212\082\012";
> >   "Sys",
> >     "\041\089\246\208\014\005\096\240\061\077\000\157\239\193\241\111";
> >   "Topdirs",
> >     "\164\224\058\210\062\157\159\029\044\254\058\220\097\244\177\215";
> >   "Toploop",
> >     "\038\007\001\223\104\189\070\057\057\062\213\241\225\121\132\111";
> >   "Unix",
> >     "\100\176\025\054\154\219\152\081\252\126\095\147\016\069\153\070";
> >   "Weak",
> >     "\180\180\008\001\065\221\239\201\173\053\038\214\000\202\187\083";
> >   "Balloon",
> >     "\064\130\212\209\166\007\028\236\137\067\132\239\066\078\240\172";
> >   "Bell",
> >     "\017\183\096\172\169\146\009\071\065\080\067\231\011\088\184\145";
> >   "Button",
> >     "\228\106\173\140\076\048\063\055\228\010\106\073\000\157\054\103";
> >   "Canvas",
> >     "\018\123\213\204\031\021\012\106\218\240\020\003\047\011\035\087";
> >   "Checkbutton",
> >     "\082\050\250\035\240\200\013\191\168\107\238\089\104\206\068\016";
> >   "Clipboard",
> >     "\090\120\177\182\099\141\025\169\233\251\040\153\164\102\200\130";
> >   "Dialog",
> >     "\215\111\103\076\009\164\108\208\046\222\025\113\144\254\041\203";
> >   "Entry",
> >     "\090\241\159\056\214\250\171\107\145\014\042\143\189\248\093\132";
> >   "Fileevent",
> >     "\213\136\118\001\080\039\117\214\196\120\102\112\248\216\253\214";
> >   "Fileselect",
> >     "\016\042\091\024\048\222\255\072\189\205\042\141\195\173\019\025";
> >   "Focus",
> >     "\079\179\218\046\103\199\007\028\007\246\146\207\009\087\240\231";
> >   "Frame",
> >     "\067\222\053\008\203\055\121\013\189\206\219\142\169\160\211\056";
> >   "Grab",
> >     "\217\048\223\133\044\123\178\056\118\115\241\142\119\238\094\049";
> >   "Grid",
> >     "\123\214\154\096\213\037\019\209\194\242\049\062\059\087\089\127";
> >   "Imagebitmap",
> >     "\205\003\180\038\057\077\191\153\202\132\122\003\161\154\245\180";
> >   "Imagephoto",
> >     "\132\186\156\150\254\168\050\097\146\249\159\173\214\194\163\248";
> >   "Label",
> >     "\030\162\169\108\217\134\207\143\097\007\015\088\009\047\168\112";
> >   "Listbox",
> >     "\255\091\065\145\151\247\020\103\234\034\115\204\014\247\202\243";
> >   "Menu",
> >     "\133\213\100\249\249\029\073\255\154\030\187\015\067\024\214\010";
> >   "Menubutton",
> >     "\215\155\194\167\196\152\066\013\148\035\062\095\181\076\152\042";
> >   "Message",
> >     "\137\228\064\194\061\220\048\156\177\194\193\218\153\105\245\029";
> >   "Option",
> >     "\002\048\023\081\052\014\221\032\078\004\079\127\008\153\241\127";
> >   "Optionmenu",
> >     "\132\032\144\168\045\172\052\110\234\147\145\036\125\098\105\014";
> >   "Pack",
> >     "\007\057\162\105\211\180\208\132\037\061\148\070\011\171\207\128";
> >   "Palette",
> >     "\014\068\206\100\061\249\187\150\248\168\052\127\235\171\003\030";
> >   "Place",
> >     "\074\007\070\132\132\124\203\041\177\117\118\129\064\169\207\006";
> >   "Protocol",
> >     "\044\093\149\050\026\194\067\214\011\224\026\017\085\193\231\100";
> >   "Radiobutton",
> >     "\128\129\131\210\169\194\242\058\141\128\163\033\133\192\094\120";
> >   "Scale",
> >     "\227\078\017\132\154\090\007\086\144\195\166\055\233\180\183\131";
> >   "Scrollbar",
> >     "\177\242\191\174\051\150\159\225\108\101\233\010\112\084\057\216";
> >   "Selection",
> >     "\173\172\218\213\029\036\130\012\033\235\031\238\076\067\219\017";
> >   "Support",
> >     "\159\177\172\212\190\133\232\032\192\082\170\250\049\082\063\184";
> >   "Text",
> >     "\027\143\132\012\023\218\179\073\003\002\081\199\183\010\107\161";
> >   "Textvariable",
> >     "\172\029\217\109\207\144\254\185\068\049\028\090\224\087\177\139";
> >   "Timer",
> >     "\168\141\189\094\081\187\049\026\012\239\025\071\220\014\024\188";
> >   "Tk",
> >     "\155\008\032\103\156\245\158\235\161\052\121\080\091\119\211\242";
> >   "Tkwait",
> >     "\221\238\138\104\160\070\189\107\092\058\048\098\052\137\127\153";
> >   "Toplevel",
> >     "\091\097\016\210\132\101\149\002\036\075\240\001\240\192\132\178";
> >   "Widget",
> >     "\049\215\061\172\124\063\244\113\107\137\123\208\197\169\136\037";
> >   "Winfo",
> >     "\020\023\187\002\192\057\213\009\192\237\092\046\228\130\021\142";
> >   "Wm",
> >     "\169\231\071\215\217\053\030\124\162\209\103\160\145\052\110\120"
> > ]
> > 
> > open Dynlink
> > 
> > let _ =
> >   init ();
> >   add_available_units crc_unit_list;
> >   allow_unsafe_modules true;
> >   try
> >     for i = 1 to Array.length Sys.argv - 1 do
> >       loadfile Sys.argv.(i)
> >     done
> >   with
> >     Error err -> prerr_endline (error_message err)
> >   | exn -> Printexc.catch raise exn
> > -------------------
> > To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr
> > 
> 

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
@ 2001-05-01  1:27 David Gurr
  2001-05-01  2:57 ` Patrick M Doane
  0 siblings, 1 reply; 9+ messages in thread
From: David Gurr @ 2001-05-01  1:27 UTC (permalink / raw)
  To: patrick, garrigue; +Cc: caml-list

Hi,  That is what I though at first.  But I think this is not fully
what he wishes.  Dynlink.add_available_units makes digests available to
the dynlinker but it does not make the persistent structures (cmi's)
available to the compiler in the toplevel environment.  One could argue
that ocmalmktop should embed both the cmo's and their cmi's  in such a
way that the cmi's would be added to the initial env of the custom
toplevel.  -D

> From owner-caml-list@pauillac.inria.fr Mon Apr 30 18:11:29 2001
> From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
> To: patrick@watson.org
> Cc: caml-list@inria.fr
> X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f
> Subject: Re: [Caml-list] ocamlmktop and includes
> Mime-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Date: Tue, 01 May 2001 10:05:37 +0900
> X-Dispatcher: imput version 20000228(IM140)
> 
> From: Patrick M Doane <patrick@watson.org>
> 
> > Alternatively, it would be really nice to make stand-alone byte code
> > interpreters which have the .cmo files builtin.
> 
> If you just need a custome bytecode interpreter, that's not (too)
> difficult.
> The idea is to use the Dynlink module:
> Just build a custom executable, including all the libraries you need,
> and registering the modules you want to use with
> Dynlink.add_available_units. This function takes the unit name, and a
> CRC (in fact a MD5) for the .cmi, which you can get with
> lib/ocaml/extract_crc. This way you don't need neither the .cma nor
> the .cmi's for your libraries.
> The your program will load all .cmo or .cma given on the command line,
> using Dynlink.loadfile.
> I join an exemple of such a bytecode interpreter including plenty of
> libraries. (The CRC's are not up to date)
> 
> Cute, no?
> There is a small pitfall: you can only make available an interface
> when there is an implementation. So if you have pure interfaces (a .cmi
> but no .cmo), you have to copy the the .mli to .ml, and compile it,
> to get an empty implementation matching the .cmi.
> 
> Hope this helps,
> 
> Jacques Garrigue
> 
> (* Link with everything. Compile with:
>    ocamlc -I +labltk -o ocamlloader -linkall dynlink.cma unix.cma dbm.cma \
>        str.cma nums.cma labltk.cma stdclass.cma crcs.ml
>    To get all crcs in one directory:
> 	extract_crc `\ls *.cmi | sed "s/.cmi//" | capitalize`
> *)
> 
> let crc_unit_list = [
>   "Arg",
>     "\132\241\139\095\018\209\141\180\176\082\093\079\208\235\049\083";
>   "Arith_status",
>     "\089\253\033\080\043\135\175\127\166\158\179\030\223\236\054\166";
>   "Array",
>     "\146\022\203\069\253\093\134\037\233\194\070\176\050\248\097\172";
>   "Big_int",
>     "\243\042\214\129\099\114\179\135\162\146\175\227\015\202\143\160";
>   "Callback",
>     "\213\119\018\062\250\024\055\143\129\161\094\222\057\023\146\248";
>   "Char",
>     "\184\168\151\226\206\081\149\197\060\011\054\064\207\150\178\138";
>   "Dbm",
>     "\224\114\137\160\060\165\253\220\099\067\179\255\250\145\095\153";
>   "Digest",
>     "\132\054\239\158\106\045\248\017\082\204\225\229\020\063\091\254";
>   "Dynlink",
>     "\135\180\176\101\073\127\073\073\127\151\142\161\067\053\021\073";
>   "Filename",
>     "\097\078\243\010\046\199\169\212\199\183\242\067\050\043\255\112";
>   "Format",
>     "\255\061\006\074\141\083\248\109\242\099\050\153\088\097\166\055";
>   "Gc",
>     "\089\227\107\050\058\044\003\036\239\188\130\047\116\033\090\028";
>   "Genlex",
>     "\179\252\157\000\199\039\171\234\006\063\191\135\168\067\016\174";
>   "Graphics",
>     "\205\233\013\180\028\114\139\004\004\109\049\042\182\126\001\137";
>   "Hashtbl",
>     "\069\196\160\110\103\090\223\223\129\219\190\170\014\091\012\007";
>   "Lazy",
>     "\079\216\032\236\211\038\005\010\162\001\239\179\109\114\117\147";
>   "Lexing",
>     "\182\088\003\040\254\005\244\149\087\093\237\123\178\173\001\112";
>   "List",
>     "\034\235\035\108\154\120\077\156\180\011\013\141\063\152\055\055";
>   "Map",
>     "\112\213\080\192\236\152\247\119\049\174\106\154\198\248\038\243";
>   "Marshal",
>     "\212\185\081\165\100\136\097\073\164\142\082\147\055\242\088\149";
>   "Nat",
>     "\015\202\018\039\135\054\224\200\222\013\194\080\165\243\250\146";
>   "Num",
>     "\243\243\021\151\036\013\082\157\233\216\151\178\043\006\159\056";
>   "Obj",
>     "\194\237\101\179\047\114\046\161\072\117\212\196\008\083\213\072";
>   "Oformat",
>     "\040\190\172\213\155\053\141\220\205\093\073\042\228\252\159\179";
>   "Ogenlex",
>     "\248\206\017\001\181\044\188\030\052\115\066\169\211\058\231\051";
>   "Ohashtbl",
>     "\211\072\131\214\164\212\100\103\164\246\170\106\196\007\157\180";
>   "Omap",
>     "\052\094\138\008\100\038\194\008\000\094\175\065\019\178\109\103";
>   "Omapping",
>     "\225\081\091\064\046\201\022\178\088\089\230\124\177\109\178\248";
>   "Oo",
>     "\253\246\076\227\151\115\217\141\048\042\155\159\061\051\168\158";
>   "Oqueue",
>     "\147\020\229\095\046\075\213\196\181\031\216\209\074\236\217\075";
>   "Oset",
>     "\056\213\244\036\127\109\042\098\080\098\130\063\120\114\043\084";
>   "Ostack",
>     "\173\008\203\219\123\041\247\255\037\148\016\143\155\023\020\021";
>   "Ostream",
>     "\105\211\112\045\064\001\225\086\221\013\086\221\012\174\011\188";
>   "Parsing",
>     "\238\091\167\164\087\104\115\231\007\133\009\041\001\020\238\217";
>   "Pervasives",
>     "\081\190\153\116\206\164\208\178\173\067\134\249\076\133\233\089";
>   "Printexc",
>     "\068\225\231\087\144\035\057\101\195\150\166\074\076\076\191\093";
>   "Printf",
>     "\114\086\103\091\204\204\191\201\249\027\107\015\067\094\248\184";
>   "Profiling",
>     "\124\209\206\043\202\119\097\026\229\151\251\185\190\080\244\189";
>   "Queue",
>     "\106\035\239\245\185\045\075\131\162\053\038\054\070\007\103\098";
>   "Random",
>     "\225\240\003\163\080\059\165\202\076\018\224\180\160\191\100\140";
>   "Ratio",
>     "\176\030\022\221\242\249\175\107\233\038\141\239\208\245\187\163";
>   "Set",
>     "\241\198\021\016\215\179\209\129\251\204\237\117\232\142\136\012";
>   "Sort",
>     "\042\013\126\242\024\204\017\183\155\004\123\201\200\197\152\248";
>   "Stack",
>     "\035\108\042\081\047\041\088\231\118\222\233\248\184\053\215\118";
>   "Std_exit",
>     "\167\124\048\151\124\056\054\043\214\131\251\242\175\132\166\243";
>   "Str",
>     "\135\231\101\157\048\245\001\093\024\242\163\178\065\016\157\020";
>   "Stream",
>     "\068\127\097\226\098\205\064\112\082\037\105\079\236\126\121\046";
>   "String",
>     "\013\045\050\104\222\055\220\090\092\179\113\181\072\212\082\012";
>   "Sys",
>     "\041\089\246\208\014\005\096\240\061\077\000\157\239\193\241\111";
>   "Topdirs",
>     "\164\224\058\210\062\157\159\029\044\254\058\220\097\244\177\215";
>   "Toploop",
>     "\038\007\001\223\104\189\070\057\057\062\213\241\225\121\132\111";
>   "Unix",
>     "\100\176\025\054\154\219\152\081\252\126\095\147\016\069\153\070";
>   "Weak",
>     "\180\180\008\001\065\221\239\201\173\053\038\214\000\202\187\083";
>   "Balloon",
>     "\064\130\212\209\166\007\028\236\137\067\132\239\066\078\240\172";
>   "Bell",
>     "\017\183\096\172\169\146\009\071\065\080\067\231\011\088\184\145";
>   "Button",
>     "\228\106\173\140\076\048\063\055\228\010\106\073\000\157\054\103";
>   "Canvas",
>     "\018\123\213\204\031\021\012\106\218\240\020\003\047\011\035\087";
>   "Checkbutton",
>     "\082\050\250\035\240\200\013\191\168\107\238\089\104\206\068\016";
>   "Clipboard",
>     "\090\120\177\182\099\141\025\169\233\251\040\153\164\102\200\130";
>   "Dialog",
>     "\215\111\103\076\009\164\108\208\046\222\025\113\144\254\041\203";
>   "Entry",
>     "\090\241\159\056\214\250\171\107\145\014\042\143\189\248\093\132";
>   "Fileevent",
>     "\213\136\118\001\080\039\117\214\196\120\102\112\248\216\253\214";
>   "Fileselect",
>     "\016\042\091\024\048\222\255\072\189\205\042\141\195\173\019\025";
>   "Focus",
>     "\079\179\218\046\103\199\007\028\007\246\146\207\009\087\240\231";
>   "Frame",
>     "\067\222\053\008\203\055\121\013\189\206\219\142\169\160\211\056";
>   "Grab",
>     "\217\048\223\133\044\123\178\056\118\115\241\142\119\238\094\049";
>   "Grid",
>     "\123\214\154\096\213\037\019\209\194\242\049\062\059\087\089\127";
>   "Imagebitmap",
>     "\205\003\180\038\057\077\191\153\202\132\122\003\161\154\245\180";
>   "Imagephoto",
>     "\132\186\156\150\254\168\050\097\146\249\159\173\214\194\163\248";
>   "Label",
>     "\030\162\169\108\217\134\207\143\097\007\015\088\009\047\168\112";
>   "Listbox",
>     "\255\091\065\145\151\247\020\103\234\034\115\204\014\247\202\243";
>   "Menu",
>     "\133\213\100\249\249\029\073\255\154\030\187\015\067\024\214\010";
>   "Menubutton",
>     "\215\155\194\167\196\152\066\013\148\035\062\095\181\076\152\042";
>   "Message",
>     "\137\228\064\194\061\220\048\156\177\194\193\218\153\105\245\029";
>   "Option",
>     "\002\048\023\081\052\014\221\032\078\004\079\127\008\153\241\127";
>   "Optionmenu",
>     "\132\032\144\168\045\172\052\110\234\147\145\036\125\098\105\014";
>   "Pack",
>     "\007\057\162\105\211\180\208\132\037\061\148\070\011\171\207\128";
>   "Palette",
>     "\014\068\206\100\061\249\187\150\248\168\052\127\235\171\003\030";
>   "Place",
>     "\074\007\070\132\132\124\203\041\177\117\118\129\064\169\207\006";
>   "Protocol",
>     "\044\093\149\050\026\194\067\214\011\224\026\017\085\193\231\100";
>   "Radiobutton",
>     "\128\129\131\210\169\194\242\058\141\128\163\033\133\192\094\120";
>   "Scale",
>     "\227\078\017\132\154\090\007\086\144\195\166\055\233\180\183\131";
>   "Scrollbar",
>     "\177\242\191\174\051\150\159\225\108\101\233\010\112\084\057\216";
>   "Selection",
>     "\173\172\218\213\029\036\130\012\033\235\031\238\076\067\219\017";
>   "Support",
>     "\159\177\172\212\190\133\232\032\192\082\170\250\049\082\063\184";
>   "Text",
>     "\027\143\132\012\023\218\179\073\003\002\081\199\183\010\107\161";
>   "Textvariable",
>     "\172\029\217\109\207\144\254\185\068\049\028\090\224\087\177\139";
>   "Timer",
>     "\168\141\189\094\081\187\049\026\012\239\025\071\220\014\024\188";
>   "Tk",
>     "\155\008\032\103\156\245\158\235\161\052\121\080\091\119\211\242";
>   "Tkwait",
>     "\221\238\138\104\160\070\189\107\092\058\048\098\052\137\127\153";
>   "Toplevel",
>     "\091\097\016\210\132\101\149\002\036\075\240\001\240\192\132\178";
>   "Widget",
>     "\049\215\061\172\124\063\244\113\107\137\123\208\197\169\136\037";
>   "Winfo",
>     "\020\023\187\002\192\057\213\009\192\237\092\046\228\130\021\142";
>   "Wm",
>     "\169\231\071\215\217\053\030\124\162\209\103\160\145\052\110\120"
> ]
> 
> open Dynlink
> 
> let _ =
>   init ();
>   add_available_units crc_unit_list;
>   allow_unsafe_modules true;
>   try
>     for i = 1 to Array.length Sys.argv - 1 do
>       loadfile Sys.argv.(i)
>     done
>   with
>     Error err -> prerr_endline (error_message err)
>   | exn -> Printexc.catch raise exn
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr
> 
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-04-29  5:46     ` Chris Hecker
@ 2001-04-29 16:44       ` Patrick M Doane
  0 siblings, 0 replies; 9+ messages in thread
From: Patrick M Doane @ 2001-04-29 16:44 UTC (permalink / raw)
  To: Chris Hecker; +Cc: caml-list

On Sat, 28 Apr 2001, Chris Hecker wrote:

> 
> >My initial expectation was that building a top-level interpreter would
> >link the object files into that interpeter.  That maybe an alternative
> >approach to addressing this issue.
> 
> Yes, but you want both.  You link the .cmos (or .cmas) in, but you also
> need a path to their .cmi files, which is what the include dirs are for. 
> It might be nice if there was some way to also have the .cmi files
> onboard with the toplevel (or in libraries), so it was just all there
> with no need for other stuff.  I'm not going to implement that, though. 
> ;) 

I thought initially the include path was for the .cmo, but I see it is for
the .cmi files now.  I agree that having a mechanism to include the .cmi
files would work out very well.

My goal is to provide a application which can execute Caml source files. 
The source files should have access to some of the modules which are part
of the application. I'm not particularly interested in the interactive
aspect, but I want to make sure that the Caml source files do not need to
be compiled to byte-code before being exeucted.  My top-level application
should have its own command-line options and usage messages which are
separate from those provided by Topmain. 

My current approach to this goes through several layers of indirection:

1) Write my program with code to execute script files similarly to the
approach used in Topmain. 

2) Write a one line Caml script which calls the entry point to my program

3) Build a top-level interpreter using ocamlmktop for my program. 

4) Write a shell-script which calls the top-level interpreter with the
include directories for the .cmi files that I want the scripts to be able
to access and execute the one line Caml script.  All arugments passed to
the shell script are then forwarded to the entry point. 

I think I could remove some of these steps if it were possible to access
the Clflags.include_dirs variable.  The top-level code to execute a script
will only look for .cmi files in that directory. So to get around this, I
source a script in the traditional mechanism which can then source more
scripts.

Any thoughts on a better approach?

Patrick Doane

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-04-28 22:26   ` Patrick M Doane
@ 2001-04-29  5:46     ` Chris Hecker
  2001-04-29 16:44       ` Patrick M Doane
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Hecker @ 2001-04-29  5:46 UTC (permalink / raw)
  To: Patrick M Doane; +Cc: caml-list


>My initial expectation was that building a top-level interpreter would
>link the object files into that interpeter.  That maybe an alternative
>approach to addressing this issue.

Yes, but you want both.  You link the .cmos (or .cmas) in, but you also need a path to their .cmi files, which is what the include dirs are for.  It might be nice if there was some way to also have the .cmi files onboard with the toplevel (or in libraries), so it was just all there with no need for other stuff.  I'm not going to implement that, though.  ;)

Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
  2001-04-28 21:50 ` Chris Hecker
@ 2001-04-28 22:26   ` Patrick M Doane
  2001-04-29  5:46     ` Chris Hecker
  0 siblings, 1 reply; 9+ messages in thread
From: Patrick M Doane @ 2001-04-28 22:26 UTC (permalink / raw)
  To: Chris Hecker; +Cc: caml-list

On Sat, 28 Apr 2001, Chris Hecker wrote:

> 
> >Alternatively, it would be really nice to make stand-alone byte code
> >interpreters which have the .cmo files builtin.
> 
> Do you just mean a standalone executable (with no need for ocamlrun)? 
> If so, use the "-custom" flag to ocamlc and it'll put the intepreter
> inside the output file (and it appears the file is still recognized as a
> bytecode file by ocamlrun, so it's still portable as long as you don't
> link any C objects into it).  Maybe that's not what you meant... 

For some additional context,  I'm trying to create a front-end for
regression testing.  I would like to have a top-level application which
can execute O'caml scripts with an additional module preloaded. It was
pretty easy to use ocamlmktop to build my module into a top-level
interpeter. Unfortunately, the user then has to supply the location of my
module to use it.  I was hoping to provide a single executable that could
be used to run the scripts.

The '-custom' flag might do the trick.  I'm not too worried about
requiring ocamlrun to be on the same machine though.

> Putting the include paths in the generated toplevel sounds like a good
> idea to me.  I decided to implement this.  I've attached the new
> tools/ocamlmktop.ml below.  You should be able to build this by itself
> with "ocamlc -o ocamlmktop ocamlmktop", without building the compiler or
> even having the compiler source installed. 

Ah, very good.  I'll try this out and let you know how it works.

> Random Notes & Issues:
> 
> - I need to build a temp .ml file and compile it, which assumes the
>   ocamlc compiler is around.  Of course, ocamlmktop already assumes
>   this. 

Certainly reasonable.

> - I use Topdirs.dir_directory to add the include directories...I doubt
> it's supposed to be an exposed API. 

I think there is some intent for the toplevel commands to be exposed APIs.
I remember seeing a comment in one of those modules about allowing custom
top-levels to call them.

It would be great for the APIs to be officially documented and supported.
I've had to do a bit of hacking using the toplevel commands to implement
the regression testing.  This includes the need to save/restore an
environment and execute an external script.

> - It expands directories at runtime, so if you add -I +foo it'll work
> even if you move CAMLLIB. 

That's handy!

> - What you probably really want here is a new command line parm so you
>   can differentiate betwen include dirs that should be added to the
>   toplevel and those that shouldn't. 

My initial expectation was that building a top-level interpreter would
link the object files into that interpeter.  That maybe an alternative
approach to addressing this issue.

Thanks for your help,
Patrick

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ocamlmktop and includes
       [not found] <Pine.BSF.3.96.1010428104723.97098B-100000@fledge.watson.or g>
@ 2001-04-28 21:50 ` Chris Hecker
  2001-04-28 22:26   ` Patrick M Doane
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Hecker @ 2001-04-28 21:50 UTC (permalink / raw)
  To: Patrick M Doane, caml-list


>Alternatively, it would be really nice to make stand-alone byte code
>interpreters which have the .cmo files builtin.

Do you just mean a standalone executable (with no need for ocamlrun)?  If so, use the "-custom" flag to ocamlc and it'll put the intepreter inside the output file (and it appears the file is still recognized as a bytecode file by ocamlrun, so it's still portable as long as you don't link any C objects into it).  Maybe that's not what you meant...

Putting the include paths in the generated toplevel sounds like a good idea to me.  I decided to implement this.  I've attached the new tools/ocamlmktop.ml below.  You should be able to build this by itself with "ocamlc -o ocamlmktop ocamlmktop", without building the compiler or even having the compiler source installed.

Random Notes & Issues:

- I need to build a temp .ml file and compile it, which assumes the ocamlc compiler is around.  Of course, ocamlmktop already assumes this.

- Filename.temp_file does not seem safe to me since it doesn't return an open handle, but I'm not a security expert.  I play kind of fast and loose with the temp files.  I create the *.ml file with temp_file, but I don't check for *.cmi or *.cmo before compiling it.  I wouldn't run this setuid root.  :)

- I use Topdirs.dir_directory to add the include directories...I doubt it's supposed to be an exposed API.

- It expands directories at runtime, so if you add -I +foo it'll work even if you move CAMLLIB.

- What you probably really want here is a new command line parm so you can differentiate betwen include dirs that should be added to the toplevel and those that shouldn't.

Let me know if anybody has problems with this.

Chris

------- tools/ocamlmktop.ml --------

(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
(*                                                                     *)
(*  Copyright 1996 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the Q Public License version 1.0.               *)
(*                                                                     *)
(***********************************************************************)

(* $Id: ocamlmktop.ml,v 1.3 1999/11/17 18:58:48 xleroy Exp $ *)

(* stolen from Misc so we don't have to modify the tools/ makefile *)
let remove_file filename =
  try
    Sys.remove filename
  with Sys_error msg ->
    ()
  
let _ =
  let args =
    String.concat " " (List.tl (Array.to_list Sys.argv)) in

  (* capture all the -I include dirs, ignoring everything else *)
  (* I can't use Arg.parse because we don't know all the parms *)
  let dirs = ref [] in
  for i = 1 to Array.length Sys.argv - 1 do
    if Sys.argv.(i) = "-I" then
      dirs := Sys.argv.(i+1) :: !dirs;  (* this throws on ending -I *)
  done;

  (* make a temporary .ml file and have it include the directories *)
  let ml_ext = ".ml" and cmo_ext = ".cmo" and cmi_ext = ".cmi" in
  let tmp_ml = Filename.temp_file "mktopinc" ml_ext in
  let tmp_oc = open_out tmp_ml in
  output_string tmp_oc "let _ = \n";
  output_string tmp_oc "List.iter Topdirs.dir_directory [\n";
  List.iter (fun dir -> output_string tmp_oc
      ("\"" ^ (String.escaped dir) ^ "\"; ")) !dirs;
  output_string tmp_oc "\n]";
  close_out tmp_oc;

  (* compile the temp file *)
  let tmp_root = String.sub tmp_ml 0
      (String.length tmp_ml - String.length ml_ext) in 
  let tmp_cmo = tmp_root ^ cmo_ext in
  let ec = ref (Sys.command ("ocamlc -c " ^ tmp_ml)) in
  if !ec = 0 then
    (* link the new toplevel *)
    ec := Sys.command("ocamlc -linkall toplevellib.cma "
                     ^ args ^ " " ^ tmp_cmo ^ " topmain.cmo");
  remove_file tmp_ml;
  remove_file tmp_cmo;
  remove_file (tmp_root ^ cmi_ext);
  exit !ec
    


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2001-05-01  3:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-28 14:54 [Caml-list] ocamlmktop and includes Patrick M Doane
2001-05-01  1:05 ` Jacques Garrigue
2001-05-01  3:39   ` John Gerard Malecki
     [not found] <Pine.BSF.3.96.1010428104723.97098B-100000@fledge.watson.or g>
2001-04-28 21:50 ` Chris Hecker
2001-04-28 22:26   ` Patrick M Doane
2001-04-29  5:46     ` Chris Hecker
2001-04-29 16:44       ` Patrick M Doane
2001-05-01  1:27 David Gurr
2001-05-01  2:57 ` Patrick M Doane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).