feat(charka): SET ... TO TRUE — escribir nombres de condición (88)

La cara de escritura de los nombres de condición de COBOL: si
IF ES-VALIDO los lee, SET ES-VALIDO TO TRUE los escribe.

- IR: Stmt::SetTrue { conditions }.
- Parser: SET cond-1 cond-2 ... TO TRUE. Otras formas de SET
  (índices, TO FALSE) caen a Stmt::Unknown.
- Codegen y shadow: SET cond TO TRUE asigna a su dato padre el valor
  del 88 (un MOVE del valor a la variable).
- Corpus: programa nuevo 16-bandera (cambia banderas de texto y de
  número con SET). Verificado: el intérprete sombra y el crate
  compilado por scaffold dan la misma salida.

Tests: charka-ir 29, charka-codegen 23, charka-shadow 21. fmt +
clippy limpios.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
sergio
2026-05-21 22:32:08 +00:00
parent fa65f20206
commit 82ba0b7a1a
12 changed files with 115 additions and 4 deletions
@@ -427,6 +427,18 @@ mod tests {
assert!(out.contains("self.ws_b.fill(' ');"));
}
#[test]
fn set_to_true_moves_the_88_value() {
let out = gen("DATA DIVISION.\n\
WORKING-STORAGE SECTION.\n\
01 WS-F PIC X VALUE 'N'.\n\
88 LISTO VALUE 'S'.\n\
PROCEDURE DIVISION.\n\
MAIN.\n\
SET LISTO TO TRUE.\n");
assert!(out.contains("self.ws_f.store(\"S\");"));
}
#[test]
fn empty_program_still_compiles_shape() {
let out = gen("");
@@ -87,6 +87,7 @@ pub(crate) fn emit_stmt(em: &mut Emitter, sym: &Symbols, stmt: &Stmt) {
} => emit_unstring(em, sym, source, delimiter, into),
Stmt::Inspect { target, op } => emit_inspect(em, sym, target, op),
Stmt::Initialize { targets } => emit_initialize(em, sym, targets),
Stmt::SetTrue { conditions } => emit_set_true(em, sym, conditions),
Stmt::Perform(p) => emit_perform(em, sym, p),
Stmt::GoTo { target } => {
em.line(&format!(
@@ -492,6 +493,21 @@ fn emit_initialize(em: &mut Emitter, sym: &Symbols, targets: &[Operand]) {
}
}
/// `SET cond... TO TRUE` — asigna a cada dato padre el valor que hace
/// verdadero su nombre de condición (nivel 88).
fn emit_set_true(em: &mut Emitter, sym: &Symbols, conditions: &[String]) {
for name in conditions {
match sym.condition(name) {
Some(cn) => {
let target = Operand::Data(cn.parent.clone());
let value = cn.value.clone();
emit_move(em, sym, &value, std::slice::from_ref(&target));
}
None => em.line(&format!("// charka: condición 88 no resuelta — {name}")),
}
}
}
/// Resetea un campo completo (escalar o tabla entera).
fn emit_reset(em: &mut Emitter, sym: &Symbols, name: &str) {
let Some(f) = sym.lookup(name) else {