From e8c2b091051674d322b6c25ca4de15e7711427f4 Mon Sep 17 00:00:00 2001 From: arookas Date: Wed, 3 Feb 2016 23:02:25 -0500 Subject: [PATCH] Added address literals I don't know why someone would want to use a pointer literal in a script, but now you can because there's an opcode for it and fuck it. --- ssc/ast/nodes.literals.cs | 15 +++++++++++++++ ssc/parser.cs | 1 + ssc/sunscript.grammar | 1 + 3 files changed, 17 insertions(+) diff --git a/ssc/ast/nodes.literals.cs b/ssc/ast/nodes.literals.cs index 18fd63f..6517482 100644 --- a/ssc/ast/nodes.literals.cs +++ b/ssc/ast/nodes.literals.cs @@ -52,6 +52,21 @@ namespace arookas { } } + class sunAddressLiteral : sunToken, sunTerm { + public sunAddressLiteral(sunSourceLocation location, string literal) + : base(location) { + Value = UInt32.Parse(literal.Substring(1), NumberStyles.AllowHexSpecifier); + } + + public override void Compile(sunCompiler compiler) { + compiler.Binary.WriteADR(Value); + } + + sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) { + return sunExpressionFlags.Literals; + } + } + class sunStringLiteral : sunToken, sunTerm { public sunStringLiteral(sunSourceLocation location, string literal) : base(location) { diff --git a/ssc/parser.cs b/ssc/parser.cs index 2892fb9..1b50afd 100644 --- a/ssc/parser.cs +++ b/ssc/parser.cs @@ -93,6 +93,7 @@ namespace arookas { case __sunConstants.INT_NUMBER: return new sunIntLiteral(location, token); case __sunConstants.HEX_NUMBER: return new sunHexLiteral(location, token); case __sunConstants.DEC_NUMBER: return new sunFloatLiteral(location, token); + case __sunConstants.ADR_NUMBER: return new sunAddressLiteral(location, token); case __sunConstants.STRING: return new sunStringLiteral(location, token); case __sunConstants.IDENTIFIER: return new sunIdentifier(location, token); case __sunConstants.ELLIPSIS: return new sunEllipsis(location); diff --git a/ssc/sunscript.grammar b/ssc/sunscript.grammar index b4cfa15..bc42bc4 100644 --- a/ssc/sunscript.grammar +++ b/ssc/sunscript.grammar @@ -94,6 +94,7 @@ IDENTIFIER = <<[_A-Za-z][_A-Za-z0-9]*>> DEC_NUMBER = <<-?[0-9]+\.[0-9]+>> HEX_NUMBER = <<-?0x[0-9A-Fa-f]+>> INT_NUMBER = <<-?[0-9]+>> +ADR_NUMBER = <<\$[0-9A-Fa-f]{8}>> STRING = <<"(\\.|[^"])*">> %productions%