# HG changeset patch # User Paul Boddie # Date 1624403747 -7200 # Node ID 8b6488daf7f688e95026ea8962382a0f8ba8b602 # Parent e6da95e33e43e2ee0be438bb49b7535978b08840 Added sys.argv initialisation. diff -r e6da95e33e43 -r 8b6488daf7f6 generator.py --- a/generator.py Tue Jun 22 23:03:52 2021 +0200 +++ b/generator.py Wed Jun 23 01:15:47 2021 +0200 @@ -1230,9 +1230,14 @@ """ print >>f_code, """\ +int __argc; +char **__argv; + int main(int argc, char *argv[]) { __exc __tmp_exc; + __argc = argc; + __argv = argv; GC_INIT(); diff -r e6da95e33e43 -r 8b6488daf7f6 lib/native/system.py --- a/lib/native/system.py Tue Jun 22 23:03:52 2021 +0200 +++ b/lib/native/system.py Wed Jun 23 01:15:47 2021 +0200 @@ -8,7 +8,7 @@ non-core exceptions used by the native functions because they need to be identified as being needed by the program. -Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie +Copyright (C) 2011, 2015, 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -27,7 +27,7 @@ # NOTE: Example values used to provide type information. def exit(status): pass -def get_argv(): return "" +def get_argv(): return [] def get_path(): return [] # vim: tabstop=4 expandtab shiftwidth=4 diff -r e6da95e33e43 -r 8b6488daf7f6 templates/native/system.c --- a/templates/native/system.c Tue Jun 22 23:03:52 2021 +0200 +++ b/templates/native/system.c Wed Jun 23 01:15:47 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for system operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -17,7 +17,9 @@ */ #include /* abs, exit */ +#include /* strlen */ #include "types.h" +#include "common.h" #include "exceptions.h" #include "ops.h" #include "progconsts.h" @@ -27,6 +29,9 @@ /* Environment support. */ +extern int __argc; +extern char **__argv; + __attr __fn_native_system_exit(__attr __self, __attr status) { exit(__TOINT(status)); @@ -35,8 +40,13 @@ __attr __fn_native_system_get_argv(__attr __self) { - /* NOTE: To be written. */ - return __builtins___none_None; + __attr args[__argc]; + unsigned int i; + + for (i = 0; i < __argc; i++) + args[i] = __new_str(__argv[i], strlen(__argv[i])); + + return __newdata_list(__argc, args); } __attr __fn_native_system_get_path(__attr __self)