Merge remote-tracking branch 'dotjrich/issue-172' into master

This commit is contained in:
Michael Hansen
2020-10-20 21:10:55 -07:00
6 changed files with 77 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ public:
NODE_TUPLE, NODE_LIST, NODE_MAP, NODE_SUBSCR, NODE_PRINT,
NODE_CONVERT, NODE_KEYWORD, NODE_RAISE, NODE_EXEC, NODE_BLOCK,
NODE_COMPREHENSION, NODE_LOADBUILDCLASS, NODE_AWAITABLE,
NODE_FORMATTEDVALUE, NODE_JOINEDSTR,
NODE_FORMATTEDVALUE, NODE_JOINEDSTR, NODE_CONST_MAP,
// Empty node types
NODE_LOCALS,
@@ -359,6 +359,21 @@ private:
map_t m_values;
};
class ASTConstMap : public ASTNode {
public:
typedef std::vector<PycRef<ASTNode>> values_t;
ASTConstMap(PycRef<ASTNode> keys, const values_t& values)
: ASTNode(NODE_CONST_MAP), m_keys(std::move(keys)), m_values(std::move(values)) { }
const PycRef<ASTNode>& keys() const { return m_keys; }
const values_t& values() const { return m_values; }
private:
PycRef<ASTNode> m_keys;
values_t m_values;
};
class ASTSubscr : public ASTNode {
public:

View File

@@ -290,6 +290,24 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.push(new ASTMap());
}
break;
case Pyc::BUILD_CONST_KEY_MAP_A:
// Top of stack will be a tuple of keys.
// Values will start at TOS - 1.
{
PycRef<ASTNode> keys = stack.top();
stack.pop();
ASTConstMap::values_t values;
values.reserve(operand);
for (int i = 0; i < operand; ++i) {
PycRef<ASTNode> value = stack.top();
stack.pop();
values.push_back(value);
}
stack.push(new ASTConstMap(keys, values));
}
break;
case Pyc::STORE_MAP:
{
PycRef<ASTNode> key = stack.top();
@@ -2524,6 +2542,24 @@ void print_src(PycRef<ASTNode> node, PycModule* mod)
fputs(" }", pyc_output);
}
break;
case ASTNode::NODE_CONST_MAP:
{
PycRef<ASTConstMap> const_map = node.cast<ASTConstMap>();
PycTuple::value_t keys = const_map->keys().cast<ASTObject>()->object().cast<PycTuple>()->values();
ASTConstMap::values_t values = const_map->values();
auto map = new ASTMap;
for (const auto& key : keys) {
// Values are pushed onto the stack in reverse order.
PycRef<ASTNode> value = values.back();
values.pop_back();
map->add(new ASTObject(key), value);
}
print_src(map, mod);
}
break;
case ASTNode::NODE_NAME:
fprintf(pyc_output, "%s", node.cast<ASTName>()->name()->value());
break;

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,22 @@
cookie = 1
constant_headers_1 = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'es,ca;q=0.9,en;q=0.8',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
'Pragma': 'no-cache',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
'Cookie': cookie }
constant_headers_2 = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'es,ca;q=0.9,en;q=0.8',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
'Pragma': 'no-cache',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
'Cookie': 'constant cookie' }

View File

@@ -0,0 +1,3 @@
cookie = 1 <EOL>
constant_headers_1 = { 'Accept' : 'application/json' , 'Accept-Encoding' : 'gzip, deflate, br' , 'Accept-Language' : 'es,ca;q=0.9,en;q=0.8' , 'Cache-Control' : 'no-cache' , 'Connection' : 'keep-alive' , 'Content-Type' : 'application/x-www-form-urlencoded' , 'Pragma' : 'no-cache' , 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36' , 'Cookie' : cookie } <EOL>
constant_headers_2 = { 'Accept' : 'application/json' , 'Accept-Encoding' : 'gzip, deflate, br' , 'Accept-Language' : 'es,ca;q=0.9,en;q=0.8' , 'Cache-Control' : 'no-cache' , 'Connection' : 'keep-alive' , 'Content-Type' : 'application/x-www-form-urlencoded' , 'Pragma' : 'no-cache' , 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36' , 'Cookie' : 'constant cookie' } <EOL>