Uxntal

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Uxntal is the programming language for the Uxn virtual machine. It is a stack-based concatenative assembly style language designed to be highly portable and lightweight. It has been ported to many platforms and is well suited for creating and sharing graphical and audio tools and games.

The reference implementation consists of 150 line of C, the assembler is self-hosted.

Terminology

  • Uxn is the name of the virtual CPU.
  • Varvara is the virtual computer system consisting of input controllers, audio and video output, and other system devices which runs on Uxn.
  • Uxntal is a human readable concatenative programming language used for assembling ROMs to run on a Uxn system.

Examples

Deadfish interpreter in Uxntal

Factorial

@factorial ( n -- res )
	DUP ?{ INC JMP2r }
	DUP #01 SUB factorial MUL JMP2r

Fizzbuzz

#6500
@fizzbuzz ( n i -- )
	#00
	OVR #03 DIVk MUL SUB ?{ INC
		LIT2 "F 18 DEO LIT2 "i 18 DEO LIT2 "z 18 DEOk DEO }
	OVR #05 DIVk MUL SUB ?{ INC
		LIT2 "B 18 DEO LIT2 "u 18 DEO LIT2 "z 18 DEOk DEO }
	?{ 
		DUP #0a DIVk #30 ADD #18 DEO
		DIVk MUL SUB #30 ADD #18 DEO }
	#0a18 DEO
	INC GTHk ?fizzbuzz
	POP2 BRK

This self-replicating program will emit its own bytecode when run:

@q ( -> )
	;&end ;q &l LDAk #18 DEO INC2 GTH2k ?&l &end

This cyclical self-replicating program will emit a program that prints ying and which emits a program like itself that will print yang, which in turn will emit a program that prints ying again, and so forth:

@y ( -> )
	[ LIT2 "y 19 ] DEO [ LIT2 &c "ai ] SWPk ,&c STR2 #19 DEO 
	[ LIT2 "n 19 ] DEO [ LIT2 "g 19 ] DEO 
	;&end ;y &w LDAk #18 DEO INC2 GTH2k ?&w &end

This quine program will emit a second program that emits its own bytecode as hexadecimal ascii characters, which is also a valid program source:

a001 32a0 0100 b460 000b a020 1817 2121 
aa20 fff2 0004 6000 0006 8004 1f60 0000 
800f 1c06 8009 0a80 271a 1880 3018 8018 
176c

This ambigram program executes the same backward or forward, every single opcode is evaluated, and prints the palindrome "tenet".

1702 a018 a002 a074 a002 0417 1702 a018
a002 a065 a002 0417 1702 a018 a002 a06e
a002 a018 a002 1717 0402 a065 a002 a018
a002 1717 0402 a074 a002 a018 a002 17

This self-replicating program produces exactly 1 copy of itself, names the copy "4", does not execute the copied file, and prints the number 4.

|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|100
	[ LIT2 13 -File/length ] DEO2
	INC [ LIT2 -&filename -File/name ] DEO2
	INC SWP .File/write DEO2
	[ LIT2 "4 18 ] DEO
	&filename "4

External resources