Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While Primitives are not triggering, missing specialization logic? #279

Open
smarr opened this issue Dec 18, 2018 · 0 comments
Open

While Primitives are not triggering, missing specialization logic? #279

smarr opened this issue Dec 18, 2018 · 0 comments
Labels
bug Fixes an issue, incorrect implementation good first issue Are you trying to have a good at SOMns? Start here! help wanted Would be great if you could help out here.

Comments

@smarr
Copy link
Owner

smarr commented Dec 18, 2018

Some of following tests are failing with stack overflows.
Inspection shows that the SOMns version of the while methods run, instead of the primitives:

diff --git a/core-lib/TestSuite/LanguageTests.ns b/core-lib/TestSuite/LanguageTests.ns
index 68baf641..f487c8a3 100644
--- a/core-lib/TestSuite/LanguageTests.ns
+++ b/core-lib/TestSuite/LanguageTests.ns
@@ -982,4 +982,143 @@ class LanguageTests usingPlatform: platform testFramework: minitest = Value (
       assert: #overridden2 equals: OtherScope new AnotherA new B new C new localTarget.
     )
   ) : ( TEST_CONTEXT = () )
+
+  public class WhileLoops = TestContext (
+  | private BOUND = 3000. |
+  )(
+
+    public testLiteralBlocksForTrue = (
+      | i |
+      i:: 1.
+      [ i < BOUND ] whileTrue: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralBlocksForFalse = (
+      | i |
+      i:: 1.
+      [ i >= BOUND ] whileFalse: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralReceiverAndVarArgForTrue = (
+      | i block |
+      block:: [ i:: i + 1 ].
+      i:: 1.
+      [ i < BOUND ] whileTrue: block.
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralReceiverAndVarArgForFalse = (
+      | i block |
+      block:: [ i:: i + 1 ].
+      i:: 1.
+      [ i >= BOUND ] whileFalse: block.
+      assert: BOUND equals: i.
+    )
+
+    public testVarReceiverAndLiteralArgForTrue = (
+      | i block |
+      block:: [ i < BOUND ].
+      i:: 1.
+      block whileTrue: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testVarReceiverAndLiteralArgForFalse = (
+      | i block |
+      block:: [ i >= BOUND ].
+      i:: 1.
+      block whileFalse: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testVarBlocksForTrue = (
+      | i blockRcvr blockArg |
+      blockRcvr:: [ i < BOUND ].
+      blockArg:: [ i:: i + 1 ].
+      i:: 1.
+      blockRcvr whileTrue: blockArg.
+      assert: BOUND equals: i.
+    )
+
+    public testVarBlocksForFalse = (
+      | i blockRcvr blockArg |
+      blockRcvr:: [ i >= BOUND ].
+      blockArg:: [ i:: i + 1 ].
+      i:: 1.
+      blockRcvr whileFalse: blockArg.
+      assert: BOUND equals: i.
+    )
+
+    public testPolymorpicBlocksForTrue = (
+      | rcvrBlocks argBlocks j |
+      rcvrBlocks:: Array new: 10.
+      rcvrBlocks at:  1 put: [j < 3].
+      rcvrBlocks at:  2 put: [j < 3].
+      rcvrBlocks at:  3 put: [j < 3].
+      rcvrBlocks at:  4 put: [j < 3].
+      rcvrBlocks at:  5 put: [j < 3].
+      rcvrBlocks at:  6 put: [j < 3].
+      rcvrBlocks at:  7 put: [j < 3].
+      rcvrBlocks at:  8 put: [j < 3].
+      rcvrBlocks at:  9 put: [j < 3].
+      rcvrBlocks at: 10 put: [j < 3].
+
+      argBlocks:: Array new: 10.
+      argBlocks at:  1 put: [j:: j + 1].
+      argBlocks at:  2 put: [j:: j + 1].
+      argBlocks at:  3 put: [j:: j + 1].
+      argBlocks at:  4 put: [j:: j + 1].
+      argBlocks at:  5 put: [j:: j + 1].
+      argBlocks at:  6 put: [j:: j + 1].
+      argBlocks at:  7 put: [j:: j + 1].
+      argBlocks at:  8 put: [j:: j + 1].
+      argBlocks at:  9 put: [j:: j + 1].
+      argBlocks at: 10 put: [j:: j + 1].
+
+      1 to: 10 do: [:i |
+        j:: 1.
+        (rcvrBlocks at: i)
+          whileTrue:
+            (argBlocks at: i).
+        assert: 3 equals: j.
+      ].
+    )
+
+    public testPolymorpicBlocksForFalse = (
+      | rcvrBlocks argBlocks j |
+      rcvrBlocks:: Array new: 10.
+      rcvrBlocks at:  1 put: [j >= 3].
+      rcvrBlocks at:  2 put: [j >= 3].
+      rcvrBlocks at:  3 put: [j >= 3].
+      rcvrBlocks at:  4 put: [j >= 3].
+      rcvrBlocks at:  5 put: [j >= 3].
+      rcvrBlocks at:  6 put: [j >= 3].
+      rcvrBlocks at:  7 put: [j >= 3].
+      rcvrBlocks at:  8 put: [j >= 3].
+      rcvrBlocks at:  9 put: [j >= 3].
+      rcvrBlocks at: 10 put: [j >= 3].
+
+      argBlocks:: Array new: 10.
+      argBlocks at:  1 put: [j:: j + 1].
+      argBlocks at:  2 put: [j:: j + 1].
+      argBlocks at:  3 put: [j:: j + 1].
+      argBlocks at:  4 put: [j:: j + 1].
+      argBlocks at:  5 put: [j:: j + 1].
+      argBlocks at:  6 put: [j:: j + 1].
+      argBlocks at:  7 put: [j:: j + 1].
+      argBlocks at:  8 put: [j:: j + 1].
+      argBlocks at:  9 put: [j:: j + 1].
+      argBlocks at: 10 put: [j:: j + 1].
+
+      1 to: 10 do: [:i |
+        j:: 1.
+        (rcvrBlocks at: i)
+          whileFalse:
+            (argBlocks at: i).
+        assert: 3 equals: j.
+      ].
+    )
+  ) : ( TEST_CONTEXT = () )
 )

The solution for this would be to add the necessary logic into the while specializers.
The specializers need to have the checks for this case, and the node creation needs to instantiate the WhileCache-nodes, I think.

@smarr smarr added bug Fixes an issue, incorrect implementation help wanted Would be great if you could help out here. good first issue Are you trying to have a good at SOMns? Start here! labels Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes an issue, incorrect implementation good first issue Are you trying to have a good at SOMns? Start here! help wanted Would be great if you could help out here.
Projects
None yet
Development

No branches or pull requests

1 participant