# HG changeset patch # User Paul Boddie # Date 1624406076 -7200 # Node ID f19950e74e7f2250ec21360c492993cdf814c87a # Parent 326570523de539c28bcd6f70ab87e0f63f8f1d83# Parent 2edb612ab13499fedd851618abbc71c7072c1a99 Merged changes from the default branch. diff -r 326570523de5 -r f19950e74e7f common.py --- a/common.py Tue Jun 22 23:04:00 2021 +0200 +++ b/common.py Wed Jun 23 01:54:36 2021 +0200 @@ -3,8 +3,7 @@ """ Common functions. -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, - 2017, 2018, 2019 Paul Boddie +Copyright (C) 2007-2019, 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 @@ -1595,7 +1594,9 @@ "Return the module name containing the given type 'name'." - if name == "string": + if name == "integer": + modname = "int" + elif name == "string": modname = "str" elif name == "utf8string": modname = "unicode" @@ -1610,7 +1611,9 @@ "Return the type name provided by the given Python value 'name'." - if name == "str": + if name == "int": + return "integer" + elif name == "str": return "string" elif name == "unicode": return "utf8string" diff -r 326570523de5 -r f19950e74e7f generator.py --- a/generator.py Tue Jun 22 23:04:00 2021 +0200 +++ b/generator.py Wed Jun 23 01:54:36 2021 +0200 @@ -3,7 +3,7 @@ """ Generate C code from object layouts and other deduced information. -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018, 2019, 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 @@ -45,7 +45,7 @@ dict_type = "__builtins__.dict.dict" float_type = "__builtins__.float.float" function_type = "__builtins__.core.function" - int_type = "__builtins__.int.int" + int_type = "__builtins__.int.integer" list_type = "__builtins__.list.list" none_type = "__builtins__.none.NoneType" string_type = "__builtins__.str.string" @@ -1293,9 +1293,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 326570523de5 -r f19950e74e7f lib/__builtins__/__init__.py --- a/lib/__builtins__/__init__.py Tue Jun 22 23:04:00 2021 +0200 +++ b/lib/__builtins__/__init__.py Wed Jun 23 01:54:36 2021 +0200 @@ -61,7 +61,7 @@ from __builtins__.dict import dict from __builtins__.file import file from __builtins__.float import float -from __builtins__.int import int +from __builtins__.int import int, integer from __builtins__.span import range, slice, xrange from __builtins__.list import list from __builtins__.long import long diff -r 326570523de5 -r f19950e74e7f lib/__builtins__/buffer.py --- a/lib/__builtins__/buffer.py Tue Jun 22 23:04:00 2021 +0200 +++ b/lib/__builtins__/buffer.py Wed Jun 23 01:54:36 2021 +0200 @@ -3,7 +3,7 @@ """ Buffer object. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 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 @@ -31,7 +31,7 @@ if args is not None: n = len(args) - elif isinstance(size, int): + elif isinstance(size, integer): n = size else: raise ValueError(size) diff -r 326570523de5 -r f19950e74e7f lib/__builtins__/int.py --- a/lib/__builtins__/int.py Tue Jun 22 23:04:00 2021 +0200 +++ b/lib/__builtins__/int.py Wed Jun 23 01:54:36 2021 +0200 @@ -3,7 +3,7 @@ """ Integer objects. -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018, 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 @@ -26,18 +26,19 @@ int_neg, int_not, int_or, int_pow, int_rshift, int_str, \ int_sub, int_xor -class int: +def int(number_or_string): + + "Initialise the integer with the given 'number_or_string'." + + if is_int(number_or_string): + return number_or_string + else: + raise TypeError + +class integer: "An integer abstraction." - def __init__(self, number_or_string=None): - - "Initialise the integer with the given 'number_or_string'." - - # NOTE: To be implemented. - - pass - def __hash__(self): "Return a value for hashing purposes." diff -r 326570523de5 -r f19950e74e7f lib/native/system.py --- a/lib/native/system.py Tue Jun 22 23:04:00 2021 +0200 +++ b/lib/native/system.py Wed Jun 23 01:54:36 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 326570523de5 -r f19950e74e7f templates/native/system.c --- a/templates/native/system.c Tue Jun 22 23:04:00 2021 +0200 +++ b/templates/native/system.c Wed Jun 23 01:54:36 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) diff -r 326570523de5 -r f19950e74e7f tests/identity.py --- a/tests/identity.py Tue Jun 22 23:04:00 2021 +0200 +++ b/tests/identity.py Wed Jun 23 01:54:36 2021 +0200 @@ -1,6 +1,6 @@ print isinstance("string", string) # True -print isinstance("string", int) # False -print isinstance(123, int) # True +print isinstance("string", integer) # False +print isinstance(123, integer) # True print isinstance(123, string) # False print diff -r 326570523de5 -r f19950e74e7f transresults.py --- a/transresults.py Tue Jun 22 23:04:00 2021 +0200 +++ b/transresults.py Wed Jun 23 01:54:36 2021 +0200 @@ -3,7 +3,7 @@ """ Translation result abstractions. -Copyright (C) 2016, 2017, 2018 Paul Boddie +Copyright (C) 2016, 2017, 2018, 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 @@ -142,7 +142,7 @@ # NOTE: Should reference a common variable for the type name. - if self.ref.get_origin() == "__builtins__.int.int": + if self.ref.get_origin() == "__builtins__.int.integer": return "__INTVALUE(%s)" % self.value else: return encode_literal_constant(self.number)