Skip to content

Complex patterns in sequence are finally handled in Scala codegen - #204

Open
amir734jj wants to merge 6 commits into
boyland:masterfrom
amir734jj:user/amir734jj/complex-pattern-finally-handled
Open

Complex patterns in sequence are finally handled in Scala codegen#204
amir734jj wants to merge 6 commits into
boyland:masterfrom
amir734jj:user/amir734jj/complex-pattern-finally-handled

Conversation

@amir734jj

@amir734jj amir734jj commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

For too long, complex sequence expressions were not handled in Scala code gen and we would get

/workspace/amir/aps/examples$ make -B simple-binding.scala
../bin/aps2scala -DCOTo -p .:../base simple-binding
simple-binding.aps:156:Sequence pattern too complicated for now
shesamian@TDC3791211823:/workspace/amir/aps/examples$ 

Example:

  var function lookup(name : String; scope : Scope) : EntityRef begin
    if scope = root_scope then
      result := not_found;
    else
      case scope.entities begin
	match {...,?e:EntityRef if e.entity_name=name,...} begin
	  result := e;
	end;
      else
	result := lookup(name,scope.enclosing);
      end;
    endif;
  end;

Becomes

  val v_lookup = f_lookup _;
  def f_lookup(v_name : T_String, v_scope : T_Scope):T_EntityRef = {

    { val cond = new M__basic_2[ T_Scope](t_Scope).v__op_0(v_scope,
        v_root_scope);
      if (cond) {
        return v_not_found;
      }
      if (!cond) {
        {
          val sequenceMatch2673192656 = new M__basic_14[ T_EntityRef,T_Entities](t_EntityRef,t_Entities).p__op_AC.unapplySeq(v_entities(v_scope)).get._2.collectFirst {
            case v_e if new M__basic_2[ T_String](t_String).v__op_0(v_entity_name(v_e),
              v_name) => {
              return v_e;
              ()
            }
          }
          if (sequenceMatch2673192656.isEmpty) {
            return v_lookup(v_name,
              v_enclosing(v_scope));
          }
        }
      }
    }
    throw Evaluation.UndefinedAttributeException("local lookup");
  }

@amir734jj amir734jj changed the title complex patterns in sequence are finally handled in Scala codegen Complex patterns in sequence are finally handled in Scala codegen Sep 3, 2026
@amir734jj
amir734jj marked this pull request as ready for review September 3, 2026 17:28
#include "dump.h"
#include "implement.h"

#ifdef APS2SCALA

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why opnly emit for Scala? How difficult is to make this work for C++ too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants