This instance will be upgraded to Heptapod 0.25.0 (final) on 2021-09-22 at 15:00 UTC+2 (a few minutes of down time)

Commit 2ef87b07 authored by Jesse McGrew's avatar Jesse McGrew
Browse files

Improve source line tracking in CHTYPE and QQ.

Add SET-SOURCE-INFO (in the READER-MACROS package) for use by QQ.
parent 36fd009811ce
......@@ -1166,6 +1166,8 @@ namespace Zilf.Interpreter
if (value.GetTypeAtom(this) == newType)
return value;
ZilObject result;
// TODO: standardize special cases
switch (newType.StdAtom)
{
......@@ -1178,34 +1180,42 @@ namespace Zilf.Interpreter
if (value.PrimType != PrimType.ATOM)
throw new InterpreterError(InterpreterMessages.CHTYPE_To_0_Requires_1, "GVAL or LVAL", "ATOM");
return new ZilForm(new[] { newType, value.GetPrimitive(this) }) { SourceLine = SourceLines.Chtyped };
result = new ZilForm(new[] { newType, value.GetPrimitive(this) });
break;
case StdAtom.ATOM when value.StdTypeAtom == StdAtom.FORM:
if (value.IsGVAL(out var atom) || value.IsLVAL(out atom))
{
// don't set SourceLine
return atom;
}
throw new InterpreterError(InterpreterMessages.CHTYPE_To_0_Requires_1, "ATOM", "ATOM, GVAL, or LVAL");
// special case for TABLE: its primtype is TABLE, but VECTOR can be converted too
case StdAtom.TABLE when value.PrimType == PrimType.VECTOR:
var vector = (ZilVector)value.GetPrimitive(this);
return ZilTable.Create(1, vector.ToArray(), 0, null);
}
result = ZilTable.Create(1, vector.ToArray(), 0, null);
break;
// look it up in the typemap
if (typeMap.TryGetValue(newType, out var entry))
{
if (value.PrimType != entry.PrimType)
{
throw new InterpreterError(
InterpreterMessages.CHTYPE_To_0_Requires_1, newType, entry.PrimType);
}
// look it up in the typemap
case var _ when typeMap.TryGetValue(newType, out var entry):
if (value.PrimType != entry.PrimType)
{
throw new InterpreterError(
InterpreterMessages.CHTYPE_To_0_Requires_1, newType, entry.PrimType);
}
return entry.ChtypeMethod(this, value.GetPrimitive(this));
result = entry.ChtypeMethod(this, value.GetPrimitive(this));
break;
// unknown type
default:
throw new InterpreterError(InterpreterMessages.Unrecognized_0_1, "type", newType);
}
// unknown type
throw new InterpreterError(InterpreterMessages.Unrecognized_0_1, "type", newType);
result.SourceLine ??= SourceLines.Chtyped;
return result;
}
void InitTellPatterns()
......
......@@ -314,5 +314,12 @@ namespace Zilf.Interpreter
: (SimplePrefixMacroHandlerWithContext?)null);
return ctx.TRUE;
}
[Subr("SET-SOURCE-INFO", ObList = "READER-MACROS!-PACKAGE")]
public static ZilObject SET_SOURCE_INFO(Context ctx, ZilObject dest, ZilObject src)
{
dest.SourceLine = src.SourceLine;
return dest;
}
}
}
......@@ -27,7 +27,7 @@
(<NOT <AND <GBOUND? .P> <APPLICABLE? ,.P>>>
<ERROR CANNOT-RECREATE-PRIMTYPE .P>)
(ELSE
<CHTYPE <APPLY ,.P !<QQ-ELEMS .ENV .STRUC>> .T>)>>
<SET-SOURCE-INFO <CHTYPE <APPLY ,.P !<QQ-ELEMS .ENV .STRUC>> .T> .STRUC>)>>
<DEFINE QQ-ELEMS (ENV STRUC "AUX" (ALLOW-SPLICING? T))
<MAPF ,VECTOR
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment