From d1c69efc0f4843dafa4fc201fdfb68523d9613dc Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 16 Sep 2009 17:38:01 -0500 Subject: [PATCH 1/2] fix functors tests --- basis/functors/functors-tests.factor | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/basis/functors/functors-tests.factor b/basis/functors/functors-tests.factor index bcdc1bae74..32d578d05d 100644 --- a/basis/functors/functors-tests.factor +++ b/basis/functors/functors-tests.factor @@ -179,35 +179,35 @@ STRUCT: T-class { offset 0 } { class integer } { initial 0 } - { c-type "int" } + { type "int" } } T{ struct-slot-spec { name "x" } { offset 4 } { class object } { initial f } - { c-type { "char" 4 } } + { type { "char" 4 } } } T{ struct-slot-spec { name "y" } { offset 8 } { class object } { initial f } - { c-type { "short" 2 } } + { type { "short" 2 } } } T{ struct-slot-spec { name "z" } { offset 12 } { class fixnum } { initial 5 } - { c-type "char" } + { type "char" } } T{ struct-slot-spec { name "float" } { offset 16 } { class object } { initial f } - { c-type { "float" 2 } } + { type { "float" 2 } } } } ] [ a-struct struct-slots ] unit-test From 748ba4b833f2912b24d8140714a714cc73a1b551 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 16 Sep 2009 18:07:39 -0500 Subject: [PATCH 2/2] give a better error message when an invalid slot name is used in a tuple/struct literal --- basis/debugger/debugger.factor | 2 ++ core/classes/tuple/parser/parser.factor | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index 2fad0e4c2e..1e08896e8d 100644 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -174,6 +174,8 @@ M: no-method error. M: bad-slot-value summary drop "Bad store to specialized slot" ; +M: bad-slot-name summary drop "Bad slot name in object literal" ; + M: no-math-method summary drop "No suitable arithmetic method" ; diff --git a/core/classes/tuple/parser/parser.factor b/core/classes/tuple/parser/parser.factor index 0a57ad34f3..626cbd63df 100644 --- a/core/classes/tuple/parser/parser.factor +++ b/core/classes/tuple/parser/parser.factor @@ -99,9 +99,17 @@ GENERIC# boa>object 1 ( class slots -- tuple ) M: tuple-class boa>object swap prefix >tuple ; +ERROR: bad-slot-name class slot ; + +: check-slot-exists ( class initials slot-spec/f index/f name -- class initials slot-spec index ) + over [ drop ] [ nip nip nip bad-slot-name ] if ; + +: slot-named-checked ( class initials name slots -- class initials slot-spec ) + over [ slot-named* ] dip check-slot-exists drop ; + : assoc>object ( class slots values -- tuple ) [ [ [ initial>> ] map ] keep ] dip - swap [ [ slot-named* drop ] curry dip ] curry assoc-map + swap [ [ slot-named-checked ] curry dip ] curry assoc-map [ dup ] dip update boa>object ; : parse-tuple-literal-slots ( class slots -- tuple )