Commits

Anonymous committed 84a51f0

Put the version information into the executable.

Comments (0)

Files changed (6)

+^arana/_version.h
 ^arana/lexnparse.c
 ^arana/grammar.([ch]|out)
 ^arana/lexer.c
 	arana/_opmap.h \
 	arana/_opcode_targets.h \
 	arana/_astmap.h \
+	arana/_version.h \
 	arana/arana.h \
 	arana/object.h \
 	arana/primitives.h \
 	@${ECHO} "  PYTHON " tools/gen-opmap.py
 	@${PYTHON} tools/gen-opmap.py
 
+arana/_version.h:
+	@${ECHO} "      SH " tools/gen-version.sh
+	@./tools/gen-version.sh
+
 arana/lexnparse.c: arana/lexnparse.rl
 	@${ECHO} "   RAGEL " arana/lexnparse.rl
 	@${RAGEL} arana/lexnparse.rl
 	@${ECHO} "Cleaning... "
 	@rm -f ${OBJ}
 	@rm -f ${EXECUTABLE}
-	@rm -f arana/_opmap.h arana/_astmap.h arana/_opcode_targets.h
+	@rm -f arana/_opmap.h arana/_astmap.h arana/_opcode_targets.h arana/_version.h
 	@rm -f arana/grammar.c arana/grammar.h arana/grammar.out arana/lexnparse.c
 	@${ECHO} "done."
 
 
 /* build configuration defines */
 #include "config.h"
+/* the version information */
+#include "_version.h"
 /* other headers */
 #include "object.h"
 #include "error.h"
     if (!unit)
         AR_RAISE_OOM();
     unit->filename = filename;
-    unit->ops_allocated = 16;
+    unit->ops_allocated = 32;
     unit->ops = AR_ALLOCTN(ArOp, unit->ops_allocated);
     if (!unit->ops) {
         AR_FREE(unit);
 static void
 arana_compiler_visit(COMPILER_SIG, ArAstNode *node)
 {
+
+#define COMPILE(func, type) \
+    arana_compile_##func(COMPILER_ISIG, (type *)node); \
+    break
+
     switch (node->type) {
-    ON(Module):
-        arana_compile_module(COMPILER_ISIG, (ArToplevelNode *)node);
-        break;
-    ON(Compound):
-        arana_compile_compound_stmt(COMPILER_ISIG, (ArStmtNode *)node);
-        break;
-    ON(ExprStmt):
-        arana_compile_expr_stmt(COMPILER_ISIG, (ArStmtNode *)node);
-        break;
-    ON(If):
-        arana_compile_if_stmt(COMPILER_ISIG, (ArStmtNode *)node);
-        break;
-    ON(For):
-        arana_compile_for_stmt(COMPILER_ISIG, (ArStmtNode *)node);
-        break;
-    ON(Assign):
-        arana_compile_assign(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(AugAssign):
-        arana_compile_augassign(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(BinaryOp):
-        arana_compile_binary(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(UnaryOp):
-        arana_compile_unary(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Call):
-        arana_compile_call(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Attribute):
-        arana_compile_attribute(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Subscript):
-        arana_compile_subscript(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(List):
-        arana_compile_list(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Tuple):
-        arana_compile_tuple(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Interpolation):
-        arana_compile_interpolation(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Name):
-        arana_compile_name(COMPILER_ISIG, (ArExprNode *)node);
-        break;
-    ON(Literal):
-        arana_compile_literal(COMPILER_ISIG, (ArExprNode *)node);
-        break;
+    ON(Module):         COMPILE(module, ArToplevelNode);
+    ON(Compound):       COMPILE(compound_stmt, ArStmtNode);
+    ON(ExprStmt):       COMPILE(expr_stmt, ArStmtNode);
+    ON(If):             COMPILE(if_stmt, ArStmtNode);
+    ON(For):            COMPILE(for_stmt, ArStmtNode);
+    ON(Assign):         COMPILE(assign, ArExprNode);
+    ON(AugAssign):      COMPILE(augassign, ArExprNode);
+    ON(BinaryOp):       COMPILE(binary, ArExprNode);
+    ON(UnaryOp):        COMPILE(unary, ArExprNode);
+    ON(Call):           COMPILE(call, ArExprNode);
+    ON(Attribute):      COMPILE(attribute, ArExprNode);
+    ON(Subscript):      COMPILE(subscript, ArExprNode);
+    ON(List):           COMPILE(list, ArExprNode);
+    ON(Tuple):          COMPILE(tuple, ArExprNode);
+    ON(Interpolation):  COMPILE(interpolation, ArExprNode);
+    ON(Name):           COMPILE(name, ArExprNode);
+    ON(Literal):        COMPILE(literal, ArExprNode);
     default:
         AR_FATAL("arana_compiler_visit: unhandled AST node type %s\n",
                  AR_ASTMAP[node->type]);
 #include "arana.h"
 
 static char
-usage[] = "Usage: %s [-c code|filename]\n";
+usage[] = "Usage: %s [-c code|filename|-v]\n";
 
 
 int
     AR_INTERPRETER();
 
     /* parse options */
-    while ((opt = getopt(argc, argv, "c:")) != -1) {
+    while ((opt = getopt(argc, argv, "c:v")) != -1) {
         switch (opt) {
         case 'c':
             code = optarg;
             break;
+        case 'v':
+            printf("Arana version %d:%s [%s]\n",
+                   ARANA_REVISION,
+                   ARANA_HG_CHANGESET,
+                   ARANA_DATE);
+            return 0;
         default:
             fprintf(stderr, usage, argv[0]);
             exit(EXIT_FAILURE);

tools/gen-version.sh

+#!/bin/sh
+
+
+hg tip --template '\
+/* automatically generated.  do not edit */
+#define ARANA_DATE         "{date|shortdate}"
+#define ARANA_HG_CHANGESET "{node|short}"
+#define ARANA_REVISION     {rev}
+' > `dirname $0`/../arana/_version.h