From 9b3c3007fd7f74de5699645614a0317ab555d1f4 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 8 Jun 2017 14:39:17 +0000 Subject: [PATCH] Added a new syntax error code MODIMPFAIL --- moo/kernel/generr.moo | 1 + moo/kernel/test-002.moo | 4 ++- moo/lib/comp.c | 8 ++++-- moo/lib/err.c | 19 ++++++------- moo/lib/main.c | 59 ++++++++++++++++++++++++++++++++++++----- moo/lib/moo-prv.h | 1 + moo/lib/moo.c | 1 - moo/lib/moo.h | 1 + 8 files changed, 74 insertions(+), 20 deletions(-) diff --git a/moo/kernel/generr.moo b/moo/kernel/generr.moo index e026137..6885bfb 100644 --- a/moo/kernel/generr.moo +++ b/moo/kernel/generr.moo @@ -106,6 +106,7 @@ class MyObject(Object) 'wrong primitive function identifier' 'wrong primitive function argument definition' 'wrong module name' + 'failed to import module' '#include error' 'wrong namespace name' 'wrong pool dictionary name' diff --git a/moo/kernel/test-002.moo b/moo/kernel/test-002.moo index 9e95e58..2803052 100644 --- a/moo/kernel/test-002.moo +++ b/moo/kernel/test-002.moo @@ -7,6 +7,8 @@ class MyObject(Object) { +## TODO: support import in extend?? + var(#class) a := 100. method(#class) proc1 @@ -20,7 +22,7 @@ class MyObject(Object) | tc limit | tc := #{ - ## 0 - 4 + ## 0 - 4 [ self proc1 == 100 ], [ Processor sleepFor: 2. self proc1 == 200 ] }. diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 8e95ae0..1ea492a 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -4164,7 +4164,6 @@ static MOO_INLINE int find_undotted_ident (moo_t* moo, const moo_oocs_t* name, c return 0; } -MOO_DEBUG0 (moo, "2222222222222222\n"); /* find an undotted identifier in dictionaries */ if (moo->c->cls.ns_oop) { @@ -7298,6 +7297,7 @@ static int __compile_class_definition (moo_t* moo, int extend) } if (set_class_modname (moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->cls.modname_loc = *TOKEN_LOC(moo); GET_TOKEN (moo); } @@ -7441,7 +7441,11 @@ static int __compile_class_definition (moo_t* moo, int extend) * memory(not part of the object memory) to moo_importmod(). * no big overhead as it's already available. but Accessing * this extra module name, i'm free from GC headache */ - if (moo_importmod (moo, moo->c->cls.self_oop, moo->c->cls.modname.ptr, moo->c->cls.modname.len) <= -1) return -1; + if (moo_importmod (moo, moo->c->cls.self_oop, moo->c->cls.modname.ptr, moo->c->cls.modname.len) <= -1) + { + set_syntax_error (moo, MOO_SYNERR_MODIMPFAIL, &moo->c->cls.modname_loc, &moo->c->cls.modname); + return -1; + } } if (moo->c->cls.self_oop->trsize == moo->_nil && diff --git a/moo/lib/err.c b/moo/lib/err.c index 27cc08d..bbd0f9d 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -132,14 +132,15 @@ static moo_ooch_t synerrstr_58[] = {'w','r','o','n','g',' ','p','r','i','m','i', static moo_ooch_t synerrstr_59[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; static moo_ooch_t synerrstr_60[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','a','r','g','u','m','e','n','t',' ','d','e','f','i','n','i','t','i','o','n','\0'}; static moo_ooch_t synerrstr_61[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; -static moo_ooch_t synerrstr_62[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; -static moo_ooch_t synerrstr_63[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; -static moo_ooch_t synerrstr_64[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static moo_ooch_t synerrstr_65[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static moo_ooch_t synerrstr_66[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; -static moo_ooch_t synerrstr_67[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'}; -static moo_ooch_t synerrstr_68[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'}; -static moo_ooch_t synerrstr_69[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_62[] = {'f','a','i','l','e','d',' ','t','o',' ','i','m','p','o','r','t',' ','m','o','d','u','l','e','\0'}; +static moo_ooch_t synerrstr_63[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; +static moo_ooch_t synerrstr_64[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_65[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_66[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_67[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_68[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'}; +static moo_ooch_t synerrstr_69[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'}; +static moo_ooch_t synerrstr_70[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t* synerrstr[] = { synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7, @@ -150,7 +151,7 @@ static moo_ooch_t* synerrstr[] = synerrstr_40, synerrstr_41, synerrstr_42, synerrstr_43, synerrstr_44, synerrstr_45, synerrstr_46, synerrstr_47, synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55, synerrstr_56, synerrstr_57, synerrstr_58, synerrstr_59, synerrstr_60, synerrstr_61, synerrstr_62, synerrstr_63, - synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69 + synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70 }; #endif /* END: GENERATED WITH generr.moo */ diff --git a/moo/lib/main.c b/moo/lib/main.c index 046dba7..38cf474 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -32,7 +32,9 @@ #include #include -#define USE_THREAD +#if !defined(__DOS__) +# define USE_THREAD +#endif #if defined(_WIN32) # include @@ -53,10 +55,19 @@ # include # include # include +# include + + /* fake XPOLLXXX values */ +# define XPOLLIN (1 << 0) +# define XPOLLOUT (1 << 1) +# define XPOLLERR (1 << 2) +# define XPOLLHUP (1 << 3) + #elif defined(macintosh) # include # include # include + #else # if defined(MOO_ENABLE_LIBLTDL) @@ -831,7 +842,10 @@ static int _add_poll_fd (moo_t* moo, int fd, int event_mask, moo_oow_t event_dat return 0; #else -# error UNSUPPORTED + + MOO_DEBUG1 (moo, "Cannot add file descriptor %d to poll - not implemented\n", fd); + moo_seterrnum (moo, MOO_ENOIMPL); + return -1; #endif } @@ -886,11 +900,15 @@ static int _del_poll_fd (moo_t* moo, int fd) } - moo_seterrnum (moo, MOO_ENOENT); MOO_DEBUG1 (moo, "Cannot remove file descriptor %d from poll - not found\n", fd); + moo_seterrnum (moo, MOO_ENOENT); return -1; + #else -# error NOT SUPPORTED + + MOO_DEBUG1 (moo, "Cannot remove file descriptor %d from poll - not implemented\n", fd); + moo_seterrnum (moo, MOO_ENOIMPL); + return -1; #endif } @@ -946,7 +964,9 @@ static int _mod_poll_fd (moo_t* moo, int fd, int event_mask, moo_oow_t event_dat return -1; #else -# error NOT SUPPORTED + MOO_DEBUG1 (moo, "Cannot modify file descriptor %d in poll - not implemented\n", fd); + moo_seterrnum (moo, MOO_ENOIMPL); + return -1; #endif } @@ -1446,7 +1466,7 @@ static void vm_muxwait (moo_t* moo, const moo_ntime_t* dur, moo_vmprim_muxwait_c #elif defined(USE_EPOLL) revents = xtn->ev.buf[n].events; #else - # error UNSUPPORTED + revents = 0; /* TODO: fake. unsupported */ #endif mask = 0; @@ -1461,7 +1481,7 @@ static void vm_muxwait (moo_t* moo, const moo_ntime_t* dur, moo_vmprim_muxwait_c #elif defined(USE_EPOLL) muxwcb (moo, mask, xtn->ev.buf[n].data.ptr); #else - # error UNSUPPORTED + /* TODO: fake. unsupported */ #endif } @@ -1672,12 +1692,36 @@ static void handle_term (int sig) static void setup_term (void) { +#if defined(_WIN32) + SetConsoleCtrlHandler (handle_term, TRUE); +#elif defined(__OS2__) + os2_excrr.ExceptionHandler = (ERR)__intr_handler; + DosSetExceptionHandler (&os2_excrr); /* TODO: check if NO_ERROR is returned */ +#elif defined(__DOS__) + signal (SIGINT, handle_term); +#else struct sigaction sa; memset (&sa, 0, MOO_SIZEOF(sa)); sa.sa_handler = handle_term; sigaction (SIGINT, &sa, MOO_NULL); +#endif } +static void clear_term (void) +{ +#if defined(_WIN32) + SetConsoleCtrlHandler (handle_term, FALSE); +#elif defined(__OS2__) + DosUnsetExceptionHandler (&os2_excrr); +#elif defined(__DOS__) + signal (SIGINT, SIG_DFL); +#else + struct sigaction sa; + memset (&sa, 0, MOO_SIZEOF(sa)); + sa.sa_handler = SIG_DFL; + sigaction (SIGINT, &sa, MOO_NULL); +#endif +} /* ========================================================================= */ int main (int argc, char* argv[]) @@ -1858,6 +1902,7 @@ int main (int argc, char* argv[]) } cancel_tick (); + clear_term (); g_moo = MOO_NULL; /*moo_dumpsymtab(moo); diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index 4cf636d..426f8c5 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -517,6 +517,7 @@ struct moo_compiler_t moo_oocs_t modname; /* module name after 'from' */ moo_oow_t modname_capa; + moo_ioloc_t modname_loc; /* instance variable, class variable, class instance variable, constant * var[0] - named instance variables diff --git a/moo/lib/moo.c b/moo/lib/moo.c index aba0274..91ab0a8 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -473,7 +473,6 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int)); -MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_POW2((moo_oow_t)mdp, 8)); mdp->mod.hints = hints; if (load (moo, &mdp->mod) <= -1) { diff --git a/moo/lib/moo.h b/moo/lib/moo.h index afc9652..7e719a4 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -1351,6 +1351,7 @@ enum moo_synerrnum_t MOO_SYNERR_PFIDINVAL, /* wrong primitive function identifier */ MOO_SYNERR_PFARGDEFINVAL, /* wrong primitive function argument definition */ MOO_SYNERR_MODNAMEINVAL, /* wrong module name */ + MOO_SYNERR_MODIMPFAIL, /* failed to import module */ MOO_SYNERR_INCLUDE, /* #include error */ MOO_SYNERR_NAMESPACEINVAL, /* wrong namespace name */ MOO_SYNERR_POOLDICINVAL, /* wrong pool dictionary */