|
| 1 | +// Built-in functions |
| 2 | +package builtin |
| 3 | + |
| 4 | +import ( |
| 5 | + "fmt" |
| 6 | + "github.com/ncw/gpython/py" |
| 7 | +) |
| 8 | + |
| 9 | +const builtin_doc = `Built-in functions, exceptions, and other objects. |
| 10 | +
|
| 11 | +Noteworthy: None is the 'nil' object; Ellipsis represents '...' in slices.` |
| 12 | + |
| 13 | +// Initialise the module |
| 14 | +func init() { |
| 15 | + methods := []*py.Method{ |
| 16 | + // py.NewMethodWithKeywords("__build_class__", builtin___build_class__, py.METH_VARARGS|py.METH_KEYWORDS, build_class_doc), |
| 17 | + // py.NewMethodWithKeywords("__import__", builtin___import__, py.METH_VARARGS|py.METH_KEYWORDS, import_doc), |
| 18 | + // py.NewMethod("abs", builtin_abs, py.METH_O, abs_doc), |
| 19 | + // py.NewMethod("all", builtin_all, py.METH_O, all_doc), |
| 20 | + // py.NewMethod("any", builtin_any, py.METH_O, any_doc), |
| 21 | + // py.NewMethod("ascii", builtin_ascii, py.METH_O, ascii_doc), |
| 22 | + // py.NewMethod("bin", builtin_bin, py.METH_O, bin_doc), |
| 23 | + // py.NewMethod("callable", builtin_callable, py.METH_O, callable_doc), |
| 24 | + // py.NewMethod("chr", builtin_chr, py.METH_VARARGS, chr_doc), |
| 25 | + // py.NewMethodWithKeywords("compile", builtin_compile, py.METH_VARARGS|py.METH_KEYWORDS, compile_doc), |
| 26 | + // py.NewMethod("delattr", builtin_delattr, py.METH_VARARGS, delattr_doc), |
| 27 | + // py.NewMethod("dir", builtin_dir, py.METH_VARARGS, dir_doc), |
| 28 | + // py.NewMethod("divmod", builtin_divmod, py.METH_VARARGS, divmod_doc), |
| 29 | + // py.NewMethod("eval", builtin_eval, py.METH_VARARGS, eval_doc), |
| 30 | + // py.NewMethod("exec", builtin_exec, py.METH_VARARGS, exec_doc), |
| 31 | + // py.NewMethod("format", builtin_format, py.METH_VARARGS, format_doc), |
| 32 | + // py.NewMethod("getattr", builtin_getattr, py.METH_VARARGS, getattr_doc), |
| 33 | + // py.NewMethod("globals", builtin_globals, py.METH_NOARGS, globals_doc), |
| 34 | + // py.NewMethod("hasattr", builtin_hasattr, py.METH_VARARGS, hasattr_doc), |
| 35 | + // py.NewMethod("hash", builtin_hash, py.METH_O, hash_doc), |
| 36 | + // py.NewMethod("hex", builtin_hex, py.METH_O, hex_doc), |
| 37 | + // py.NewMethod("id", builtin_id, py.METH_O, id_doc), |
| 38 | + // py.NewMethod("input", builtin_input, py.METH_VARARGS, input_doc), |
| 39 | + // py.NewMethod("isinstance", builtin_isinstance, py.METH_VARARGS, isinstance_doc), |
| 40 | + // py.NewMethod("issubclass", builtin_issubclass, py.METH_VARARGS, issubclass_doc), |
| 41 | + // py.NewMethod("iter", builtin_iter, py.METH_VARARGS, iter_doc), |
| 42 | + // py.NewMethod("len", builtin_len, py.METH_O, len_doc), |
| 43 | + // py.NewMethod("locals", builtin_locals, py.METH_NOARGS, locals_doc), |
| 44 | + // py.NewMethodWithKeywords("max", builtin_max, py.METH_VARARGS|py.METH_KEYWORDS, max_doc), |
| 45 | + // py.NewMethodWithKeywords("min", builtin_min, py.METH_VARARGS|py.METH_KEYWORDS, min_doc), |
| 46 | + // py.NewMethod("next", builtin_next, py.METH_VARARGS, next_doc), |
| 47 | + // py.NewMethod("oct", builtin_oct, py.METH_O, oct_doc), |
| 48 | + // py.NewMethod("ord", builtin_ord, py.METH_O, ord_doc), |
| 49 | + // py.NewMethod("pow", builtin_pow, py.METH_VARARGS, pow_doc), |
| 50 | + py.NewMethodWithKeywords("print", builtin_print, py.METH_VARARGS|py.METH_KEYWORDS, print_doc), |
| 51 | + // py.NewMethod("repr", builtin_repr, py.METH_O, repr_doc), |
| 52 | + // py.NewMethodWithKeywords("round", builtin_round, py.METH_VARARGS|py.METH_KEYWORDS, round_doc), |
| 53 | + // py.NewMethod("setattr", builtin_setattr, py.METH_VARARGS, setattr_doc), |
| 54 | + // py.NewMethodWithKeywords("sorted", builtin_sorted, py.METH_VARARGS|py.METH_KEYWORDS, sorted_doc), |
| 55 | + // py.NewMethod("sum", builtin_sum, py.METH_VARARGS, sum_doc), |
| 56 | + // py.NewMethod("vars", builtin_vars, py.METH_VARARGS, vars_doc), |
| 57 | + } |
| 58 | + py.NewModule("builtins", builtin_doc, methods) |
| 59 | +} |
| 60 | + |
| 61 | +const print_doc = `print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False) |
| 62 | +
|
| 63 | +Prints the values to a stream, or to sys.stdout by default. |
| 64 | +Optional keyword arguments: |
| 65 | +file: a file-like object (stream); defaults to the current sys.stdout. |
| 66 | +sep: string inserted between values, default a space. |
| 67 | +end: string appended after the last value, default a newline. |
| 68 | +flush: whether to forcibly flush the stream.` |
| 69 | + |
| 70 | +func builtin_print(self py.Object, args py.Tuple, kwargs py.Dict) py.Object { |
| 71 | + fmt.Printf("print %v, %v, %v\n", self, args, kwargs) |
| 72 | + return py.None |
| 73 | +} |
0 commit comments