Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1import {2 LEAF_NODE_TYPES_COUNT,3 NODE_TYPE_IDS_MAP,4 NODE_TYPES_COUNT,5} from "../generated/lazy/type_ids.js";6 7// Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.8let getVisitorsArrTemp;9 10/**11 * Visitor class, used to visit an AST.12 */13export class Visitor {14 #visitorsArr;15 16 /**17 * Create `Visitor`.18 *19 * Provide an object where keys are names of AST nodes you want to visit,20 * and values are visitor functions which receive AST node objects of that type.21 *22 * Keys can also be postfixed with `:exit` to visit when exiting the node, rather than entering.23 *24 * ```js25 * const visitor = new Visitor({26 * BinaryExpression(binExpr) {27 * // Do stuff when entering a `BinaryExpression`28 * },29 * 'BinaryExpression:exit'(binExpr) {30 * // Do stuff when exiting a `BinaryExpression`31 * },32 * });33 * ```34 *35 * @class36 * @param {Object} visitor - Object defining visit functions for AST nodes37 * @returns {Visitor}38 */39 constructor(visitor) {40 this.#visitorsArr = createVisitorsArr(visitor);41 }42 43 static {44 getVisitorsArrTemp = (visitor) => visitor.#visitorsArr;45 }46}47 48export const getVisitorsArr = getVisitorsArrTemp;49 50/**51 * Create array of visitors, keyed by node type ID.52 *53 * Each element of array is one of:54 *55 * * No visitor for this type = `null`.56 * * Visitor for leaf node = visit function.57 * * Visitor for non-leaf node = object of form `{ enter, exit }`,58 * where each property is either a visitor function or `null`.59 *60 * @param {Object} visitor - Visitors object from user61 * @returns {Array<Object|Function|null>} - Array of visitors62 */63function createVisitorsArr(visitor) {64 if (visitor === null || typeof visitor !== "object") {65 throw new Error("`visitor` must be an object");66 }67 68 // Create empty visitors array69 const visitorsArr = [];70 for (let i = NODE_TYPES_COUNT; i !== 0; i--) {71 visitorsArr.push(null);72 }73 74 // Populate visitors array from provided object75 for (let name of Object.keys(visitor)) {76 const visitFn = visitor[name];77 if (typeof visitFn !== "function") {78 throw new Error(`'${name}' property of \`visitor\` object is not a function`);79 }80 81 const isExit = name.endsWith(":exit");82 if (isExit) name = name.slice(0, -5);83 84 const typeId = NODE_TYPE_IDS_MAP.get(name);85 if (typeId === void 0) throw new Error(`Unknown node type '${name}' in \`visitor\` object`);86 87 if (typeId < LEAF_NODE_TYPES_COUNT) {88 // Leaf node. Store just 1 function.89 const existingVisitFn = visitorsArr[typeId];90 if (existingVisitFn === null) {91 visitorsArr[typeId] = visitFn;92 } else if (isExit) {93 visitorsArr[typeId] = combineVisitFunctions(existingVisitFn, visitFn);94 } else {95 visitorsArr[typeId] = combineVisitFunctions(visitFn, existingVisitFn);96 }97 continue;98 }99 100 let enterExit = visitorsArr[typeId];101 if (enterExit === null) {102 enterExit = visitorsArr[typeId] = { enter: null, exit: null };103 }104 105 if (isExit) {106 enterExit.exit = visitFn;107 } else {108 enterExit.enter = visitFn;109 }110 }111 112 return visitorsArr;113}114 115/**116 * Combine 2 visitor functions into 1.117 *118 * @param {function} visit1 - 1st visitor function119 * @param {function} visit2 - 2nd visitor function120 * @returns {function} - Combined visitor function121 */122function combineVisitFunctions(visit1, visit2) {123 return function (node) {124 visit1(node);125 visit2(node);126 };127}128 