From 0235128456a01649c179ac9341f9a44fd8b37e07 Mon Sep 17 00:00:00 2001 From: nickyc975 Date: Wed, 29 Apr 2020 14:50:46 +0800 Subject: [PATCH] Fixed mistakes. --- src/compiler/VSCompiler.cpp | 5 +++-- src/runtime/builtins.cpp | 19 ++++++++++--------- src/tools/printers.cpp | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/compiler/VSCompiler.cpp b/src/compiler/VSCompiler.cpp index f28951b..8e9170c 100644 --- a/src/compiler/VSCompiler.cpp +++ b/src/compiler/VSCompiler.cpp @@ -89,7 +89,8 @@ OPCODE VSCompiler::get_b_op(TOKEN_TYPE tk) { } std::string VSCompiler::get_key(VSObject *value) { - VSObject *value_strobj = CALL_ATTR(value, "__str__", EMPTY_TUPLE()); + NEW_IDENTIFIER(__str__); + VSObject *value_strobj = CALL_ATTR(value, ID___str__, EMPTY_TUPLE()); std::string value_str = STRING_TO_C_STRING(value_strobj); DECREF(value_strobj); @@ -619,7 +620,7 @@ void VSCompiler::gen_func_decl(VSASTNode *node) { p_table->put(name, new SymtableEntry(SYM_VAR, name, p_code->nlvars, 0)); } - ENTER_FUNC(name); + ENTER_FUNC((VSStringObject *)name); Symtable *table = this->symtables.top(); // Add function code to parent code consts. diff --git a/src/runtime/builtins.cpp b/src/runtime/builtins.cpp index 1473577..700012a 100644 --- a/src/runtime/builtins.cpp +++ b/src/runtime/builtins.cpp @@ -32,17 +32,18 @@ name_addr_map *builtin_addrs = &_builtin_addrs_struct; VSTupleObject *builtins = vs_tuple_pack( 8, - VS_AS_OBJECT(new VSNativeFunctionObject("input", __vs_input__, NULL)), - VS_AS_OBJECT(new VSNativeFunctionObject("print", __vs_print__, NULL)), - VS_AS_OBJECT(NULL), - VS_AS_OBJECT(new VSNativeFunctionObject("bool", vs_bool, NULL)), - VS_AS_OBJECT(new VSNativeFunctionObject("char", vs_char, NULL)), - VS_AS_OBJECT(new VSNativeFunctionObject("int", vs_int, NULL)), - VS_AS_OBJECT(new VSNativeFunctionObject("float", vs_float, NULL)), - VS_AS_OBJECT(new VSNativeFunctionObject("str", vs_str, NULL))); + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("input"), __vs_input__)), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("print"), __vs_print__)), + AS_OBJECT(NULL), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("bool"), vs_bool)), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("char"), vs_char)), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("int"), vs_int)), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("float"), vs_float)), + AS_OBJECT(new VSNativeFunctionObject(NULL, C_STRING_TO_STRING("str"), vs_str))); static void __vs_print_impl__(VSObject *obj) { - VSObject *objstr = CALL_ATTR(obj, "__str__", EMPTY_TUPLE()); + NEW_IDENTIFIER(__str__); + VSObject *objstr = CALL_ATTR(obj, ID___str__, EMPTY_TUPLE()); if (objstr->type != T_STR) { err("__str__() of \"%s\" object returned \"%s\" instead of str object", TYPE_STR[obj->type], TYPE_STR[objstr->type]); terminate(TERM_ERROR); diff --git a/src/tools/printers.cpp b/src/tools/printers.cpp index 55f0ae6..ce5b03f 100644 --- a/src/tools/printers.cpp +++ b/src/tools/printers.cpp @@ -422,6 +422,7 @@ void init_printer() { // } void fprint_code(FILE *file, VSCodeObject *code) { + NEW_IDENTIFIER(__str__); int count = 0; VSObject *object; fprint_indent(file); @@ -457,7 +458,7 @@ void fprint_code(FILE *file, VSCodeObject *code) { if (object->type == T_CODE) { fprintf(file, "%s\n", STRING_TO_C_STRING(((VSCodeObject *)object)->name).c_str()); } else { - VSObject *strobj = CALL_ATTR(object, "__str__", EMPTY_TUPLE()); + VSObject *strobj = CALL_ATTR(object, ID___str__, EMPTY_TUPLE()); fprintf(file, "%s\n", STRING_TO_C_STRING(strobj).c_str()); DECREF_EX(strobj); }