Compile int and string literals to byte code

--
MOS_MIGRATED_REVID=107227795
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/IntegerLiteral.java b/src/main/java/com/google/devtools/build/lib/syntax/IntegerLiteral.java
index be9ce53..942f337 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/IntegerLiteral.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/IntegerLiteral.java
@@ -13,6 +13,13 @@
 // limitations under the License.
 package com.google.devtools.build.lib.syntax;
 
+import com.google.devtools.build.lib.syntax.compiler.ByteCodeMethodCalls;
+import com.google.devtools.build.lib.syntax.compiler.DebugInfo;
+import com.google.devtools.build.lib.syntax.compiler.VariableScope;
+
+import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
+import net.bytebuddy.implementation.bytecode.constant.IntegerConstant;
+
 /**
  * Syntax node for an integer literal.
  */
@@ -30,4 +37,11 @@
   @Override
   void validate(ValidationEnvironment env) throws EvalException {
   }
+
+  @Override
+  ByteCodeAppender compile(VariableScope scope, DebugInfo debugInfo) {
+    return new ByteCodeAppender.Simple(
+        IntegerConstant.forValue(value),
+        ByteCodeMethodCalls.BCInteger.valueOf);
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java b/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
index b2526a0..cd21c1e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StringLiteral.java
@@ -13,6 +13,12 @@
 // limitations under the License.
 package com.google.devtools.build.lib.syntax;
 
+import com.google.devtools.build.lib.syntax.compiler.DebugInfo;
+import com.google.devtools.build.lib.syntax.compiler.VariableScope;
+
+import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
+import net.bytebuddy.implementation.bytecode.constant.TextConstant;
+
 /**
  * Syntax node for a string literal.
  */
@@ -48,4 +54,9 @@
   @Override
   void validate(ValidationEnvironment env) throws EvalException {
   }
+
+  @Override
+  ByteCodeAppender compile(VariableScope scope, DebugInfo debugInfo) {
+    return new ByteCodeAppender.Simple(new TextConstant(value));
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/compiler/ByteCodeMethodCalls.java b/src/main/java/com/google/devtools/build/lib/syntax/compiler/ByteCodeMethodCalls.java
new file mode 100644
index 0000000..b93fe38
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/syntax/compiler/ByteCodeMethodCalls.java
@@ -0,0 +1,35 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.syntax.compiler;
+
+import net.bytebuddy.implementation.bytecode.StackManipulation;
+
+/**
+ * Keeps often used {@link StackManipulation}s which call often needed methods from the standard
+ * library and others.
+ *
+ * <p>Kept in a central place to reduce possible human errors in getting reflection right and
+ * improve code reuse. Inner classes are prefixed with "BC" to avoid import errors and to allow
+ * cleaner code in this class.
+ */
+public class ByteCodeMethodCalls {
+
+  /**
+   * Byte code invocations for {@link Integer}.
+   */
+  public static class BCInteger {
+    public static final StackManipulation valueOf =
+        ByteCodeUtils.invoke(Integer.class, "valueOf", int.class);
+  }
+}