/* * PCN System Compiler: VT transformations * Author: Robert Olson * Argonne National Laboratory * * Please see the DISCLAIMER file in the top level directory of the * distribution regarding the provisions under which this software * is distributed. * * vtco_walk.ptn - Walk a term * * */ walk_term(term, newterm, state, newstate, varop) {? tuple(term) -> {? term ?= {v, name, index}, v == "_var" -> {; op:apply(varop, {term, newterm, state, newstate}) }, default -> {; l = length(term), make_tuple(l, newterm), walk_tuple(0, l, term, newterm, state, newstate, varop) } }, int(term) -> {|| newterm = term, newstate = state }, char(term) -> {|| newterm = term, newstate = state }, double(term) -> {|| newterm = term, newstate = state }, default -> {|| abort("Unknown term type '%t'\n", {term}, _) } } walk_tuple(i, n, term, newterm, state, newstate, varop) {? i >= n -> {|| newstate = state }, i < n -> {; t = term[i], walk_term(t, nt, state, state1, varop), newterm[i] = nt, walk_tuple(i+1, n, term, newterm, state1, newstate, varop) } }