[Nickle] nickle: Branch 'master' - 2 commits
Keith Packard
keithp at keithp.com
Fri Feb 1 17:44:12 PST 2008
builtin-file.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
nickle.h | 5 ++
sched.c | 1
3 files changed, 122 insertions(+), 1 deletion(-)
New commits:
commit 20a5db3ef34d47fdff2dd98052b577db80f76ffc
Author: Keith Packard <keithp at keithp.com>
Date: Sat Feb 2 12:32:45 2008 +1100
Add unlink, rename, mkdir, rmdir builtins.
diff --git a/builtin-file.c b/builtin-file.c
index fbb149b..f5751f1 100644
--- a/builtin-file.c
+++ b/builtin-file.c
@@ -15,6 +15,9 @@
#include <ctype.h>
#include <strings.h>
#include <time.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "builtin.h"
NamespacePtr FileNamespace;
@@ -88,6 +91,14 @@ import_File_namespace()
"\n"
" Return whether 'f' is associated with an interactive\n"
" terminal device\n" },
+ { do_File_unlink, "unlink", "v", "s", "\n"
+ " void unlink (string name)\n"
+ "\n"
+ " Delete the filename 'name'\n" },
+ { do_File_rmdir, "rmdir", "v", "s", "\n"
+ " void rmdir (string name)\n"
+ "\n"
+ " Delete the directory 'name'\n" },
{ 0 }
};
@@ -127,6 +138,14 @@ import_File_namespace()
" int ungetc (int c, file f)\n"
"\n"
" Pushes the character 'c' back on file 'f'.\n" },
+ { do_File_rename, "rename", "v", "ss", "\n"
+ " void rename (string oldname, string newname)\n"
+ "\n"
+ " Renames a file\n" },
+ { do_File_mkdir, "mkdir", "v", "si", "\n"
+ " void mkdir (string name, int mode)\n"
+ "\n"
+ " Create the new directory 'name'\n" },
{ 0 }
};
@@ -181,6 +200,13 @@ import_File_namespace()
" io_error (string message, error_type error, file f)\n"
"\n"
" Raised when an i/o error occurs.\n" },
+ {"name_error", exception_name_error, "sEs", "\n"
+ " name_error (string message, error_type error, string name)\n"
+ "\n"
+ " Raised when an operation involving a filename fails.\n"
+ " 'message' is a printable error string.\n"
+ " 'error' is a symbolic error code.\n"
+ " 'name' is the filename which failed.\n" },
{0, 0 },
};
@@ -618,3 +644,94 @@ do_File_setbuf (Value f, Value v)
FileSetBuffer (f, i);
RETURN (v);
}
+
+Value
+do_File_unlink (Value name)
+{
+ ENTER ();
+ char *n;
+ int ret;
+
+ n = StrzPart (name, "invalid file name");
+ if (!n)
+ RETURN (Void);
+ ret = unlink (n);
+ if (ret < 0) {
+ int err = errno;
+ RaiseStandardException (exception_name_error,
+ FileGetErrorMessage (err),
+ 2, FileGetError (err), name);
+ RETURN (Void);
+ }
+ RETURN (Void);
+}
+
+Value
+do_File_rename (Value old, Value new)
+{
+ ENTER ();
+ char *o, *n;
+ int ret;
+
+ o = StrzPart (old, "invalid file name");
+ if (!o)
+ RETURN (Void);
+ n = StrzPart (new, "invalid file name");
+ if (!n)
+ RETURN (Void);
+ ret = rename (o, n);
+ if (ret < 0) {
+ int err = errno;
+ RaiseStandardException (exception_name_error,
+ FileGetErrorMessage (err),
+ 2, FileGetError (err), new);
+ RETURN (Void);
+ }
+ RETURN (Void);
+}
+
+Value
+do_File_mkdir (Value name, Value mode)
+{
+ ENTER ();
+ char *n;
+ int m;
+ int ret;
+
+ n = StrzPart (name, "invalid file name");
+ if (!n)
+ RETURN (Void);
+ m = IntPart (mode, "invalid file mode");
+ if (aborting)
+ RETURN (Void);
+ ret = mkdir (n, m);
+ if (ret < 0) {
+ int err = errno;
+ RaiseStandardException (exception_name_error,
+ FileGetErrorMessage (err),
+ 2, FileGetError (err), name);
+ RETURN (Void);
+ }
+ RETURN (Void);
+}
+
+Value
+do_File_rmdir (Value name)
+{
+ ENTER ();
+ char *n;
+ int ret;
+
+ n = StrzPart (name, "invalid file name");
+ if (!n)
+ RETURN (Void);
+ ret = rmdir (n);
+ if (ret < 0) {
+ int err = errno;
+ RaiseStandardException (exception_name_error,
+ FileGetErrorMessage (err),
+ 2, FileGetError (err), name);
+ RETURN (Void);
+ }
+ RETURN (Void);
+}
diff --git a/nickle.h b/nickle.h
index 903ae2f..c5ad821 100644
--- a/nickle.h
+++ b/nickle.h
@@ -762,6 +762,7 @@ typedef enum _standardException {
exception_invalid_unop_value, /* string poly */
exception_open_error, /* string integer string */
exception_io_error, /* string integer file */
+ exception_name_error, /* string integer string */
_num_standard_exceptions
} StandardException;
@@ -912,6 +913,8 @@ Value do_File_string_read (Value);
Value do_File_string_string (Value);
Value do_File_isatty (Value);
Value do_File_status (Value);
+Value do_File_unlink (Value);
+Value do_File_rmdir (Value);
Value do_String_length (Value);
Value do_String_new (Value);
Value do_Primitive_random (Value);
@@ -940,6 +943,8 @@ Value do_File_putc (Value, Value);
Value do_File_ungetb (Value, Value);
Value do_File_ungetc (Value, Value);
Value do_File_setbuf (Value, Value);
+Value do_File_rename (Value, Value);
+Value do_File_mkdir (Value, Value);
Value do_String_index (Value, Value);
Value do_setjmp (Value, Value);
Value do_setdims (Value, Value);
commit b5830866a10e7eed272c52e7aafc17d3593c2dac
Author: Keith Packard <keithp at keithp.com>
Date: Sat Feb 2 12:29:52 2008 +1100
Twixt mark function shouldn't reference leave instruction.
Instructions cannot be referenced directly, only the object block containing
them. The twixt continuation already has a reference to the object, so the
extra MemReference on the leave instruction is spurious (and causes
crashing).
diff --git a/sched.c b/sched.c
index 7445608..573dce3 100644
--- a/sched.c
+++ b/sched.c
@@ -1097,7 +1097,6 @@ TwixtMark (void *object)
TwixtPtr twixt = object;
ContinuationMark (&twixt->continuation);
- MemReference (twixt->leave);
}
DataType TwixtType = { TwixtMark, 0, "TwixtType" };
More information about the Nickle
mailing list