Commits

Anonymous committed d9a659f

Add driver for interpreting and compiler. Add tests for compiler.

  • Participants
  • Parent commits ea84076

Comments (0)

Files changed (3)

bin/PLexceptGOTOdotNET

+#!/bin/sh
+# Encoding: UTF-8
+
+# For now, you can only run this script from the distribution's root directory.
+
+if [ x"$1" = 'xinterpret' ]; then
+    ghc src/PLexceptGOTOdotNET.lhs -e "runFile \"$2\""
+elif [ x"$1" = 'xtranslate' ]; then
+    ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >$3
+elif [ x"$1" = 'xcompile' ]; then
+    ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >tmp.msil
+    ilasm tmp.msil /output:$3 >/dev/null
+    chmod 755 $3
+    rm tmp.msil
+elif [ x"$1" = 'xrun' ]; then
+    ghc src/PLexceptGOTOdotNET.lhs -e "compileFile \"$2\"" >tmp.msil
+    ilasm tmp.msil /output:program.exe >/dev/null
+    chmod 755 program.exe
+    rm tmp.msil
+    ./program.exe
+    rm program.exe
+else
+    echo <<EOF
+usage:
+    PLexceptGOTOdotNET interpret file.pl-g
+    --- interpret a PL-{GOTO} program directly
+
+    PLexceptGOTOdotNET translate file.pl-g file.msil
+    --- produce a CIL assembly source from a PL-{GOTO} program
+
+    PLexceptGOTOdotNET compile file.pl-g file.exe
+    --- produce a .NET executable for a PL-{GOTO} program
+
+    PLexceptGOTOdotNET run file.pl-g
+    --- produce a .NET executable for a program, then immediately run it
+
+EOF
+    exit 2
+fi

demo/compiler-demo.sh

-#!/bin/sh
-# Encoding: UTF-8
-
-# Run this script from the distribution's root directory.
-
-ghc src/PLexceptGOTOdotNET.lhs -e 'compileFile "eg/example.pl-g"' > example.msil
-ilasm example.msil /output:example.exe
-chmod 755 example.exe
-./example.exe

tests/PLexceptGOTOdotNET.markdown

     | END ← 0; LOOP END; END ← END + 1; END;
     = Block [AssignZero "END",Loop 0 "END" (Block [AssignIncr "END" "END"])]
 
+Loop Labeling
+-------------
+
+    -> Tests for functionality "Label PL-{GOTO} Loops"
+
+    -> Functionality "Label PL-{GOTO} Loops" is implemented by
+    -> shell command
+    -> "ghc src/PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
+
+    | n ← 0; m ← 0; LOOP n;
+    |     LOOP m;
+    |         n ← 0; 
+    |     END;
+    | END;
+    = (Block [AssignZero "n",AssignZero "m",Loop 1 "n" (Block [Loop 0 "m" (Block [AssignZero "n"])])],2)
+
 PL-{GOTO} Evaluation
 --------------------
 
 
     -> Functionality "Evaluate PL-{GOTO} Program" is implemented by
     -> shell command
-    -> "ghc src/PLexceptGOTOdotNET.lhs -e "runFile \"%(test-file)\"""
+    -> "bin/PLexceptGOTOdotNET interpret %(test-file)"
 
     | n ← 0;
     = [("n",0)]
 
+    | n ← 0; m ← n + 1; n ← m + 1;
+    = [("m",1),("n",2)]
+
     | n ← 0; LOOP n; m ← n; END;
     = [("n",0)]
 
     | END;
     = [("m",4),("n",1)]
 
-Loop Labeling
--------------
+Compiling
+---------
 
-    -> Tests for functionality "Label PL-{GOTO} Loops"
+    -> Tests for functionality "Compile PL-{GOTO} to .NET Executable"
 
-    -> Functionality "Label PL-{GOTO} Loops" is implemented by
+    -> Functionality "Compile PL-{GOTO} to .NET Executable" is implemented by
     -> shell command
-    -> "ghc src/PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
+    -> "bin/PLexceptGOTOdotNET run %(test-file)"
 
-    | n ← 0; m ← 0; LOOP n;
+(Ideally we should just re-use the tests above for "PL-{GOTO} Evaluation", but
+unfortunately the programs produced by the compiler have a different output
+syntax right now.  Also, the compiler puts all variables in the output
+dictionary, with unassigned variables given the value 0, instead of being not
+present in the output dictionary.)
+
+    | n ← 0;
+    = n=0
+
+    | n ← 0; m ← n + 1; n ← m + 1;
+    = m=1
+    = n=2
+
+    | n ← 0; LOOP n; m ← n; END;
+    = m=0
+    = n=0
+
+    | n ← 0; n ← n + 1; LOOP n; m ← n; END;
+    = m=1
+    = n=1
+
+    | m ← 0; n ← 0; n ← n + 1; n ← n + 1; LOOP n; m ← m + 1; END;
+    = m=2
+    = n=2
+
+    | n ← 0; n ← n + 1; n ← n + 1; n ← n + 1; n ← n + 1;
+    | m ← 0; k ← 0;
+    | LOOP n;
+    |     m ← m + 1;
     |     LOOP m;
-    |         n0; 
+    |         kk + 1;
     |     END;
     | END;
-    = (Block [AssignZero "n",AssignZero "m",Loop 1 "n" (Block [Loop 0 "m" (Block [AssignZero "n"])])],2)
+    = k=10
+    = m=4
+    = n=4
+
+    | n ← 0; n ← n + 1; n ← n + 1; n ← n + 1; n ← n + 1;
+    | m ← 0;
+    | LOOP n;
+    |     n ← 0; n ← n + 1;
+    |     m ← m + 1;
+    | END;
+    = m=4
+    = n=1