tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] S-Lang tinycc module testing script.


From: Agathoklis D.E Chatzimanikas
Subject: [Tinycc-devel] S-Lang tinycc module testing script.
Date: Mon, 26 Mar 2018 22:29:50 +0300
User-agent: Mutt/1.9.0 (2017-09-02)

On Mon, Mar 26, at 05:02 Agathoklis D.E Chatzimanikas wrote:
> On Fri, Mar 23, at 05:46 Agathoklis D.E Chatzimanikas wrote:
> > Hi,
> > 
> > I created a tinycc binding for the S-Lang programming language,
>  
> https://github.com/agathoklisx/slang-devel/tree/master/slang-modules/tcc
> 
> I updated it with a test script. But if someone wants to run this, needs
> a patched slsh with realpath(3). I've committed a realpath implementation
> in the clib, on the root directory of this same repository ...

In fact, it doesn't need to be, as I just made the definition of the
realpath(3) part of the test suite.
Here is the relevant part (comments inline (slang uses % for comments)):

```c
  % function signature
  % sladd_intrinsic_function (function_name, num_args, symbol_name,
  %    return_type, [arg_types], cbuf);

  % also: multiline string literals in slang are delimited by the
  % backqoute character, of course "" work the same but are not that
  % flexible. (caveat) every ` should be double escaped, as there isn't
  % a way to send nested strings for evaluation (however in this case,
  % (C buffers) there is no need)

  variable retval = tcc.sladd_intrinsic_function (
    "realpath", 1, "realpath_intrin", Void_Type, [String_Type], `

/* realpath(3) implementation
 *
 * Originally written by Agathoklis D.E. Chatzimanikas
 */

#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <slang.h> /* this should be done at the initialization */

/* can't use static here or can i? and how? */
void realpath_intrin (char *path)
{
  long path_max;
  char *p;

#ifdef PATH_MAX
  path_max = PATH_MAX;
#else
  path_max = pathconf (path, _PC_PATH_MAX);
  if (path_max <= 0)
    path_max = 4096;
#endif

  if (NULL == (p = (char *)SLmalloc (path_max+1)))
    return;

  if (NULL != realpath (path, p))
    {
    (void) SLang_push_malloced_string (p);
    return;
    }

  SLerrno_set_errno (errno);
  SLfree (p);
  (void) SLang_push_null ();
}
`);

```

Best,
  Αγαθοκλής



reply via email to

[Prev in Thread] Current Thread [Next in Thread]