Skip to content

Commit

Permalink
test-fix: adapt = so that it can be a replacement too
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce committed May 11, 2024
1 parent dffc48c commit c188a20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
54 changes: 27 additions & 27 deletions src/dataflow/environments/built-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function defaultBuiltInProcessor<OtherInfo>(
}

export function registerBuiltInFunctions<Config, Proc extends BuiltInIdentifierProcessorWithConfig<Config>>(
names: readonly Identifier[],
processor: Proc,
config: Config,
...names: readonly Identifier[]
config: Config
): void {
for(const name of names) {
guard(!BuiltInMemory.has(name), `Built-in ${name} already defined`)
Expand Down Expand Up @@ -123,7 +123,7 @@ export function registerReplacementFunctions(


function registerSimpleFunctions(...names: readonly Identifier[]): void {
registerBuiltInFunctions(defaultBuiltInProcessor, { readAllArguments: true }, ...names)
registerBuiltInFunctions(names, defaultBuiltInProcessor, { readAllArguments: true })
}

function registerBuiltInConstant<T>(name: Identifier, value: T): void {
Expand All @@ -147,29 +147,29 @@ registerBuiltInConstant('T', true)
registerBuiltInConstant('FALSE', false)
registerBuiltInConstant('F', false)
registerSimpleFunctions('~', '+', '-', '*', '/', '^', '!', '?', '**', '==', '!=', '>', '<', '>=', '<=', '%%', '%/%', '%*%', ':', 'list')
registerBuiltInFunctions(defaultBuiltInProcessor, {}, 'cat', 'switch') /* returns null */
registerBuiltInFunctions(defaultBuiltInProcessor, { returnsNthArgument: 0 }, 'print', '(')
registerBuiltInFunctions(defaultBuiltInProcessor, { returnsNthArgument: 0, cfg: ExitPointType.Return }, 'return')
registerBuiltInFunctions(defaultBuiltInProcessor, { cfg: ExitPointType.Break }, 'break')
registerBuiltInFunctions(defaultBuiltInProcessor, { cfg: ExitPointType.Next }, 'next')
registerBuiltInFunctions(processExpressionList, {}, '{')
registerBuiltInFunctions(processSourceCall, {}, 'source')
registerBuiltInFunctions(processAccess, { treatIndicesAsString: false }, '[', '[[')
registerBuiltInFunctions(processAccess, { treatIndicesAsString: true }, '$', '@')
registerBuiltInFunctions(processIfThenElse, {}, 'if')
registerBuiltInFunctions(processGet, {}, 'get')
registerBuiltInFunctions(processAssignment, { canBeReplacement: true }, '<-')
registerBuiltInFunctions(processAssignment, {}, ':=', '=', 'assign')
registerBuiltInFunctions(processAssignment, { quoteSource: true }, 'delayedAssign')
registerBuiltInFunctions(processAssignment, { superAssignment: true }, '<<-')
registerBuiltInFunctions(processAssignment, { swapSourceAndTarget: true }, '->')
registerBuiltInFunctions(processAssignment, { superAssignment: true, swapSourceAndTarget: true }, '->>')
registerBuiltInFunctions(processSpecialBinOp, { lazy: true }, '&&', '||', '&', '|')
registerBuiltInFunctions(processPipe, {}, '|>')
registerBuiltInFunctions(processFunctionDefinition, {}, 'function', '\\')
registerBuiltInFunctions(processQuote, { quoteArgumentsWithIndex: 0 }, 'quote', 'substitute', 'bquote')
registerBuiltInFunctions(processForLoop, {}, 'for')
registerBuiltInFunctions(processRepeatLoop, {}, 'repeat')
registerBuiltInFunctions(processWhileLoop, {}, 'while')
registerBuiltInFunctions(['cat', 'switch'], defaultBuiltInProcessor, {}) /* returns null */
registerBuiltInFunctions(['print', '('], defaultBuiltInProcessor, { returnsNthArgument: 0 }, )
registerBuiltInFunctions(['return'], defaultBuiltInProcessor, { returnsNthArgument: 0, cfg: ExitPointType.Return }, )
registerBuiltInFunctions(['break'], defaultBuiltInProcessor, { cfg: ExitPointType.Break }, )
registerBuiltInFunctions(['next'], defaultBuiltInProcessor, { cfg: ExitPointType.Next }, )
registerBuiltInFunctions(['{'], processExpressionList, {}, )
registerBuiltInFunctions(['source'], processSourceCall, {}, )
registerBuiltInFunctions(['[', '[['], processAccess, { treatIndicesAsString: false }, )
registerBuiltInFunctions(['$', '@'], processAccess, { treatIndicesAsString: true }, )
registerBuiltInFunctions(['if'], processIfThenElse, {}, )
registerBuiltInFunctions(['get'], processGet, {}, )
registerBuiltInFunctions(['<-', '='], processAssignment, { canBeReplacement: true }, )
registerBuiltInFunctions([':=', 'assign'], processAssignment, {}, )
registerBuiltInFunctions(['delayedAssign'], processAssignment, { quoteSource: true }, )
registerBuiltInFunctions(['<<-'], processAssignment, { superAssignment: true, canBeReplacement: true }, )
registerBuiltInFunctions(['->'], processAssignment, { swapSourceAndTarget: true, canBeReplacement: true }, )
registerBuiltInFunctions(['->>'], processAssignment, { superAssignment: true, swapSourceAndTarget: true, canBeReplacement: true } )
registerBuiltInFunctions(['&&', '||', '&', '|'], processSpecialBinOp, { lazy: true } )
registerBuiltInFunctions(['|>'], processPipe, {}, )
registerBuiltInFunctions(['function', '\\'], processFunctionDefinition, {}, )
registerBuiltInFunctions(['quote', 'substitute', 'bquote'], processQuote, { quoteArgumentsWithIndex: 0 }, )
registerBuiltInFunctions(['for'], processForLoop, {}, )
registerBuiltInFunctions(['repeat'], processRepeatLoop, {}, )
registerBuiltInFunctions(['while'], processWhileLoop, {}, )
/* they are all mapped to `<-` but we separate super assignments */
registerReplacementFunctions({ makeMaybe: true }, ['<-', '<<-'], '[', '[[', '$', '@', 'names', 'dimnames', 'attributes', 'attr', 'class', 'levels', 'rownames', 'colnames')
4 changes: 2 additions & 2 deletions src/dataflow/graph/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jsonReplacer } from '../../util/json'
import { arrayEqual } from '../../util/arrays'
import { VertexType } from './vertex'
import type { DataflowGraphEdge } from './edge'
import { splitEdgeTypes } from './edge'
import { edgeTypesToNames , splitEdgeTypes } from './edge'
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'
import { recoverName } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'
import type { IdentifierReference } from '../environments/identifier'
Expand Down Expand Up @@ -274,7 +274,7 @@ function diffEdge(edge: DataflowGraphEdge, otherEdge: DataflowGraphEdge, ctx: Da
}
if(edge.types !== otherEdge.types) {
ctx.report.addComment(
`Target of ${id}->${target} in ${ctx.leftname} differs in edge types: ${JSON.stringify([...edgeTypes])} vs ${JSON.stringify([...otherEdgeTypes])}`,
`Target of ${id}->${target} in ${ctx.leftname} differs in edge types: ${JSON.stringify([...edgeTypesToNames(edge.types)])} vs ${JSON.stringify([...edgeTypesToNames(otherEdge.types)])}`,
{ tag: 'edge', from: id, to: target }
)
}
Expand Down

0 comments on commit c188a20

Please sign in to comment.