This action will force synchronization from hinus/pythonvm, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#include <stdio.h>#include <assert.h>#include "code/binaryFileParser.hpp"#include "runtime/universe.hpp"#include "object/hiList.hpp"#include "object/hiDouble.hpp"BinaryFileParser::BinaryFileParser(BufferedInputStream* buf_file_stream) {file_stream = buf_file_stream;}CodeObject* BinaryFileParser::parse() {int magic_number = file_stream->read_int();printf("magic number is 0x%x\n", magic_number);int moddate = file_stream->read_int();printf("moddate is 0x%x\n", moddate);char object_type = file_stream->read();if (object_type == 'c') {CodeObject* result = get_code_object();printf("parse OK!\n");return result;}return NULL;}CodeObject* BinaryFileParser::get_code_object() {int argcount = file_stream->read_int();int nlocals = file_stream->read_int();int stacksize = file_stream->read_int();int flags = file_stream->read_int();printf("flags is 0x%x\n", flags);HiString* byte_codes = get_byte_codes();ArrayList<HiObject*>* consts = get_consts();ArrayList<HiObject*>* names = get_names();ArrayList<HiObject*>* var_names = get_var_names();ArrayList<HiObject*>* free_vars = get_free_vars();ArrayList<HiObject*>* cell_vars = get_cell_vars();HiString* file_name = get_file_name();HiString* module_name = get_name();int begin_line_no = file_stream->read_int();HiString* lnotab = get_no_table();return new CodeObject(argcount, nlocals, stacksize, flags, byte_codes,consts, names, var_names, free_vars, cell_vars, file_name, module_name,begin_line_no, lnotab);}HiString* BinaryFileParser::get_string() {int length = file_stream->read_int();char* str_value = new char[length];for (int i = 0; i < length; i++) {str_value[i] = file_stream->read();}HiString* s = new HiString(str_value, length);delete[] str_value;return s;}HiString* BinaryFileParser::get_name() {char ch = file_stream->read();if (ch == 's') {return get_string();}else if (ch == 't') {HiString* str = get_string();_string_table.add(str);return str;}else if (ch == 'R') {return _string_table.get(file_stream->read_int());}return NULL;}HiString* BinaryFileParser::get_file_name() {return get_name();}HiString* BinaryFileParser::get_byte_codes() {assert(file_stream->read() == 's');return get_string();}HiString* BinaryFileParser::get_no_table() {char ch = file_stream->read();if (ch != 's' && ch != 't') {file_stream->unread();return NULL;}return get_string();}ArrayList<HiObject*>* BinaryFileParser::get_consts() {if (file_stream->read() == '(') {return get_tuple();}file_stream->unread();return NULL;}ArrayList<HiObject*>* BinaryFileParser::get_names() {if (file_stream->read() == '(') {return get_tuple();}file_stream->unread();return NULL;}ArrayList<HiObject*>* BinaryFileParser::get_var_names() {if (file_stream->read() == '(') {return get_tuple();}file_stream->unread();return NULL;}ArrayList<HiObject*>* BinaryFileParser::get_free_vars() {if (file_stream->read() == '(') {return get_tuple();}file_stream->unread();return NULL;}ArrayList<HiObject*>* BinaryFileParser::get_cell_vars() {if (file_stream->read() == '(') {return get_tuple();}file_stream->unread();return NULL;}ArrayList<HiObject*>* BinaryFileParser::get_tuple() {int length = file_stream->read_int();HiString * str;ArrayList<HiObject*>* list = new ArrayList<HiObject*>(length);for (int i = 0; i < length; i++) {char obj_type = file_stream->read();switch (obj_type) {case 'c':printf("got a code object\n");list->add(get_code_object());break;case 'i':list->add(new HiInteger(file_stream->read_int()));break;case 'g':list->add(new HiDouble(file_stream->read_double()));break;case 'N':list->add(Universe::HiNone);break;case 't':str = get_string();list->add(str);_string_table.add(str);break;case 's':list->add(get_string());break;case 'R':list->add(_string_table.get(file_stream->read_int()));break;case '(':list->add(new HiList(get_tuple()));break;default:printf("parser, unrecognized type : %c\n", obj_type);}}return list;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。