-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass optional arguments of memoized calls by name (#1095)
Closes #1087 ### Summary of Changes Optional argument of memoized calls are now stored in a separate dict, so they can be passed by name in the runner.
- Loading branch information
1 parent
77a0c1f
commit 39d9e5a
Showing
19 changed files
with
824 additions
and
265 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/safe-ds-lang/src/language/generation/python/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const CODEGEN_PREFIX = '__gen_'; |
348 changes: 161 additions & 187 deletions
348
...ge/generation/safe-ds-python-generator.ts → ...ration/python/safe-ds-python-generator.ts
Large diffs are not rendered by default.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
packages/safe-ds-lang/src/language/generation/python/utilityFunctions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { expandToNode, Generated } from 'langium/generate'; | ||
|
||
const CODEGEN_PREFIX = '__gen_'; | ||
|
||
export const eagerOr: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}eager_or`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}eager_or(left_operand: bool, right_operand: bool) -> bool: | ||
return left_operand or right_operand | ||
`, | ||
}; | ||
|
||
export const eagerAnd: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}eager_and`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}eager_and(left_operand: bool, right_operand: bool) -> bool: | ||
return left_operand and right_operand | ||
`, | ||
}; | ||
|
||
export const eagerElvis: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}eager_elvis`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}eager_elvis(left_operand: ${CODEGEN_PREFIX}T, right_operand: ${CODEGEN_PREFIX}T) -> ${CODEGEN_PREFIX}T: | ||
return left_operand if left_operand is not None else right_operand | ||
`, | ||
typeVariables: [`${CODEGEN_PREFIX}T`], | ||
}; | ||
|
||
export const nullSafeCall: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}null_safe_call`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}null_safe_call(receiver: Any, callable: Callable[[], ${CODEGEN_PREFIX}T]) -> ${CODEGEN_PREFIX}T | None: | ||
return callable() if receiver is not None else None | ||
`, | ||
imports: [ | ||
{ importPath: 'typing', declarationName: 'Any' }, | ||
{ importPath: 'typing', declarationName: 'Callable' }, | ||
], | ||
typeVariables: [`${CODEGEN_PREFIX}T`], | ||
}; | ||
|
||
export const nullSafeIndexedAccess: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}null_safe_indexed_access`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}null_safe_indexed_access(receiver: Any, index: Any) -> ${CODEGEN_PREFIX}T | None: | ||
return receiver[index] if receiver is not None else None | ||
`, | ||
imports: [{ importPath: 'typing', declarationName: 'Any' }], | ||
typeVariables: [`${CODEGEN_PREFIX}T`], | ||
}; | ||
|
||
export const nullSafeMemberAccess: UtilityFunction = { | ||
name: `${CODEGEN_PREFIX}null_safe_member_access`, | ||
code: expandToNode` | ||
def ${CODEGEN_PREFIX}null_safe_member_access(receiver: Any, member_name: str) -> ${CODEGEN_PREFIX}T | None: | ||
return getattr(receiver, member_name) if receiver is not None else None | ||
`, | ||
imports: [{ importPath: 'typing', declarationName: 'Any' }], | ||
typeVariables: [`${CODEGEN_PREFIX}T`], | ||
}; | ||
|
||
export interface UtilityFunction { | ||
readonly name: string; | ||
readonly code: Generated; | ||
readonly imports?: ImportData[]; | ||
readonly typeVariables?: string[]; | ||
} | ||
|
||
interface ImportData { | ||
readonly importPath: string; | ||
readonly declarationName?: string; | ||
readonly alias?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../main/generated/tests/generator/runnerIntegration/expressions/calls/main/gen_input.py.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../generated/tests/generator/runnerIntegration/expressions/calls/ofClasses/gen_input.py.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.