Make a host version of acc for testing.

Don't run the code we've compiled unless the -R option is present.
diff --git a/libacc/Android.mk b/libacc/Android.mk
index 923de60..f3c2d35 100644
--- a/libacc/Android.mk
+++ b/libacc/Android.mk
@@ -1,9 +1,8 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
-#
-# Shared library
-#
+# Shared library for target
+# ========================================================
 
 LOCAL_MODULE:= libacc
 LOCAL_SRC_FILES := acc.cpp
@@ -16,4 +15,23 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
-include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
+# Shared library for host
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:= libacc
+LOCAL_SRC_FILES := acc.cpp
+
+ifeq ($(TARGET_ARCH),arm)
+LOCAL_SRC_FILES += disassem.cpp
+endif
+
+LOCAL_STATIC_LIBRARIES := libcutils
+LOCAL_LDLIBS := -ldl
+
+include $(BUILD_HOST_SHARED_LIBRARY)
+
+# Build children
+# ========================================================
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index a3a70d1..db37ee2 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1087,26 +1087,6 @@
         size_t mPosition;
     };
 
-    int ch; // Current input character, or EOF
-    intptr_t tok;     // token
-    intptr_t tokc;    // token extra info
-    int tokl;         // token operator level
-    intptr_t rsym; // return symbol
-    intptr_t loc; // local variable index
-    char* glo;  // global variable index
-    char* sym_stk;
-    char* dstk; // Define stack
-    char* dptr; // Macro state: Points to macro text during macro playback.
-    int dch;    // Macro state: Saves old value of ch during a macro playback.
-    char* last_id;
-    char* pGlobalBase;
-    char* pVarsBase; // Value of variables
-
-    InputStream* file;
-
-    CodeBuf codeBuf;
-    CodeGenerator* pGen;
-
     class String {
     public:
         String() {
@@ -1306,6 +1286,8 @@
         void pop() {
             if (mUsed > 0) {
                 mUsed -= 1;
+            } else {
+                error("internal error: Popped empty stack.");
             }
         }
 
@@ -1338,7 +1320,34 @@
         size_t mSize;
     };
 
+    struct InputState {
+        InputStream* pStream;
+        int oldCh;
+    };
+
+
+    int ch; // Current input character, or EOF
+    intptr_t tok;     // token
+    intptr_t tokc;    // token extra info
+    int tokl;         // token operator level
+    intptr_t rsym; // return symbol
+    intptr_t loc; // local variable index
+    char* glo;  // global variable index
+    char* sym_stk;
+    char* dstk; // Define stack
+    char* dptr; // Macro state: Points to macro text during macro playback.
+    int dch;    // Macro state: Saves old value of ch during a macro playback.
+    char* last_id;
+    char* pGlobalBase;
+    char* pVarsBase; // Value of variables
+
+    InputStream* file;
+
+    CodeBuf codeBuf;
+    CodeGenerator* pGen;
+
     MacroTable mMacros;
+    Array<InputState> mInputStateStack;
 
     String mErrorBuf;
 
diff --git a/libacc/tests/Android.mk b/libacc/tests/Android.mk
index 2cff9d3..1e4d328 100644
--- a/libacc/tests/Android.mk
+++ b/libacc/tests/Android.mk
@@ -1,5 +1,9 @@
 LOCAL_PATH:= $(call my-dir)
+
+# Executable for host
+# ========================================================
 include $(CLEAR_VARS)
+LOCAL_MODULE:= acc
 
 LOCAL_SRC_FILES:= \
 	main.cpp
@@ -7,9 +11,22 @@
 LOCAL_SHARED_LIBRARIES := \
     libacc
 
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_HOST_EXECUTABLE)
+
+# Executable for target
+# ========================================================
+include $(CLEAR_VARS)
 LOCAL_MODULE:= acc
 
+LOCAL_SRC_FILES:= \
+	main.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+    libacc
+
+
 LOCAL_MODULE_TAGS := tests
 
-include $(BUILD_EXECUTABLE)
-
+include $(BUILD_EXECUTABLE)
\ No newline at end of file
diff --git a/libacc/tests/data/returnval-ansi.c b/libacc/tests/data/returnval-ansi.c
index 42802c5..e386009 100644
--- a/libacc/tests/data/returnval-ansi.c
+++ b/libacc/tests/data/returnval-ansi.c
@@ -1,7 +1,10 @@
+#define VALUE (2*FOO)
+#define FOO 12
+
 int main(int argc, char** argv) {
   return f();
 }
 
 int f() {
-    return 10;
+    return VALUE;
 }
diff --git a/libacc/tests/main.cpp b/libacc/tests/main.cpp
index acee09d..d624cbb 100644
--- a/libacc/tests/main.cpp
+++ b/libacc/tests/main.cpp
@@ -32,6 +32,7 @@
 int main(int argc, char** argv) {
     const char* inFile = NULL;
     bool printListing;
+    bool runResults = false;
     FILE* in = stdin;
     int i;
     for (i = 1; i < argc; i++) {
@@ -41,6 +42,9 @@
                 case 'S':
                     printListing = true;
                     break;
+                case 'R':
+                    runResults = true;
+                    break;
             default:
                 fprintf(stderr, "Unrecognized flag %s\n", arg);
                 return 3;
@@ -108,7 +112,7 @@
     accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
 
     result = accGetError(script);
-    if (result == ACC_NO_ERROR) {
+    if (result == ACC_NO_ERROR && runResults) {
         fprintf(stderr, "Executing compiled code:\n");
         int codeArgc = argc - i + 1;
         char** codeArgv = argv + i - 1;
diff --git a/libacc/tests/testarm b/libacc/tests/testarm
index 24fbc42..1d4b866 100755
--- a/libacc/tests/testarm
+++ b/libacc/tests/testarm
@@ -6,4 +6,4 @@
 mm -j8
 cd tests
 adb sync
-adb shell /system/bin/acc -S /system/bin/returnval-ansi.c
+adb shell /system/bin/acc -R -S /system/bin/returnval-ansi.c
diff --git a/libacc/tests/testlocal b/libacc/tests/testlocal
index ccabf7d..2989e11 100755
--- a/libacc/tests/testlocal
+++ b/libacc/tests/testlocal
@@ -1,17 +1,18 @@
-#!/bin/sh
-rm -f test-acc
-cd ..
-g++ -I../include acc.cpp disassem.cpp tests/main.cpp -g -ldl -o tests/test-acc
-cd tests
-if [ -x "test-acc" ]; then
-  ./test-acc -S data/returnval-ansi.c
+#!/bin/bash
 
-  if [ "$(uname)" = "Linux" ]; then
-    if [ "$(uname -m)" = "i686" ]; then
-      echo "Linux i686. Testing otcc-ansi.c"
-      ./test-acc data/otcc-ansi.c data/returnval.c
-      echo "Linux i686. Testing otcc-ansi.c data/otcc.c"
-      ./test-acc data/otcc-ansi.c data/otcc.c data/returnval.c
-    fi
-  fi
+SCRIPT_DIR=`dirname $BASH_SOURCE`
+DATA=$SCRIPT_DIR/data
+
+echo "Compiling returnval-ansi.c"
+acc -S $DATA/returnval-ansi.c
+
+echo "Compiling whole compiler."
+acc -S "$DATA/otcc-ansi.c"
+
+if (( "$(uname)" = "Linux" )) && (( "$(uname -m)" = "i686" )); then
+	echo "Linux i686. Testing otcc-ansi.c"
+	acc -R "$DATA/otcc-ansi.c" "$DATA/returnval.c"
+	acc -R $DATA/otcc-ansi.c $DATA/otcc.c $DATA/returnval.c
 fi
+
+echo "Done with tests."