]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Add the "Flush" and "Terminate" builtins; fix a small bug in string scanning.
authorRhys Weatherley <rweather@southern-storm.com.au>
Thu, 6 May 2004 23:10:46 +0000 (23:10 +0000)
committerRhys Weatherley <rweather@southern-storm.com.au>
Thu, 6 May 2004 23:10:46 +0000 (23:10 +0000)
ChangeLog
dpas/dpas-builtin.c
dpas/dpas-scanner.l

index 1f8f870fd9e02cb98a24d692ec6484cbd3265397..6f1547fdb10f1b9fb16d4241dde6ab6adae9f3d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@
        method once a Dynamic Pascal program has been compiled;
        fix some calling convention problems with "call_external".
 
+       * dpas/dpas-builtin.c, dpas/dpas-scanner.l: add the "Flush"
+       and "Terminate" builtins; fix a small bug in string scanning.
+
 2004-05-06  Rhys Weatherley  <rweather@southern-storm.com.au>
 
        * dpas/Makefile.am, dpas/dpas-builtin.c, dpas/dpas-function.c,
index 0af678bbcf01d2bdb32ab6aff4c88048f1b323ea..44f7034a73a8a0b70a93e978879b2385b4f58ac1 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "dpas-internal.h"
 #include <stdio.h>
+#include <stdlib.h>
 
 /*
  * Functions for writing values to stdout.
@@ -120,6 +121,7 @@ static dpas_semvalue dpas_write_inner
        jit_function_t func = dpas_current_function();
        dpas_semvalue result;
        jit_type_t type;
+       jit_type_t orig_type;
        const char *name;
        void *native_func;
        int index;
@@ -132,12 +134,20 @@ static dpas_semvalue dpas_write_inner
                }
                else
                {
-                       type = jit_type_normalize(dpas_sem_get_type(result));
-                       if(type == jit_type_sbyte ||
-                          type == jit_type_ubyte ||
-                          type == jit_type_short ||
-                          type == jit_type_ushort ||
-                          type == jit_type_int)
+                       orig_type = dpas_sem_get_type(result);
+                       type = jit_type_normalize(orig_type);
+                       if(jit_type_is_pointer(orig_type) &&
+                          jit_type_get_ref(orig_type) == dpas_type_char)
+                       {
+                               type = jit_type_void_ptr;
+                               name = "dpas_write_string";
+                               native_func = (void *)dpas_write_string;
+                       }
+                       else if(type == jit_type_sbyte ||
+                               type == jit_type_ubyte ||
+                               type == jit_type_short ||
+                               type == jit_type_ushort ||
+                               type == jit_type_int)
                        {
                                type = jit_type_int;
                                name = "dpas_write_int";
@@ -169,13 +179,6 @@ static dpas_semvalue dpas_write_inner
                                name = "dpas_write_nfloat";
                                native_func = (void *)dpas_write_nfloat;
                        }
-                       else if(jit_type_is_pointer(type) &&
-                                       jit_type_get_ref(type) == dpas_type_char)
-                       {
-                               type = jit_type_void_ptr;
-                               name = "dpas_write_string";
-                               native_func = (void *)dpas_write_string;
-                       }
                        else
                        {
                                dpas_error("unprintable value for parameter %d", index + 1);
@@ -205,11 +208,47 @@ static dpas_semvalue dpas_writeln(dpas_semvalue *args, int num_args)
        return dpas_write_inner(args, num_args, 1);
 }
 
+/*
+ * Flush stdout.
+ */
+static void dpas_flush_stdout(void)
+{
+       fflush(stdout);
+}
+static dpas_semvalue dpas_flush(dpas_semvalue *args, int num_args)
+{
+       dpas_semvalue result;
+       call_write(dpas_current_function(), "dpas_flush_stdout",
+                          (void *)dpas_flush_stdout, 0, 0);
+       dpas_sem_set_void(result);
+       return result;
+}
+
+/*
+ * Terminate program execution with an exit status code.
+ */
+static void dpas_terminate_program(jit_int value)
+{
+       exit((int)value);
+}
+static dpas_semvalue dpas_terminate(dpas_semvalue *args, int num_args)
+{
+       dpas_semvalue result;
+       result = dpas_lvalue_to_rvalue(args[0]);
+       call_write(dpas_current_function(), "dpas_terminate_program",
+                          (void *)dpas_terminate_program, jit_type_int,
+                          dpas_sem_get_value(result));
+       dpas_sem_set_void(result);
+       return result;
+}
+
 /*
  * Builtins that we currently recognize.
  */
 #define        DPAS_BUILTIN_WRITE                      1
 #define        DPAS_BUILTIN_WRITELN            2
+#define        DPAS_BUILTIN_FLUSH                      3
+#define        DPAS_BUILTIN_TERMINATE          4
 
 /*
  * Table that defines the builtins.
@@ -225,6 +264,8 @@ typedef struct
 static dpas_builtin const builtins[] = {
        {"Write",               DPAS_BUILTIN_WRITE,             dpas_write,             -1},
        {"WriteLn",             DPAS_BUILTIN_WRITELN,   dpas_writeln,   -1},
+       {"Flush",               DPAS_BUILTIN_FLUSH,             dpas_flush,              0},
+       {"Terminate",   DPAS_BUILTIN_TERMINATE, dpas_terminate,  1},
 };
 #define        num_builtins    (sizeof(builtins) / sizeof(dpas_builtin))
 
index 399fcb8872eed13b6685b42623a3697e65f277d6..3d6c0ce2c16ea4a32360e97bec38e458b15c1c03 100644 (file)
@@ -55,6 +55,10 @@ static char *dpas_parse_string(const char *text)
                        *temp++ = (char)quote;
                        text += 2;
                }
+               else if(text[0] == quote)
+               {
+                       break;
+               }
                else
                {
                        *temp++ = *text++;