forked from lcompilers/lpython
-
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.
Merge pull request lcompilers#498 from namannimmo10/dict_remove
Add Dict pop in ASR
- Loading branch information
Showing
12 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def f(): | ||
d: dict[i32, str] | ||
d = {1: "a", 2: "b"} | ||
res: str | ||
res = d.pop("a") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 5 {}) main_program [] []), test_Dict: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Dict (Integer 4 []) (Integer 4 [])) Source Public Required .false.), y: (Variable 2 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.), z: (Variable 2 z Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Dict [] [(= (Var 2 x) (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Dict (Integer 4 []) (Integer 4 []))) ()) (= (Var 2 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "b" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 x (IntegerConstant 1 (Integer 4 [])) () (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_get: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 4 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_get [] [(= (Var 4 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 0 (Integer 4 [])) (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_insert: (Subroutine (SymbolTable 3 {y: (Variable 3 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_insert [] [(= (Var 3 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (DictInsert 3 y (StringConstant "c" (Character 1 1 () [])) (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] Source Public Implementation () .false. .false.)}) []) | ||
(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 6 {}) main_program [] []), test_Dict: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Dict (Integer 4 []) (Integer 4 [])) Source Public Required .false.), y: (Variable 2 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.), z: (Variable 2 z Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Dict [] [(= (Var 2 x) (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Dict (Integer 4 []) (Integer 4 []))) ()) (= (Var 2 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "b" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 x (IntegerConstant 1 (Integer 4 [])) () (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_get: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 4 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_get [] [(= (Var 4 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 0 (Integer 4 [])) (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_insert: (Subroutine (SymbolTable 3 {y: (Variable 3 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_insert [] [(= (Var 3 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (DictInsert 3 y (StringConstant "c" (Character 1 1 () [])) (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] Source Public Implementation () .false. .false.), test_dict_pop: (Subroutine (SymbolTable 5 {x: (Variable 5 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 5 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_pop [] [(= (Var 5 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 []))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 5 x) (DictPop 5 y (StringConstant "a" (Character 1 1 () [])) (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) |
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,13 @@ | ||
{ | ||
"basename": "asr-test_dict6-95e3b14", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict6.py", | ||
"infile_hash": "96cf7e14615e027428b3f60969ef27fd9dbb07171e9088dfbede5d06", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict6-95e3b14.stderr", | ||
"stderr_hash": "786fd07ddc3919823741b0db9a9ff0ba898b106d677657ea5f80fd2e", | ||
"returncode": 2 | ||
} |
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,5 @@ | ||
semantic error: Type mismatch in pop's key value, the types must be compatible | ||
--> tests/errors/test_dict6.py:5:17 | ||
| | ||
5 | res = d.pop("a") | ||
| ^^^ type mismatch (found: 'str', expected: 'i32') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(Module [(FunctionDef test_Dict ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Subscript (Name dict Load) (Tuple [(Name i32 Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name x Store)] (Dict [(ConstantInt 1 ()) (ConstantInt 3 ())] [(ConstantInt 2 ()) (ConstantInt 4 ())]) ()) (AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (AnnAssign (Name z Store) (Name i32 Load) () 1) (Assign [(Name z Store)] (Subscript (Name y Load) (ConstantStr "a" ()) Load) ()) (Assign [(Name z Store)] (Subscript (Name y Load) (ConstantStr "b" ()) Load) ()) (Assign [(Name z Store)] (Subscript (Name x Load) (ConstantInt 1 ()) Load) ())] [] () ()) (FunctionDef test_dict_insert ([] [] [] [] [] [] []) [(AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (Assign [(Subscript (Name y Load) (ConstantStr "c" ()) Store)] (UnaryOp USub (ConstantInt 3 ())) ())] [] () ()) (FunctionDef test_dict_get ([] [] [] [] [] [] []) [(AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (AnnAssign (Name x Store) (Name i32 Load) () 1) (Assign [(Name x Store)] (Call (Attribute (Name y Load) get Load) [(ConstantStr "a" ())] []) ()) (Assign [(Name x Store)] (Call (Attribute (Name y Load) get Load) [(ConstantStr "a" ()) (ConstantInt 0 ())] []) ())] [] () ())] []) | ||
(Module [(FunctionDef test_Dict ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Subscript (Name dict Load) (Tuple [(Name i32 Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name x Store)] (Dict [(ConstantInt 1 ()) (ConstantInt 3 ())] [(ConstantInt 2 ()) (ConstantInt 4 ())]) ()) (AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (AnnAssign (Name z Store) (Name i32 Load) () 1) (Assign [(Name z Store)] (Subscript (Name y Load) (ConstantStr "a" ()) Load) ()) (Assign [(Name z Store)] (Subscript (Name y Load) (ConstantStr "b" ()) Load) ()) (Assign [(Name z Store)] (Subscript (Name x Load) (ConstantInt 1 ()) Load) ())] [] () ()) (FunctionDef test_dict_insert ([] [] [] [] [] [] []) [(AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (Assign [(Subscript (Name y Load) (ConstantStr "c" ()) Store)] (UnaryOp USub (ConstantInt 3 ())) ())] [] () ()) (FunctionDef test_dict_get ([] [] [] [] [] [] []) [(AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (AnnAssign (Name x Store) (Name i32 Load) () 1) (Assign [(Name x Store)] (Call (Attribute (Name y Load) get Load) [(ConstantStr "a" ())] []) ()) (Assign [(Name x Store)] (Call (Attribute (Name y Load) get Load) [(ConstantStr "a" ()) (ConstantInt 0 ())] []) ())] [] () ()) (FunctionDef test_dict_pop ([] [] [] [] [] [] []) [(AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(ConstantInt 1 ()) (ConstantInt 2 ())]) ()) (AnnAssign (Name x Store) (Name i32 Load) () 1) (Assign [(Name x Store)] (Call (Attribute (Name y Load) pop Load) [(ConstantStr "a" ())] []) ())] [] () ())] []) |
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