Permalink
Browse files

work on linux

  • Loading branch information...
goccy committed Oct 14, 2013
1 parent 685d9b7 commit 5ef035367faa74cfc1c5fe3d9c4ed7ac8b85e6ff
View
@@ -60,7 +60,7 @@ typedef union {
#define TYPE_CHECK(o, T) do { \
if (TYPE(o) != T) { \
- fprintf(stderr, "type = [%llu]\n", TYPE(o)); \
+ fprintf(stderr, "type = [%lu]\n", TYPE(o)); \
assert(0 && "Type Error!\n"); \
} \
} while (0)
View
@@ -3,7 +3,7 @@ UnionType *base_hash_table;
HashObject *pkg_map;
int count = 0;
Object **object_pool;
-pthread_mutex_t mutex;
+//pthread_mutex_t mutex;
UnionType _open(ArrayObject *args)
{
@@ -470,7 +470,7 @@ UnionType *HashRef_get(UnionType *o, StringObject *key)
break;
}
default:
- fprintf(stderr, "type = [%llu]\n", TYPE(o->o));
+ //fprintf(stderr, "type = [%lu]\n", TYPE(o->o));
assert(0 && "Type Error!: Unknown Type");
break;
}
@@ -527,7 +527,7 @@ UnionType *ArrayRef_get(UnionType *o, int idx)
break;
}
default:
- fprintf(stderr, "type = [%llu]\n", TYPE(o->o));
+ //fprintf(stderr, "type = [%lu]\n", TYPE(o->o));
assert(0 && "Type Error!: Unknown Type");
break;
}
@@ -667,7 +667,7 @@ Object *fetch_object(void)
PackageObject *get_pkg(char *pkg_name)
{
- pthread_mutex_lock(&mutex);
+ //pthread_mutex_lock(&mutex);
//fprintf(stderr, "called get_pkg\n");
//fprintf(stderr, "pkg_name = [%s]\n", pkg_name);
PackageObject *ret = NULL;
@@ -684,12 +684,13 @@ PackageObject *get_pkg(char *pkg_name)
UnionType value;
value.o = PACKAGE_init(pkg);
Hash_add(pkg_map, key, value);
- pthread_mutex_unlock(&mutex);
+ //pthread_mutex_unlock(&mutex);
return pkg;
}
void store_method_by_pkg_name(char *pkg_name, char *mtd_name, Code code)
{
+ //fprintf(stderr, "pkg_name = [%s], mtd_name = [%s]\n", pkg_name, mtd_name);
PackageObject *pkg = get_pkg(pkg_name);
UnionType _mtd_name = new_String(mtd_name);
CodeRefObject *o = (CodeRefObject *)calloc(sizeof(CodeRefObject), 1);
@@ -857,7 +858,7 @@ HashRefObject *dynamic_hash_ref_cast_code(UnionType *o)
break;
}
default:
- fprintf(stderr, "type = [%llu]\n", TYPE(o->o));
+ //fprintf(stderr, "type = [%lu]\n", TYPE(o->o));
break;
}
return ret;
@@ -877,7 +878,7 @@ ArrayRefObject *dynamic_array_ref_cast_code(UnionType *o)
break;
}
default:
- fprintf(stderr, "type = [%llu]\n", TYPE(o->o));
+ //fprintf(stderr, "type = [%lu]\n", TYPE(o->o));
break;
}
return ret;
@@ -899,7 +900,7 @@ BlessedObject *dynamic_blessed_object_cast_code(UnionType *o)
break;
}
default:
- fprintf(stderr, "type = [%llu]\n", TYPE(o->o));
+ //fprintf(stderr, "type = [%lu]\n", TYPE(o->o));
break;
}
return ret;
View
@@ -1,6 +1,7 @@
#include <common.hpp>
+#include <setjmp.h>
+#include <unistd.h>
-class AST;
class Node {
public:
Token *tk;
@@ -12,6 +13,13 @@ class Node {
virtual ~Node(void){};
};
+class AST {
+public:
+ Node *root;
+ AST(Node *root);
+ void dump(void);
+};
+
class Nodes : public std::vector<Node *> {
public:
Nodes(void);
@@ -98,10 +106,47 @@ class PackageNode : public Node {
class RegPrefixNode : public Node {
public:
Node *exp;
+ Node *option;
RegPrefixNode(Token *tk);
void dump(size_t depth);
};
+class RegReplaceNode : public Node {
+public:
+ Node *prefix;
+ Node *from;
+ Node *to;
+ Node *option;
+ RegReplaceNode(Token *tk);
+ void dump(size_t depth);
+};
+
+class RegexpNode : public Node {
+public:
+ Node *option;
+ RegexpNode(Token *tk);
+ void dump(size_t depth);
+};
+
+class LabelNode : public Node {
+public:
+ LabelNode(Token *tk);
+ void dump(size_t depth);
+};
+
+class HandleNode : public Node {
+public:
+ Node *expr;
+ HandleNode(Token *tk);
+ void dump(size_t depth);
+};
+
+class HandleReadNode : public Node {
+public:
+ HandleReadNode(Token *tk);
+ void dump(size_t depth);
+};
+
class FunctionCallNode : public Node {
public:
Nodes *args;
@@ -136,6 +181,15 @@ class DoubleTermOperatorNode : public Node {
DoubleTermOperatorNode(Token *op);
};
+class ThreeTermOperatorNode : public Node {
+public:
+ Node *cond;
+ Node *true_expr;
+ Node *false_expr;
+ ThreeTermOperatorNode(Token *op);
+ void dump(size_t depth);
+};
+
class OtherTermOperatorNode : public Node {
public:
OtherTermOperatorNode(Token *op);
@@ -162,6 +216,13 @@ class ElseStmtNode : public Node {
void dump(size_t depth);
};
+class DoStmtNode : public Node {
+public:
+ Node *stmt;
+ DoStmtNode(Token *tk);
+ void dump(size_t depth);
+};
+
class ForStmtNode : public Node {
public:
Node *init;
@@ -198,13 +259,6 @@ class Module {
Module(const char *name, const char *args);
};
-class AST {
-public:
- Node *root;
- AST(Node *root);
- void dump(void);
-};
-
class ParseContext {
public:
Token *tk;
@@ -216,6 +270,7 @@ class ParseContext {
ParseContext(Token *tk);
Token *token(void);
Token *token(Token *base, int offset);
+ Token *nullableToken(Token *base, int offset);
Token *nextToken(void);
Node *lastNode(void);
void pushNode(Node *node);
@@ -233,8 +288,9 @@ class Parser {
Enum::Parser::Syntax::Type cur_stype;
Parser(void);
+ const char *deparse(AST *ast);
void grouping(Tokens *tokens);
- void prepare(Tokens *tokens);
+ void replaceHereDocument(Tokens *tokens);
Token *parseSyntax(Token *start_token, Tokens *tokens);
void parseSpecificStmt(Token *root);
void setIndent(Token *tk, int indent);
@@ -246,28 +302,37 @@ class Parser {
AST *parse(Tokens *tks);
Node *_parse(Token *root);
void link(ParseContext *pctx, Node *from, Node *to);
+ bool isForeach(ParseContext *pctx, Token *tk);
+ bool isForStmtPattern(Token *tk, Token *expr);
bool isSingleTermOperator(ParseContext *pctx, Token *tk);
bool isIrregularFunction(ParseContext *pctx, Token *tk);
+ bool isMissingSemicolon(Enum::Token::Type::Type prev_type, Enum::Token::Type::Type type, Tokens *tokens);
+ bool isMissingSemicolon(Tokens *tokens);
+ bool canGrouping(Token *tk, Token *next_tk);
+ Token *replaceToStmt(Tokens *tokens, Token *cur_tk, size_t offset);
void parseStmt(ParseContext *pctx, Node *stmt);
void parseExpr(ParseContext *pctx, Node *expr);
void parseToken(ParseContext *pctx, Token *tk);
void parseModifier(ParseContext *pctx, Token *term);
void parseTerm(ParseContext *pctx, Token *term);
void parseSymbol(ParseContext *pctx, Token *symbol);
void parseSingleTermOperator(ParseContext *pctx, Token *op);
+ void parseThreeTermOperator(ParseContext *pctx, Token *op);
void parseBranchType(ParseContext *pctx, Token *branch);
void parseSpecificKeyword(ParseContext *pctx, Token *stmt);
void parseSpecificStmt(ParseContext *pctx, Token *stmt);
void parseDecl(ParseContext *pctx, Token *comma);
void parseModule(ParseContext *pctx, Token *mod);
void parseModuleArgument(ParseContext *pctx, Token *args);
void parseRegPrefix(ParseContext *pctx, Token *reg);
+ void parseRegReplace(ParseContext *pctx, Token *reg);
void parseFunction(ParseContext *pctx, Token *func);
void parseFunctionCall(ParseContext *pctx, Token *func);
void parseIrregularFunction(ParseContext *pctx, Token *func);
private:
bool isExpr(Token *tk, Token *prev_tk, Enum::Token::Type::Type type, Enum::Token::Kind::Kind kind);
void insertStmt(Token *tk, int idx, size_t grouping_num);
+ void insertExpr(Token *syntax, int idx, size_t grouping_num);
void insertParenthesis(Tokens *tokens);
};
@@ -285,7 +350,7 @@ class Completer {
void completeExprFromRight(Token *root, Enum::Token::Type::Type type);
void completeExprFromRight(Token *root, Enum::Token::Kind::Kind kind);
void completePointerExpr(Token *root);
- void completeIncDecExpr(Token *root);
+ void completeIncDecGlobExpr(Token *root);
void completePowerExpr(Token *root);
void completeSingleTermOperatorExpr(Token *root);
void completeRegexpMatchExpr(Token *root);
@@ -297,6 +362,7 @@ class Completer {
void completeNamedUnaryOperators(Token *root);
void completeBitOperatorExpr(Token *root);
void completeAndOrOperatorExpr(Token *root);
+ void completeThreeTermOperatorExpr(Token *root);
void completeAssignExpr(Token *root);
void completeCommaArrowExpr(Token *root);
void completeFunctionListExpr(Token *root);
@@ -60,7 +60,7 @@ typedef union {
#define TYPE_CHECK(o, T) do { \
if (TYPE(o) != T) { \
- fprintf(stderr, "type = [%llu]\n", TYPE(o)); \
+ fprintf(stderr, "type = [%lu]\n", TYPE(o)); \
assert(0 && "Type Error!\n"); \
} \
} while (0)
@@ -149,11 +149,16 @@ const char *LLVM::gen(AST *ast)
pm.add(createFunctionInliningPass());
pm.run(*module);
- AssemblyAnnotationWriter writer;
- ostringstream os;
- raw_os_ostream raw_stream(os);
- module->print(raw_stream, &writer);
- return os.str().c_str();
+ std::string string;
+ llvm::raw_string_ostream rss(string);
+ rss << *module;
+ rss.flush();
+ const char *llvm_ir = string.c_str();
+ size_t ir_size = strlen(llvm_ir) + 1;
+ char *ret = (char *)malloc(ir_size);
+ memset(ret, 0, ir_size);
+ strncpy(ret, llvm_ir, ir_size);
+ return ret;
}
void LLVM::write(void)
@@ -1814,7 +1819,7 @@ llvm::Value *LLVM::generateFunctionCallCode(IRBuilder<> *builder, FunctionCallNo
name == "abs" || name == "int" || name == "rand" ||
name == "sin" || name == "cos" || name == "atan2" ||
name == "open" || name == "chr" || name == "binmode" || name == "close" ||
- name == "print_with_handler" || name == "Data::Dumper" | name == "IOS::init" || name == "IOS::store_ios_native_library") {
+ name == "print_with_handler" || name == "Data::Dumper" || name == "IOS::init" || name == "IOS::store_ios_native_library") {
ret = generateReceiveUnionValueCode(builder, result);
} else {
ret = result;
Oops, something went wrong.

0 comments on commit 5ef0353

Please sign in to comment.