From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Vladimir Zhbanov Newsgroups: gmane.lisp.guile.user Subject: Re: primitive eval with module => Unbound variable? Date: Wed, 17 May 2017 20:58:42 +0300 Message-ID: <20170517175842.GA15012@localhost.localdomain> References: <87ziec4g62.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: blaine.gmane.org 1495043956 17456 195.159.176.226 (17 May 2017 17:59:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 17:59:16 +0000 (UTC) User-Agent: Mutt/1.5.23 (2014-03-12) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed May 17 19:59:08 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dB3E4-0004OS-2U for guile-user@m.gmane.org; Wed, 17 May 2017 19:59:08 +0200 Original-Received: from localhost ([::1]:50196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB3E9-0004NZ-Fg for guile-user@m.gmane.org; Wed, 17 May 2017 13:59:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB3Do-0004NU-Pe for guile-user@gnu.org; Wed, 17 May 2017 13:58:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB3Dj-0007ao-Tm for guile-user@gnu.org; Wed, 17 May 2017 13:58:52 -0400 Original-Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:36364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB3Dj-0007aV-LD for guile-user@gnu.org; Wed, 17 May 2017 13:58:47 -0400 Original-Received: by mail-wm0-x22b.google.com with SMTP id 70so19239493wmq.1 for ; Wed, 17 May 2017 10:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=V5l5F0XOUokkiBVYpVPKDoWwMzhiXqZcI1qJxdzNiB8=; b=ssCWjbP+kn5M422p+SntIeDPa5awD0dFZpD7XFucdoEUevUzYpdw0Z8Rcqw92WJHeP uWO6wk83Qry4keSlR2AzW42dbp6c2B3PuJ1IsGhW88FfPToyYRptbCdDm3/ACHSVKJSb 3r5lBor5Ak55Ax/eGO7zI0gRg63+Mevl1/LLDVepAkGYUuHH4xxkxnVbWBmFRbsa79PR w2CKeCl0u3hvVjs8iuRdufiyiKIBjoIzPIxTwhrxaaRnBlviPO2qA6FtVI0b6Cch+9Vf B/RhnaM75v/PS9l62RUhWLsVYd7IY4vFEr/Alvmfbzh7egcX7qhIEFX7BPwa3owReaXW 6WgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=V5l5F0XOUokkiBVYpVPKDoWwMzhiXqZcI1qJxdzNiB8=; b=O9KHGPeif7UbK/yGWWOoDSm4WSQmeKiNwGVCGUMN9HJ34+gAHhJ+JkMmTT9lKRuj3A 49w2DyxSsfzxweDFYYn3Mob6WRWj8Dy30OGUtgy1rJ35kTS9pWL1JYFJiy6FlPTrNAPE L6QFzIXsWZBitvhf8kxCYYmgpT53esCXiQPrUtJ6tM1kQ6VfgWDi0pcWWhINiMYw7/pd GIH/ngKn7dc9Bj3ElyfMLN0cvfHmLrKBJELzGlZWLeik6FuBQCmQtaPVrgDHe9F+2tNw sjlLUdl0ybz3eqgbjcRokCXusyQfOQggM/mJJLtcdFjlXGfQJ90T1UKgEloStQJ9bxaD BsTA== X-Gm-Message-State: AODbwcA7CMS0BgdS6NzAHr4XTB1fVfI9McW/dbgzDBbtZq/SpjtVtcVt N8+8bKNKN/vnu09Y X-Received: by 10.25.72.66 with SMTP id v63mr4690lfa.124.1495043925872; Wed, 17 May 2017 10:58:45 -0700 (PDT) Original-Received: from newvzh.vzh ([213.24.126.113]) by smtp.gmail.com with ESMTPSA id g70sm499080ljb.14.2017.05.17.10.58.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 10:58:45 -0700 (PDT) Original-Received: from vovka by newvzh.vzh with local (Exim 4.84_2) (envelope-from ) id 1dB3De-0003SX-KB for guile-user@gnu.org; Wed, 17 May 2017 20:58:42 +0300 Mail-Followup-To: guile-user@gnu.org Content-Disposition: inline In-Reply-To: <87ziec4g62.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22b X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13723 Archived-At: On Tue, May 16, 2017 at 11:59:01PM +0200, Jan Nieuwenhuizen wrote: > Hi! > > My Mescc C compiler produces from C > > int main () {return 0;} > > a list of functions (lambdas), that are called with text-address, > data-address, globals, functions to produce lists of x86 instructions: > > # > => (85 137 229 131 236 64) > # > => (184 0 0 0 0) > # > => (80) > # > ... > > I hoped to instead produce intermediate results in a sexp that can be > written to file (like .o object files). So instead of evaluating > the lambdas, I tried quoting them to now produce > > ==> > > (lambda (f g ta t d) (list 85 137 229 131 236 64)) > (lambda (f g ta t d) (list 184 0 0 0 0)) > (lambda (f g ta t d) (list 80)) > (lambda (f g ta t d) (i386:push-global-address (+ (data-offset "s:scaffold/mesmes" g) d))) > ... > > and primitive-eval and run them later.... However, when I do this, > i386:push-global-address is an Unbound variable. Here's a small test > that demonstrates my problem > > --8<---------------cut here---------------start------------->8--- > ;; this works without define-module: > ;; guile -e 'main' -s foo.scm > > ;; uncomment define-module below and run: > ;; guile -e '(@ (foo) main)' -s foo.scm > ;; => ERROR: Unbound variable: bar > ;; (define-module (foo) #:export (main)) > > (define (bar) (display "bar!!!\n")) > > (define foo '(lambda (x) (bar))) > > (define (main . rest) > (let () > (format (current-error-port) "eval: foo=~s\n" foo) > (let ((x (primitive-eval foo))) > (format (current-error-port) " =>~s\n" x) > (x 0)))) > --8<---------------cut here---------------end--------------->8--- > > This code works when not put in a module; make it a module and I get > > => ERROR: Unbound variable: bar > > What should I be doing differently? > I've found two working variants: First: --------------------------------8<-------------------------------- (define-module (foo) #:export (main)) ; this is as is ... (define foo '(lambda (x) ((@@ (foo) bar)))) ... -------------------------------->8-------------------------------- Second: --------------------------------8<-------------------------------- (define-module (foo) #:export (main bar)) ; export bar ... (define foo '(lambda (x) ((@ (foo) bar)))) ... -------------------------------->8-------------------------------- It seems bar is not exported when guile tries to eval (compile?) the code. Should it compile it here? -- Vladimir