Skip to content
Permalink
Browse files

Merge pull request #28 from quajak/variableDefinitions

Implement Variable definitions Emitters
  • Loading branch information
charlesbetros committed Nov 24, 2019
2 parents b009f5d + 76bee07 commit 16aae7cc5abd9a502aae01faced0664e3210fa5d
Showing with 29 additions and 3 deletions.
  1. +29 −3 source/XSharp/XSharp/Emitters/x86/AllEmitters.cs
@@ -1,4 +1,5 @@
using System;
using System.Text;
using Spruce.Attribs;
using Spruce.Tokens;
using XSharp.Tokens;
@@ -49,20 +50,43 @@ protected void RepeatBlockStart(string aOpRepeat, UInt32 loops, string aOpTimes,

// const i = 0
[Emitter(typeof(ConstKeyword), typeof(Identifier), typeof(OpEquals), typeof(Int32u))]
[Emitter(typeof(ConstKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
protected void ConstDefinition(string aConstKeyword, string aConstName, string oOpEquals, object aConstValue)
{
string xConstName = Compiler.GetFullName($"Const_{aConstName}");
Compiler.WriteLine($"{xConstName} equ {aConstValue}");
}

[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Int32u))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
[Emitter(typeof(ConstKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
protected void ConstDefinition(string aConstKeyword, string aConstName, string oOpEquals, string aConstValue)
{
string xConstName = Compiler.GetFullName($"Const_{aConstName}");
byte[] chars = Encoding.ASCII.GetBytes(aConstValue);
Compiler.WriteLine($"{xConstName}:");
Compiler.WriteLine($"\t\tdb {string.Join(", ", chars)}");
}

[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Const))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Variable))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(VariableAddress))]
protected void VariableDefinition(string aVarKeyword, string aVariableName, string oOpEquals, object aVariableValue)
{
throw new NotImplementedException();
}

[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Int32u))]
protected void VariableDefinition(string aVarKeyword, string aVariableName, string oOpEquals, uint aVariableValue)
{
string xVariableName = Compiler.GetFullName(aVariableName);
Compiler.WriteLine($"{xVariableName} dd {aVariableValue}");
}

[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
protected void VariableDefinition(string aVarKeyword, string aVariableName, string oOpEquals, string aStringLiteral)
{
string xVariableName = Compiler.GetFullName(aVariableName);
byte[] chars = Encoding.ASCII.GetBytes(aStringLiteral);
Compiler.WriteLine($"{xVariableName}:");
Compiler.WriteLine($"\t\tdb {string.Join(", ", chars)}");
}

[Emitter(typeof(VarKeyword), typeof(Identifier))]
@@ -75,6 +99,8 @@ protected void VariableDefinition(string aVarKeyword, string aVariableName)
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(Size), typeof(OpOpenBracket), typeof(Int32u), typeof(OpCloseBracket))]
protected void VariableArrayDefinition(string aVarKeyword, string aVariableName, string aSize, string aOpOpenBracket, object aNumberOfItems, string aOpCloseBracket)
{
string xVariableName = Compiler.GetFullName(aVariableName);
Compiler.WriteLine($"{xVariableName} dd 0");
}

// interrupt iNmae123 {

0 comments on commit 16aae7c

Please sign in to comment.
You can’t perform that action at this time.