fu7mu4’s diary

はてなダイアリーから移転しました。

eclで遊んでみた。

eclで cとhがつくれるらしいので。やってみた。

(defconstant lower 0)
(defconstant upper 300)
(defconstant step 30)

(defun main()
  (do ((fahr lower (+ fahr step)))
      ((> fahr upper) 'done)
    (format t "~3D ~6,1,,,' F ~%"
	    fahr
	    (float (* 5/9 (- fahr 32))))))

(main)
(quit)

を fah.lispで保存して

ecl

起動してから

(compile-file "fah.lisp" :c-file "fah.c" :h-file "fah.h" :system-p t)

したら、

;;;/usr/bin/gcc-4.2 -I. -I/opt/local/include/ -I/opt/local/include -pipe -O2 -arch x86_64 -fPIC -fno-common -Ddarwin -O2 -w -c test.c -o fahr2cels.o 
;;; Finished compiling fahr2cels.lisp.
;;;
;;;
#P"/Users/******/Documents/fahr2cels.o"
NIL
NIL

とでてたこれで、できたcのファイルを見てみよう

/*	Compiler: ECL 11.1.1                                          */
/*	Date: 2011/12/27 00:03 (yyyy/mm/dd)                           */
/*	Machine: Darwin 10.8.0 i386                                   */
/*	Source: fahr2cels.lisp                                        */
#include <ecl/ecl-cmp.h>
#include "test.h"
/*	function definition for MAIN                                  */
/*	optimize speed 3, debug 0, space 0, safety 2                  */
static cl_object L1main()
{ VT2 VLEX2 CLSR2 STCK2
	const cl_env_ptr cl_env_copy = ecl_process_env();
	cl_object value0;
	ecl_cs_check(cl_env_copy,value0);
	{
TTL:
	{cl_object V1;                            /*  FAHR            */
	V1= MAKE_FIXNUM(0);
	goto L5;
L4:;
	T0= ecl_minus(V1,MAKE_FIXNUM(32));
	T1= ecl_times(VV[2],T0);
	T2= cl_float(1,T1)                        /*  FLOAT           */;
	(void)cl_format(4,Ct,_ecl_static_0,V1,T2) /*  FORMAT          */;
	V1= ecl_plus(V1,MAKE_FIXNUM(30));
L5:;
	if(ecl_number_compare(V1,MAKE_FIXNUM(300))>0){
	goto L12;}
	goto L4;
L12:;
	goto L10;
L10:;
	goto L2;
L2:;
	value0=VV[3]; cl_env_copy->nvalues=1;
	return value0;
	}
}}
	
#include "fahr2cels.data"
#ifdef __cplusplus
extern "C"
#endif
ECL_DLLEXPORT void _eclO8OVNDxQ4HD2X_wPuSPD01(cl_object flag)
{ VT1 VLEX1 CLSR1 STCK1
	const cl_env_ptr cl_env_copy = ecl_process_env();
	cl_object value0;
	cl_object *VVtemp;
	if (!FIXNUMP(flag)){
	Cblock=flag;
	#ifndef ECL_DYNAMIC_VV
	flag->cblock.data = VV;
	#endif
	flag->cblock.data_size = VM;
	flag->cblock.temp_data_size = VMtemp;
	flag->cblock.data_text = compiler_data_text;
	flag->cblock.data_text_size = compiler_data_text_size;
	flag->cblock.cfuns_size = compiler_cfuns_size;
	flag->cblock.cfuns = compiler_cfuns;
	flag->cblock.source = make_constant_base_string("/Users/******/Documents/fahr2cels.lisp");
	return;}
	#ifdef ECL_DYNAMIC_VV
	VV = Cblock->cblock.data;
	#endif
	Cblock->cblock.data_text = "@EcLtAg:_eclO8OVNDxQ4HD2X_wPuSPD01@";
	VVtemp = Cblock->cblock.temp_data;
	(void)si_Xmake_constant(VV[0],MAKE_FIXNUM(0)) /*  *MAKE-CONSTANT */;
	(void)si_Xmake_constant(VV[1],MAKE_FIXNUM(300)) /*  *MAKE-CONSTANT */;
	(void)si_Xmake_constant(ECL_SYM("STEP",794),MAKE_FIXNUM(30)) /*  *MAKE-CONSTANT */;
	ecl_cmp_defun(VV[5]);
	(void)L1main()                            /*  MAIN            */;
	(void)si_quit(0)                          /*  QUIT            */;
}
#ifdef ECL_DYNAMIC_VV
static cl_object *VV;
#else
static cl_object VV[VM];
#endif

#ifdef __cplusplus
extern "C" {
#endif
static cl_object L1main();
#define VT2 cl_object T0,T1,T2;
#define VLEX2
#define CLSR2
#define STCK2
#define VT1
#define VLEX1
#define CLSR1
#define STCK1
static cl_object Cblock;
#define VM1 0
#define VM2 3
#define VM 6
#define VMtemp 0
#ifdef __cplusplus
}
#endif
/*
 * Statically defined constants
 */
ecl_def_ct_base_string(_ecl_static_0,"~3D ~6,1,,,' F ~%",17,static,const);
/*
 * Exported Lisp functions
 */
#define compiler_cfuns_size 1
static const struct ecl_cfun compiler_cfuns[] = {
 /*t,m,narg,padding,name,block,entry*/
{0,0,0,0,MAKE_FIXNUM(5),MAKE_FIXNUM(4),(cl_objectfn)L1main,Cnil,MAKE_FIXNUM(67)},
};

でも(c:build-program "a.out" :lisp-files '("fahr2cels.o"))したらちゃんとa.outが作成される。

うーん。