Thursday, August 29, 2019

ZILF 0.9 released

Version 0.9 of ZILF was released recently! Highlights include easier setup for non-Windows platforms, compatibility with the unearthed Infocom source, and lots of bug fixes.

Get it at zilf.io.

Sunday, March 19, 2017

ZILF 0.8 released

Version 0.8 of ZILF is here! Highlights include compiler/assembler support for V6 games, a more complete MDL interpreter (i.e. macros can be a lot more useful), better error reporting and optimization, and lots of bug fixes.

Release Notes
Download ZILF 0.8

Sunday, February 5, 2017

Parsing in ZILF, part 3: From noun phrase to object

This is the third in a series of posts describing ZILF's parser. Read part 2 here.

In the second post, we covered noun phrases -- phrases like "all cubes except red" and "lamp, food, and bottle" that the player can type to refer to objects.

We also covered how the parser recognizes them and how it represents them in memory: the PARSE-NOUN-PHRASE routine scans the player's command and fills in a NOUN-PHRASE structure, which holds a list of adjective/noun pairs called OBJSPECs.

But how does the parser identify which objects the player is referring to?

After MATCH-SYNTAX finds a syntax line that matches the player's command, the FIND-OBJECTS routine combines the noun phrases with the find flag and search options from the syntax line, and decides what needs to be done for each object required by the syntax line.

There are a few possibilities, depending on what the player typed. It can:

  • match a noun phrase,
  • expand a pronoun,
  • supply a missing object,
  • ask the player to clarify,
  • or fail, printing an error message.

Tuesday, July 19, 2016

It's an amazing smile, even the suit has teeth

(Note: vaporware: interactive fiction normally sticks to technical topics, but I'm making an exception to respond to a post directed at me that doesn't allow comments.)

In a way, it's flattering. Pillars of the IF community like Zarf and Emily Short have had detractors following them around for years, sniping at them in one forum after another. Now, I finally have one of my own.

And mine knows how to hold a grudge.

Last week, that grudge led him to write a number of false, demeaning things about me. Most of those were on a forum thread, which has since been expunged for code-of-conduct violations. Some were on a syndicated blog, which is why (with some regret) I'm responding here.

This all started about a year ago, when I made a flippant remark in an interactive fiction chat room run by this person in response to a bit of language policing: after one person made an announcement to the room, addressing it to "you guys [and] ladies", a second person took offense to this idiom for addressing a group and chided him to be more inclusive. I responded, sarcastically, that I too was offended because the second person's language theoretically still left some people out.

The moderator of this chat room warned me that such comments were unwelcome there, so I didn't repeat them. I wasn't banned, but I haven't returned there since last year, because there are a number of things I find unappealing about that environment, including a clumsy web interface. ifMUD is more welcoming, more usable, and it has a parrot.

I haven't really thought about that episode again until this weekend, when I saw his posts, which were prompted by a discussion in which other people mentioned feeling alienated in that chat room as a result of hostile interactions with the same moderator.

I guess he's been stewing over it all year, because today, his account of it is couched in so much hyperbole it's barely recognizable: misrepresenting the content of our exchange, assigning me motivations that are insulting and divorced from reality, and abusing words like "deliberately" and "explicitly" to dress up false assumptions in the language of impartial observations. He even accuses me of an unexplained "pattern" of "nasty behavior" that, from what I can tell, refers to a couple times over the years when I've defended critics and competition judges against attacks very similar to the ones he's making now.

I won't respond point-by-point here, partly because those attacks don't deserve any more airtime, and partly because I hope this was caused by misunderstanding rather than malice. I'd rather not burden him with being forever linked to those remarks if he chooses to retract them.

He could have reached out to me at any time in the past year to clear this up, but maybe he's been busy. I know when I get into the groove working on Guncho or ZILF, it can be hard to find time for anything else besides sleep and work, so this could be a sign that something great is in the works.

(Now back to the usual topics.)

Monday, November 30, 2015

New optimizations coming in ZILF 0.8

Left: Code generated by ZILF 0.7 (11 instructions).
Right: Code after new optimizations (1 instruction).


How ZILF turns the nasty code on the left into a single instruction, using three new optimizations:

==1==

?L14: BAND STACK,2048 >STACK
BAND STACK,32767 >STACK
ZERO? STACK /?L12
PUSH 1
JUMP ?L13
?L12: PUSH 0
?L13: ZERO? STACK \?L6
PUSH 1
JUMP ?L7
?L6:  PUSH 0
?L7: ZERO? STACK \FALSE

Combine sequential bitwise operations (this is new). BAND STACK,32767 goes away, because 2048 & 32767 == 2048.

==2==

?L14: BAND STACK,2048 >STACK
ZERO? STACK /?L12
PUSH 1
JUMP ?L13
?L12: PUSH 0
?L13: ZERO? STACK \?L6
PUSH 1
JUMP ?L7
?L6: PUSH 0
?L7:  ZERO? STACK \FALSE

Convert single-bit BAND+ZERO? test to BTST (this is new). BAND STACK,2048 >STACK followed by ZERO? STACK /?L12 becomes BTST STACK,2048 \?L12, because 2048 is a power of two.

==3==

?L14: BTST STACK,2048 \?L12
PUSH 1
JUMP ?L13
?L12: PUSH 0
?L13: ZERO? STACK \?L6
PUSH 1
JUMP ?L7
?L6: PUSH 0
?L7:  ZERO? STACK \FALSE

Bypass controlled conditional branch (this is new). PUSH 1 followed by a JUMP to ZERO? STACK \?L6 becomes JUMP ?L6, because we know the negative ZERO? branch will be taken.

==4==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
JUMP ?L13
?L12: PUSH 0
?L13: ZERO? STACK \?L6
PUSH 1
JUMP ?L7
?L6:  PUSH 0
?L7:  ZERO? STACK \FALSE

Bypass controlled conditional branch. PUSH 0 followed by ZERO? STACK \?L6 becomes a JUMP to the new ?L15 (the instruction after ZERO?), because we know the negative branch won't be taken.

==5==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
JUMP ?L13
?L12: JUMP ?L15
?L13: ZERO? STACK \?L6
?L15: PUSH 1
JUMP ?L7
?L6: PUSH 0
?L7: ZERO? STACK \FALSE

Bypass controlled conditional branch. PUSH 1 followed by a JUMP to ZERO? STACK \FALSE becomes RFALSE, because we know the negative branch will be taken.

==6==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
JUMP ?L13
?L12: JUMP ?L15
?L13: ZERO? STACK \?L6
?L15: RFALSE
JUMP ?L7
?L6: PUSH 0
?L7: ZERO? STACK \FALSE

Bypass controlled conditional branch. PUSH 0 followed by ZERO? STACK \FALSE becomes a JUMP to the new ?L16, because we know the negative branch won't be taken.

==7==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
JUMP ?L13
?L12: JUMP ?L15
?L13: ZERO? STACK \?L6
?L15: RFALSE
JUMP ?L7
?L6: JUMP ?L16
?L7: ZERO? STACK \FALSE
?L16: ...

Eliminate dead code and unused labels.

==8==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
?L12: JUMP ?L15
?L15: RFALSE
?L6:  JUMP ?L16
ZERO? STACK \FALSE
?L16: ...

Eliminate branch to next instruction. JUMP ?L15 goes away; ?L15 merges with ?L12.

==9==

?L14: BTST STACK,2048 \?L12
JUMP ?L6
?L12: RFALSE
?L6: JUMP ?L16
ZERO? STACK \FALSE
?L16: ...

Disintermediate branch. BTST STACK,2048 \?L12 becomes BTST STACK,2048 \FALSE, because the instruction at ?L12 is RFALSE.

==10==

?L14: BTST STACK,2048 \FALSE
JUMP ?L6
?L12: RFALSE
?L6: JUMP ?L16
ZERO? STACK \FALSE
?L16: ...

Disintermediate branch. JUMP ?L6 becomes JUMP ?L16, because the instruction at ?L6 is JUMP ?L16.

==11==

?L14: BTST STACK,2048 \FALSE
JUMP ?L16
?L12: RFALSE
?L6: JUMP ?L16
ZERO? STACK \FALSE
?L16: ...


Eliminate dead code and unused labels.

==12==

?L14: BTST STACK,2048 \FALSE
JUMP ?L16
?L16: ...

Eliminate branch to next instruction. JUMP ?L16 goes away.

==13==

?L14: BTST STACK,2048 \FALSE

Sunday, October 25, 2015

Parsing in ZIL, part 2: Noun phrases

This is the second in a series of posts describing ZILF's parser. Read part 1 here, or read part 3 here.

In the first post, we covered the basic structure of a command: verbs, prepositions, and noun phrases. Recognizing a verb or preposition is easy; it's just a word tagged with that part of speech. Once the parser has the verb and prepositions, it uses them to find a matching grammar line. But how does it recognize noun phrases, and what does it do with them?

What is a noun phrase, anyway?

Here are some sample commands, with the noun phrases in bold:
throw axe at dwarf
get shiny brass lamp, tasty food, and bottle
drop any
get set of keys
get all except sign
put all cubes except red and blue in the chute
A noun phrase is anything the player can type to identify the object of a command. It can refer to a single object, like "axe"; a list of objects, like "lamp, bottle, and food"; a set of objects answering to the same name, like "cubes"; or a set of objects implicitly defined by what the player can see, like "all" or "any". It can exclude objects with "except" or "but". And it can quantify what you mean when there's more than one similar object: do you want all of them, a specific one, or any random one?

The grammar of an acceptable noun phrase is, more or less:
[all/any] [article] [adjective...] [noun]
The individual parts are optional, but at least one must be given. Larger phrases can also be made by stringing small ones together with commas or words like "and", "except", "but", and "of":
[noun phrase], [noun phrase] and [noun phrase] of [noun phrase] except [noun phrase] and [noun phrase]
When the parser encounters a noun phrase, it records the important parts in a data structure called NOUN-PHRASE, which it uses later to find matches within the set of objects available to the player. The structure itself is very simple, containing only a "mode", a list of adjective/noun pairs (called OBJSPECs) to include, and another list of OBJSPECs to exclude.

Let's see what the parser does with some of the noun phrases from above:

"axe"

Mode default
Include (*, AXE)
Exclude none

Simple enough: we're just looking for an object that lists AXE in its SYNONYM property. We're using the default match mode, which means if there's more than one "axe" in sight, the parser will ask which one you mean.

"shiny brass lamp, tasty food, and bottle"

Mode default
Include (SHINY, LAMP)
(TASTY, FOOD)
(*, BOTTLE)
Exclude none

This time we have a few pairs in the Include list, and two of them have adjectives. The parser will look for objects with SHINY in their ADJECTIVE properties and LAMP in their SYNONYM properties. Likewise for TASTY and FOOD. Notice that BRASS is nowhere to be seen -- the parser only remembers one adjective per OBJSPEC.

But BOTTLE can be surprising in a game like Adventure where "bottle" and "bottled water" are both objects. Because of Z-machine limits, "bottle" and "bottled" are treated as the same word: if the player types "get bottled", referring to the bottled water by its adjective, to the parser it looks the same as "get bottle", referring to the bottle by its noun. The parser needs to support both. So even though the structure lists BOTTLE as a noun, the parser will see there's no adjective paired with it and notice that BOTTLE can also be used as an adjective, and it'll look for it in the ADJECTIVE property as well. This is a lower-quality match, so if another nearby object has the word in its SYNONYM property, the parser will pick that one instead.

"set of keys"

Mode default
Include (*, KEYS)
Exclude none

Hey, what happened to SET?

Object names containing "of" are special. SET and KEYS are both in the object's SYNONYM property, but the parser only thinks about one adjective and one noun at a time, so they can't both be used. Adjacent nouns normally belong to separate noun phrases, e.g. "give troll money".

However, when the parser sees "of" in a noun phrase, it forgets the last noun it saw! So "set of keys" becomes simply "keys". This makes the parser's job easier, but at the cost of being unable to know whether the player wants the set of keys, the pile of keys, or the stack of boxes of pictures of keys. (It can still tell them apart by asking questions, as we'll see in the post on orphaning.)

"any"

Mode any
Include none
Exclude none

This time, we didn't give any nouns or adjectives, only a mode. Since the Include list is empty, the parser will choose from all available objects, and since the match mode is "any", it'll choose a random object if there's more than one match.

"all except sign"

Mode all
Include none
Exclude (*, SIGN)

Again, the Include list is empty, so the parser chooses from all available objects, then excludes any object with the word SIGN in its SYNONYM property. Since the match mode is "all", if there's more than one "sign" available, the parser will include exclude all of them.

"all cubes except red and blue"

Mode all
Include (*, CUBES)
Exclude (RED, *)
(BLUE, *)

This time, the Include and Exclude lists are both present. The parser will find all available objects with CUBES in their SYNONYM property, then exclude any that have RED or BLUE in their ADJECTIVE property.

Thursday, October 1, 2015

ZILF 0.7 and Adventure

Update: IF Archive links: ZILF 0.7, Advent.z3.

The IF Archive upload is still being processed, but for now you can download ZILF 0.7 from Bitbucket. (Or read the release notes.)

Among other things, this version includes a new sample project: a port of Adventure, aka Colossal Cave. Download Advent.z3 to play!