-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for
eval(expr)
to evaluate constant expressions to …
…a value - renamed `lol` files to `yasm` - Added some extra utilities to `lib.yasm`
- Loading branch information
1 parent
46618a9
commit f8b7fe5
Showing
14 changed files
with
140 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Yolol.Execution.Extensions; | ||
using YololAssembler.Grammar.Errors; | ||
|
||
namespace YololAssembler.Grammar.AST | ||
{ | ||
internal class EvalReplacement | ||
: BaseDefine | ||
{ | ||
protected override string FindRegex => $"eval\\((?<body>.*?)\\)"; | ||
|
||
protected override string Replace(string part) | ||
{ | ||
// Convert the floating expression into a statement assigning a variable; | ||
const string name = "_95efe616"; | ||
var stmtCode = $"{name}={part}"; | ||
|
||
// Try to parse this tiny little program | ||
var parsed = Yolol.Grammar.Parser.ParseProgram(stmtCode); | ||
if (!parsed.IsOk) | ||
throw new CannotParseEval(part, parsed.Err); | ||
|
||
// Get the parsed expression back out | ||
var stmt = (Yolol.Grammar.AST.Statements.Assignment)parsed.Ok.Lines[0].Statements.Statements[0]; | ||
var expr = stmt.Right; | ||
|
||
if (!expr.IsConstant) | ||
throw new EvalNotConst(expr); | ||
|
||
var v = expr.StaticEvaluate(); | ||
|
||
if (v.Type == Yolol.Execution.Type.Number) | ||
return v.ToString(); | ||
else | ||
return $"\"{v}\""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace YololAssembler.Grammar.Errors | ||
{ | ||
public class CannotParseEval | ||
: BaseCompileException | ||
{ | ||
public string Expression { get; } | ||
public Yolol.Grammar.Parser.ParseError ParseError { get; } | ||
|
||
public CannotParseEval(string expression, Yolol.Grammar.Parser.ParseError parseError) | ||
: base($"Cannot parse expression pass to eval `{expression}`.") | ||
{ | ||
Expression = expression; | ||
ParseError = parseError; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace YololAssembler.Grammar.Errors | ||
{ | ||
public class EvalNotConst | ||
: BaseCompileException | ||
{ | ||
public Yolol.Grammar.AST.Expressions.BaseExpression Expression { get; } | ||
|
||
public EvalNotConst(Yolol.Grammar.AST.Expressions.BaseExpression expression) | ||
: base($"Expression pass to eval is not constant `{expression}`.") | ||
{ | ||
Expression = expression; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
YololAssembler/Properties/PublishProfiles/FolderProfile.pubxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>C:\Users\Martin\Desktop\yasm</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<SelfContained>false</SelfContained> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
#define l_pin_char d | ||
#define r_pin_char e | ||
|
||
#import lib.lol | ||
#import lib.yasm | ||
|
||
@line1: | ||
b="" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#define undefined _ | ||
|
||
#define err_if_not(expr) undefined/=expr | ||
#define continue_if(expr) undefined/=expr | ||
|
||
#define pop_char(stack) stack---stack | ||
#define push_char(stack, c) stack+=c | ||
|
||
#define dequeue_char(q) q---q | ||
#define enqueue_char(q, c) q=c+q | ||
|
||
#define set_add_char(set, c) set+=c | ||
#define set_find_char(set, c) set-c!=set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters