git @ Cat's Eye Technologies PL-GOTO.NET / 1f7622f
Add driver for interpreting and compiler. Add tests for compiler. --HG-- rename : demo/compiler-demo.sh => bin/PLexceptGOTOdotNET Cat's Eye Technologies 11 years ago
3 changed file(s) with 106 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/sh
1 # Encoding: UTF-8
2
3 # For now, you can only run this script from the distribution's root directory.
4
5 if [ x"$1" = 'xinterpret' ]; then
6 ghc src/PLexceptGOTOdotNET.lhs -e "runFile \"$2\""
7 elif [ x"$1" = 'xtranslate' ]; then
8 ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >$3
9 elif [ x"$1" = 'xcompile' ]; then
10 ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >tmp.msil
11 ilasm tmp.msil /output:$3 >/dev/null
12 chmod 755 $3
13 rm tmp.msil
14 elif [ x"$1" = 'xrun' ]; then
15 ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >tmp.msil
16 ilasm tmp.msil /output:program.exe >/dev/null
17 chmod 755 program.exe
18 rm tmp.msil
19 ./program.exe
20 rm program.exe
21 else
22 echo <<EOF
23 usage:
24 PLexceptGOTOdotNET interpret file.pl-g
25 --- interpret a PL-{GOTO} program directly
26
27 PLexceptGOTOdotNET translate file.pl-g file.msil
28 --- produce a CIL assembly source from a PL-{GOTO} program
29
30 PLexceptGOTOdotNET compile file.pl-g file.exe
31 --- produce a .NET executable for a PL-{GOTO} program
32
33 PLexceptGOTOdotNET run file.pl-g
34 --- produce a .NET executable for a program, then immediately run it
35
36 EOF
37 exit 2
38 fi
+0
-9
demo/compiler-demo.sh less more
0 #!/bin/sh
1 # Encoding: UTF-8
2
3 # Run this script from the distribution's root directory.
4
5 ghc src/PLexceptGOTOdotNET.lhs -e 'compileFile "eg/example.pl-g"' > example.msil
6 ilasm example.msil /output:example.exe
7 chmod 755 example.exe
8 ./example.exe
3939 | END ← 0; LOOP END; END ← END + 1; END;
4040 = Block [AssignZero "END",Loop 0 "END" (Block [AssignIncr "END" "END"])]
4141
42 Loop Labeling
43 -------------
44
45 -> Tests for functionality "Label PL-{GOTO} Loops"
46
47 -> Functionality "Label PL-{GOTO} Loops" is implemented by
48 -> shell command
49 -> "ghc src/PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
50
51 | n ← 0; m ← 0; LOOP n;
52 | LOOP m;
53 | n ← 0;
54 | END;
55 | END;
56 = (Block [AssignZero "n",AssignZero "m",Loop 1 "n" (Block [Loop 0 "m" (Block [AssignZero "n"])])],2)
57
4258 PL-{GOTO} Evaluation
4359 --------------------
4460
4662
4763 -> Functionality "Evaluate PL-{GOTO} Program" is implemented by
4864 -> shell command
49 -> "ghc src/PLexceptGOTOdotNET.lhs -e "runFile \"%(test-file)\"""
65 -> "bin/PLexceptGOTOdotNET interpret %(test-file)"
5066
5167 | n ← 0;
5268 = [("n",0)]
69
70 | n ← 0; m ← n + 1; n ← m + 1;
71 = [("m",1),("n",2)]
5372
5473 | n ← 0; LOOP n; m ← n; END;
5574 = [("n",0)]
81100 | END;
82101 = [("m",4),("n",1)]
83102
84 Loop Labeling
85 -------------
103 Compiling
104 ---------
86105
87 -> Tests for functionality "Label PL-{GOTO} Loops"
106 -> Tests for functionality "Compile PL-{GOTO} to .NET Executable"
88107
89 -> Functionality "Label PL-{GOTO} Loops" is implemented by
108 -> Functionality "Compile PL-{GOTO} to .NET Executable" is implemented by
90109 -> shell command
91 -> "ghc src/PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
110 -> "bin/PLexceptGOTOdotNET run %(test-file)"
92111
93 | n ← 0; m ← 0; LOOP n;
112 (Ideally we should just re-use the tests above for "PL-{GOTO} Evaluation", but
113 unfortunately the programs produced by the compiler have a different output
114 syntax right now. Also, the compiler puts all variables in the output
115 dictionary, with unassigned variables given the value 0, instead of being not
116 present in the output dictionary.)
117
118 | n ← 0;
119 = n=0
120
121 | n ← 0; m ← n + 1; n ← m + 1;
122 = m=1
123 = n=2
124
125 | n ← 0; LOOP n; m ← n; END;
126 = m=0
127 = n=0
128
129 | n ← 0; n ← n + 1; LOOP n; m ← n; END;
130 = m=1
131 = n=1
132
133 | m ← 0; n ← 0; n ← n + 1; n ← n + 1; LOOP n; m ← m + 1; END;
134 = m=2
135 = n=2
136
137 | n ← 0; n ← n + 1; n ← n + 1; n ← n + 1; n ← n + 1;
138 | m ← 0; k ← 0;
139 | LOOP n;
140 | m ← m + 1;
94141 | LOOP m;
95 | n ← 0;
142 | k ← k + 1;
96143 | END;
97144 | END;
98 = (Block [AssignZero "n",AssignZero "m",Loop 1 "n" (Block [Loop 0 "m" (Block [AssignZero "n"])])],2)
145 = k=10
146 = m=4
147 = n=4
148
149 | n ← 0; n ← n + 1; n ← n + 1; n ← n + 1; n ← n + 1;
150 | m ← 0;
151 | LOOP n;
152 | n ← 0; n ← n + 1;
153 | m ← m + 1;
154 | END;
155 = m=4
156 = n=1