Lichen

Changeset

922:357c34868faf
5 months ago Paul Boddie raw files shortlog changelog graph Merged changes from the default branch. int-as-function
generator.py (file)
     1.1 --- a/generator.py	Tue Jun 22 23:36:04 2021 +0200
     1.2 +++ b/generator.py	Wed Jun 23 01:17:14 2021 +0200
     1.3 @@ -1230,9 +1230,14 @@
     1.4          """
     1.5  
     1.6          print >>f_code, """\
     1.7 +int __argc;
     1.8 +char **__argv;
     1.9 +
    1.10  int main(int argc, char *argv[])
    1.11  {
    1.12      __exc __tmp_exc;
    1.13 +    __argc = argc;
    1.14 +    __argv = argv;
    1.15  
    1.16      GC_INIT();
    1.17  
     2.1 --- a/lib/native/system.py	Tue Jun 22 23:36:04 2021 +0200
     2.2 +++ b/lib/native/system.py	Wed Jun 23 01:17:14 2021 +0200
     2.3 @@ -8,7 +8,7 @@
     2.4  non-core exceptions used by the native functions because they need to be
     2.5  identified as being needed by the program.
     2.6  
     2.7 -Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     2.8 +Copyright (C) 2011, 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     2.9  
    2.10  This program is free software; you can redistribute it and/or modify it under
    2.11  the terms of the GNU General Public License as published by the Free Software
    2.12 @@ -27,7 +27,7 @@
    2.13  # NOTE: Example values used to provide type information.
    2.14  
    2.15  def exit(status): pass
    2.16 -def get_argv(): return ""
    2.17 +def get_argv(): return []
    2.18  def get_path(): return []
    2.19  
    2.20  # vim: tabstop=4 expandtab shiftwidth=4
     3.1 --- a/templates/native/system.c	Tue Jun 22 23:36:04 2021 +0200
     3.2 +++ b/templates/native/system.c	Wed Jun 23 01:17:14 2021 +0200
     3.3 @@ -1,6 +1,6 @@
     3.4  /* Native functions for system operations.
     3.5  
     3.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     3.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     3.8  
     3.9  This program is free software; you can redistribute it and/or modify it under
    3.10  the terms of the GNU General Public License as published by the Free Software
    3.11 @@ -17,7 +17,9 @@
    3.12  */
    3.13  
    3.14  #include <stdlib.h> /* abs, exit */
    3.15 +#include <string.h> /* strlen */
    3.16  #include "types.h"
    3.17 +#include "common.h"
    3.18  #include "exceptions.h"
    3.19  #include "ops.h"
    3.20  #include "progconsts.h"
    3.21 @@ -27,6 +29,9 @@
    3.22  
    3.23  /* Environment support. */
    3.24  
    3.25 +extern int __argc;
    3.26 +extern char **__argv;
    3.27 +
    3.28  __attr __fn_native_system_exit(__attr __self, __attr status)
    3.29  {
    3.30      exit(__TOINT(status));
    3.31 @@ -35,8 +40,13 @@
    3.32  
    3.33  __attr __fn_native_system_get_argv(__attr __self)
    3.34  {
    3.35 -    /* NOTE: To be written. */
    3.36 -    return __builtins___none_None;
    3.37 +    __attr args[__argc];
    3.38 +    unsigned int i;
    3.39 +
    3.40 +    for (i = 0; i < __argc; i++)
    3.41 +        args[i] = __new_str(__argv[i], strlen(__argv[i]));
    3.42 +
    3.43 +    return __newdata_list(__argc, args);
    3.44  }
    3.45  
    3.46  __attr __fn_native_system_get_path(__attr __self)