Skip to content

Commit

Permalink
added namespaces yes
Browse files Browse the repository at this point in the history
#release
  • Loading branch information
marceldobehere committed Oct 31, 2022
1 parent 2400e37 commit 9f0c210
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 81 deletions.
20 changes: 10 additions & 10 deletions MAAL/Compiling/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,12 +910,12 @@ public static List<byte> Compile(Parser.ParsedStuff stuff)

List<AlmostByte> almostCompiledCode = new List<AlmostByte>();

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
Expand All @@ -925,7 +925,7 @@ public static List<byte> 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<string, ulong> strLocs = new Dictionary<string, ulong>();

Expand Down Expand Up @@ -1414,7 +1414,7 @@ public static List<byte> Compile(Parser.ParsedStuff stuff)
almostCompiledCode.Add(new AlmostByte(new byte[8]));
}
#endregion




Expand Down Expand Up @@ -1448,17 +1448,17 @@ public static List<byte> 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);
}

Expand Down Expand Up @@ -1491,15 +1491,15 @@ public static List<byte> 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)
{
Expand Down
53 changes: 52 additions & 1 deletion MAAL/Docs/MAAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```






Expand Down
48 changes: 48 additions & 0 deletions MAAL/Examples/MAAL/namespaces.maal
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions MAAL/MAAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<None Include="Examples\MAAL\hello world.maal" />
<None Include="Examples\MAAL\some math and var stuff.maal" />
<None Include="Examples\MAAL\some math and var stuff.maal.maab" />
<None Include="Examples\MAAL\namespaces.maal" />
<None Include="Examples\MAAL\speedtest.maal" />
<None Include="Examples\MAAL\speedtest.maal.maab" />
<None Include="Examples\MAAL\readline.maal" />
Expand Down
Loading

0 comments on commit 9f0c210

Please sign in to comment.