From feb1825c41b16b637b009c64ce9327a4cf417253 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 24 Oct 2019 15:17:46 +0000 Subject: [PATCH] set processor's primitive error information before handling #lenient --- moo/kernel/Apex.moo | 10 ---------- moo/kernel/Except.moo | 5 +++++ moo/kernel/IO.moo | 13 ++++++++++--- moo/kernel/System.moo | 2 +- moo/lib/exec.c | 16 ++++++++-------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/moo/kernel/Apex.moo b/moo/kernel/Apex.moo index 9d63a41..a09841d 100644 --- a/moo/kernel/Apex.moo +++ b/moo/kernel/Apex.moo @@ -285,16 +285,6 @@ extend Apex self primitiveFailed } - - /* ------------------------------------------------------------------ - * COMMON ERROR/EXCEPTION HANDLERS - * ------------------------------------------------------------------ */ - method(#dual) error: msgText - { - /* TODO: implement this - Error signal: msgText. */ - msgText dump. - } } class Object(Apex) diff --git a/moo/kernel/Except.moo b/moo/kernel/Except.moo index a94d802..74ad229 100644 --- a/moo/kernel/Except.moo +++ b/moo/kernel/Except.moo @@ -489,6 +489,11 @@ class IndexNotFoundException(NotFoundException) extend Apex { + method(#dual) error: text + { + Exception signal: text. + } + method(#dual,#liberal) primitiveFailed(method) { | a b msg ec ex | diff --git a/moo/kernel/IO.moo b/moo/kernel/IO.moo index bd0a972..52d0435 100644 --- a/moo/kernel/IO.moo +++ b/moo/kernel/IO.moo @@ -9,20 +9,27 @@ class(#limited) InputOutputStud(Object) from "io" class FileAccessor(InputOutputStud) from "io.file" { + pooldic Flag + { + O_RDONLY := 0, + O_WRONLY := 1 + //O_RDONLY from "O_RDONLY", + //O_WRONLY from "O_WRONLY" + } + method(#primitive,#lenient) _open: path flags: flags. method(#class) on: path for: flags { | fa | fa := self new _open: path flags: flags. - if (fa isError) { self error: "unable to open file" }. - self addToBeFinalized. + if (fa isError) { self error: "Unable to open file %s - %s" strfmt(path, thisProcess primErrorMessage) }. + fa addToBeFinalized. ^fa. } method close { -"CLOSING HANDLLE>..................." dump. self _close. self removeToBeFinalized. } diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index d611436..260049c 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -69,7 +69,7 @@ class System(Apex) class := self at: class_name. // System at: class_name. if (class isError) { - self error: ('Cannot find the class - ' & class_name). + self error: ("Unable to find the class - " & class_name). }. self _initialize. diff --git a/moo/lib/exec.c b/moo/lib/exec.c index fe916c7..b4c8e6c 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -4802,14 +4802,6 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) } activate_primitive_method_body: - if (MOO_METHOD_GET_PREAMBLE_FLAGS(preamble) & MOO_METHOD_PREAMBLE_FLAG_LENIENT) - { - /* convert soft failure to error return */ - moo->sp = stack_base; - MOO_STACK_PUSH (moo, MOO_ERROR_TO_OOP(moo->errnum)); - break; - } - /* set the error number in the current process for 'thisProcess primError' */ moo->processor->active->perr = MOO_ERROR_TO_OOP(moo->errnum); if (moo->errmsg.len > 0) @@ -4832,6 +4824,14 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) moo->processor->active->perrmsg = moo->_nil; } + if (MOO_METHOD_GET_PREAMBLE_FLAGS(preamble) & MOO_METHOD_PREAMBLE_FLAG_LENIENT) + { + /* convert soft failure to error return */ + moo->sp = stack_base; + MOO_STACK_PUSH (moo, moo->processor->active->perr); + break; + } + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TRAILER(method)); if (MOO_METHOD_GET_CODE_SIZE(method) == 0) /* this trailer size field is not a small integer */ {