From: Leo Prikler <leo.prikler@student.tugraz.at>
To: 45131@debbugs.gnu.org
Cc: tommi.hoynalanmaa@gmail.com
Subject: bug#45131: [PATCH] Compile directly to target language if no joint is found.
Date: Tue, 29 Dec 2020 19:09:07 +0100 [thread overview]
Message-ID: <20201229180907.28922-1-leo.prikler@student.tugraz.at> (raw)
In-Reply-To: <5d806c0f-4542-71de-f06a-844ea3d79240@gmail.com>
This enables the compilation from "manually" written Tree-IL to
bytecode. See also <https://bugs.gnu.org/45131>.
* system/base/compile.scm (read-and-compile)[(joint #f)]<? eof-object?>:
Join exps using the default joiner for to.
<exp>: Compute compiler for to.
* test-suite/test/compiler.test ("read-and-compile tree-il"): New test.
---
module/system/base/compile.scm | 26 +++++++++++++++-----------
test-suite/tests/compiler.test | 22 ++++++++++++++++++++++
2 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/module/system/base/compile.scm b/module/system/base/compile.scm
index 567765dc0..41ad0158a 100644
--- a/module/system/base/compile.scm
+++ b/module/system/base/compile.scm
@@ -310,16 +310,20 @@
(match (read-and-parse (current-language) port cenv)
((? eof-object?)
(close-port port)
- (compile ((or (language-joiner joint)
- (default-language-joiner joint))
- (reverse exps)
- env)
- #:from joint #:to to
- ;; env can be false if no expressions were read.
- #:env (or env (default-environment joint))
- #:optimization-level optimization-level
- #:warning-level warning-level
- #:opts opts))
+ (if joint
+ (compile ((or (language-joiner joint)
+ (default-language-joiner joint))
+ (reverse exps)
+ env)
+ #:from joint #:to to
+ ;; env can be false if no expressions were read.
+ #:env (or env (default-environment joint))
+ #:optimization-level optimization-level
+ #:warning-level warning-level
+ #:opts opts)
+ ((default-language-joiner to)
+ (reverse exps)
+ env)))
(exp
(let with-compiler ((from from) (compile1 compile1))
(cond
@@ -332,7 +336,7 @@
(let ((from (current-language)))
(with-compiler
from
- (compute-compiler from joint optimization-level
+ (compute-compiler from (or joint to) optimization-level
warning-level opts))))))))))))
(define* (compile x #:key
diff --git a/test-suite/tests/compiler.test b/test-suite/tests/compiler.test
index dc75d0ac7..cdc26c751 100644
--- a/test-suite/tests/compiler.test
+++ b/test-suite/tests/compiler.test
@@ -337,3 +337,25 @@
(pass-if-equal "test terminates without error" 42
(test-proc)))
+(with-test-prefix "read-and-compile tree-il"
+ (let ((code
+ "\
+(seq
+ (define forty-two
+ (lambda ((name . forty-two))
+ (lambda-case ((() #f #f #f () ()) (const 42)))))
+ (toplevel forty-two))")
+ (bytecode #f)
+ (proc #f))
+ (pass-if "compiling tree-il works"
+ (begin
+ (set! bytecode
+ (call-with-input-string code
+ (lambda (port)
+ (read-and-compile port #:from 'tree-il))))
+ #t))
+ (pass-if "bytecode can be read"
+ (begin
+ (set! proc ((load-thunk-from-memory bytecode)))
+ (procedure? proc)))
+ (pass-if-equal "proc executes" 42 (proc))))
--
2.29.2
next prev parent reply other threads:[~2020-12-29 18:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 12:05 bug#45131: guild fails to compile a Tree-IL file Tommi Höynälänmaa
2020-12-29 18:09 ` Leo Prikler [this message]
2021-05-10 8:17 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201229180907.28922-1-leo.prikler@student.tugraz.at \
--to=leo.prikler@student.tugraz.at \
--cc=45131@debbugs.gnu.org \
--cc=tommi.hoynalanmaa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).