# HG changeset patch # User Paul Boddie # Date 1478800155 -3600 # Node ID 466d287306b4a17a2d8cc66d86baf82673f6db6c # Parent f9cd0d5c92d5e8ceca08e513ebde82568446e9b8 Added tentative support for the exit function. diff -r f9cd0d5c92d5 -r 466d287306b4 lib/sys.py --- a/lib/sys.py Thu Nov 10 18:19:17 2016 +0100 +++ b/lib/sys.py Thu Nov 10 18:49:15 2016 +0100 @@ -3,7 +3,7 @@ """ System functions and objects. -Copyright (C) 2008, 2012, 2014 Paul Boddie +Copyright (C) 2008, 2012, 2014, 2016 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 @@ -19,6 +19,8 @@ this program. If not, see . """ +from native import _exit + # Placeholders for run-time data. stdin = file() @@ -36,6 +38,6 @@ # Functions to be implemented natively. def exit(status=0): - pass + _exit(int(status)) # vim: tabstop=4 expandtab shiftwidth=4 diff -r f9cd0d5c92d5 -r 466d287306b4 templates/native.c --- a/templates/native.c Thu Nov 10 18:19:17 2016 +0100 +++ b/templates/native.c Thu Nov 10 18:49:15 2016 +0100 @@ -1,4 +1,4 @@ -#include +#include /* calloc, exit */ #include "types.h" #include "exceptions.h" #include "ops.h" @@ -7,6 +7,17 @@ #include "progtypes.h" #include "main.h" +/* Native functions. */ + +__attr __fn_native__exit(__attr __args[]) +{ + #define status (__args[1]) + + exit(__load_via_object(status.value, __pos___data__).intvalue); + return __builtins___none_None; + #undef status +} + __attr __fn_native__is(__attr __args[]) { #define x (__args[1]) diff -r f9cd0d5c92d5 -r 466d287306b4 templates/native.h --- a/templates/native.h Thu Nov 10 18:19:17 2016 +0100 +++ b/templates/native.h Thu Nov 10 18:49:15 2016 +0100 @@ -1,6 +1,9 @@ #ifndef __NATIVE_H__ #define __NATIVE_H__ +/* Native functions. */ + +__attr __fn_native__exit(__attr __args[]); __attr __fn_native__is(__attr __args[]); __attr __fn_native__is_not(__attr __args[]); __attr __fn_native__int_add(__attr __args[]);