From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 86BC582355 for ; Wed, 10 Jan 2018 17:46:30 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=basile@starynkevitch.net; spf=Pass smtp.mailfrom=basile@starynkevitch.net; spf=None smtp.helo=postmaster@ovh.starynkevitch.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of basile@starynkevitch.net) identity=pra; client-ip=46.105.17.220; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="basile@starynkevitch.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of basile@starynkevitch.net designates 46.105.17.220 as permitted sender) identity=mailfrom; client-ip=46.105.17.220; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="basile@starynkevitch.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@ovh.starynkevitch.net) identity=helo; client-ip=46.105.17.220; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="postmaster@ovh.starynkevitch.net"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AEM2azhMhvbaHdWeFQNwl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0I/n/rarrMEGX3/hxlliBBdydt6odzbKO+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1?= =?us-ascii?q?Ov71GonPhMiryuy+4ZLebxlViDanfb9+MAi9oBnMuMURnYZsMLs6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D9eNDZ3CXZyqmLy2/Lm0E4ceMmtGEFGXDXDwd8OEXPoDZTi6KcJlnyYN?= =?us-ascii?q?Ur6sDYQm0Efq/CjRwr9jZs/d+ykZs52r8Nlu+6WHnhg38XlwDt+B+2CLVWB92G?= =?us-ascii?q?0SEWwYxqd69GZ00VaH3OBDn/VCBNpQ6u1ITgw6fcrWxvd7D93aQR7IZMaPS1u4?= =?us-ascii?q?Q8mtAXc3Q85nkIxGWFp0B9j31kOL5CGtGbJA0uXTXMVloJKZ5GD4IoNG81iD0a?= =?us-ascii?q?Agi1c8Rc4WZD+9mqdl5g7QCpDIj06Z0aCnafZFhXKfxCK41WOL+XpgfktoS6yc?= =?us-ascii?q?DCIEekLMvNL6613DU7SuT7IqLlkZkJPQGu5xctTsyG5+arLjNdDZOTnjnHmwQw?= =?us-ascii?q?2Uz6mdaonnZWQB1yWbDkUYwVge?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CaBADWQlZa/9wRaS5eGgEBAQEBAgEBA?= =?us-ascii?q?QEIAQEBAYM+A2YDcSeEB4sYjUofggKHYY9iggIKI4UYAgiEPkMUAQEBAQEBAQE?= =?us-ascii?q?BAWoogjgkAYJHAQUjDwEFCAEBOA8LGAICJgICVwYBDAgBAYozAQuuR26CJ4MKA?= =?us-ascii?q?QEFhygBCwEdCIEPgxGBaiuDaYMFgxgMCwOBOINPgmWZd4lyiAuHZoZHgUhEiSS?= =?us-ascii?q?Ha40hGoEEiGKBOgI2IoFQego9gioJgjwPHIFod4kVK4IgAQEB?= X-IPAS-Result: =?us-ascii?q?A0CaBADWQlZa/9wRaS5eGgEBAQEBAgEBAQEIAQEBAYM+A2Y?= =?us-ascii?q?DcSeEB4sYjUofggKHYY9iggIKI4UYAgiEPkMUAQEBAQEBAQEBAWoogjgkAYJHA?= =?us-ascii?q?QUjDwEFCAEBOA8LGAICJgICVwYBDAgBAYozAQuuR26CJ4MKAQEFhygBCwEdCIE?= =?us-ascii?q?PgxGBaiuDaYMFgxgMCwOBOINPgmWZd4lyiAuHZoZHgUhEiSSHa40hGoEEiGKBO?= =?us-ascii?q?gI2IoFQego9gioJgjwPHIFod4kVK4IgAQEB?= X-IronPort-AV: E=Sophos;i="5.46,341,1511823600"; d="scan'208";a="308484933" Received: from ovh.starynkevitch.net ([46.105.17.220]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2018 17:46:29 +0100 Received: from ovh.starynkevitch.net (localhost [127.0.0.1]) by ovh.starynkevitch.net (Postfix) with ESMTP id 33244A0207 for ; Wed, 10 Jan 2018 17:46:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= starynkevitch.net; h=content-language:content-transfer-encoding :content-type:content-type:in-reply-to:mime-version:user-agent :date:date:message-id:from:from:references:to:subject:subject; s=dkim; t=1515602782; x=1516466783; bh=DaYATxmKtfSpM/J5RpRxkJVh RtsW4iD7iF/8Kj1cBZo=; b=XyEvX7ToaoKrDmREZCKEMqrxCOpwFgZXN7L/dz+G 1x8HCtRqHZBIS5+Bw6DHTzBybWW8aFRzt2nrViKO4T0OL8uBSUoe+Ll+LIFfWSWb Il0JUdHwSggL105YO4LoVNBy7Jd8Jqrttp7FkLgt2JSxVzFX9pNj9rMCtenkD8us A+U= X-Virus-Scanned: Debian amavisd-new at ovh.starynkevitch.net Received: from ovh.starynkevitch.net ([127.0.0.1]) by ovh.starynkevitch.net (ovh.starynkevitch.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CwEf4Y3oFIO9 for ; Wed, 10 Jan 2018 17:46:22 +0100 (CET) Received: from [192.168.1.2] (LStLambert-656-1-266-187.w193-248.abo.wanadoo.fr [193.248.54.187]) by ovh.starynkevitch.net (Postfix) with ESMTPSA id 79A27A01F9; Wed, 10 Jan 2018 17:46:22 +0100 (CET) To: =?UTF-8?Q?Christoph_H=c3=b6ger?= , OCaml Mailing List References: From: Basile Starynkevitch Message-ID: <24887eea-d5d3-21f8-bc1e-2e23af47cccd@starynkevitch.net> Date: Wed, 10 Jan 2018 17:46:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [Caml-list] In-memory assembly On 01/10/2018 11:20 AM, Christoph Höger wrote: > Dear all, > > I want to trigger OCaml compilation programmatically from a C++ > application and avoid the usage of subprocesses. It is fairly > straightforward to generate an OCaml AST, but I cannot compile it. You should explain what kind and size is the generated code, and why do you want to avoid the usage of subprocesses. My impression is that you should not be afraid of using subprocesses and temporary files. Some hints and feelings (which I did not got from generating Ocaml code, but C code, in my past http://starynkevitch.net/Basile/gcc-melt/ project) Generating Ocaml code is a good idea (I am very fond of metaprogramming in general). Perhaps you should into MetaOcaml (see http://okmij.org/ftp/ML/MetaOCaml.html for more) I'm guessing you might generate a non-tiny amount of Ocaml code, and since you want to use the native Ocaml compiler, that code will run for a non-short period of time. Notice that if both assumptions are false (tiny amount of generated code, running for a short period of time) you'll be happy by embedding the Ocaml bytecompiler in your C++ application (and there is no real point in using the native Ocaml compiler), which I believe is a solved problem. So, I am assuming you generate a non-small Ocaml file (e.g. a thousand lines), and it runs for a non-tiny amount of time (e.g. at least half a second, or perhaps 0.1 second). Then you probably want to ask your ocamlopt compiler to optimize, e.g. with its -O2 flag. This probably takes a few tenths of seconds (on a file of a few thousand lines of Ocaml), or more. That delay (even 0.1 seconds of compilation time by ocaml) is long enough to make the usage of subprocesses insignificant: a modern system can run hundreds of processes every second. If you care about filesystem delays (which are not that important), consider putting the generated Ocaml source code on some fast filesystem, e.g. some tmpfs on Linux. Cleaning up temporary files and running short processes from C++ code is a solved problem (and a very common practice). Cheers. Basile STARYNKEVITCH == http://starynkevitch.net/Basile opinions are mine only - les opinions sont seulement miennes Bourg La Reine, France