/*
 * Copyright (c) 2015-2018 Dzikoysk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.panda_lang.panda.framework.language.architecture.prototype;

import org.panda_lang.panda.framework.design.architecture.prototype.ClassPrototype;
import org.panda_lang.panda.framework.design.architecture.value.Value;
import org.panda_lang.panda.framework.design.runtime.ExecutableBranch;
import org.panda_lang.panda.framework.language.architecture.dynamic.AbstractScopeInstance;
import org.panda_lang.panda.framework.language.architecture.value.PandaValue;

import java.util.concurrent.atomic.AtomicInteger;

public class ClassScopeInstance extends AbstractScopeInstance<ClassScope> {

    private static final AtomicInteger idAssigner = new AtomicInteger();

    private final int id;
    private final ClassPrototype prototype;

    public ClassScopeInstance(ClassScope scope, ClassPrototype classPrototype) {
        super(scope, classPrototype.getFields().getAmountOfFields());

        this.id = idAssigner.getAndIncrement();
        this.prototype = classPrototype;
    }

    @Override
    public void execute(ExecutableBranch branch) {
        throw new RuntimeException("Cannot execute instance");
    }

    public Value toValue() {
        return new PandaValue(prototype, this);
    }

    @Override
    public String toString() {
        return "@(" + prototype.getClassName() + " :: " + id + ")";
    }

}

@@ -1867,15 +1867,8 @@
 turn
- %22@(%22 +
  pro
@@ -1896,24 +1896,48 @@
  + %22
- :: %22 + id + %22)%22
+#%22 + String.format(%22%2506X%22, id & 0xFFFFF)
 ;%0A  

Improve default #toString for panda objects