DotNetOISC

From Esolang
Jump to navigation Jump to search

DotNetOISC is an OISC-like esolang by User:BoundedBeans based off of the dotnet executable.

Syntax

Each logical line consists of at least five strings. Logical lines are separated by newlines. @:anything; gets removed from the program before any processing, including self-modification. The anything can include newlines, which will not be considered to separate logical lines. Empty logical lines are also removed, and leading and trailing whitespace on logical lines are trimmed.

Strings are text enclosed in single quotes. Inside, =variable-name] translates to the contents of the variable with that name. If the variable does not exist, it translates to the empty string (but other things could still be around it, allowing the argument to have more) Variable names may contain any printable character (0x20 to 0x7e) other than the closing square bracket. The @ character can be followed by two uppercase hexadecimal digits to escape any byte, and must be used to encode ', =, @, carriage return, or linefeed. @00 ends the string early, since the arguments are considered to be c-style null-terminated strings. Variables cannot contain @ escapes; the symbol is interpreted as a literal at sign.

Operation

The program starts at the top line, and moves down. If the program is at the last line and tries to go further, the program ends.

The first string is ignored unless a jump needs to be performed.

If the fifth string is dotnet, all the remaining strings will be put as arguments to the dotnet CLI program detailed here. The second string will be piped to stdin, the stdout of the program will be passed to the variable with the name in the third string, and the stderr program similarly for the fourth string. A variable name of ]] for redirections does not redirect.

If the fifth string is not dotnet, including whitespace or control characters differences (ignoring null and anything afterwards), all strings will be assigned to variables named ##-index, and the variable ##-+ will be assigned the number of arguments in decimal. Then, a jump will be performed. The lines will be searched from top to bottom, evaluating each first string (which may contain variables which will be expanded, potentially allowing computed labels) until it finds one equal to the fifth string in the original line. This means strings with a first string of dotnet are not valid labels. Labels starting with ]] are used for library functions not expressible or even necessary to use this language. Library functions starting with ]]: are reserved for extensions. If the label is not found, the program randomly jumps to either the line before the original line or the line after the original line with a 50/50 chance.

Library functions

Return labels behave similarly to jumps.

Name Arguments Action
]]SET ##-6 should be a return label to jump to. ##-7 should be a string. ##-8 should be a variable name. Sets the variable to the string.
]]WRITE ##-6 should be a return label to jump to. ##-7 should be a file path, which could be relative. ##-8 should be text to write to the file. Nulls cannot be done with this, you have to use dotnet to do that, potentially compiling a C# program and running it. Writes text to the file.
]]DEL ##-6 should be a return label to jump to. ##-7 should be a file path, which could be relative; if it ends with a slash, it represents a folder. Deletes the file or folder and all subfolders and files within the folder.
]]CHANGE+LINE ##-6 should be a return label to jump to. ##-7 should be a zero-based line number in the DotNetOISC program. ##-8 should be a line to change it to. Self-modifies a line in the code. A negative line goes from the last line backwards. Setting a line to ; (which would be invalid as it has no single quotes) removes it.
]]GET+LINE ##-6 should be a return label to jump to. ##-7 should be a zero-based line number. ##-8 should be a variable name to set. Puts the contents of a line into a variable, without line continuations. A negative line goes from the last line backwards. Getting line number ]]NUM instead gets the number of lines currently in the program.
]]INSERT+LINE ##-6 should be a return label to jump to. ##-7 should be a zero-based line number. ##-8 should be a line to insert. Inserts the line into the code at the position, moving the code at the position and everything afterwards one line later in the program. A negative line goes from the last line backwards. Position ]]END appends (a prepend can be done with 0).

Examples

Hello, world!

@: Make the framework easily changeable for users of this program
   who may not have .NET 6.0 ;
'dotnet' 'junk' 'junk' 'junk' ']]SET' 'set return 1' @:
    ;'net6.0' 'framework'
@: Create the .csproj file ;
'set return 1' 'junk' 'junk' 'junk' ']]WRITE' 'write return 1' @:
    ;'hello.csproj' '@:
    ;@3CProject Sdk="Microsoft.NET.Sdk"@3E@0A@:
    ;@3CPropertyGroup@3E@0A@:
    ;@3COutputType@3EExe@3C/OutputType@3E@0A@:
    ;@3CTargetFramework@3E=framework]@3C/TargetFramework@3E@0A@:
    ;@3C/PropertyGroup@3E@0A@:
    ;@3C/Project@3E'
@: Create the .cs file ;
'write return 1' 'junk' 'junk' 'junk' ']]WRITE' 'write re@:
    ;turn 2' 'hello.cs' '@:
    ;using System;@0A@:
    ;@0A@:
    ;public class Program {@0A@:
    ;    public static void Main() {@0A@:
    ;        Console.WriteLine("Hello, world!");@0A@:
    ;    }@0A@:
    ;}'
@: Build the program into ./bin/Debug/net6.0/ 
   (may be different if you changed the 'framework' variable) ;
'write return 2' 'junk' 'junk' 'junk' 'dotnet' 'build' @:
    ;'hello.csproj'
@: Run the program ;
'dotnet' ']]' ']]' ']]' 'dotnet' './bin/Debug/=framework]/@:
    ;hello.dll'
@: Delete the files created by this program ;
'dotnet' 'junk' 'junk' 'junk' ']]DEL' 'del return 1' './bin/'
'del return 1' 'junk' 'junk' 'junk' ']]DEL' 'del return 2' @:
    ;'hello.cs'
'del return 2' 'junk' 'junk' 'junk' ']]DEL' 'end' 'hello.csproj'
@: An effective no-op statement to end the program.

   Not technically a no-op, since the 'junk' variable becomes
   the output, but since we won't use 'junk' anymore, it won't
   matter.
 
   Note that using most other commands would cause some change to
   the filesystem, and library commands won't work since they require
   a place to jump to. ;
'end' 'junk' 'junk' 'junk' 'dotnet' '--version'

Truth-machine

This program doesn't delete the files it creates since inputting 1 would never allow it to get to that point anyway.

'dotnet' 'junk' 'junk' 'junk' ']]SET' 'set return 1' @:
    ;'net6.0' 'framework'
'set return 1' 'junk' 'junk' 'junk' ']]WRITE' 'write return 1' @:
    ;'cat.csproj' '@:
    ;@3CProject Sdk="Microsoft.NET.Sdk"@3E@0A@:
    ;@3CPropertyGroup@3E@0A@:
    ;@3COutputType@3EExe@3C/OutputType@3E@0A@:
    ;@3CTargetFramework@3E=framework]@3C/TargetFramework@3E@0A@:
    ;@3C/PropertyGroup@3E@0A@:
    ;@3C/Project@3E'
'write return 1' 'junk' 'junk' 'junk' ']]WRITE' 'write return 2' @:
    ;'one.csproj' '@:
    ;@3CProject Sdk="Microsoft.NET.Sdk"@3E@0A@:
    ;@3CPropertyGroup@3E@0A@:
    ;@3COutputType@3EExe@3C/OutputType@3E@0A@:
    ;@3CTargetFramework@3E=framework]@3C/TargetFramework@3E@0A@:
    ;@3C/PropertyGroup@3E@0A@:
    ;@3C/Project@3E'
'write return 2' 'junk' 'junk' 'junk' ']]WRITE' 'write return 3' @:
    ;'zero.csproj' '@:
    ;@3CProject Sdk="Microsoft.NET.Sdk"@3E@0A@:
    ;@3CPropertyGroup@3E@0A@:
    ;@3COutputType@3EExe@3C/OutputType@3E@0A@:
    ;@3CTargetFramework@3E=framework]@3C/TargetFramework@3E@0A@:
    ;@3C/PropertyGroup@3E@0A@:
    ;@3C/Project@3E'
'write return 3' 'junk' 'junk' 'junk' ']]WRITE' 'write return 4' @:
    ;'cat.cs' '@:
    ;public class Cat {@0A@:
    ;    public static void Main() {@0A@:
    ;        string input = System.Console.ReadLine();@0A@:
    ;        System.Console.Write(input @3D@3D@:
    ,           ; "1" ? "1" : "0");@0A@:
    ;    }@0A@:
    ;}'
'write return 4' 'junk' 'junk' 'junk' ']]WRITE' 'write return 5' @:
    ;'zero.cs' '@:
    ;public class Zero {@0A@:
    ;    public static void Main() {@0A@:
    ;        System.Console.Write(0);@0A@:
    ;    }@0A@:
    ;}'
'write return 5' 'junk' 'junk' 'junk' ']]WRITE' 'write return 6' @:
    ;'one.cs' '@:
    ;public class One {@0A@:
    ;    public static void Main() {@0A@:
    ;        System.Console.Write(1);@0A@:
    ;    }@0A@:
    ;}'
'write return 6' 'junk' 'junk' 'junk' 'dotnet' 'build' 'cat.csproj'
'dotnet'         'junk' 'junk' 'junk' 'dotnet' 'build' 'one.csproj'
'dotnet'         'junk' 'junk' 'junk' 'dotnet' 'build' 'zero.csproj'
'dotnet' ']]' 'truth' 'junk' 'dotnet' './bin/Debug/=framework]/cat.dll'
'dotnet' 'junk' 'junk' 'junk' '=truth]'
'0' ']]' ']]' ']]' 'dotnet' './bin/Debug/=framework]/zero.dll'
'dotnet' 'junk' 'junk' 'junk' 'end'
'1' ']]' ']]' ']]' 'dotnet' './bin/Debug/=framework]/one.dll'
'dotnet' ']]' ']]' ']]' '1'
'end' 'junk' 'junk' 'junk' 'dotnet' '--version'