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
1/** @import * as ESTree from 'estree' */2import { walk } from 'zimmerframe';3import { regex_is_valid_identifier } from '../phases/patterns.js';4import { sanitize_template_string } from './sanitize_template_string.js';5import { has_await_expression } from './ast.js';6 7/**8 * @param {Array<ESTree.Expression | ESTree.SpreadElement | null>} elements9 * @returns {ESTree.ArrayExpression}10 */11export function array(elements = []) {12 return { type: 'ArrayExpression', elements };13}14 15/**16 * @param {Array<ESTree.Pattern | null>} elements17 * @returns {ESTree.ArrayPattern}18 */19export function array_pattern(elements) {20 return { type: 'ArrayPattern', elements };21}22 23/**24 * @param {ESTree.Pattern} left25 * @param {ESTree.Expression} right26 * @returns {ESTree.AssignmentPattern}27 */28export function assignment_pattern(left, right) {29 return { type: 'AssignmentPattern', left, right };30}31 32/**33 * @param {Array<ESTree.Pattern>} params34 * @param {ESTree.BlockStatement | ESTree.Expression} body35 * @param {boolean} async36 * @returns {ESTree.ArrowFunctionExpression}37 */38export function arrow(params, body, async = false) {39 // optimize `async () => await x()`, but not `async () => await x(await y)`40 if (async && body.type === 'AwaitExpression') {41 if (!has_await_expression(body.argument)) {42 return arrow(params, body.argument);43 }44 }45 46 return {47 type: 'ArrowFunctionExpression',48 params,49 body,50 expression: body.type !== 'BlockStatement',51 generator: false,52 async53 };54}55 56/**57 * @param {ESTree.AssignmentOperator} operator58 * @param {ESTree.Pattern} left59 * @param {ESTree.Expression} right60 * @returns {ESTree.AssignmentExpression}61 */62export function assignment(operator, left, right) {63 return { type: 'AssignmentExpression', operator, left, right };64}65 66/**67 * @param {ESTree.Expression} argument68 * @returns {ESTree.AwaitExpression}69 */70function await_builder(argument) {71 return { type: 'AwaitExpression', argument };72}73 74/**75 * @param {ESTree.BinaryOperator} operator76 * @param {ESTree.Expression} left77 * @param {ESTree.Expression} right78 * @returns {ESTree.BinaryExpression}79 */80export function binary(operator, left, right) {81 return { type: 'BinaryExpression', operator, left, right };82}83 84/**85 * @param {ESTree.Statement[]} body86 * @returns {ESTree.BlockStatement}87 */88export function block(body) {89 return { type: 'BlockStatement', body };90}91 92/**93 * @param {ESTree.Identifier | null} id94 * @param {ESTree.ClassBody} body95 * @param {ESTree.Expression | null} [superClass]96 * @param {ESTree.Decorator[]} [decorators]97 * @returns {ESTree.ClassExpression}98 */99export function class_expression(id, body, superClass, decorators = []) {100 return { type: 'ClassExpression', body, superClass, decorators };101}102 103/**104 * @param {string} name105 * @param {ESTree.Statement} body106 * @returns {ESTree.LabeledStatement}107 */108export function labeled(name, body) {109 return { type: 'LabeledStatement', label: id(name), body };110}111 112/**113 * @param {string | ESTree.Expression} callee114 * @param {...(ESTree.Expression | ESTree.SpreadElement | false | undefined | null)} args115 * @returns {ESTree.CallExpression}116 */117export function call(callee, ...args) {118 if (typeof callee === 'string') callee = id(callee);119 args = args.slice();120 121 // replacing missing arguments with `void(0)`, unless they're at the end in which case remove them122 let i = args.length;123 let popping = true;124 while (i--) {125 if (!args[i]) {126 if (popping) {127 args.pop();128 } else {129 args[i] = void0;130 }131 } else {132 popping = false;133 }134 }135 136 return {137 type: 'CallExpression',138 callee,139 arguments: /** @type {Array<ESTree.Expression | ESTree.SpreadElement>} */ (args),140 optional: false141 };142}143 144/**145 * @param {string | ESTree.Expression} callee146 * @param {...ESTree.Expression} args147 * @returns {ESTree.ChainExpression}148 */149export function maybe_call(callee, ...args) {150 const expression = /** @type {ESTree.SimpleCallExpression} */ (call(callee, ...args));151 expression.optional = true;152 153 return {154 type: 'ChainExpression',155 expression156 };157}158 159/**160 * @param {ESTree.UnaryOperator} operator161 * @param {ESTree.Expression} argument162 * @returns {ESTree.UnaryExpression}163 */164export function unary(operator, argument) {165 return { type: 'UnaryExpression', argument, operator, prefix: true };166}167 168export const void0 = unary('void', literal(0));169 170/**171 * @param {ESTree.Expression} test172 * @param {ESTree.Expression} consequent173 * @param {ESTree.Expression} alternate174 * @returns {ESTree.ConditionalExpression}175 */176export function conditional(test, consequent, alternate) {177 return { type: 'ConditionalExpression', test, consequent, alternate };178}179 180/**181 * @param {ESTree.LogicalOperator} operator182 * @param {ESTree.Expression} left183 * @param {ESTree.Expression} right184 * @returns {ESTree.LogicalExpression}185 */186export function logical(operator, left, right) {187 return { type: 'LogicalExpression', operator, left, right };188}189 190/**191 * @param {ESTree.VariableDeclaration['kind']} kind192 * @param {ESTree.VariableDeclarator[]} declarations193 * @returns {ESTree.VariableDeclaration}194 */195export function declaration(kind, declarations) {196 return {197 type: 'VariableDeclaration',198 kind,199 declarations200 };201}202 203/**204 * @param {ESTree.Pattern | string} pattern205 * @param {ESTree.Expression | null} [init]206 * @returns {ESTree.VariableDeclarator}207 */208export function declarator(pattern, init) {209 if (typeof pattern === 'string') pattern = id(pattern);210 return { type: 'VariableDeclarator', id: pattern, init };211}212 213/** @type {ESTree.EmptyStatement} */214export const empty = {215 type: 'EmptyStatement'216};217 218/**219 * @param {ESTree.Expression | ESTree.MaybeNamedClassDeclaration | ESTree.MaybeNamedFunctionDeclaration} declaration220 * @returns {ESTree.ExportDefaultDeclaration}221 */222export function export_default(declaration) {223 return { type: 'ExportDefaultDeclaration', declaration };224}225 226/**227 * @param {ESTree.VariableDeclaration | ESTree.Pattern} left228 * @param {ESTree.Expression} right229 * @param {ESTree.Statement} body230 * @param {boolean} [_await]231 * @returns {ESTree.ForOfStatement}232 */233export function for_of(left, right, body, _await = false) {234 return {235 type: 'ForOfStatement',236 left,237 right,238 body,239 await: _await240 };241}242 243/**244 * @param {ESTree.Identifier} id245 * @param {ESTree.Pattern[]} params246 * @param {ESTree.BlockStatement} body247 * @param {boolean} async248 * @returns {ESTree.FunctionDeclaration}249 */250export function function_declaration(id, params, body, async = false) {251 return {252 type: 'FunctionDeclaration',253 id,254 params,255 body,256 generator: false,257 async258 };259}260 261/**262 * @param {string} name263 * @param {ESTree.Statement[]} body264 * @returns {ESTree.Property & { value: ESTree.FunctionExpression}}}265 */266export function get(name, body) {267 return prop('get', key(name), function_builder(null, [], block(body)));268}269 270/**271 * @param {string} name272 * @param {ESTree.SourceLocation | null} [loc]273 * @returns {ESTree.Identifier}274 */275export function id(name, loc) {276 const node = /** @type {ESTree.Identifier} */ ({ type: 'Identifier', name });277 if (loc) node.loc = loc;278 279 return node;280}281 282/**283 * @param {string} name284 * @returns {ESTree.PrivateIdentifier}285 */286export function private_id(name) {287 return { type: 'PrivateIdentifier', name };288}289 290/**291 * @param {string} local292 * @returns {ESTree.ImportNamespaceSpecifier}293 */294function import_namespace(local) {295 return {296 type: 'ImportNamespaceSpecifier',297 local: id(local)298 };299}300 301/**302 * @param {string} name303 * @param {ESTree.Expression} value304 * @returns {ESTree.Property}305 */306export function init(name, value) {307 return prop('init', key(name), value);308}309 310/**311 * @param {string | boolean | null | number | RegExp} value312 * @returns {ESTree.Literal}313 */314export function literal(value) {315 // @ts-expect-error we don't want to muck around with bigint here316 return { type: 'Literal', value };317}318 319/**320 * @param {ESTree.Expression | ESTree.Super} object321 * @param {string | ESTree.Expression | ESTree.PrivateIdentifier} property322 * @param {boolean} computed323 * @param {boolean} optional324 * @returns {ESTree.MemberExpression}325 */326export function member(object, property, computed = false, optional = false) {327 if (typeof property === 'string') {328 property = id(property);329 }330 331 return { type: 'MemberExpression', object, property, computed, optional };332}333 334/**335 * @param {string} path336 * @returns {ESTree.Identifier | ESTree.MemberExpression}337 */338export function member_id(path) {339 const parts = path.split('.');340 341 /** @type {ESTree.Identifier | ESTree.MemberExpression} */342 let expression = id(parts[0]);343 344 for (let i = 1; i < parts.length; i += 1) {345 expression = member(expression, id(parts[i]));346 }347 return expression;348}349 350/**351 * @param {Array<ESTree.Property | ESTree.SpreadElement>} properties352 * @returns {ESTree.ObjectExpression}353 */354export function object(properties) {355 return { type: 'ObjectExpression', properties };356}357 358/**359 * @param {Array<ESTree.RestElement | ESTree.AssignmentProperty | ESTree.Property>} properties360 * @returns {ESTree.ObjectPattern}361 */362export function object_pattern(properties) {363 // @ts-expect-error the types appear to be wrong364 return { type: 'ObjectPattern', properties };365}366 367/**368 * @template {ESTree.Expression} Value369 * @param {'init' | 'get' | 'set'} kind370 * @param {ESTree.Expression} key371 * @param {Value} value372 * @param {boolean} computed373 * @returns {ESTree.Property & { value: Value }}374 */375export function prop(kind, key, value, computed = false) {376 return { type: 'Property', kind, key, value, method: false, shorthand: false, computed };377}378 379/**380 * @param {ESTree.Expression | ESTree.PrivateIdentifier} key381 * @param {ESTree.Expression | null | undefined} value382 * @param {boolean} computed383 * @param {boolean} is_static384 * @returns {ESTree.PropertyDefinition}385 */386export function prop_def(key, value, computed = false, is_static = false) {387 return {388 type: 'PropertyDefinition',389 decorators: [],390 key,391 value,392 computed,393 static: is_static394 };395}396 397/**398 * @param {string} cooked399 * @param {boolean} tail400 * @returns {ESTree.TemplateElement}401 */402export function quasi(cooked, tail = false) {403 const raw = sanitize_template_string(cooked);404 return { type: 'TemplateElement', value: { raw, cooked }, tail };405}406 407/**408 * @param {ESTree.Pattern} argument409 * @returns {ESTree.RestElement}410 */411export function rest(argument) {412 return { type: 'RestElement', argument };413}414 415/**416 * @param {ESTree.Expression[]} expressions417 * @returns {ESTree.SequenceExpression}418 */419export function sequence(expressions) {420 return { type: 'SequenceExpression', expressions };421}422 423/**424 * @param {string} name425 * @param {ESTree.Statement[]} body426 * @returns {ESTree.Property & { value: ESTree.FunctionExpression}}427 */428export function set(name, body) {429 return prop('set', key(name), function_builder(null, [id('$$value')], block(body)));430}431 432/**433 * @param {ESTree.Expression} argument434 * @returns {ESTree.SpreadElement}435 */436export function spread(argument) {437 return { type: 'SpreadElement', argument };438}439 440/**441 * @param {ESTree.Expression} expression442 * @returns {ESTree.ExpressionStatement}443 */444export function stmt(expression) {445 return { type: 'ExpressionStatement', expression };446}447 448/**449 * @param {ESTree.TemplateElement[]} elements450 * @param {ESTree.Expression[]} expressions451 * @returns {ESTree.TemplateLiteral}452 */453export function template(elements, expressions) {454 return { type: 'TemplateLiteral', quasis: elements, expressions };455}456 457/**458 * @param {ESTree.Expression | ESTree.BlockStatement} expression459 * @param {boolean} [async]460 * @returns {ESTree.Expression}461 */462export function thunk(expression, async = false) {463 return unthunk(arrow([], expression, async));464}465 466/**467 * Replace "(arg) => func(arg)" to "func"468 * @param {ESTree.ArrowFunctionExpression} expression469 * @returns {ESTree.Expression}470 */471export function unthunk(expression) {472 if (473 expression.async === false &&474 expression.body.type === 'CallExpression' &&475 expression.body.callee.type === 'Identifier' &&476 expression.params.length === expression.body.arguments.length &&477 expression.params.every((param, index) => {478 const arg = /** @type {ESTree.SimpleCallExpression} */ (expression.body).arguments[index];479 return param.type === 'Identifier' && arg.type === 'Identifier' && param.name === arg.name;480 })481 ) {482 return expression.body.callee;483 }484 return expression;485}486 487/**488 *489 * @param {string | ESTree.Expression} expression490 * @param {...ESTree.Expression} args491 * @returns {ESTree.NewExpression}492 */493function new_builder(expression, ...args) {494 if (typeof expression === 'string') expression = id(expression);495 496 return {497 callee: expression,498 arguments: args,499 type: 'NewExpression'500 };501}502 503/**504 * @param {ESTree.UpdateOperator} operator505 * @param {ESTree.Expression} argument506 * @param {boolean} prefix507 * @returns {ESTree.UpdateExpression}508 */509export function update(operator, argument, prefix = false) {510 return { type: 'UpdateExpression', operator, argument, prefix };511}512 513/**514 * @param {ESTree.Expression} test515 * @param {ESTree.Statement} body516 * @returns {ESTree.DoWhileStatement}517 */518export function do_while(test, body) {519 return { type: 'DoWhileStatement', test, body };520}521 522const true_instance = literal(true);523const false_instance = literal(false);524const null_instance = literal(null);525 526/** @type {ESTree.DebuggerStatement} */527const debugger_builder = {528 type: 'DebuggerStatement'529};530 531/** @type {ESTree.ThisExpression} */532const this_instance = {533 type: 'ThisExpression'534};535 536/**537 * @param {string | ESTree.Pattern} pattern538 * @param {ESTree.Expression | null} [init]539 * @returns {ESTree.VariableDeclaration}540 */541function let_builder(pattern, init) {542 return declaration('let', [declarator(pattern, init)]);543}544 545/**546 * @param {string | ESTree.Pattern} pattern547 * @param {ESTree.Expression | null} init548 * @returns {ESTree.VariableDeclaration}549 */550function const_builder(pattern, init) {551 return declaration('const', [declarator(pattern, init)]);552}553 554/**555 * @param {string | ESTree.Pattern} pattern556 * @param {ESTree.Expression | null} [init]557 * @returns {ESTree.VariableDeclaration}558 */559function var_builder(pattern, init) {560 return declaration('var', [declarator(pattern, init)]);561}562 563/**564 *565 * @param {ESTree.VariableDeclaration | ESTree.Expression | null} init566 * @param {ESTree.Expression} test567 * @param {ESTree.Expression} update568 * @param {ESTree.Statement} body569 * @returns {ESTree.ForStatement}570 */571function for_builder(init, test, update, body) {572 return { type: 'ForStatement', init, test, update, body };573}574 575/**576 *577 * @param {'constructor' | 'method' | 'get' | 'set'} kind578 * @param {ESTree.Expression | ESTree.PrivateIdentifier} key579 * @param {ESTree.Pattern[]} params580 * @param {ESTree.Statement[]} body581 * @param {boolean} computed582 * @param {boolean} is_static583 * @returns {ESTree.MethodDefinition}584 */585export function method(kind, key, params, body, computed = false, is_static = false) {586 return {587 type: 'MethodDefinition',588 decorators: [],589 key,590 kind,591 value: function_builder(null, params, block(body)),592 computed,593 static: is_static594 };595}596 597/**598 *599 * @param {ESTree.Identifier | null} id600 * @param {ESTree.Pattern[]} params601 * @param {ESTree.BlockStatement} body602 * @returns {ESTree.FunctionExpression}603 */604function function_builder(id, params, body, async = false) {605 return {606 type: 'FunctionExpression',607 id,608 params,609 body,610 generator: false,611 async612 };613}614 615/**616 * @param {ESTree.Expression} test617 * @param {ESTree.Statement} consequent618 * @param {ESTree.Statement} [alternate]619 * @returns {ESTree.IfStatement}620 */621function if_builder(test, consequent, alternate) {622 return { type: 'IfStatement', test, consequent, alternate };623}624 625/**626 * @param {string} as627 * @param {string} source628 * @returns {ESTree.ImportDeclaration}629 */630export function import_all(as, source) {631 return {632 type: 'ImportDeclaration',633 attributes: [],634 source: literal(source),635 specifiers: [import_namespace(as)]636 };637}638 639/**640 * @param {Array<[string, string]>} parts641 * @param {string} source642 * @returns {ESTree.ImportDeclaration}643 */644export function imports(parts, source) {645 return {646 type: 'ImportDeclaration',647 attributes: [],648 source: literal(source),649 specifiers: parts.map((p) => ({650 type: 'ImportSpecifier',651 imported: id(p[0]),652 local: id(p[1])653 }))654 };655}656 657/**658 * @param {ESTree.Expression | null} argument659 * @returns {ESTree.ReturnStatement}660 */661function return_builder(argument = null) {662 return { type: 'ReturnStatement', argument };663}664 665/**666 * @param {string} str667 * @returns {ESTree.ThrowStatement}668 */669export function throw_error(str) {670 return {671 type: 'ThrowStatement',672 argument: new_builder('Error', literal(str))673 };674}675 676export {677 await_builder as await,678 let_builder as let,679 const_builder as const,680 var_builder as var,681 true_instance as true,682 false_instance as false,683 for_builder as for,684 function_builder as function,685 return_builder as return,686 if_builder as if,687 this_instance as this,688 null_instance as null,689 debugger_builder as debugger,690 new_builder as new691};692 693/**694 * @param {string} name695 * @returns {ESTree.Expression}696 */697export function key(name) {698 return regex_is_valid_identifier.test(name) ? id(name) : literal(name);699}700 