public Instruction(EP_InstCode cmd, Merker param = null, CodeNode cn = null) { _param = param; _cn = cn; _blob = false; Prepare(cmd); }
public Scope(EP_Compiler c, Merker fm, Scope parent) { _compiler = c; _parent = parent; this.fm = fm; memBlocks = new SortedSet <DP_MemBlock>(); memBlocks.Add(new DP_MemBlock(0, 16384)); code = new List <Instruction>(); memory = new List <Merker>(); loops = new Stack <EP_VP2.Loop>(); }
internal Scope ScopePush(Merker fm) { var tmp = cur; cur = _programm.FirstOrDefault(z => z.fm == fm); if (cur == null) { cur = new Scope(this, fm, tmp); _programm.Add(cur); } _scope.Push(cur); return(cur); }
internal Merker GetMerker(VariableDescriptor v) { Merker m = null; m = cur.memory.FirstOrDefault(z => z.vd == v); if (m == null) { m = global.memory.FirstOrDefault(z => z.vd == v); } if (m == null) { m = LoadNativeFunctions(v); } return(m); }
public Merker GetProperty(string name, EP_Type type = EP_Type.NONE) { Merker m; string fName = fm.fName + "." + name; m = memory.FirstOrDefault(z => z.pName == name); if (m == null && _parent != null) { m = _parent.memory.FirstOrDefault(z => z.pName == name); } if (type != EP_Type.NONE && m == null && !string.IsNullOrEmpty(name)) { m = new Merker() { fName = fName, pName = name, type = type }; memory.Add(m); } return(m); }
private Merker LoadNativeFunctions(VariableDescriptor v) { Merker m; switch (v.Name) { case "TwiControl": m = new Merker() { type = EP_Type.API, Addr = 1, vd = v, pIn = 1 }; break; case "TwiStatus": m = new Merker() { type = EP_Type.API, Addr = 2, vd = v, pOut = 1 }; break; case "TwiPutByte": m = new Merker() { type = EP_Type.API, Addr = 3, vd = v, pIn = 1 }; break; case "TwiGetByte": m = new Merker() { type = EP_Type.API, Addr = 4, vd = v, pOut = 1 }; break; case "NodeStatus": m = new Merker() { type = EP_Type.API, Addr = 5, vd = v, pOut = 1 }; break; case "getMilliseconds": m = new Merker() { type = EP_Type.API, Addr = 6, vd = v, pOut = 1 }; break; case "getSeconds": m = new Merker() { type = EP_Type.API, Addr = 7, vd = v, pOut = 1 }; break; case "Random": m = new Merker() { type = EP_Type.API, Addr = 8, vd = v, pOut = 1 }; break; case "NowSeconds": // total seconds since 0:00:00 m = new Merker() { type = EP_Type.API, Addr = 9, vd = v, pOut = 1 }; break; case "Today": // (year[0..99]<<24) | (month[1..12]<<16) | (day[1..31]<<8) | (dayOfWeek[1-Monday..7-Sunday]) m = new Merker() { type = EP_Type.API, Addr = 10, vd = v, pOut = 1 }; break; case "UartInit": // void UartInit(port, speed) m = new Merker() { type = EP_Type.API, Addr = 20, vd = v, pIn = 2 }; break; case "UartBytesToRead": // int UartBytesToRead(port) m = new Merker() { type = EP_Type.API, Addr = 21, vd = v, pOut = 1, pIn = 1 }; break; case "UartGetByte": // int UartGetByte(port) m = new Merker() { type = EP_Type.API, Addr = 22, vd = v, pOut = 1, pIn = 1 }; break; case "UartPutByte": // bool UartPutByte(port, data) m = new Merker() { type = EP_Type.API, Addr = 23, vd = v, pOut = 1, pIn = 2 }; break; default: return(null); } global.memory.Add(m); return(m); }
internal Merker DefineMerker(VariableDescriptor v, EP_Type type = EP_Type.NONE) { Merker m = null; uint addr; m = cur.memory.FirstOrDefault(z => z.vd == v); if (m == null) { m = global.memory.FirstOrDefault(z => z.vd == v); } if (m == null) { addr = uint.MaxValue; var nt = Periphery.MsDevice.NTTable.FirstOrDefault(z => v.Name.StartsWith(z.Item1)); if (nt != null && v.Name.Length > 2 && UInt32.TryParse(v.Name.Substring(2), out addr)) { addr = (uint)((uint)(((byte)v.Name[0]) << 24) | (uint)(((byte)v.Name[1]) << 16) | addr & 0xFFFF); type = (nt.Item2 & Periphery.MsDevice.DType.Output) != 0?EP_Type.OUTPUT:EP_Type.INPUT; } else if (type == EP_Type.NONE) { if (v.Initializer != null && v.Initializer is FunctionDefinition) { type = EP_Type.FUNCTION; } else if (v.LexicalScope) { type = EP_Type.LOCAL; addr = (uint)cur.memory.Where(z => z.type == EP_Type.LOCAL).Count(); if (addr > 15) { throw new ArgumentOutOfRangeException("Too many local variables: " + v.Name + cur.fm == null ? string.Empty : ("in " + cur.fm.ToString())); } } else { type = EP_Type.SINT32; addr = uint.MaxValue; } } m = new Merker() { type = type, vd = v, pName = v.Name, Addr = addr, init = v.Initializer }; if (type == EP_Type.API || type == EP_Type.INPUT || type == EP_Type.OUTPUT) { global.memory.Add(m); m.fName = v.Name; } else { cur.memory.Add(m); m.fName = (cur == global ? v.Name : cur.fm.fName + (cur.fm.type == EP_Type.FUNCTION ? "+" : ".") + v.Name); } } else if (m.type != type && m.type == EP_Type.NONE) { m.type = type; } return(m); }