Add more help information and some startup text to the repl

This commit is contained in:
K Lange 2021-01-07 20:00:57 +09:00
parent 330f697800
commit 2d012e4126
4 changed files with 98 additions and 2 deletions

View File

@ -68,15 +68,41 @@ const char _builtins_src[] =
" except:\n"
" print('No docstring avaialble for', obj)\n"
" else:\n"
" print('(Interactive help is not yet available)')\n"
" from help import interactive\n"
" interactive()\n"
" def __repr__(self):\n"
" return 'Type help() for more help, or help(obj) to describe an object.'\n"
"\n"
"let help = Helper()\n"
"\n"
"let _licenseText = '''\n"
"Copyright (c) 2020-2021 K. Lange <klange@toaruos.org>\n"
"\n"
"Permission to use, copy, modify, and/or distribute this software for any\n"
"purpose with or without fee is hereby granted, provided that the above\n"
"copyright notice and this permission notice appear in all copies.\n"
"\n"
"THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n"
"WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n"
"MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n"
"ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n"
"WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n"
"ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n"
"OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
"'''\n"
"\n"
"class LicenseReader():\n"
" def __call__(self):\n"
" print(_licenseText)\n"
" def __repr__(self):\n"
" return 'Copyright 2020-2021 K. Lange <klange@toaruos.org>. Type `license()` for more information.'\n"
"\n"
"let license = LicenseReader()\n"
"\n"
"__builtins__.list = list\n"
"__builtins__.dict = dict\n"
"__builtins__.help = help\n"
"__builtins__.license = license\n"
"__builtins__.module_paths = ['./','./modules/','/home/klange/Projects/kuroko/modules/','/usr/share/kuroko/']\n"
"\n"
"return object()\n"

View File

@ -67,15 +67,41 @@ class Helper():
except:
print('No docstring avaialble for', obj)
else:
print('(Interactive help is not yet available)')
from help import interactive
interactive()
def __repr__(self):
return 'Type help() for more help, or help(obj) to describe an object.'
let help = Helper()
let _licenseText = '''
Copyright (c) 2020-2021 K. Lange <klange@toaruos.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
class LicenseReader():
def __call__(self):
print(_licenseText)
def __repr__(self):
return 'Copyright 2020-2021 K. Lange <klange@toaruos.org>. Type `license()` for more information.'
let license = LicenseReader()
__builtins__.list = list
__builtins__.dict = dict
__builtins__.help = help
__builtins__.license = license
__builtins__.module_paths = ['./','./modules/','/home/klange/Projects/kuroko/modules/','/usr/share/kuroko/']
return object()

View File

@ -250,6 +250,28 @@ int main(int argc, char * argv[]) {
/* Bind a callback for \t */
rline_exp_set_tab_complete_func(tab_complete_func);
/**
* Python stores version info in a built-in module called `sys`.
* We are not Python, we'll use `sys` to pretend to be Python
* in emulation mode, so we use a different module to store
* this sort of thing: kuroko
*
* This module won't be imported by default, but it's still in
* the modules list, so we can look for it there.
*/
KrkValue systemModule;
if (krk_tableGet(&vm.modules, OBJECT_VAL(krk_copyString("kuroko",6)), &systemModule)) {
KrkValue version, buildenv, builddate;
krk_tableGet(&AS_INSTANCE(systemModule)->fields, OBJECT_VAL(krk_copyString("version",7)), &version);
krk_tableGet(&AS_INSTANCE(systemModule)->fields, OBJECT_VAL(krk_copyString("buildenv",8)), &buildenv);
krk_tableGet(&AS_INSTANCE(systemModule)->fields, OBJECT_VAL(krk_copyString("builddate",9)), &builddate);
fprintf(stdout, "Kuroko %s (%s) with %s\n",
AS_CSTRING(version), AS_CSTRING(builddate), AS_CSTRING(buildenv));
}
fprintf(stdout, "Type `help` for guidance, `paste()` to toggle automatic indentation, `license` for copyright information.\n");
while (!exitRepl) {
size_t lineCapacity = 8;
size_t lineCount = 0;

22
modules/help.krk Normal file
View File

@ -0,0 +1,22 @@
'''
Implements the interactive help() command.
'''
from kuroko import version
let __introText = ('''\
Kuroko {version}
Kuroko is a bytecode-compiled, duck-typed language with familiar indentation-
driven block syntax. This documentation is incomplete. For more information,
please consult the README or website (https://github.com/klange/kuroko).
To leave the REPL, type `exit()` or press Ctrl-D on a blank line.
The REPL will automatically indent blocks when a line ends with a `:`. To turn
this functionality off, type `paste()`. Tab completion of global variable names
and attribute field names is available.
'''.format(version=version))
def interactive():
'''Runs the detailed help tool. Currently that means just printing a longer help string.'''
print(__introText)