Esempio n. 1
0
        public NFT(string name, VarType romType, VarType ramType, Module parent) : base(name, ModuleKind.NFT, parent)
        {
            this.romType = romType;
            this.ramType = ramType;

            this.nftType = (StructVarType)VarType.Find(VarKind.Struct, name);
            //this.nftType.decl = new StructDeclaration(name, new[] { new StructField("id", VarKind.Number), new StructField("owner", VarKind.Address), new StructField("chain", VarKind.String), new StructField("rom", romType), new StructField("ram", ramType) });

            this.Scope.AddVariable(new VarDeclaration(this.Scope, "_tokenID", VarType.Find(VarKind.Number), VarStorage.NFT));
            this.Scope.AddVariable(new VarDeclaration(this.Scope, "_seriesID", VarType.Find(VarKind.Number), VarStorage.NFT));
            this.Scope.AddVariable(new VarDeclaration(this.Scope, "_mintID", VarType.Find(VarKind.Number), VarStorage.NFT));
            this.Scope.AddVariable(new VarDeclaration(this.Scope, "_ROM", romType, VarStorage.NFT));
            this.Scope.AddVariable(new VarDeclaration(this.Scope, "_RAM", ramType, VarStorage.NFT));
        }
Esempio n. 2
0
        public static VarType Find(VarKind kind, object extra = null)
        {
            var key = kind.ToString();

            if (extra != null)
            {
                key = $"{key}<{extra}>";
            }

            if (_cache.ContainsKey(key))
            {
                return(_cache[key]);
            }

            VarType result;

            switch (kind)
            {
            case VarKind.Number:
            case VarKind.Bool:
            case VarKind.String:
            case VarKind.Timestamp:
            case VarKind.Address:
            case VarKind.Hash:
            case VarKind.Bytes:
            case VarKind.Task:
            case VarKind.Type:
            case VarKind.None:
            case VarKind.Any:
            case VarKind.Storage_List:
            case VarKind.Storage_Map:
            case VarKind.Storage_Set:
            case VarKind.Unknown:
                result = new PrimitiveVarType(kind);
                break;

            case VarKind.Decimal:
                Throw.IfNull(extra, kind + " type requires extra data for initialization");
                result = new DecimalVarType((int)extra);
                break;

            case VarKind.Struct:
                result = new StructVarType((string)extra);
                break;

            case VarKind.Enum:
                result = new EnumVarType((string)extra);
                break;

            case VarKind.Method:
                result = new MethodVarType((MethodDeclaration)extra);
                break;

            case VarKind.Module:
                result = new ModuleVarType((Module)extra);
                break;

            case VarKind.Generic:
                result = new GenericVarType((int)extra);
                break;

            default:
                throw new CompilerException($"Could not initialize type: {kind}");
            }

            _cache[key] = result;
            return(result);
        }