slang-users mailing list

[2018 Date Index] [2018 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Re: tcc module


On Wed, Mar 28, at 08:09 Ag. D.E Chatzimanikas wrote:
> Hi John,
> 
> I took it of to mailing list, as others might want to chime in.
> 
> On Tue, Mar 27, at 08:41 John E. Davis wrote:
> > Hi Αγαθοκλή,
> > 
> > Sorry for the delay.  I am very busy with job related stuff.  However,
> > I did manage to get the test script run with the debian tcc package.
> > I had to make a few changes though.  I have appended the diffs below.
> 
> Thanks. Could you show me the following command output?
> 
>   ls -l /lib/i386-linux-gnu /usr/lib/i386-linux-gnu
> 
> I'm mostly interest if they are symbolic links.

Scratch that, as now it is possible to use qualifiers, see patch inlined
at the end of this mail.
 
> Does also Debian set any of the following environment variables?
> 
> LD_LIBRARY_PATH and C_INCLUDE_PATH
> 
> or any other relative?

On Tue, Mar 27, at 08:41 John E. Davis wrote:

-  _for i (0, length (s.sys_lib_path) - 1)
-    if (-1 == s.add_library_path (s.sys_lib_path[i]))
+   foreach ([s.sys_lib_path, "/lib/i386-linux-gnu",
+	     "/usr/lib/i386-linux-gnu", "/usr/lib/i386-linux-gnu/tcc"])
+     {
+	variable p = ();
+	% () = fprintf (stderr, "Adding lib path %S\n", p);
+	if (-1 == s.add_library_path (p))
       return -1;
+     }

Hmm,

/lib/i386-linux-gnu and /usr/lib/i386-linux-gnu

I guess we can use something like uname.(machine|sysname) to determinate
(without resorting to specific system support (which is undesirable))
the library path.

And what tcc has to do with gnu? it is not gnu (lemme see (checked:
This project is not part of the GNU Project. (that is what it says))),
(not a big deal though).

By the way, does the above paths mandated by FHS or LSB, i could bet not.

> > On Wed, 7 Mar 2018 "Ag. D.E Chatzimanikas" <aga.chatzimanikas@xxxxxxxxx> said:
> > > But the question is how to integrate?
> > > If you give me some thoughts then it might give me a direction to
> > > concentrate.  Don't have to be explicit.
> > 
> > For me the most important thing is that the use of the jit tcc
> > compiler is that it should not cause the interpreter to crash.  I have
> > users that use the interpreter in long running interactive
> > environments sessions analysing scientific data.  Many times, some
> > task could benefit from a jit compiled language, e.g., indexing an
> > array that does not parallelize.
> > 
> > I know that one can embed inline assembly code within a C program
> > using, e.g., an "asm" keyword, e.g.,
> > 
> >  __asm__ ("movl %eax, %ebx\n\t"
> >           "movl $56, %esi\n\t"
> > 	  "movl %ecx, $label(%edx,%ebx,$4)\n\t"
> > 	  "movb %ah, (%ebx)");
> > 
> > For slang, it might look like:
> > 
> >    __tcc__ ("C code here that interacts with interpreter variables");

So you say to me that, in the C side of code, at some point the program,
lets say: it had to realloc (var)
but you still want to work reliably with that reference from slang?

(if you can give me an example and the possible ways that the interpreter
will crash, that will be helpfull (not one of quick John Davis algorithms,
that takes years to understand (something simple (for dumbs))))

> > However, I have no idea how to go about doing this in a way that would
> > guaranteee that the interpreter does not crash.
> 
> First, the tcc api gives the freedom to call a callback function when
> encounters an error, with the following signature:
> 
>   void __tcc_error_handler (void *opaque, const char *msg)
> 
> For now, the default handler in the tcc-module looks first for a slang
> defined function "tcc_error_handler".
> If it is defined, it pushes the message string and calls that function.
> 
> But we can do better, but I don't know the way. I guess the opaque
> pointer argument should be the current state of tcc, which doesn't help
> much since the tcc state is an opaque object anyway and we don't have
> any access to its fields. Or am i missing something? Ideally, we would
> like, this argument to be our own TCC_Type. We can of course declaring
> a global variable when running any code through tcc, but this wouldn't
> make it, how they call it in programming: not thread safe?
> 
> Ideally again, we could give to any job e.g., a specific id, which we
> could store a reference of the type in a table in C side or in slang
> side.
> But this needs cooperation from tcc, to add one more field to its state
> to store this id and the ability to manipulate it (something like a user
> defined field, could be enough).
> 
> Perhaps I have to take it this on the tcc mailing list.

What I really i want here is that various tcc states shouldn't interfere
with others, but public variables or functions are not adequate for this.

Ideally every state should have the choice to has its own error handler,
and this could be done easily with qualifiers.

(though slang now has no support for threads but it might have tomorrow)

Here is the patch for comments, but please use the code from repository
to test.


```patch

diff --git a/slang-modules/tcc/Tcc.sl b/slang-modules/tcc/Tcc.sl
index 04b09e6..73ec26b 100644
--- a/slang-modules/tcc/Tcc.sl
+++ b/slang-modules/tcc/Tcc.sl
@@ -38,15 +38,22 @@ private define new (s)
   if (NULL == s.tcc)
     return -1;
 
-  s.add_tcc_path ("/usr/local/lib/tcc");
+  ifnot (qualifier_exists ("disable_tcc_support"))
+    s.add_tcc_path ("/usr/local/lib/tcc");
 
   variable i;
-  _for i (0, length (s.sys_include_path) - 1)
-    if (-1 == s.add_include_sys_path (s.sys_include_path[i]))
+  variable incl_path = [s.sys_include_path, qualifier ("include_path",
+      String_Type[0])];
+
+  _for i (0, length (incl_path) - 1)
+    if (-1 == s.add_include_sys_path (incl_path[i]))
       return -1;
 
-  _for i (0, length (s.sys_lib_path) - 1)
-    if (-1 == s.add_library_path (s.sys_lib_path[i]))
+  variable lib_path = [s.sys_lib_path, qualifier ("lib_path",
+      String_Type[0])];
+
+  _for i (0, length (lib_path) - 1)
+    if (-1 == s.add_library_path (lib_path[i]))
       return -1;
 
   if (-1 == s.link_against_library ("slang"))
@@ -385,14 +392,15 @@ private define init (self)
     };
 
   ifnot (qualifier_exists ("no_init"))
-    if (-1 == s.new ())
+    if (-1 == s.new (;;__qualifiers))
       return NULL;
   s;
 }
 
-
 public variable Tcc = struct {init = &init};
 
+% this doesn't really belongs here
+
 define add_required_functions ()
 {
   if (1 == is_defined ("realpath"))
@@ -429,8 +437,12 @@ void realpath_intrin (char *path)
     path_max = 4096;
 #endif
 
-  if (NULL == (p = (char *)SLmalloc (path_max+1)))
+  if (NULL == (p = (char *) SLmalloc (path_max + 1)))
+    {
+    SLerrno_set_errno (SL_Malloc_Error);
+    (void) SLang_push_null ();
     return;
+    }
 
   if (NULL != realpath (path, p))
     {
@@ -442,10 +454,6 @@ void realpath_intrin (char *path)
    SLfree (p);
    (void) SLang_push_null ();
 }
-
-/* 
-  MAKE_INTRINSIC_S("realpath", realpath_intrin, SLANG_VOID_TYPE),
- */
 `);
 
  tcc.delete ();
diff --git a/slang-modules/tcc/test.sl b/slang-modules/tcc/test.sl
index b38f6bf..2e1cb5c 100755
--- a/slang-modules/tcc/test.sl
+++ b/slang-modules/tcc/test.sl
@@ -16,11 +16,32 @@ if (-1 == add_required_functions ())
 if (-1 == test_required_functions ())
   exit (1);
 
-variable t;
+private variable t;
+
+% this is for convenience
+% use appropriate paths for the specific system
+private variable
+  lib_path = String_Type[0],
+  incl_path = String_Type[0];
+
+% do not modify this
+private variable __qual = struct {lib_path = lib_path, incl_path = incl_path};
+
+private define re_init (tcc)
+{
+  if (-1 == tcc.new (;;__qual))
+    {
+    () = fprintf (stderr, "failed to re-initialize tcc instance\n");
+    return -1;
+    }
+
+  0;
+}
 
 loop (1) {
   variable retval = -1;
-  if (NULL == (t = Tcc.init (), t))
+
+  if (NULL == (t = Tcc.init (;;__qual), t))
     {
     () = fprintf (stderr, "failed to initialize tcc instance\n");
     break;
@@ -42,11 +63,8 @@ loop (1) {
 
   t.delete ();
 
-  if (-1 == (retval = t.new (), retval))
-    {
-    () = fprintf (stderr, "failed to re-initialize tcc instance\n");
+  if (-1 == (retval = re_init (t), retval))
     break;
-    }
 
   if (-1 == (retval = t.sladd_intrinsic_variable ("Array_Var_IntType", "int_arr_var",
       Array_Type, `const int int_arr_var[3] = {10, 10, 10};`;
@@ -65,16 +83,13 @@ loop (1) {
 
   t.delete ();
 
-  if (-1 == (retval = t.new (), retval))
-    {
-    () = fprintf (stderr, "failed to re-initialize tcc instance\n");
+  if (-1 == (retval = re_init (t), retval))
     break;
-    }
 
   if (-1 == (retval = t.sladd_intrinsic_variable ("Array_Var_StrType", "str_arr_var",
       Array_Type, `const char *str_arr_var[] = {"a", "a", "a", '\0'};`), retval))
     {
-    () = fprintf (stderr, "failed to add Array_Type of Integer_Type intrinsic variable\n");
+    () = fprintf (stderr, "failed to add Array_Type of String_Type intrinsic variable\n");
     break;
     }
 
@@ -87,11 +102,8 @@ loop (1) {
 
   t.delete ();
 
-  if (-1 == (retval = t.new (), retval))
-    {
-    () = fprintf (stderr, "failed to re-initialize tcc instance\n");
+  if (-1 == (retval = re_init (t), retval))
     break;
-    }
 
   if (-1 == (retval = t.sladd_intrinsic_variable ("STR_VAR", "str_var", String_Type,
       `const char *str_var = "const_var";`), retval))
@@ -110,11 +122,8 @@ loop (1) {
 
   t.delete ();
 
-  if (-1 == (retval = t.new (), retval))
-    {
-    () = fprintf (stderr, "failed to re-initialize tcc instance\n");
+  if (-1 == (retval = re_init (t), retval))
     break;
-    }
 
   if (-1 == (retval = t.sladd_intrinsic_function ("add_two", 1, "c_add_two",
        Integer_Type, [Integer_Type],
@@ -131,13 +140,10 @@ loop (1) {
     break;
     }
 
-   t.delete ();
+  t.delete ();
 
-  if (-1 == (retval = t.new (), retval))
-    {
-    () = fprintf (stderr, "failed to initialize tcc instance\n");
+  if (-1 == (retval = re_init (t), retval))
     break;
-    }
 
   % create executable
   if (-1 == (retval = t.compile_string (`#include <stdio.h>
@@ -145,10 +151,10 @@ loop (1) {
         fprintf (stderr, "howl\n");
         return 0;}`
      ;create_exe, output_file = "/tmp/tcc_executable", overwrite), retval))
-   {
-   () = fprintf (stderr, "failed to create executable\n");
-   break;
-   }
+    {
+    () = fprintf (stderr, "failed to create executable\n");
+    break;
+    }
 
   if (retval = system ("/tmp/tcc_executable"), retval == -1)
     () = fprintf (stderr, "failed executable test\n");

```
_______________________________________________
For list information, visit <http://jedsoft.org/slang/mailinglists.html>.


[2018 date index] [2018 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]