|
|
@@ -4543,7 +4543,7 @@ const char *STD[][2] = {
|
|
|
" s = bytes(s)\n"
|
|
|
" var l = utf8_chrlen(s)\n"
|
|
|
" if !l\n"
|
|
|
- " throw \"malformed sequence\"\n"
|
|
|
+ " throw ValueError(\"malformed sequence\")\n"
|
|
|
" var c = (s[0] & ((1 << (8 - l)) - 1)) << (l - 1) * 6\n"
|
|
|
" for var i = 1; i < l; i++\n"
|
|
|
" c |= (s[i] & 0x3f) << (l - i - 1) * 6\n"
|
|
|
@@ -4560,7 +4560,7 @@ const char *STD[][2] = {
|
|
|
" elif c >= 0x10000 && c <= 0x10ffff\n"
|
|
|
" return bytes([0xf0 | ((c >> 18) & 0x7), 0x80 | ((c >> 12) & "
|
|
|
"0x3f), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f)])\n"
|
|
|
- " throw \"malformed codepoint\"\n"
|
|
|
+ " throw ValueError(\"malformed codepoint\")\n"
|
|
|
"}\n"
|
|
|
"class ustr {\n"
|
|
|
" _ucs = nil\n"
|
|
|
@@ -4612,11 +4612,11 @@ const char *STD[][2] = {
|
|
|
"include `pthread.h`\n"
|
|
|
"func thread_create(fn, args=[]) {\n"
|
|
|
" if type(fn) != \"function\"\n"
|
|
|
- " throw \"expected first argument to be: function, but got: \" + "
|
|
|
- "type(fn)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: function, but got: \" + "
|
|
|
+ "type(fn))\n"
|
|
|
" if type(args) != \"list\"\n"
|
|
|
- " throw \"expected second argument to be: list, but got: \" + "
|
|
|
- "type(args)\n"
|
|
|
+ " throw TypeError(\"expected second argument to be: list, but got: \" + "
|
|
|
+ "type(args))\n"
|
|
|
" inline `qi_value_t *args = qi_get(state, \"args\")`\n"
|
|
|
" inline `qi_list_t *list`\n"
|
|
|
" inline `LOCKED(args, {list = qi_list_copy(args->value.list);})`\n"
|
|
|
@@ -4726,22 +4726,22 @@ const char *STD[][2] = {
|
|
|
"header `#endif`\n"
|
|
|
"func system(s) {\n"
|
|
|
" if type(s) != \"string\"\n"
|
|
|
- " throw \"expected first argument to be: string, but got: \" + "
|
|
|
- "type(s)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: string, but got: \" + "
|
|
|
+ "type(s))\n"
|
|
|
" inline `return qi_make_number(state, system(qi_get(state, "
|
|
|
"\"s\")->value.string))`"
|
|
|
"}\n"
|
|
|
"func getenv(n) {\n"
|
|
|
" if type(n) != \"string\"\n"
|
|
|
- " throw \"expected first argument to be: string, but got: \" + "
|
|
|
- "type(n)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: string, but got: \" + "
|
|
|
+ "type(n))\n"
|
|
|
" inline `char *value = getenv(qi_get(state, \"n\")->value.string)`\n"
|
|
|
" inline `return value? qi_make_string_copy(state, value): state->nil`\n"
|
|
|
"}\n"
|
|
|
"func setenv(n, v) {\n"
|
|
|
" if type(n) != \"string\"\n"
|
|
|
- " throw \"expected first argument to be: string, but got: \" + "
|
|
|
- "type(n)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: string, but got: \" + "
|
|
|
+ "type(n))\n"
|
|
|
" v = str(v)\n"
|
|
|
" inline \"#ifdef _WIN32\"\n"
|
|
|
" var s = n + \"=\" + v\n"
|
|
|
@@ -4753,7 +4753,7 @@ const char *STD[][2] = {
|
|
|
"}\n"
|
|
|
"func exit(c) {\n"
|
|
|
" if type(c) != \"number\"\n"
|
|
|
- " throw \"expected first argument to be: number, but got: \" + type(c)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: number, but got: \" + type(c))\n"
|
|
|
" inline `qi_exit(state, qi_get(state, \"c\")->value.number)`\n"
|
|
|
"}\n"
|
|
|
"func die(msg, c=1) {\n"
|
|
|
@@ -4787,11 +4787,11 @@ const char *STD[][2] = {
|
|
|
"}\n"
|
|
|
"func strftime(f, t=time()) {\n"
|
|
|
" if type(f) != \"string\"\n"
|
|
|
- " throw \"expected first argument to be: string, but got: \" + "
|
|
|
- "type(f)\n"
|
|
|
+ " throw TypeError(\"expected first argument to be: string, but got: \" + "
|
|
|
+ "type(f))\n"
|
|
|
" if type(t) != \"number\"\n"
|
|
|
- " throw \"expected second argument to be: number, but got: \" + "
|
|
|
- "type(t)\n"
|
|
|
+ " throw TypeError(\"expected second argument to be: number, but got: \" + "
|
|
|
+ "type(t))\n"
|
|
|
" inline `time_t ts = qi_get(state, \"t\")->value.number`\n"
|
|
|
" inline `struct tm lt`\n"
|
|
|
" inline `lt = *localtime(&ts)`\n"
|
|
|
@@ -4828,14 +4828,16 @@ const char *STD[][2] = {
|
|
|
"func random_int(min, max): return rand() % (max + 1 - min) + min\n"
|
|
|
"func random_choice(l, k=1) {\n"
|
|
|
" if k < 0 || k > len(l)\n"
|
|
|
- " throw \"sample larger than population or is negative\"\n"
|
|
|
+ " throw ValueError(\"sample larger than population or is negative\")\n"
|
|
|
" l = list_copy(list(l))\n"
|
|
|
" var r = []\n"
|
|
|
" for var i = 0; i < k; i++\n"
|
|
|
" list_push(r, list_pop_at(l, random_int(0, len(l)-1)))\n"
|
|
|
" return r\n"
|
|
|
"}\n"
|
|
|
- "func random_pick(l, k=1) {\n"
|
|
|
+ "func random_pick(l, k=-1) {\n"
|
|
|
+ " if k < 0\n"
|
|
|
+ " return l[random_int(0, len(l)-1)]\n"
|
|
|
" var r = []\n"
|
|
|
" for var i = 0; i < k; i++\n"
|
|
|
" list_push(r, l[random_int(0, len(l)-1)])\n"
|
|
|
@@ -4876,8 +4878,8 @@ void genmathlib(void)
|
|
|
else if (MATHFUNCS[i].arity == 1)
|
|
|
buffer_fmt(
|
|
|
buffer,
|
|
|
- "\"%s\": func (x) { if type(x) != \"number\" { throw \"expected "
|
|
|
- "first argument to be: number, but got: \" + type(x) } inline "
|
|
|
+ "\"%s\": func (x) { if type(x) != \"number\" { throw TypeError(\"expected "
|
|
|
+ "first argument to be: number, but got: \" + type(x)) } inline "
|
|
|
"`double n = %s(qi_get(state, \"x\")->value.number)`; inline `return "
|
|
|
"qi_make_number(state, n)` }",
|
|
|
MATHFUNCS[i].name,
|
|
|
@@ -4885,10 +4887,10 @@ void genmathlib(void)
|
|
|
else
|
|
|
buffer_fmt(
|
|
|
buffer,
|
|
|
- "\"%s\": func (x, y) { if type(x) != \"number\" { throw \"expected "
|
|
|
- "first argument to be: number, but got: \" + type(x) } if type(y) != "
|
|
|
- "\"number\" { throw \"expected second argument to be: number, but "
|
|
|
- "got: \" + type(y) } inline `double n = %s(qi_get(state, "
|
|
|
+ "\"%s\": func (x, y) { if type(x) != \"number\" { throw TypeError(\"expected "
|
|
|
+ "first argument to be: number, but got: \" + type(x)) } if type(y) != "
|
|
|
+ "\"number\" { throw TypeError(\"expected second argument to be: number, but "
|
|
|
+ "got: \" + type(y)) } inline `double n = %s(qi_get(state, "
|
|
|
"\"x\")->value.number, qi_get(state, \"y\")->value.number)`; inline "
|
|
|
"`return qi_make_number(state, n)` }",
|
|
|
MATHFUNCS[i].name,
|