def gen_get_or_create(cls, top, _):
        func = top.define_function('_internal/entity_ptr')
        func.preamble.add(i.PureInsn())
        retvar = func.preamble.define(i.ReturnVarInsn(i.VarType.i32))
        ct = func.create_compiletime()
        entry = func.create_block('entry')
        set_uid = func.create_block('set_uid')
        set_uid.set_is_function()
        ctblock = ct.create_block('ct_entry')

        uid_obj = top.preamble.add(cls.objective(), True, '__uid')
        sender = func.preamble.define(i.CreateSelector(i.SelectorType.SENDER))
        self_uid = func.preamble.define(
            i.CreateEntityLocalAccess(uid_obj, sender))
        next_uid = func.preamble.define(
            i.CreateEntityLocalAccess(uid_obj, top.lookup('_global_entity')))
        ex = func.preamble.define(i.CreateExec())

        # unless our uid is 1 or greater...
        ctblock.add(i.ExecUnlessVar(ex, self_uid, 1, None))

        ct.run_and_return()

        entry.add(i.ExecRun(ex, set_uid))
        entry.add(i.SetScore(retvar, self_uid))
        entry.add(i.Return())

        set_uid.add(i.SetScore(self_uid, next_uid))
        set_uid.add(i.AddScore(next_uid, 1))
        func.end()
        return func
 def get_member(self, compiler, name):
     if name == 'global':
         if self.__global is None:
             ge = compiler.top.lookup('_global_entity')
             ela = i.CreateEntityLocalAccess(self.__obj, ge)
             val = compiler.insn_def(ela)
             self.__global = InstanceSymbol(self, self._l_type, val)
         return self.__global
     return super().get_member(compiler, name)
    def gen_get_or_create(cls, top, _):
        func = top.define_function('_internal/entity_ptr')
        func.preamble.add(i.PureInsn())
        retvar = func.preamble.define(i.ReturnVarInsn(i.VarType.i32))
        entry = func.create_block('entry')
        set_uid = func.create_block('set_uid')
        end = func.create_block('end')

        uid_obj = top.preamble.add(cls.objective(), True, '__uid')
        sender = entry.define(i.CreateSelector(i.SelectorType.SENDER))
        self_uid = entry.define(i.CreateEntityLocalAccess(uid_obj, sender))
        next_uid = entry.define(
            i.CreateEntityLocalAccess(uid_obj, top.lookup('_global_entity')))
        entry.add(i.RangeBr(self_uid, 0, 0, set_uid, end))
        set_uid.add(i.SetScore(self_uid, next_uid))
        set_uid.add(i.AddScore(next_uid, 1))
        set_uid.add(i.Branch(end))
        end.add(i.SetScore(retvar, self_uid))
        end.add(i.Return())
        func.end()
        return func
Пример #4
0
    def _create_func(self):
        func = self.compiler.define_function('_internal/entity_ptr')
        func.preamble.add(i.PureInsn())
        retvar = func.preamble.define(i.ReturnVarInsn(i.VarType.i32))
        entry = func.create_block('entry')
        set_uid = func.create_block('set_uid')
        end = func.create_block('end')

        self.uid_obj = self.compiler.global_def(
            '__uid', i.DefineObjective(i.VirtualString('__uid'), None))
        sender = entry.define(i.CreateSelector(i.SelectorType.SENDER))
        self_uid = entry.define(i.CreateEntityLocalAccess(
            self.uid_obj, sender))
        next_uid = entry.define(
            i.CreateEntityLocalAccess(
                self.uid_obj, self.compiler.top.lookup('_global_entity')))
        entry.add(i.RangeBr(self_uid, 0, 0, set_uid, end))
        set_uid.add(i.SetScore(self_uid, next_uid))
        set_uid.add(i.AddScore(next_uid, 1))
        set_uid.add(i.Branch(end))
        end.add(i.SetScore(retvar, self_uid))
        end.add(i.Return())
        func.end()
        return func
    def as_entity(self, ptr):
        block = self.compiler.create_block('as_entity')
        block.set_is_function()
        sender = self.compiler.insn_def(i.CreateSelector(
            i.SelectorType.SENDER))

        if ptr != self._current_sender:
            exec = self.compiler.insn_def(i.CreateExec())
            sel = self.compiler.insn_def(
                i.CreateSelector(i.SelectorType.ALL_ENTITIES))
            test_uid = self.compiler.insn_def(
                i.CreateEntityLocalAccess(self.uid_obj, sender))
            self.compiler.add_insn(i.ExecAsEntity(exec, sel))
            self.compiler.add_insn(i.ExecIfCmp(exec, test_uid, 'eq', ptr))
            self.compiler.add_insn(i.ExecRun(exec, block))
        else:
            self.compiler.add_insn(i.Call(block))

        return block, sender  # sender for convenience
 def elocal_access(self, objective):
     block, sender = self.as_entity()
     var = self.sup.compiler.insn_def(
         i.CreateEntityLocalAccess(objective, sender))
     return var
Пример #7
0
 def elocal_access(self, objective):
     block, sender = self.as_entity()
     var = block.define(i.CreateEntityLocalAccess(objective, sender))
     return var