TFWR.Compiler 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TFWR.Compiler --version 1.0.1
                    
NuGet\Install-Package TFWR.Compiler -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TFWR.Compiler" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TFWR.Compiler" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TFWR.Compiler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TFWR.Compiler --version 1.0.1
                    
#r "nuget: TFWR.Compiler, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TFWR.Compiler@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TFWR.Compiler&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TFWR.Compiler&version=1.0.1
                    
Install as a Cake Tool

TFWR.Compiler

The Farmer Was Replaced용 C# 소스를 인게임 DSL(.py)로 번역하는 컴파일러 라이브러리입니다.

Roslyn으로 C#을 파싱·분석한 뒤, TFWR IR로 낮추고 Python 텍스트를 생성합니다. CLI는 tfwrc가 이 라이브러리를 호출합니다. 게임 API 스텁은 TFWR.Api를 참조합니다.

메타데이터 참조는 런타임 Assembly.Location/TPA 파일 경로가 아니라, 임베디드 net10.0 참조 어셈블리(Basic.Reference.Assemblies.Net100)와 디스크의 TFWR.Api.dll(exe 옆 또는 %TFWRC_HOME%\bin)로 구성합니다. single-file 배포에서도 API DLL은 exe 옆에 둡니다.

파이프라인

C# (.cs)  →  Roslyn 파싱/바인딩  →  Lowering (IR)  →  Emit (.py)
단계 구성 설명
진입 TfwrCompiler 입력 검증, 컴파일레이션 구성, 모듈별 lowering·emit 조율
Lowering LoweringContext C# AST → TFWR IR (TfwrModule / TfwrStmt / TfwrExpr)
Emit TfwrEmitter IR → Python 소스 텍스트
IR TFWR.Compiler.Ir 모듈·함수·문·식 노드

공개 API

var result = TfwrCompiler.Compile(new CompileOptions
{
    InputFiles = [@"D:\farm\Program.cs"],
    OutputDirectory = @"D:\farm\out",
    Language = "cs",
    EmitTopLevelEntry = false // true면 Main/[TfwrEntry]를 def 없이 최상위 문으로 emit
});

if (!result.Success)
{
    foreach (var d in result.Diagnostics)
        Console.Error.WriteLine(d);
    return;
}

foreach (var (path, text) in result.EmittedFiles)
    Console.WriteLine($"{path}: {text.Length} chars");

테스트·도구용 인메모리 컴파일:

var result = TfwrCompiler.CompileToMemory(new Dictionary<string, string>
{
    ["Program.cs"] = source
}, emitTopLevelEntry: true);
타입 역할
CompileOptions 입력 파일, 출력 디렉터리, 언어, --toplevel 대응 옵션
CompileResult 성공 여부, 진단, 상대 경로 → emit 텍스트
CompileDiagnostic 심각도·메시지·위치
TfwrEmitter IR 모듈을 Python 문자열로 변환 (고급/테스트용)

출력 규칙 (요약)

  • 파일명 → 모듈명, .cs.py (상대 경로 유지)
  • Main / [TfwrEntry] → 엔트리 (if __name__ == "__main__" 또는 --toplevel 시 최상위 문)
  • 인스턴스 타입 → dict + TypeName_Method / TypeName_new 프리 함수
  • Game.* → snake_case builtins (Harvestharvest)
  • Direction → 전역 (North 등), 기타 게임 enum → Entities.Carrot 형태
  • 교차 모듈 참조 → import + 한정 호출

v1 지원 범위

지원: 클래스·record(단일 상속)·필드·자동 프로퍼티·생성자·메서드, if/while/for/foreach/switch, 삼항 ?:(if/else+temp), 게임 API·enum, 문자열 보간, List/Dictionary/HashSet, 다중 파일 import

거부: try/catch, async/await, LINQ, yield, unsafe, 사용자 제네릭 타입, 대부분의 BCL

EmitTopLevelEntry가 켜진 모듈에 다른 함수/생성자가 있으면(추가 def 필요) 오류입니다.

패키지 정보

  • 대상 프레임워크: net10.0
  • 의존성: Microsoft.CodeAnalysis.CSharp, TFWR.Api
  • XML 문서 파일 포함 (GenerateDocumentationFile)
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 87 9/14/2026
1.0.2 89 9/13/2026
1.0.1 85 9/13/2026
1.0.0 91 9/13/2026