Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Slartibartfass2 committed Nov 20, 2024
1 parent 593edab commit 8a2d646
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/dataflow/environments/built-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function defaultBuiltInProcessor<OtherInfo>(
data: DataflowProcessorInformation<OtherInfo & ParentInformation>,
config: DefaultBuiltInProcessorConfiguration
): DataflowInformation {
// console.log('processing default:', name.content);
const { information: res, processedArguments } = processKnownFunctionCall({ name, args, rootId, data, forceArgs: config.forceArgs });
if(config.returnsNthArgument !== undefined) {
const arg = config.returnsNthArgument === 'last' ? processedArguments[args.length - 1] : processedArguments[config.returnsNthArgument];
Expand Down
8 changes: 8 additions & 0 deletions src/dataflow/environments/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import type { AssignmentConfiguration } from '../internal/process/functions/call
function defInEnv(newEnvironments: IEnvironment, name: string, definition: IdentifierDefinition, config?: AssignmentConfiguration | undefined) {
const existing = newEnvironments.memory.get(name);
// check if it is maybe or not
// console.log('existing:', existing, 'definition:', definition);
// TODO: check if indices are already defined regarding overwrite
if(config?.indices !== undefined) {
console.log(config.indices);
}
if(existing === undefined || definition.controlDependencies === undefined) {
newEnvironments.memory.set(name, [definition]);
} else {
existing.push(definition);
}
// console.log('after:', newEnvironments.memory.get(name));
}

/**
Expand All @@ -22,6 +28,8 @@ function defInEnv(newEnvironments: IEnvironment, name: string, definition: Ident
*/
export function define(definition: IdentifierDefinition, superAssign: boolean | undefined, environment: REnvironmentInformation, config?: AssignmentConfiguration | undefined): REnvironmentInformation {
const name = definition.name;
// console.log('defining:', name);
// console.log('definition:', definition);
guard(name !== undefined, () => `Name must be defined, but isn't for ${JSON.stringify(definition)}`);
let newEnvironment;
if(superAssign) {
Expand Down
1 change: 1 addition & 0 deletions src/dataflow/environments/resolve-by-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TargetTypePredicate = {
* @returns A list of possible definitions of the identifier (one if the definition location is exactly and always known), or `undefined` if the identifier is undefined in the current scope/with the current environment information.
*/
export function resolveByName(name: Identifier, environment: REnvironmentInformation, target: ReferenceType = ReferenceType.Unknown): IdentifierDefinition[] | undefined {
// console.log('resolving:', name);
let current: IEnvironment = environment.current;
let definitions: IdentifierDefinition[] | undefined = undefined;
const wantedType = TargetTypePredicate[target];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function processAccess<OtherInfo>(
dataflowLogger.warn(`Access ${name.content} has less than 2 arguments, skipping`);
return processKnownFunctionCall({ name, args, rootId, data, forceArgs: config.forceArgs }).information;
}
// console.log('processing access:', name.content);
const head = args[0];
guard(head !== EmptyArgument, () => `Access ${name.content} has no source, impossible!`);

Expand Down Expand Up @@ -112,14 +113,20 @@ export function processAccess<OtherInfo>(
if(newArgs[0] !== EmptyArgument) {
const accessArg = newArgs[1] === EmptyArgument ? 'all' : newArgs[1].lexeme;
const resolvedFirstParameter = resolveByName(newArgs[0].lexeme ?? '', data.environment);
// console.log('requesting to access', accessArg);
// console.log('resolvedFirstParameter', resolvedFirstParameter);
const resolvedFirstParameterIndices = resolvedFirstParameter?.flatMap(param => (param as InGraphIdentifierDefinition)?.indices ?? []);
console.log('resolved', newArgs[0].lexeme, 'to', resolvedFirstParameterIndices);
accessedArgument = resolvedFirstParameterIndices?.find(index => index.lexeme === accessArg);
}

const indices = accessedArgument === undefined ? undefined : [accessedArgument];
fnCall = processKnownFunctionCall({ name, args: newArgs, rootId, data, forceArgs: config.forceArgs }, indices);
if(accessedArgument !== undefined) {
// console.log('Accessing known index');
fnCall.information.graph.addEdge(name.info.id, accessedArgument.nodeId, EdgeType.Reads);
} else {
// console.log('Accessing unknown index');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ export function markAsAssignment(
if(sourceIds.length === 1) {
// support for tracking indices
indices = information.graph.getVertex(sourceIds[0])?.indices;
if(indices) {
console.log(`Defining indices ${indices.map((index) => `{ lexeme: ${index.lexeme}, nodeId: ${index.nodeId} }`).join(',')} for ${nodeToDefine.name}`);
}
}
if(config?.indices !== undefined) {
indices = (indices ?? []).concat(config.indices);
Expand Down
3 changes: 2 additions & 1 deletion src/dataflow/internal/process/functions/call/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function forceVertexArgumentValueReferences(rootId: NodeId, value: DataflowInfor


export function processAllArguments<OtherInfo>(
{ functionName, args, data, finalGraph, functionRootId, forceArgs = [], patchData = d => d }: ProcessAllArgumentInput<OtherInfo>
{ functionName, args, data, finalGraph, functionRootId, forceArgs = [], patchData = d => d }: ProcessAllArgumentInput<OtherInfo>,
// indices: ContainerIndices = undefined,
): ProcessAllArgumentResult {
let finalEnv = functionName.environment;
// arg env contains the environments with other args defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function processKnownFunctionCall<OtherInfo>(
callArgs,
remainingReadInArgs,
processedArguments
} = processAllArguments<OtherInfo>({ functionName, args: processArgs, data, finalGraph, functionRootId: rootId, patchData, forceArgs });
} = processAllArguments<OtherInfo>({ functionName, args: processArgs, data, finalGraph, functionRootId: rootId, patchData, forceArgs }); // , indices
if(markAsNSE) {
markNonStandardEvaluationEdges(markAsNSE, processedArguments, finalGraph, rootId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function processNamedCall<OtherInfo>(
data: DataflowProcessorInformation<OtherInfo & ParentInformation>
): DataflowInformation {
const resolved = resolveByName(name.content, data.environment, ReferenceType.Function) ?? [];
// console.log('processing named call:', name.content, 'resolved:', resolved);
let defaultProcessor = resolved.length === 0;

let information: DataflowInformation | undefined = undefined;
Expand Down

0 comments on commit 8a2d646

Please sign in to comment.