Skip to content
Snippets Groups Projects
Select Git revision
  • 3b285086d45a3d885c9aa4066184cac58c93de80
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

runtime-macro.ts

Blame
  • runtime-macro.ts 2.97 KiB
    // /**
    //  * Copyright (c) 2018 Mol* contributors, licensed under MIT, See LICENSE file for more info.
    //  *
    //  * @author David Sehnal <david.sehnal@gmail.com>
    //  */
    
    // import Expression from '../language/expression';
    
    // interface Macro {
    //     readonly argNames: ReadonlyArray<string>,
    //     readonly argIndex: { [name: string]: number },
    //     readonly expression: Expression
    // }
    
    // namespace Macro {
    //     export type Table = Map<string, Macro>
    
    //     function subst(table: Table, expr: Expression, argIndex: { [name: string]: number }, args: ArrayLike<Expression>): Expression {
    //         if (Expression.isLiteral(expr)) return expr;
    //         if (Expression.isSymbol(expr)) {
    //             const idx = argIndex[expr.name];
    //             if (typeof idx !== 'undefined') return args[idx];
    
    //             if (table.has(expr.name)) {
    //                 const macro = table.get(expr.name)!;
    //                 if (macro.argNames.length === 0) return macro.expression;
    //             }
    
    //             return expr;
    //         }
    
    //         const head = subst(table, expr.head, argIndex, args);
    //         const headChanged = head !== expr.head;
    //         if (!expr.args) {
    //             return headChanged ? Expression.Apply(head) : expr;
    //         }
    
    //         let argsChanged = false;
    
    //         if (Expression.isArgumentsArray(expr.args)) {
    //             let newArgs: Expression[] = [];
    //             for (let i = 0, _i = expr.args.length; i < _i; i++) {
    //                 const oldArg = expr.args[i];
    //                 const newArg = subst(table, oldArg, argIndex, args);
    //                 if (oldArg !== newArg) argsChanged = true;
    //                 newArgs[newArgs.length] = newArg;
    //             }
    //             if (!argsChanged) newArgs = expr.args;
    
    //             if (Expression.isSymbol(head) && table.has(head.name)) {
    //                 const macro = table.get(head.name)!;
    //                 if (macro.argNames.length === newArgs.length) {
    //                     return subst(table, macro.expression, macro.argIndex, newArgs);
    //                 }
    //             }
    
    //             if (!headChanged && !argsChanged) return expr;
    //             return Expression.Apply(head, newArgs);
    //         } else {
    
    //             let newArgs: any = {}
    //             for (const key of Object.keys(expr.args)) {
    //                 const oldArg = expr.args[key];
    //                 const newArg = subst(table, oldArg, argIndex, args);
    //                 if (oldArg !== newArg) argsChanged = true;
    //                 newArgs[key] = newArg;
    //             }
    //             if (!headChanged && !argsChanged) return expr;
    //             if (!argsChanged) newArgs = expr.args;
    
    //             return Expression.Apply(head, newArgs);
    //         }
    //     }
    
    //     export function substitute(table: Table, macro: Macro, args: ArrayLike<Expression>) {
    //         if (args.length === 0) return macro.expression;
    //         return subst(table, macro.expression, macro.argIndex, args);
    //     }
    // }
    
    // export { Macro }