Example #1
0
 def _create_obj(self, orig_obj: 'context.Obj',
                 verb: 'context.Compound') -> 'context.Obj':
     obj = context.Compound()
     for value, metadata in self._modifiers:
         # If this is a "global" modifier, just process it.
         if isinstance(value, context.Unit):
             for name, literal in metadata.items():
                 obj.append_actor(context.Named(Pattern([name]), literal))
     obj.append_actor(context.Named(Pattern(["self"]), self._subject))
     obj.append_actor_inherited(self._subject.value)
     obj.append_actor_inherited(self._verb.grab_variables())
     obj.append_actor_inherited(orig_obj.value)
     return obj
Example #2
0
 def _generic_header(self, name, **kwargs):
     self.__current.append(
         context.Named(
             Pattern(name),
             context.Compound(name=name,
                              fqn=self._construct_fqn(name),
                              **kwargs)))
     return self._current
Example #3
0
def create_smalltalk():
    objects = {
        "class": Compound(name=("class", ), actor=True),
        "object": Compound(name=("object", ), actor=True),
        "magnitude": Compound(name=("magnitude", ), actor=True),
        "number": Compound(name=("number", ), actor=True),
        "integer": Compound(name=("integer", ), actor=True),
        "var": Compound(name=("var", ), actor=True)
    }
    # set classes for everything
    objects["class"].append_actor(Named(Pattern(["class"]), objects["class"]))
    objects["object"].append_actor(Named(Pattern(["class"]), objects["class"]))
    objects["magnitude"].append_actor(
        Named(Pattern(["class"]), objects["class"]))
    objects["number"].append_actor(Named(Pattern(["class"]), objects["class"]))
    objects["integer"].append_actor(Named(Pattern(["class"]),
                                          objects["class"]))
    objects["var"].append_actor(Named(Pattern(["class"]), objects["integer"]))

    # set inheritance
    objects["magnitude"].append_actor_inherited(objects["object"])
    objects["number"].append_actor_inherited(objects["magnitude"])
    objects["integer"].append_actor_inherited(objects["number"])

    # set method for example
    objects["object"].append_actor(
        Named(Pattern(["get", "class"]),
              Compound(command=lambda self: self.find_actor(["class"]))))

    return objects
Example #4
0
 def has_property(self, is_meta, name, _type, value=None):
     ret = None
     type_name, type_ctor_call, type_overrides = _type
     ret = context.Named(Pattern(name),
                         self.parse_type(type_name, type_ctor_call,
                                         type_overrides, value),
                         is_meta=is_meta)
     self._current.value.append_actor(ret)
     return ret
Example #5
0
 def can_property(self, keyword, name, _colon, variables, modifiers,
                  *directives):
     c = context.Compound(then_meanwhile_tree.Then(directives))
     for pattern, modifier in modifiers:
         c.append_actor(context.Named(pattern, modifier))
     for pattern, type_ in variables:
         c.append_actor(context.VariableLink(context.Named(pattern, type_)))
     ret = context.CanLink(context.Named(Pattern(name), c))
     self._current.value.append_actor(ret)
     return ret
Example #6
0
 def load_directive(self, to_load, filename):
     filename = parse_literal([filename], self._current.value).stringify(
         self._current, ())
     if not os.path.isabs(filename):
         filename = os.path.join(self._cwd, filename)
     # TODO: Cache
     with open(filename, "r") as f:
         parser = TopLevelParser(self._cwd)
         obj = parser.parse(f.read())
     for importable in to_load:
         importing = obj
         for name in split_by_scope_operator(importable):
             importing, _ = one_or_raise(importing.find_character(name),
                                         LookupException)
             basename = name
             assert importing is not None
         # Clone to support caching in the future
         importing = importing.clone(scope=self._current.value, first=True)
         self._current.value.append_character(
             context.Named(Pattern(basename), importing))
Example #7
0
 def constructor_param(self, name, type_):
     return (Pattern(name), self.parse_type(type_, None, [], None))
Example #8
0
 def can_variable(self, name, tokens):
     return (Pattern(name), parse_literal(tokens, self._current.value))
Example #9
0
 def has_property_inferrence(self, is_meta, name, value):
     ret = context.Named(Pattern(name), value, is_meta=is_meta)
     self._current.value.append_actor(ret)
     return ret