txlyre 20 hours ago
parent
commit
7bdbfa5c7d
3 changed files with 13 additions and 2 deletions
  1. 3 0
      qirt.c
  2. 8 1
      qistd.c
  3. 2 1
      std.qi

+ 3 - 0
qirt.c

@@ -3624,6 +3624,9 @@ qi_value_t *qi_builtin_fwrite(qi_state_t *state, qi_size_t pargc,
     qi_throw_format(state, "expected first argument to be: file, but got: %s",
                     _qi_type(state, a));
 
+  if (b->type == QI_STRING || b->type == QI_LIST)
+    b = qi_to_bytes(state, b);
+
   if (b->type != QI_BYTES)
     qi_throw_format(state, "expected second argument to be: bytes, but got: %s",
                     _qi_type(state, b));

+ 8 - 1
qistd.c

@@ -417,7 +417,7 @@ qi_value_t *__qistd63(qi_state_t *state, qi_size_t pargc, qi_list_t *pargs) {
 qi_decl(state, "l", qi_list_index(pargs, 0));
 qi_new_scope(state);
 if (_qi_truthy(state, qi_not_equals(state, qi_call(state, qi_get(state, "type"), __qistd64(state)), qi_make_string(state, "list")))) {
-qi_throw(state, qi_add(state, qi_make_string(state, "expected first argument to be: list, but got: "), qi_call(state, qi_get(state, "type"), __qistd65(state))));}
+qi_throw(state, qi_add(state, qi_make_string(state, "expected first argumient to be: list, but got: "), qi_call(state, qi_get(state, "type"), __qistd65(state))));}
 qi_old_scope(state);
 qi_decl(state, "r", state->empty_string);
 qi_decl(state, "s", state->nil);
@@ -3171,6 +3171,12 @@ qi_list_data(list, 0) = qi_make_string(state, "file.__leave");
 qi_list_data(list, 1) = qi_make_function(state, "<anon>", 1, __qistd541, NULL);
 return list;
 }
+inline static qi_list_t *__qistd544(qi_state_t *state) {
+qi_list_t *list = qi_list_make_n(2);
+qi_list_data(list, 0) = qi_make_string(state, "file.close");
+qi_list_data(list, 1) = qi_get(state, "fclose");
+return list;
+}
 static void qi_init_std(qi_state_t *state) {
 qi_set(state, false, "head", qi_make_function(state, "head", 1, __qistd0, NULL));
 qi_set(state, false, "tail", qi_make_function(state, "tail", 1, __qistd2, NULL));
@@ -3277,4 +3283,5 @@ qi_decl_const(state, "__slice", qi_get(state, "slice"));
 (void)(qi_call(state, qi_get(state, "set_pseudomethod"), __qistd537(state)));
 (void)(qi_call(state, qi_get(state, "set_pseudomethod"), __qistd538(state)));
 (void)(qi_call(state, qi_get(state, "set_pseudomethod"), __qistd540(state)));
+(void)(qi_call(state, qi_get(state, "set_pseudomethod"), __qistd544(state)));
 }

+ 2 - 1
std.qi

@@ -77,7 +77,7 @@ func list_remove(l, x, first=false) {
 set_pseudomethod("list.remove", list_remove)
 func list_join(l) {
   if type(l) != "list"
-    throw "expected first argument to be: list, but got: " + type(l)
+    throw "expected first argumient to be: list, but got: " + type(l)
   var r = ""
   var s
   if len(arguments) == 1
@@ -514,6 +514,7 @@ func input() {
 func open(path, mode="r"): fopen(path, mode)
 set_pseudomethod("file.__enter", func () {})
 set_pseudomethod("file.__leave", func (f): fclose(f))
+set_pseudomethod("file.close", fclose)
 func assert(cond, msg="assertion failed")
   if !cond
     throw msg