29 lines
931 B
C#
29 lines
931 B
C#
using Amogulator.Suslang;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Amogulator;
|
|
public partial class AmogulatorVM : ObservableObject {
|
|
|
|
[ObservableProperty]
|
|
private string output = "test", input = "2 + 3";
|
|
|
|
[RelayCommand]
|
|
private void run() {
|
|
try {
|
|
var ast = new Parser(this.Input, new Lexer(this.Input)).parseExpr();
|
|
var compiler = new Compiler();
|
|
compiler.compileExpr(ast);
|
|
var bytecode = compiler.result();
|
|
var vm = new VM(bytecode);
|
|
vm.evaluate();
|
|
this.Output = $"ast = {ast.astString(0)}\n\nbytecode = [\n{string.Join("", bytecode.Select((op) => " " + op.operationString() + "\n"))}]\n\nresult = {vm.stack.Peek().valueString()}";
|
|
} catch (Exception e) {
|
|
this.Output = $"error = {e.Message}";
|
|
}
|
|
}
|
|
|
|
}
|