Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to use custom alphabet for 4 first objects #276

Open
heasm66 opened this issue Mar 13, 2024 · 8 comments
Open

Impossible to use custom alphabet for 4 first objects #276

heasm66 opened this issue Mar 13, 2024 · 8 comments

Comments

@heasm66
Copy link
Contributor

heasm66 commented Mar 13, 2024

When using a custom alphabet there's no way to apply the alphabet on the first for objects (Class, Object, Routine and String), the descriptions are always done in the default alphabet for these objects. Guess it's because they are defined before a single line in the story-file is read. Not very important but it is a bit annoying.

@erkyrath
Copy link
Contributor

erkyrath commented Mar 14, 2024

The result of this is that the class-object names come out wrong if you redefine the basic alphabet characters. For example:

! Swap "c" and "C"; swap "t" and "i"
Zcharacter "abCdefgHtjklmnopqrsiuvwxyz"
           "ABcDEFGhIJKLMNOPQRSTUVWXYZ"
           "0123456789!$&*():;.,<>`";

[ Main;
	print "Class objects: ", (object) Class, " ", (object) Object,
	    " ", (object) Routine, " ", (object) string, "^";
];

Class objects: class ObjeCi Rouitne Sirtng

This is a bug but, as you say, not very important. (These objects are generally only printed for debugging purposes, and why would you rearrange the alphabet like that in the first place.)

@heasm66
Copy link
Contributor Author

heasm66 commented Mar 14, 2024

Actually (to continue on this minor bug), if you do a frequency check on an english story (this example is Curses) , an alphabet like this is more economical:

Zcharacter
    "abcdefghi.klmnop,rstuvwTy'"
    "ABCDEFGHIJKLMNOPQRSxUVWjYZ"
    "0123456789qz!?*;>/[-:()";

Swapping in . for j, , for q, T for x and ' for z in the cheaper A0 (affects Object --> Ob.ect).

But... minor bug.

@heasm66
Copy link
Contributor Author

heasm66 commented Dec 14, 2024

Suggestion is to move creating the metaclasses to last possible moment, just before the first regulasr object is created.

Remove from inform.c:

@@ -414,18 +414,6 @@ static void begin_pass(void)
        /*  Compile a Main__ routine (see "veneer.c")  */
    
        compile_initial_routine();
    
        /*  Make the four metaclasses: Class must be object number 1, so
             it must come first  */
-   
-      veneer_mode = TRUE;
-   
-      make_class("Class");
-      make_class("Object");
-      make_class("Routine");
-      make_class("String");
-   
-      veneer_mode = FALSE;
   }

   extern void allocate_arrays(void)

Add to directs.c:

@@ -79,6 +79,19 @@ extern int parse_given_directive(int internal_flag)
           }
       }
    
+      if (no_objects == 0 && (token_value == NEARBY_CODE || token_value == OBJECT_CODE || token_value == CLASS_CODE)) {
+            /*  Make the four metaclasses: Class must be object number 1, so
+                 it must come first  */
+            put_token_back();
+            veneer_mode = TRUE;
+            make_class("Class");
+            make_class("Object");
+            make_class("Routine");
+            make_class("String");
+            veneer_mode = FALSE;
+            return FALSE;
+        }
+
         switch(token_value)
         {

@erkyrath
Copy link
Contributor

That will probably work but it's probably a compiled-output change. It might not be worth it to fix such a corner case.

I notice there's no guard against changing the alphabet later in compilation! I'll file that separately, but we'll want to think about the problems together.

@erkyrath
Copy link
Contributor

Well, the idea above (moving the construction of the four metaclasses down) does not work. With that change, the original example above doesn't compile at all:

line 8: Error:  No such constant as "Class"
line 8: Error:  No such constant as "Object"
line 8: Error:  No such constant as "Routine"
line 8: Error:  No such constant as "string"

I could imagine tweaking the change: perhaps we create the metaclasses immediately before the first object or routine or array or... But this seems like it's getting more and more disruptive. I don't think this is the way to go.

@erkyrath
Copy link
Contributor

erkyrath commented Dec 19, 2024

How about a different plan: add a new compiler option, and then deprecate the Zcharacter "..." "..." "..." directive.

This is how I've dealt with other troublesome directives like Version and Switches that are hard to handle in mid-compile.

I think we can keep the other forms, Zcharacter table and Zcharacter 'x' as fully supported (non-deprecated). I'd want to add compiler switches for those too, but they can be used as directives without causing trouble (as long as they're early in the code!)

Note that Zcharacter 'x' alters the alphabet table, but it looks like it's built to only alter the third alphabet (non-alphabetic characters). The metaclass creation stage only uses alphabetic characters so there's no problem there.

@erkyrath
Copy link
Contributor

erkyrath commented Dec 19, 2024

This wouldn't be a $FOO=N option, as those are parsed as integers. Could go with $"..." (where the string is exactly 75 characters -- no need to split into three parts).

Or maybe I think that we'll have other string-formatted options in the future, in which case I'd want to use $ZALPHABET="...".

Unix-style: --opt ZALPHABET="...". You'd have to quote the quotes for the Unix shell. A bit of care for escaping everything, but it's workable.

@heasm66
Copy link
Contributor Author

heasm66 commented Dec 19, 2024

An option to set the alphabet already on the command line (and maybe the !% syntax?) is a good solution. Fixes both the name of the metaclasses and encourages against changing alphabet in the middle of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants