ref: c0a64b0495e9517a553d76882c44e02f8d7e64a8
parent: 6c5270ccccbaea5518ca34302bc2019095614d99
author: spew <spew@cbza.org>
date: Sun Apr 20 19:57:53 EDT 2025
lsd: fix rune creation, add more documentation
--- a/src/plan9/lsd.c
+++ b/src/plan9/lsd.c
@@ -67,12 +67,9 @@
static sl_v
mk_symbol(Symbol *s)
{
- Rune r;
- static char b[2];
+ sl_v r;
- b[0] = s->type;
- chartorune(&r, b);
- fprint(2, "rune is %C\n", r);
+ r = s->type;
return sl_applyn(3, sym_value(mksymbolsym), str_from_cstr(s->name), mk_rune(r), mk_lsdptr(s->value));
}
@@ -264,7 +261,7 @@
pid = -1;
argcount(nargs, 1);
if(sl_unlikely(!isstr(args[0]) && !isnum(args[0])))
- bthrow(type_error(nil, "str|num", args[0]));
+ bthrow(type_error("program", "(or str num)", args[0]));
if(isnum(args[0])){
pid = tosize(args[0]);
@@ -351,7 +348,7 @@
argcount(nargs, 1);
if(sl_unlikely(!isnum(args[0])))
- bthrow(type_error(nil, "num", args[0]));
+ bthrow(type_error("addr", "num", args[0]));
addr = tosize(args[0]);
n = machdata->foll(coremap, addr, rget, f);
@@ -373,7 +370,7 @@
argcount(nargs, 1);
if(sl_unlikely(!isnum(args[0])))
- bthrow(type_error(nil, "num", args[0]));
+ bthrow(type_error("addr", "num", args[0]));
addr = tosize(args[0]);
if(machdata->das(coremap, addr, 'i', buf, sizeof(buf)) < 0)
@@ -388,7 +385,7 @@
argcount(nargs, 1);
if(sl_unlikely(!isnum(args[0])))
- bthrow(type_error(nil, "num", args[0]));
+ bthrow(type_error("addr", "num", args[0]));
addr = tosize(args[0]);
sz = machdata->instsize(coremap, addr);
@@ -404,7 +401,7 @@
argcount(nargs, 1);
if(sl_unlikely(!isnum(args[0])))
- bthrow(type_error(nil, "num", args[0]));
+ bthrow(type_error("addr", "num", args[0]));
addr = tosize(args[0]);
if(!fileline(buf, sizeof(buf), addr))
@@ -420,9 +417,9 @@
argcount(nargs, 2);
if(sl_unlikely(!isstr(args[0])))
- bthrow(type_error(nil, "str", args[0]));
+ bthrow(type_error("file", "str", args[0]));
if(sl_unlikely(!isfixnum(args[1])))
- bthrow(type_error(nil, "num", args[1]));
+ bthrow(type_error("line", "num", args[1]));
file = cvalue_data(args[0]);
line = numval(args[1]);
@@ -439,7 +436,7 @@
argcount(nargs, 1);
if(sl_unlikely(!isnum(args[0])))
- bthrow(type_error(nil, "num", args[0]));
+ bthrow(type_error("addr", "num", args[0]));
addr = tosize(args[0]);
if(!findsym(addr, CTEXT, &s))
--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -151,7 +151,7 @@
(defmacro (defcval name size)
(let {[sizesym `(sym ,size)]}
`(def (,name loc (n NIL))
- ,(str "Read the value at the location as a " size " value.\n\n"
+ ,(str "Read the " size " value at the given location\n\n"
" Optionally read an array of n values\n\n"
" The input to this function is as in @.")
:doc-see @
@@ -177,8 +177,19 @@
(def (c-str loc (n NIL))
«Read the null-terminated strings at the pointer location.
+ Optionally read a vector of n strings.
+
+ The input to this function is as in @.
+
Examples:
- (c-str (c-ptr "argv") (c-int "argc")); read the args.»
+
+ Read all the arguments to the program.
+ `(c-str (c-ptr "argv") (c-int "argc"))`
+
+ Read a value `s` of type `char*`.
+ `(c-str "s")`»
+ :doc-see @
+ :doc-group lsd
(def (readstr loc)
(unless coref (error "not attached to proc"))
(io-seek coref loc)
@@ -195,7 +206,9 @@
2. A number which is the address itself,
3. A symbol in which case the symbol's address is used.
- Examples:»
+ Examples:
+
+ (@ "argc") → #p64(0x7fffffffeed0)»
:doc-group lsd
(def (symb-addr s)
(let {[type (symbol-type s)]}
@@ -203,7 +216,9 @@
(eq? type #\p)
(eq? type #\d)
(eq? type #\D)
- (error "expected a data symbol" s)))
+ (eq? type #\b)
+ (eq? type #\B)
+ (error "expected a data symbol: " s)))
(symbol-addr s))
(def (str-addr s)
(symb-addr (or (local-symbol s)
@@ -232,6 +247,12 @@
:doc-see filepc
:doc-see symbol
:doc-group lsd
+ (def (symb-addr s)
+ (let {[type (symbol-type s)]}
+ (or (eq? type #\t)
+ (eq? type #\T)
+ (error "expected a text symbol: " s)))
+ (symbol-addr s))
(def (str-addr s)
(trycatch
(filepc s)
@@ -238,11 +259,11 @@
(λ (e) (when (eq? (car e) 'io-error) (raise e))
(let {[symb (global-symbol s :text T)]}
(if symb
- (symbol-addr symb)
+ (symb-addr symb)
(error "could not find symbol " s))))))
(cond ((str? loc) (str-addr loc))
((num? loc) (ptr loc))
- ((symbol? loc) (symbol-addr loc))
+ ((symbol? loc) (symb-addr loc))
(else (error "str|num|symbol"))))
(def (bpsave a) (core-read a 'u8 (length bpinst)))