mirror of
https://github.com/Wack0/IFPSTools.NET.git
synced 2025-06-19 03:05:40 -04:00

libifpscc: initial commit readme: document ifpscc/libifpscc license: add credits for ifpscc/libifpscc (derived from code also MIT licensed) libifps: make additional fields/types public for libifpscc libifps: fix field documentation for some opcodes libifps: fix loading functions that are not exported libifps: allow saving a nonexistant primitive type if the same primitive type was added already libifps: fix parsing Extended constants libifps: fix ushort/short being mapped to the wrong types in one table csproj: set Prefer32Bit=false for release builds
58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace AST {
|
|
public interface ISemantReturn<out T> {
|
|
T Value { get; }
|
|
ABT.Env Env { get; }
|
|
}
|
|
|
|
public class SemantReturn<T> : ISemantReturn<T> {
|
|
protected SemantReturn(ABT.Env env, T value) {
|
|
this.Value = value;
|
|
this.Env = env;
|
|
}
|
|
|
|
public static ISemantReturn<T> Create(ABT.Env env, T value) =>
|
|
new SemantReturn<T>(env, value);
|
|
|
|
public T Value { get; }
|
|
public ABT.Env Env { get; }
|
|
}
|
|
|
|
public class SemantReturn {
|
|
public static ISemantReturn<T> Create<T>(ABT.Env env, T value) =>
|
|
SemantReturn<T>.Create(env, value);
|
|
}
|
|
|
|
public static class SemanticAnalysis {
|
|
public class SemantMethod : System.Attribute { }
|
|
|
|
public static R Semant<R>(Func<ABT.Env, ISemantReturn<R>> semantFunc, ref ABT.Env env) {
|
|
var semantReturn = semantFunc(env);
|
|
env = semantReturn.Env;
|
|
return semantReturn.Value;
|
|
}
|
|
|
|
public static R Semant<I, R>(Func<ABT.Env, I, ISemantReturn<R>> semantFunc, I arg, ref ABT.Env env) {
|
|
var semantReturn = semantFunc(env, arg);
|
|
env = semantReturn.Env;
|
|
return semantReturn.Value;
|
|
}
|
|
|
|
public static ABT.Expr SemantExpr(Func<ABT.Env, ILineInfo, ABT.Expr> semantFunc, ILineInfo info, ref ABT.Env env) {
|
|
var semantReturn = semantFunc(env, info);
|
|
env = semantReturn.Env;
|
|
return semantReturn;
|
|
}
|
|
|
|
public static ABT.Expr SemantExpr(Expr expr, ref ABT.Env env) =>
|
|
SemantExpr(expr.GetExpr, expr, ref env);
|
|
|
|
public static ABT.Stmt SemantStmt(Func<ABT.Env, Tuple<ABT.Env, ABT.Stmt>> semantFunc, ref ABT.Env env) {
|
|
var semantReturn = semantFunc(env);
|
|
env = semantReturn.Item1;
|
|
return semantReturn.Item2;
|
|
}
|
|
}
|
|
|
|
} |