From b1d57540e0767b9d8078dbc0742bb0f71515d661 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Tue, 5 Dec 2023 14:58:04 +0000 Subject: [PATCH 1/2] Add Inner frame documentation based on AST frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - this seems correct to me, but I didn’t actually check it… Signed-off-by: Stefan Marr --- src/som/interpreter/ast/frame.py | 4 ++-- src/som/interpreter/bc/frame.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/som/interpreter/ast/frame.py b/src/som/interpreter/ast/frame.py index ded5c8cb..5534f505 100644 --- a/src/som/interpreter/ast/frame.py +++ b/src/som/interpreter/ast/frame.py @@ -46,9 +46,9 @@ # Inner # # +-----------------+ -# | OnStack | +# | OnStack | boolean indicating whether the frame is still on the stack # +-----------------+ -# | Receiver | +# | Receiver | the same as the receiver in the frame, not to be changed # +-----------------+ # | ArgForInner 1 | # | ... | diff --git a/src/som/interpreter/bc/frame.py b/src/som/interpreter/bc/frame.py index 4ff2a885..12343a3c 100644 --- a/src/som/interpreter/bc/frame.py +++ b/src/som/interpreter/bc/frame.py @@ -32,6 +32,22 @@ # | ... | # | Local n | # +-----------+ +# +# Inner +# +# +-----------------+ +# | OnStack | boolean indicating whether the frame is still on the stack +# +-----------------+ +# | Receiver | the same as the receiver in the frame, not to be changed +# +-----------------+ +# | ArgForInner 1 | +# | ... | +# | ArgForInner n | +# +-----------------+ +# | LocalForInner 1 | +# | ... | +# | LocalForInner n | +# +-----------------+ def create_frame( From 1cc69fffbbfa40cd838250e2af2b00fa0b7aab9b Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Thu, 4 Apr 2024 13:45:34 +0100 Subject: [PATCH 2/2] Add primitive implementation for String>>#charAt: Signed-off-by: Stefan Marr --- src/som/primitives/string_primitives.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/som/primitives/string_primitives.py b/src/som/primitives/string_primitives.py index 680b54f8..5ac79afd 100644 --- a/src/som/primitives/string_primitives.py +++ b/src/som/primitives/string_primitives.py @@ -39,6 +39,15 @@ def _substring(rcvr, start, end): return String(string[s:e]) +def _char_at(rcvr, idx): + i = idx.get_embedded_integer() - 1 + string = rcvr.get_embedded_string() + + if i < 0 or i >= len(string): + return String("Error - index out of bounds") + return String(string[i]) + + def _hashcode(rcvr): return Integer(compute_hash(rcvr.get_embedded_string())) @@ -81,6 +90,7 @@ def _is_digits(self): class StringPrimitivesBase(Primitives): def install_primitives(self): + self._install_instance_primitive(BinaryPrimitive("charAt:", _char_at)) self._install_instance_primitive(BinaryPrimitive("concatenate:", _concat)) self._install_instance_primitive(UnaryPrimitive("asSymbol", _as_symbol)) self._install_instance_primitive(UnaryPrimitive("length", _length))