Commit graph

74 commits

Author SHA1 Message Date
Roger Crew
324cf46237 WAIF_CORE ifdef festival 2025-09-30 23:04:53 -07:00
Roger Crew
9798d17bcf fix OP_INDEXSET, OP_REF, and OP_CALL_VERB + cleanup waif.{c,h}
move struct Waif and WAIF_MAPSZ to waif.h (C allows forward references)
fix include orderings in waif.{h,c}
register_waif() needs to be at the bottom of the file
2025-09-30 23:04:53 -07:00
Roger Crew
e256355d9b unicode-waif from codepoint
This commit is the substantive portion of the Waif implementation.
The combination of this commit with its parent
(add back waif-related cvs log comments)
is intended to match either of the differences:

  codepoint/unicode (51761cdc98)
  ..codepoint/unicode-waif (8f892adbf7b6a5973c3268942087584eb01242f1)
  codepoint/unicode-xml (67aa153f76bcdbd9917bdf57fd380d9e7ffb419e)
   ..codepoint/unicode-waif-xml( c3d6fa5e58e358a0a75662a6ddaaecab4d39f306)

(these are both essentially the same) except for those files for which
the only differences are in the CVS log entries.

This version is purposefully broken (in order that the differences
line up as well as possible), notably in execute.c
(OP_INDEXSET,OP_REF,OP_CALL_VERB).
2025-09-30 23:04:53 -07:00
Kenny Root
1086e7374d Add bitwise operators
Add in bitwise AND ".&.", OR ".|.", and XOR ".^."

Add arithmetic left shift "<<", arithmetic right shift ">>",
and logical right shift operators ">>>"

This retains the original parsing of something like "9.^.5" to be
interpreted as "square root of 9"  However, "9.^. 5" is interpreted as
"9 XOR 5".

( The number parsing code moving to parse_number() is the only
  significant change in adapting this extension to the new server;
  the original behavior of the extension is retained in this commit
    --wrog )

Change-Id: I99291bed3d07d68ced204ea27bf684dc09a861fc
2025-09-30 23:04:53 -07:00
H. Peter Anvin
a40c956ec8 Unicode phase one (introduce the API)
Phase one = use the various API calls everywhere, but define them all
as inline routines that perform the straight-ASCII functions we were
doing before, so as to make this is a grand no-op to re create the
non-Unicode server we already had previously.

Important differences from the original implementation:

(1)
In this timeline, HPA's libucd (Unicode Character Database) and the
inclusion of a subdirectory to build it in (ucd/) NEVER HAPPENED;
In phase two, we'll instead go straight to an implementation using
GNU libunistring as a shared lib, only (re-)introducing libucd and
libicuuc as alternatives later.

(...in other news we have *always* been at war with Eastasia.
Also, Bobby Ewing is dead; as you may recall, Dallas received a
long-overdue cancellation at the end of its 8th season.
Alsoalso, Skywalker Ranch was struck by a meteor in 1981,
so the Star Wars series ended with The Empire Strikes Back;
Ron Moore is currently busy on a reboot/reimagining....)

(2)
There is no skip_utf().  Instead, we have
  (*) utf_byte_index(),
      a re-arranged version that is more explicit about
      the mission of converting character indices to byte indices
      and can be used prior to any range checking,
  (*) utf_byte_range()
      converts *pairs* of char indices to byte indices
      since this seems to come up a lot.
  (*) utf_char_index(),
      goes the other way, but with fewer traversals

(3)
my-ctype.h retains its role of working around mistakes in ctype.h on
broken systems.  All changes you might have thought you made there are
actually in utf-ctype.h, which, oddly enough serves as the header file
for the new functions being introduced in utf-ctype.c

Original commits cannibalized from the codepoint branch:

. Initial work on Unicode compatibility
  -- hpa

. fix ok_identifier (was: Correct which ctype to use ...)
  revised to leave my-ctype.h reference in db_io.c alone
  since it is solely there to provide (ascii) isspace().
  -- hpa

. Kenny's fixes to get it to load Minimal.db and JHCore. (2)
  -- james <james@nanaka.home.place.org>

. Slew a few bugs, made string handling unicode-y.
      --james <james@nanaka.home.place.org>

. make NET_SINGLE do utf8
      --wrog <crew@cs.stanford.edu>
    (since, among other things, fixing net_single.c
     should have been done at the same time.)

. Don't consider U+007F or surrogates to be printable
      --Rob Leslie <rob@mars.org>
    (changes my_is_printable())

    This commit alters my_is_printable() to reject surrogate code
    points, in part so that bf_tochar() doesn't end up returning an
    empty string instead of generating an error.  (Surrogates are
    already rejected by put_utf().)

. Caused online programming of verbs containing unicode to stop almost
  working for the wrong reasons and, along with reading of verbs
  containing unicode from saved databases, start working for the right
  reasons.
     --james <james@nanaka.home.place.org>

   (adds a number of stream_add_utf() uses to parser.y  --wrog)

. Let stream_add_utf() return the result of put_utf()
    --Rob Leslie <rob@mars.org>

    There's no point duplicating all the validity checks in put_utf()
    elsewhere.
2025-09-30 23:04:52 -07:00
Roger Crew
0631b16825 remove dbio_read_string_temp()
now that we have dbio_scxnf()
we no longer need dbio_read_string_temp()
2025-09-30 23:03:42 -07:00
Roger Crew
0c534fb806 dbio_scanf -> dbio_scxnf
scanf has too many annoying behaviors so we are replacing it.

E.g., Pavel was unhappy about %* specs not being counted in the
return value and was having to add 'dummy' variables all over.

I myself am unhappy about how you can put a \n at the end of a pattern
giving the false sense that you want it to match a newline when in
fact there's no guarantee of that at all, or that, in ANY pattern with
characters after the last % spec that you'll have any idea whether
those characters were reached or not (hence the need for all of these
%c-at-the-end bullshit patterns)

But worst of all, you cannot count on E_RANGE errors being raised when
they're needed because there's disagreement about when that should
happen, putting this in the realm of undefined behavior (hence certain
vendors putting deprecation warnings on %d and all of the other integer
conversions)

So.., fuck it.  We write our own function from the ground up that does
what we need (and very little more) and will thence be completely
portable (knock wood).

Well okay, it still relies on strtoimax() continuing to behave sensibly.
We'll see how that goes.

  --wrog
2025-09-30 23:03:42 -07:00
Roger Crew
0f8a851b52 dbio_peek_byte, dbio_skip_lines, dbio_read_var_value
new auxiliary functions
that will simplify the post-dbio_scxnf() world
2025-09-30 23:03:42 -07:00
Roger Crew
4a6d5cce6f new calling convention for dbio_read_* + range_checking
Every dbio_read_*() returns status and uses a return argument.
...makes it much harder to *not* check success/failure.

We need to be clear about what we expect to see in the db file.
Accepting out-of-range integers leads to silent corruption of data.

Some new rules:

Do not try to make use of [INTMAX_MAX+1..UINTMAX_MAX]; all integers we
care about are in the intmax_t range.  If something needs to be
unsigned, fine; it's in [0..INTMAX_MAX]

Do all integer range checks in the intmax_t world to avoid surprises.
2025-09-30 23:03:42 -07:00
Roger Crew
bb6f71d73d clean up dbio line reading
We need to consolidate line reading in one place,
remove pointless optimizations (Yes, the " recycled" line is less
than 20 characters, but is using the stream *that* expensive?
Also I'm done with having static streams all over the place)
and make it easier to introduce EOF-checking later.

dbio_read_line()
 = internal/static routine that does the actual work
dbio_read_string_temp <- dbio_read_string
 = public routine for non-persistent strings
dbio_read_string_intern
 = public routine for persistent strings
2025-09-30 23:03:42 -07:00
Roger Crew
3911ff6351 introduce FlNum/FlBox abstraction + make_float_pack
new functions
  FlBox box_fl(FlNum)
  FlNum fl_unbox(FlBox)
  void  flbox_negate_in_place(FlBox *)
  stream_unparse_float(s,FlNum,is_tostr?)
  stream_float_printf(s,fmt,Num prec,FlNum)

old functions that go away:
  new_float(d) = (Var){ .type = TYPE_FLOAT, .v.fnum = box_fl(d) };
  alloc_float(d) = astpool_recv_float(box_fl(d));

FLOATS_ARE_BOXED = 1
  so that nothing actually changes just yet
2025-09-30 23:03:42 -07:00
H. Peter Anvin
495cd63da7 Propagate Num everywhere (3b / Type handling cleanup)
this subphase:  Do all of the int(32_t)->Num retypings.

!(- use C99-like macros for printf)
!(- use [u]int*_t types (autoconf can verify they exist))
- abstract Num and Objid out
- default to 64 bit integers
!(- un-pointerify floating-point numbers (makes no sense on modern hardware))
2025-09-30 23:03:42 -07:00
H. Peter Anvin
9246b306aa Propagate PRI*N,SCN*N everywhere (3b / Type handling cleanup)
this subphase:  Fix all of the printf/scanf format strings.

!(- use C99-like macros for printf)
!(- use [u]int*_t types (autoconf can verify they exist))
- abstract Num and Objid out
- default to 64 bit integers
!(- un-pointerify floating-point numbers (makes no sense on modern hardware))

- - from james

Kenny's fixes to get it to load Minimal.db and JHCore. (1)

(evidently Kenny found two PRI*N goofs in db_file.c  --wrog)
2025-09-30 23:03:42 -07:00
Roger Crew
1a886129f6 max_stack_size is UNum 2025-09-30 23:03:41 -07:00
Rob Leslie
e6aaaacbae Fix for-statement infinite loop bug
The following MOO code caused an infinite loop:

  for i in [x..$maxint]
    ...
  endfor

To fix, we check whether incrementing `i' would overflow.
2025-09-30 23:03:41 -07:00
Roger Crew
2f314d6d51 introduce TaskID abstraction
(yes, we chased down all of the places where task ids can live).

For now, this is a no-op, but having identified all of the places
where they occur, we can range-check them later.
2025-09-30 23:03:41 -07:00
H. Peter Anvin
e2905809df db_io issues (1b / Type handling cleanup)
(phase 1 = changes having nothing to do with introducing [u]int*_t,
missing headers and adding/fixing function prototypes,
Num-introduction, float-unboxing, autoconf, or the new math builtins

here: everything having to do with db file reading/writing
 --wrog)

was:
- use C99-like macros for printf
- use [u]int*_t types (autoconf can verify they exist)
- abstract Num and Objid out
- default to 64 bit integers
- un-pointerify floating-point numbers (makes no sense on modern hardware)
2025-09-30 23:03:41 -07:00
Roger Crew
4df7dc8064 OP_REF, OP_INDEXSET, OP_RANGE_REF, EOP_RANGESET cleanup
For Unicode, the TYPE_LIST and TYPE_STR cases for these operators
will need to be handled separately, so I'm separating them *now*.

Also took the opportunity to restructure their error checking
(to remove redundant tests and unnecessarily repeated blocks
of free_var() calls).

Also correspondingly changed the API on sublist(), listrangeset(),
substr(), strrangeset() -- going forward, it will turn out far easier
if these functions continue to take byte indicies rather than
character indices and instead do the translation *before* calling
them.  That way they won't need to be modified at all for Unicode.

It also turns out that using 'from' and 'after' parameters rather than
'from' and 'to' will be *way* more convenient in Unicode Land (see,
a byte index is most conveniently identified with the *start* of
the respective character, so to get a proper byte range, what you
need is the start of the first character *following* the range;
subtract 1 and you're done; being instead given the start of the
last character of the range is a bit more complicated and a PITA.

Also took the opportunity to replace character twiddling loops in the
list.c routines with memcpy() + reordering them so that (maybe) we get
a bit less cache-miss buggery.
2025-09-30 23:03:41 -07:00
Roger Crew
9c77bc6846 OP_LE/GT/GE/LT rewrite
allows comparing integers with floats
2025-09-30 23:03:41 -07:00
Roger Crew
578e09e5a5 (2) Fix memory leak in run_interpreter/save_handler_info 2025-09-30 23:03:41 -07:00
Roger Crew
8d9e3f08ae signed vs. unsigned EOP_RANGE_SET 2025-09-30 23:03:40 -07:00
Roger Crew
3d3e06d26f lineno, pc are unsigned; db time is intmax_t 2025-09-30 23:03:40 -07:00
Roger Crew
0f90f2dede signed vs. unsigned (rt_env size/num_var_names is unsigned) 2025-09-30 23:03:40 -07:00
Roger Crew
c41aec545c signed vs. unsigned (top_activ_stack is unsigned) 2025-09-30 23:03:40 -07:00
Roger Crew
f17daf7305 suppress warnings re monster opcode switch in run() 2025-09-30 23:03:40 -07:00
Roger Crew
2aa5ab682e mark nonreturning functions
we can now remove useless "NOTREACHED" and post-panic() control flow
2025-09-30 23:03:40 -07:00
Roger Crew
90813ffba6 mark unused parameters and variables 2025-09-30 23:03:40 -07:00
james
1d60cb15c7 Add DEBUG_LOG_TRACEBACKS option (default 'no')
(original default was 'yes' --wrog)
2025-09-30 23:01:45 -07:00
Roger Crew
0e0d6bf8e1 config.h must be first!!! options.h must be second!!!
Time to impose some discipline on #include header ordering:

(1) We need to be absolutely certain everybody is seeing
    the SAME #define settings from config.h and options.h
    (so many of the my_foo.h depend on config.h settings
    and yet config.h was being listed later.  how did this happen?)

(2) It REALLY helps for documentation and code comprehension
    to have .c files clearly point to the .h files that
    export their interfaces (usually it's the like-named .h
    but sometimes it is not and this can be confusing to
    the newbie maintainer)

So... new rules:

For .h files:
  config.h if referenced, goes FIRST.
  options.h if referenced, goes SECOND.

For .c files the ordering of #includes shall be:

(1) The .h file(s) defining the exported interfaces
    that this .c file is implementing
    (typically this will be just one file, foo.h
     if this is foo.c, but exceptions exist)

(2) config.h, then options.h, in a stanza by themselves
    if referenced and not already included by (1)

For both .c and .h files we then have two more stanzas:

(3) system headers,
    including the "my-foo.h" corrective headers.

(4) own headers, other than the ones that go in (1)

Except for special cases like net_proto.c and net_mplex.c
where the whole purpose of the file is to BE an #include festival,
there should be no further #includes after the initial block.
All includes should appear at the top of the file where we can see them.

... ok, I'm done.
2025-09-29 00:44:47 -07:00
Roger Crew
84c228322a advance module .h files
include foo.h should generally be the first thing in foo.c
if the file defines register_FILE function, bf_register.h is next
2025-09-29 00:44:47 -07:00
Roger Crew
32dd7127d5 function prototype and missing header fixes 2025-09-13 14:53:30 -07:00
Roger Crew
dc99267723 mark fall throughs 2025-09-03 22:11:59 -07:00
Roger Crew
da71ecad6a Simplify setup_task_execution_limits 2025-09-03 22:11:59 -07:00
Roger Crew
fd24da9b49 cleaner make_abort_pack; BI_KILL->BI_ABORT
and BI_ABORT gets its own dedicated field
2025-09-03 22:11:59 -07:00
Roger Crew
d51a1eeb73 better unwind_stack and Finally_Reason comments 2025-09-03 22:11:59 -07:00
Roger Crew
0cc95c3f6c remove trailing whitespace, fix comment weirdness, Makefile refill 2024-12-30 03:04:09 -08:00
Roger Crew
bd0aa66cf0 cvs log keep PARC entries only
All of the Sourceforge-era log entries are in git
so there's no point to having them repeated in the files.
2024-12-30 03:02:52 -08:00
Roger Crew
6ae0d3b667 cvs log reconciliation 2023-08-17 09:06:46 -07:00
Roger Crew
54edd2de26 Implement max_list_concat: OP_LIST_ADD_TAIL
arguably gratuitous, but this does make it so that
{@biglist,x} and {x,@biglist} behave the same way
2010-04-23 15:32:26 -07:00
Roger Crew
7a2639763b Implement max_string_concat: OP_ADD 2010-04-23 15:32:25 -07:00
Roger Crew
c1d03d6888 Implement max_list_concat: OP_LIST_APPEND 2010-04-23 15:32:25 -07:00
Roger Crew
8211783290 Implement max_list_concat/max_string_concat: EOP_RANGE_SET 2010-04-23 15:32:25 -07:00
Roger Crew
9217f2129c New $server_option .max_concat_catchable 2010-04-23 15:32:25 -07:00
Roger Crew
d0139a371c New $server_options .max_list_concat and .max_string_concat
Introduces the options.h #defines, the server.h SVO_ constants,
and the canonicalization/caching code; nothing actually pays
attention to their values yet.
2010-04-23 15:32:25 -07:00
Roger Crew
f205185d12 Make value2str() return addref'ed value; eliminates string copy 2010-04-23 15:32:24 -07:00
Roger Crew
cca2db0c79 Cache protect_<property> options; deprecate IGNORE_PROP_PROTECTED
bi_prop_protected now references cached option values;
2010-04-23 15:32:24 -07:00
Roger Crew
3a1d961f19 Move builtin properties into a macro 2010-04-23 15:32:24 -07:00
Roger Crew
e34039e882 Make protect_<property> prevent non-wizard WRITEs to .name/.r/.w/.f
Granted, the programmer's manual only says it has to prevent reads,
but it's decidedly wacky to have, e.g., $server_options.protect_name
set, and a nonwizard viewing .name or doing .name[1]="a" or
.name[1..1]="a" getting errors, while .name="fred" sails through
just fine.  You can tell this code got used a lot.
2010-04-23 15:32:23 -07:00
Roger Crew
0e3176944c New package constructor make_abort_pack; replaces make_kill_pack 2010-04-23 15:32:23 -07:00
Roger Crew
c71feebb3d New enum abort_reason; change abort_task() argument 2010-04-23 15:32:23 -07:00