diff --git a/MAAL/Compiling/Compiler.cs b/MAAL/Compiling/Compiler.cs index c8d3db6..dc7fab2 100644 --- a/MAAL/Compiling/Compiler.cs +++ b/MAAL/Compiling/Compiler.cs @@ -910,12 +910,12 @@ public static List Compile(Parser.ParsedStuff stuff) List almostCompiledCode = new List(); - if (!stuff.Locations.ContainsKey("MAIN")) + if (!stuff.HasLocFromNameAndNamespace("", "MAIN")) throw new Exception("NO MAIN LOCATION/ENTRY POINT DECLARED!!!"); almostCompiledCode.Add(new AlmostByte("Jumping to MAIN")); almostCompiledCode.Add(new AlmostByte(IToByte[InstructionEnum.JUMP_FIX])); - almostCompiledCode.Add(new AlmostByte(new LocationNameToken(stuff.Locations["MAIN"]))); + almostCompiledCode.Add(new AlmostByte(new LocationNameToken(stuff.GetLocFromNameAndNamespace("", "MAIN")))); //almostCompiledCode.Add(new AlmostByte(0)); // might not need that if I change casting @@ -925,7 +925,7 @@ public static List Compile(Parser.ParsedStuff stuff) almostCompiledCode.Add(new AlmostByte("VARIABLE DATA:")); foreach (var usedVar in stuff.Variables) - almostCompiledCode.Add(new AlmostByte(usedVar.Value)); + almostCompiledCode.Add(new AlmostByte(usedVar)); Dictionary strLocs = new Dictionary(); @@ -1414,7 +1414,7 @@ public static List Compile(Parser.ParsedStuff stuff) almostCompiledCode.Add(new AlmostByte(new byte[8])); } #endregion - + @@ -1448,17 +1448,17 @@ public static List Compile(Parser.ParsedStuff stuff) { if (aByte.IsDefineLocation) { - locAddresses.Add(aByte.DefineLocation.LocationName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); + locAddresses.Add(aByte.DefineLocation.NamespacePrefix + aByte.DefineLocation.LocationName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); //compiledCode.AddRange(aByte.FixedData); } else if (aByte.IsDefineSubroutine) { - subAddresses.Add(aByte.DefineSubroutine.SubroutineName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); + subAddresses.Add(aByte.DefineSubroutine.NamespacePrefix + aByte.DefineSubroutine.SubroutineName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); //compiledCode.AddRange(aByte.FixedData); } else if (aByte.IsDeclaredVarName) { - varAddresses.Add(aByte.DeclaredVarName.VarName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); + varAddresses.Add(aByte.DeclaredVarName.NamespacePrefix + aByte.DeclaredVarName.VarName, GetAddrOfAlmostByte(almostCompiledCode, aByte)); //compiledCode.AddRange(aByte.FixedData); } @@ -1491,15 +1491,15 @@ public static List Compile(Parser.ParsedStuff stuff) } else if (aByte.IsVarName) { - compiledCode.AddRange(BEC.UInt64ToByteArr(varAddresses[aByte.VarName.VarName])); + compiledCode.AddRange(BEC.UInt64ToByteArr(varAddresses[aByte.VarName.NamespacePrefix + aByte.VarName.VarName])); } else if (aByte.IsLocationName) { - compiledCode.AddRange(BEC.UInt64ToByteArr(locAddresses[aByte.LocationName.Location.LocationName])); + compiledCode.AddRange(BEC.UInt64ToByteArr(locAddresses[aByte.LocationName.Location.NamespacePrefix + aByte.LocationName.Location.LocationName])); } else if (aByte.IsSubroutineName) { - compiledCode.AddRange(BEC.UInt64ToByteArr(subAddresses[aByte.SubroutineName.Subroutine.SubroutineName])); + compiledCode.AddRange(BEC.UInt64ToByteArr(subAddresses[aByte.SubroutineName.Subroutine.NamespacePrefix + aByte.SubroutineName.Subroutine.SubroutineName])); } else if (aByte.IsAlmostByteOffset) { diff --git a/MAAL/Docs/MAAL.md b/MAAL/Docs/MAAL.md index 2edefec..1a3178f 100644 --- a/MAAL/Docs/MAAL.md +++ b/MAAL/Docs/MAAL.md @@ -178,7 +178,58 @@ You can directly manipulate the memory by doing. ### Dynamic Memory Stuff -none yet +There are some syscalls related to dynamic memory. +(Mainly malloc and free) + + +### Namespaces +You can define namespaces like this: +``` +namespace NAME +{ + ... + ... +} +``` +If you want to refer to Variables/Locations/Subroutines/... inside the namespace you can use \:\:. +``` +int x; + +namespace TEST +{ + int x; +} + + +x = 10; +TEST::x = 20; + +``` +If you want to refer to Variables/etc which are outside the current namespace you can use GLOBAL\:\:. +``` +int x; + +namespace TEST +{ + int x; + + sub SET_VARS: + x = 5; // x in TEST + GLOBAL::x = 10; // global x + GLOBAL::TEST::x = 20; // still x in TEST + ret;_ +} + +x = 100; // global x +TEST::x = 5; // x in TEST + +sub TEST::SET_VARS; +// will set the global x to 10 and +// the x in TEST to 5 and then to 20. +``` + + + diff --git a/MAAL/Examples/MAAL/namespaces.maal b/MAAL/Examples/MAAL/namespaces.maal new file mode 100644 index 0000000..f8d4c23 --- /dev/null +++ b/MAAL/Examples/MAAL/namespaces.maal @@ -0,0 +1,48 @@ +loc MAIN: + // "local" x + int x; + + // This sets the local x to 10 + x = 10; + // This sets the x in the namespace TEST to 20 + TEST::x = 20; + + // Prints the Variables + sub PRINT_VARS; + + // Sets the variables from inside the TEST namespace + sub TEST::SET_X; + print "CALLING TEST::SET_X...\n"; + + // Prints the changed Variables + sub PRINT_VARS; + + // Done + exit; + + +sub PRINT_VARS: + print "VARS:\n"; + print "X: "; + print x; + print "\n"; + + print "TEST:X: "; + print TEST::x; + print "\n\n"; + + ret; + + + +namespace TEST +{ + int x; + + sub SET_X: + x = 50; + GLOBAL::x = 100; + ret; + + // You can also have nested namespaces +} \ No newline at end of file diff --git a/MAAL/MAAL.csproj b/MAAL/MAAL.csproj index 682aa65..18841e9 100644 --- a/MAAL/MAAL.csproj +++ b/MAAL/MAAL.csproj @@ -100,6 +100,7 @@ + diff --git a/MAAL/Parsing/Parser.cs b/MAAL/Parsing/Parser.cs index 660ff6f..5ccfdef 100644 --- a/MAAL/Parsing/Parser.cs +++ b/MAAL/Parsing/Parser.cs @@ -10,12 +10,53 @@ public partial class Parser { public class ParsedStuff { - public Dictionary Variables = new Dictionary(); - public Dictionary Locations = new Dictionary(); - public Dictionary Subroutines = new Dictionary(); + public List Variables = new List(); + public List Locations = new List(); + public List Subroutines = new List(); public List Strings = new List(); + public List Namespaces = new List(); public List parsedTokens = new List(); + + public DeclareVarToken GetVarFromNameAndNamespace(string namespacePref, string varName) + { + foreach (var v in Variables) + if (v.NamespacePrefix.Equals(namespacePref) && v.VarName.Equals(varName)) + return v; + + return null; + } + public DefineLocationToken GetLocFromNameAndNamespace(string namespacePref, string locName) + { + foreach (var v in Locations) + if (v.NamespacePrefix.Equals(namespacePref) && v.LocationName.Equals(locName)) + return v; + + return null; + } + public DefineSubroutineToken GetSubFromNameAndNamespace(string namespacePref, string subName) + { + foreach (var v in Subroutines) + if (v.NamespacePrefix.Equals(namespacePref) && v.SubroutineName.Equals(subName)) + return v; + + return null; + } + + public bool HasVarFromNameAndNamespace(string namespacePref, string tName) + { + return GetVarFromNameAndNamespace(namespacePref, tName) != null; + } + public bool HasLocFromNameAndNamespace(string namespacePref, string tName) + { + return GetLocFromNameAndNamespace(namespacePref, tName) != null; + } + public bool HasSubFromNameAndNamespace(string namespacePref, string tName) + { + return GetSubFromNameAndNamespace(namespacePref, tName) != null; + } + + } public static ParsedStuff ParseFile(string filename) @@ -105,8 +146,112 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf { Token cTok = data[mIndex]; + #region NAMESPACE + if (cTok is KeywordToken && mIndex + 2 < data.Count && + (cTok as KeywordToken).Keyword.Equals("namespace") && + data[mIndex + 1] is GenericNameToken && + data[mIndex + 2] is CurlyBracketOpenToken) + { + string namespaceName = (data[mIndex + 1] as GenericNameToken).Name + "::"; + string namespacePref = (data[mIndex + 1] as GenericNameToken).NamespacePrefix; + + int cCloseIndex = -1; + int layer = 1; + for (int tI = mIndex + 3; layer > 0 && tI < data.Count; tI++) + { + if (data[tI] is CurlyBracketOpenToken) + layer++; + if (data[tI] is CurlyBracketCloseToken) + layer--; + if (layer == 0) + cCloseIndex = tI; + } + if (layer != 0) + { + throw new Exception($"NAMESPACE WAS NOT CLOSED!"); + } + + for (int tI = mIndex + 3; tI < cCloseIndex; tI++) + data[tI].NamespacePrefix += namespaceName; + stuff.Namespaces.Add(namespacePref+namespaceName); + + data.RemoveAt(cCloseIndex); + data.RemoveAt(mIndex + 2); + data.RemoveAt(mIndex + 1); + data.RemoveAt(mIndex); + + change = true; + break; + } + #endregion + + + #region NAMESPACE:: + else if (cTok is GenericNameToken && mIndex + 1 < data.Count && + data[mIndex + 1] is DoubleColonToken) + { + string pref = (cTok as GenericNameToken).NamespacePrefix; + string name = (cTok as GenericNameToken).Name; + + int sIndex = mIndex + 1; + + string tPref = pref; + + if (name.ToLower().Equals("global")) + { + tPref = ""; + } + else + tPref += name + "::"; + //if (name.ToLower().Equals("global")) + //{ + // data[mIndex] = new NamespaceUseToken(""); + // data.RemoveAt(mIndex + 1); + // change = true; + // break; + //} + + int wIndex = mIndex + 2; + + while (wIndex + 1 < data.Count && + (data[wIndex] is GenericNameToken) && + (data[wIndex + 1] is DoubleColonToken)) + { + tPref += (data[wIndex] as GenericNameToken).Name + "::"; + wIndex += 2; + } + + if (!tPref.Equals("") && !stuff.Namespaces.Contains(tPref)) + { + continue; + //throw new Exception($"NAMESPACE {tPref} DOES NOT EXIST! {cTok}"); + } + + + int eIndex = wIndex - 2; + data[mIndex] = new NamespaceUseToken(tPref); + for (int i = sIndex; i < wIndex; i++) + data.RemoveAt(sIndex); + + change = true; + break; + } + #endregion + #region NAMESPACE::x + if (cTok is NamespaceUseToken && mIndex + 1 < data.Count) + { + Console.WriteLine($" - 1: {data[mIndex + 1]}"); + data[mIndex + 1].NamespacePrefix = (cTok as NamespaceUseToken).NamespacePrefix; + Console.WriteLine($" - 2: {data[mIndex + 1]}\n"); + data.RemoveAt(mIndex); + change = true; + break; + } + #endregion + + #region STRINGS - if (cTok is BasicValueToken && (cTok as BasicValueToken).ValueType == BasicValueToken.BasicValueTypeEnum.CHAR_POINTER) + else if (cTok is BasicValueToken && (cTok as BasicValueToken).ValueType == BasicValueToken.BasicValueTypeEnum.CHAR_POINTER) { //GlobalStuff.WriteLine("BRUH"); BasicValueToken sTok = (cTok as BasicValueToken); @@ -125,8 +270,8 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf if (kWord.Equals("loc") || kWord.Equals("location")) { string locName = (data[mIndex + 1] as GenericNameToken).Name; - data[mIndex] = new DefineLocationToken(locName); - stuff.Locations.Add(locName, data[mIndex] as DefineLocationToken); + data[mIndex] = new DefineLocationToken(locName, (data[mIndex + 1] as GenericNameToken).NamespacePrefix); + stuff.Locations.Add(data[mIndex] as DefineLocationToken); data.RemoveAt(mIndex + 1); data.RemoveAt(mIndex + 1); change = true; @@ -135,8 +280,8 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf else if (kWord.Equals("sub") || kWord.Equals("subroutine")) { string locName = (data[mIndex + 1] as GenericNameToken).Name; - data[mIndex] = new DefineSubroutineToken(locName); - stuff.Subroutines.Add(locName, data[mIndex] as DefineSubroutineToken); + data[mIndex] = new DefineSubroutineToken(locName, (data[mIndex + 1] as GenericNameToken).NamespacePrefix); + stuff.Subroutines.Add( data[mIndex] as DefineSubroutineToken); data.RemoveAt(mIndex + 1); data.RemoveAt(mIndex + 1); change = true; @@ -189,6 +334,8 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf } #endregion + + #region SYSCALL else if (cTok is KeywordToken && mIndex + 1 < data.Count && (cTok as KeywordToken).Keyword.Equals("syscall")) @@ -331,10 +478,11 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf #region VARIABLE NAMES // x - if (cTok is GenericNameToken && (stuff.Variables.ContainsKey((cTok as GenericNameToken).Name))) + if (cTok is GenericNameToken && (stuff.HasVarFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix, (cTok as GenericNameToken).Name)) && + (mIndex < 1 || (!(data[mIndex - 1] is DoubleColonToken) && !(data[mIndex - 1] is NamespaceUseToken)))) { - DeclareVarToken tTok = stuff.Variables[(cTok as GenericNameToken).Name]; - data[mIndex] = new VarNameToken(tTok.VarName, tTok.VarType); + DeclareVarToken tTok = stuff.GetVarFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix, (cTok as GenericNameToken).Name); + data[mIndex] = new VarNameToken(tTok.VarName, tTok.VarType, (cTok as GenericNameToken).NamespacePrefix); change = true; break; } @@ -344,9 +492,10 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf // ... // // test - if (cTok is GenericNameToken && (stuff.Locations.ContainsKey((cTok as GenericNameToken).Name))) + if (cTok is GenericNameToken && (stuff.HasLocFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix, (cTok as GenericNameToken).Name)) && + (mIndex < 1 || (!(data[mIndex - 1] is DoubleColonToken) && !(data[mIndex - 1] is NamespaceUseToken)))) { - data[mIndex] = new LocationNameToken(stuff.Locations[(cTok as GenericNameToken).Name]); + data[mIndex] = new LocationNameToken(stuff.GetLocFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix, (cTok as GenericNameToken).Name)); change = true; break; } @@ -357,15 +506,23 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf // ret; // // testrout - if (cTok is GenericNameToken && (stuff.Subroutines.ContainsKey((cTok as GenericNameToken).Name))) + if (cTok is GenericNameToken && (stuff.HasSubFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix, (cTok as GenericNameToken).Name)) && + (mIndex < 1 || (!(data[mIndex - 1] is DoubleColonToken) && !(data[mIndex - 1] is NamespaceUseToken)))) { - data[mIndex] = new SubroutineNameToken(stuff.Subroutines[(cTok as GenericNameToken).Name]); + data[mIndex] = new SubroutineNameToken(stuff.GetSubFromNameAndNamespace((cTok as GenericNameToken).NamespacePrefix,(cTok as GenericNameToken).Name)); change = true; break; } #endregion + + + + + + + #region JUMP // jump TEST; if (cTok is KeywordToken && ((cTok as KeywordToken).Keyword.Equals("jump")) && mIndex + 2 < data.Count && @@ -457,7 +614,7 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf break; } #endregion - #region GET ADDRES + #region GET ADDRESS //&test if (cTok is OperatorToken && ((cTok as OperatorToken).Operator == OperatorToken.OperatorEnum.BitAnd) && mIndex + 1 < data.Count && data[mIndex + 1] is VarNameToken) { @@ -570,8 +727,8 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf //GlobalStuff.WriteLine(); ParsedStuff tempParsedStuff = new ParsedStuff(); - foreach (var pair in stuff.Variables) - tempParsedStuff.Variables.Add(pair.Key, pair.Value); + foreach (var thingy in stuff.Variables) + tempParsedStuff.Variables.Add(thingy); ParseStringAdvanced(tempList, tempParsedStuff); stuff.Strings.AddRange(tempParsedStuff.Strings); @@ -647,11 +804,9 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf (data[mIndex + 1] is GenericNameToken) && (data[mIndex + 2] is EndCommandToken)) { string varName = (data[mIndex + 1] as GenericNameToken).Name; - DeclareVarToken tok = new DeclareVarToken( - varName, - (data[mIndex] as TypeToken)); + DeclareVarToken tok = new DeclareVarToken(varName, (data[mIndex] as TypeToken), (data[mIndex + 1] as GenericNameToken).NamespacePrefix); - stuff.Variables.Add(varName, tok); + stuff.Variables.Add(tok); data.RemoveAt(mIndex); data.RemoveAt(mIndex); @@ -670,9 +825,10 @@ public static ParsedStuff ParseStringAdvanced(List data, ParsedStuff stuf string varName = (data[mIndex + 1] as GenericNameToken).Name; DeclareVarToken tok = new DeclareVarToken( varName, - (data[mIndex] as TypeToken)); + (data[mIndex] as TypeToken), + (data[mIndex + 1] as GenericNameToken).NamespacePrefix); - stuff.Variables.Add(varName, tok); + stuff.Variables.Add(tok); data.RemoveAt(mIndex); change = true; @@ -991,12 +1147,32 @@ public static List ParseStringBasic(string data) tokens.Add(new EndCommandToken()); tempString = ""; } - else if (tChar == ':') + else if (tChar == '{') { if (tempString != "") tokens.Add(ConvertStringToToken(tempString)); - tokens.Add(new ColonToken()); tempString = ""; + tokens.Add(new CurlyBracketOpenToken()); + } + else if (tChar == '}') + { + if (tempString != "") + tokens.Add(ConvertStringToToken(tempString)); + tempString = ""; + tokens.Add(new CurlyBracketCloseToken()); + } + else if (tChar == ':') + { + if (tempString != "") + tokens.Add(ConvertStringToToken(tempString)); + tempString = ""; + if (mIndex + 1 < len && data[mIndex + 1] == ':') + { + tokens.Add(new DoubleColonToken()); + mIndex++; + } + else + tokens.Add(new ColonToken()); } else if (tChar == '"') { diff --git a/MAAL/Parsing/Token.cs b/MAAL/Parsing/Token.cs index b29c459..fb3b038 100644 --- a/MAAL/Parsing/Token.cs +++ b/MAAL/Parsing/Token.cs @@ -6,6 +6,8 @@ namespace MAAL.Parsing { public class Token { + public string NamespacePrefix = string.Empty; + public override string ToString() => $""; } @@ -19,6 +21,21 @@ public class ColonToken : Token public override string ToString() => $"<:>"; } + public class DoubleColonToken : Token + { + public override string ToString() + => $"<::>"; + } + public class CurlyBracketOpenToken : Token + { + public override string ToString() + => "<{>"; + } + public class CurlyBracketCloseToken : Token + { + public override string ToString() + => "<}>"; + } public class OperatorToken : Token { public enum OperatorEnum @@ -95,7 +112,7 @@ public class KeywordToken : Token "if_jump", "if_sub", "#include", "syscall", "print", "malloc", "free", - "readline" + "readline", "namespace" }; public string Keyword = ""; @@ -324,20 +341,21 @@ public class VarNameToken : Token public TypeToken VarType; public bool UseAddr = false; - public VarNameToken(string name, TypeToken typeToken) + public VarNameToken(string name, TypeToken typeToken, string namespacePref) { VarName = name; VarType = typeToken; UseAddr = false; + NamespacePrefix = namespacePref; } public override string ToString() { string res; if (UseAddr) - res = $""; + res = $""; else - res = $""; + res = $""; return res; } @@ -372,14 +390,15 @@ public class DeclareVarToken : Token public string VarName; public TypeToken VarType; - public DeclareVarToken(string varName, TypeToken varType) + public DeclareVarToken(string varName, TypeToken varType, string namespacePref) { VarName = varName; VarType = varType; + NamespacePrefix = namespacePref; } public override string ToString() - => $"<{VarType} \"{VarName}\">"; + => $"<{VarType} \"{NamespacePrefix}{VarName}\">"; } public class DerefToken : Token @@ -542,25 +561,27 @@ public class DefineLocationToken : Token { public string LocationName; - public DefineLocationToken(string name) + public DefineLocationToken(string name, string namespacePref) { LocationName = name; + NamespacePrefix = namespacePref; } public override string ToString() - => $""; + => $""; } public class DefineSubroutineToken : Token { public string SubroutineName; - public DefineSubroutineToken(string name) + public DefineSubroutineToken(string name, string namespacePref) { SubroutineName = name; + NamespacePrefix = namespacePref; } public override string ToString() - => $""; + => $""; } public class ExitToken : Token @@ -599,7 +620,7 @@ public override string ToString() if (JumpToFixedAddress) return $""; else - return $""; + return $""; } } public class SubroutineNameToken : Token @@ -612,7 +633,7 @@ public SubroutineNameToken(DefineSubroutineToken subroutine) } public override string ToString() - => $""; + => $""; } public class FixedJumpToken : Token { @@ -765,6 +786,22 @@ public override string ToString() } } + public class NamespaceUseToken : Token + { + public NamespaceUseToken(string namespacePref) + { + NamespacePrefix = namespacePref; + } + + public override string ToString() + { + if (NamespacePrefix.Equals("")) + return $""; + else + return $""; + } + } + } // 12 diff --git a/MAAL/Program.cs b/MAAL/Program.cs index c8db125..02ed3a0 100644 --- a/MAAL/Program.cs +++ b/MAAL/Program.cs @@ -150,15 +150,19 @@ static void DoStuff(string[] args) GlobalStuff.WriteLine(); GlobalStuff.WriteLine(); GlobalStuff.WriteLine($"Variables: (Count: {stuff.Variables.Count})"); - foreach (var token in stuff.Variables.Values) + foreach (var token in stuff.Variables) GlobalStuff.WriteLine($" - {token}"); GlobalStuff.WriteLine(); + GlobalStuff.WriteLine($"Namespaces: (Count: {stuff.Namespaces.Count})"); + foreach (var token in stuff.Namespaces) + GlobalStuff.WriteLine($" - \"{token}\""); + GlobalStuff.WriteLine(); GlobalStuff.WriteLine($"Locations: (Count: {stuff.Locations.Count})"); - foreach (var token in stuff.Locations.Values) + foreach (var token in stuff.Locations) GlobalStuff.WriteLine($" - {token}"); GlobalStuff.WriteLine(); GlobalStuff.WriteLine($"Subroutines: (Count: {stuff.Subroutines.Count})"); - foreach (var token in stuff.Subroutines.Values) + foreach (var token in stuff.Subroutines) GlobalStuff.WriteLine($" - {token}"); GlobalStuff.WriteLine(); diff --git a/MAAL/bin/Debug/MAAL.exe b/MAAL/bin/Debug/MAAL.exe index 3033425..50df3f4 100644 Binary files a/MAAL/bin/Debug/MAAL.exe and b/MAAL/bin/Debug/MAAL.exe differ diff --git a/MAAL/bin/Debug/test.maal b/MAAL/bin/Debug/test.maal index 0717d55..f8d4c23 100644 --- a/MAAL/bin/Debug/test.maal +++ b/MAAL/bin/Debug/test.maal @@ -1,40 +1,48 @@ loc MAIN: - char* input; - int option; + // "local" x + int x; - print "Two Options\n"; - print "1) HELLO\n"; - print "2) HOI\n"; - - print "\nSelect one: "; - sub SetOptionBasedOnChar; - print "\n"; + // This sets the local x to 10 + x = 10; + // This sets the x in the namespace TEST to 20 + TEST::x = 20; - if_jump (option != 1) HELLO_END; - print "HELLO!"; -loc HELLO_END: + // Prints the Variables + sub PRINT_VARS; - if_jump (option != 2) HOI_END; - print "HOI!"; -loc HOI_END: + // Sets the variables from inside the TEST namespace + sub TEST::SET_X; + print "CALLING TEST::SET_X...\n"; - if_jump (option != -1) INV_END; - print "INVALID OPTION PICKED"; -loc INV_END: + // Prints the changed Variables + sub PRINT_VARS; + // Done exit; -sub SetOptionBasedOnChar: - readline &input; - option = -1; - - if_jump (*input != '1') NO_1; - option = 1; -loc NO_1: +sub PRINT_VARS: + print "VARS:\n"; + print "X: "; + print x; + print "\n"; + + print "TEST:X: "; + print TEST::x; + print "\n\n"; - if_jump (*input != '2') NO_2; - option = 2; -loc NO_2: + ret; - ret; \ No newline at end of file + + +namespace TEST +{ + int x; + + sub SET_X: + x = 50; + GLOBAL::x = 100; + ret; + + // You can also have nested namespaces +} \ No newline at end of file diff --git a/MAAL/bin/Debug/test.maal.maab b/MAAL/bin/Debug/test.maal.maab index c6ecabf..270cc92 100644 Binary files a/MAAL/bin/Debug/test.maal.maab and b/MAAL/bin/Debug/test.maal.maab differ diff --git a/MAAL/obj/Debug/MAAL.exe b/MAAL/obj/Debug/MAAL.exe index 3033425..50df3f4 100644 Binary files a/MAAL/obj/Debug/MAAL.exe and b/MAAL/obj/Debug/MAAL.exe differ