今回は前回に続いて、
Luaインタープリタの導入
Lua言語とは?
Lua言語は、
Lua言語処理系の設計における基本的な思想は、
たとえば、
Lua言語はインタープリタなので、
導入に際して
Luaインタープリタは軽量でポータブルな言語処理系で、
これらのライブラリはPC上の組込みボード用のクロスコンパイラに対してインストールを行い、
readlineの導入
まず、
# ./configure --prefix=/usr/sh3-linux/sh3-linux --host=sh3-linux
--prefixオプションでインストール先を指定し、
コンパイルとインストールは以下のように行います。
# make # make install
インストールはPC上の組込みボード用のクロスコンパイラに対して行いました。
Lua言語処理系はインタープリタなので、
SH7706LSRに共有ライブラリのみインストールするには、
# cd /usr/sh3-linux/sh3-linux/lib # cp -a libhistory.so* [メモリカード]/lib # cp -a libreadline.so* [メモリカード]/lib
ncursesの導入
ここではreadline-6.
コンパイル環境の構築は以下のように行います。
# ./configure --prefix=/usr/sh3-linux/sh3-linux --host=sh3-linux
--prefixオプションでインストール先を指定し、
コンパイルとインストールは以下のようにします。
# make # make install
これで、
Luaの導入
ここではlua-5.
Lua言語処理系のソースコードのコンパイルでは、
トップフォルダではインストール先の指定を行うのでSH3向けクロスコンパイラのフォルダを指定します。トップフォルダのMakefileの書き換えはリスト1のように行います。
01: # makefile for installing Lua
02: # see INSTALL for installation instructions
03: # see src/Makefile and src/luaconf.h for further customization
04:
05: # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
06:
07: # Your platform. See PLATS for possible values.
08: PLAT= none
09:
10: # Where to install. The installation starts in the src and doc directories,
11: # so take care if INSTALL_TOP is not an absolute path.
12: INSTALL_TOP= /usr/sh3-linux/sh3-linux ←変更
13: INSTALL_BIN= $(INSTALL_TOP)/bin
14: INSTALL_INC= $(INSTALL_TOP)/include
15: INSTALL_LIB= $(INSTALL_TOP)/lib
16: INSTALL_MAN= $(INSTALL_TOP)/man/man1
《以下略》
srcフォルダでは使用するコンパイラの指定を行うのでSH3向けクロスコンパイラを指定します。srcフォルダのMakefileの書き換えはリスト2のように行います。
01: # makefile for building Lua
02: # see ../INSTALL for installation instructions
03: # see ../Makefile and luaconf.h for further customization
04:
05: # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
06:
07: # Your platform. See PLATS for possible values.
08: PLAT= none
09:
10: CC= sh3-linux-gcc ← 変更
11: CFLAGS= -O2 -Wall $(MYCFLAGS)
12: AR= sh3-linux-ar rcu ← 変更
13: RANLIB= sh3-linux-ranlib ← 変更
14: RM= rm -f
15: LIBS= -lm $(MYLIBS)
16:
17: MYCFLAGS=
18: MYLDFLAGS=
19: MYLIBS=
コンパイルは以下のように行います。
# make
実行ファイルはLua言語インタープリタであるluaと、
# cp src/lua [メモリカード]/bin # cp src/luac [メモリカード]/bin
Lua言語処理系では、
# make install
実行
Lua言語はC言語よりもどちらかというとPascal言語に近いので、
まず、
01: sum = 0
02: for n = 1,10 do
03: sum = sum + n
04: print(string.format("n=%d sum=%d",n,sum))
05: end
C言語での書式出力であるprintfはそのまま書式出力が可能ですが、
ためしに、
~ # lua sum.lua n=1 sum=1 n=2 sum=3 n=3 sum=6 n=4 sum=10 n=5 sum=15 n=6 sum=21 n=7 sum=28 n=8 sum=36 n=9 sum=45 n=10 sum=55 ~ #
次に、
01: io.write("Input number1:")
02: a = io.read("*n")
03: io.write("Input number2:")
04: b = io.read("*n")
05: if b 06: print(string.format("%d - %d = %d",a,b*(-1),a+b))
07: print(string.format("%d + %d = %d",a,b*(-1),a-b))
08: print(string.format("%d x (%d) = %d",a,b,a*b))
09: else
10: print(string.format("%d + %d = %d",a,b,a+b))
11: print(string.format("%d - %d = %d",a,b,a-b))
12: print(string.format("%d x %d = %d",a,b,a*b))
13: end
ためしに、
~ # lua calc.lua Input number1:23 Input number2:17 23 + 17 = 40 23 - 17 = 6 23 x 17 = 391 ~ #
tclインタープリタの導入
tcl言語の概要
PCではtcl言語はtcl/
tcl言語処理系の設計における基本的な思想は、
多くの言語では演算機能というプリミティブな機能は言語仕様に含まれていますが、
とくに組込みボードでは標準的でないローカルなハードウェア制御を目的とすることが多いので、
tclインタープリタの導入
tclインタープリタは軽量でポータブルな言語処理系で、
tcl言語処理系は言語処理系そのものを極力簡素にして、
また、
ここではtcl-8.
tcl/
最初に以下のように初期設定をします。
# cd unix # export ac_cv_func_strtod=yes # export tcl_cv_strtod_buggy=1
1回目の作業は、
# ./configure --prefix=/usr/sh3-linux/sh3-linux # make # make install # make clean # make distclean
インストールが終わったら、
2回目の作業は、
# ./configure --prefix=[SD Card]/usr # make # make install # make clean # make distclean
ここでもインストールが終わったら、
3回目の作業は、
# ./configure --prefix=/usr/sh3-linux/sh3-linux --host=sh3-linux # make # make install # make clean # make distclean
インストールが終わったソースパッケージ内の作業結果をすべてクリアしておかなければいけません。
4回目の作業はSH7706LSRに対してSH3プロセッサのアーキテクチャでコンパイルのみを以下のように行います。
# ./configure --prefix=/usr --host=sh3-linux # make
SH3プロセッサに依存するものだけ、
# cp libtcl8.5.so [メモリカード]/usr/lib/ # cp tclsh [メモリカード]/bin # cp tclConfig.sh [メモリカード]/usr/lib/
実行
まず、
01: set sum 0
02: for {set n 1} {$n 03: set sum [expr $sum + $n]
04: puts [format "n = %d sum = %d" $n $sum]
05: }
C言語での書式出力であるprintfはそのまま書式出力が可能ですが、
ためしに、
~ # tclsh sum.tcl n = 1 sum = 1 n = 2 sum = 3 n = 3 sum = 6 n = 4 sum = 10 n = 5 sum = 15 n = 6 sum = 21 n = 7 sum = 28 n = 8 sum = 36 n = 9 sum = 45 n = 10 sum = 55 ~ #
次に、
01: puts "Input number1:"
02: scan [gets stdin] %d a
03: puts "Input number2:"
04: scan [gets stdin] %d b
05: if {$b 06: puts [format "%d - %d = %d" $a [expr $b * -1] [expr $a + $b]]
07: puts [format "%d + %d = %d" $a [expr $b * -1] [expr $a - $b]]
08: puts [format "%d x (%d) = %d" $a $b [expr $a * $b]]
09: } else {
10: puts [format "%d + %d = %d" $a $b [expr $a + $b]]
11: puts [format "%d - %d = %d" $a $b [expr $a - $b]]
12: puts [format "%d x %d = %d" $a $b [expr $a * $b]]
13: }
ためしに、
~ # tclsh calc.tcl Input number1: 34 Input number2: 45 34 + 45 = 79 34 - 45 = -11 34 x 45 = 1530 ~ #
次回は
次回は、