Commit c7e7e24e

c7e7e24ea718Merged

Ryan Seys <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

feat(parse): support ImplicitNode top-level via parser-side unwrap

PM_ASSOC_NODE at line 445 already unwraps PM_IMPLICIT_NODE inline when it appears as an AssocNode value (the hash-shorthand {x:} form added in PR #143). But PM_IMPLICIT_NODE can appear in other contexts too -- KeywordHashNode kwarg shorthand, pattern-match implicit values in future Prism evolutions -- and any of those paths fell into Phase 0's UnsupportedNode loud-error.

Adds a top-level PM_IMPLICIT_NODE case that lowers to the inner value at the same id slot via the node_counter rewind trick:

case PM_IMPLICIT_NODE: {
  pm_implicit_node_t *n = (pm_implicit_node_t *)node;
  node_counter--;
  return flatten(n->value);
}

Same idiom PM_SHAREABLE_CONSTANT_NODE and PM_IT_LOCAL_VARIABLE_READ_NODE already use. The codegen never sees an ImplicitNode -- it sees the unwrapped inner expression directly, so no codegen arm is needed.

No test fixture: PM_IMPLICIT_NODE only reaches the top-level case in contexts that rely on later-phase work (kwarg shorthand needs KeywordHashNode arm work; pattern-match implicit values need HashPatternNode). The case is defensive -- it future-proofs against those phases without changing observable behaviour today.

Tests: 256 pass (no new fixture). Bootstrap: gen2.c == gen3.c.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
c7e7e24ea718
Parent
135e1a3a3938

spinel_parse.cmodifiedView file

@@ -462,14 +462,10 @@
462462 N("AssocNode");
463463 R("key", n->key);
464464 /* Hash shorthand `{ x: }` lowers to an AssocNode whose value is a
465- PM_IMPLICIT_NODE wrapping the actual LocalVariableReadNode (or
466- MethodCallNode for an undeclared name). Unwrap one level here so
467- the codegen never sees the implicit wrapper. */
468- pm_node_t *val = n->value;
469- if (val && PM_NODE_TYPE_P(val, PM_IMPLICIT_NODE)) {
470- val = ((pm_implicit_node_t *)val)->value;
471- }
472- R("value", val);
465+ PM_IMPLICIT_NODE. The top-level PM_IMPLICIT_NODE case below
466+ handles the unwrap by recursing into n->value at the same id
467+ slot, so the codegen never sees the implicit wrapper here. */
468+ R("value", n->value);
473469 break;
474470 }
475471 case PM_KEYWORD_HASH_NODE: {
@@ -760,6 +756,16 @@
760756 N("SourceEncodingNode");
761757 break;
762758 }
759+ case PM_IMPLICIT_NODE: {
760+ /* Wraps an implicit value reference, e.g. the value side of a
761+ hash-shorthand `{x:}`. Lowers to its inner value at the same
762+ id slot so the codegen never sees the implicit wrapper. Covers
763+ PM_IMPLICIT_NODE in any context (AssocNode value, kwarg
764+ shorthand inside KeywordHashNode, future Prism evolutions). */
765+ pm_implicit_node_t *n = (pm_implicit_node_t *)node;
766+ node_counter--;
767+ return flatten(n->value);
768+ }
763769 case PM_SPLAT_NODE: {
764770 pm_splat_node_t *n = (pm_splat_node_t *)node;
765771 N("SplatNode");