Walkson
Walkson is a stack based 1 dimensional programming language meant as a easy as possible to implement scripting language with a unique architecture to completely forego needing a parser. It was invented and implemented by User:Uff20xd. See here
Concepts
Walkson is meant to be a fully usable and readable c-like language that abuses stacks where they shouldnt be to be implementable without needing a pesky parser to handle Context. To achieve this the language has 3 Stacks:
- The Primary Stack
- The Name Stack
- The Type Stack
Every non keyword token is put onto one of these stacks and pop them based on the keyword.
Instructions
The instruction type looks like this:
struct Instruction {
origin_file: &Path,
line: usize,
pos: usize,
instruction_type: InstructionType
}
where InstructionType is a tagged union (or in rusts case enum) which contains token etc.
Full List of Instructions
PushString String
- Pushes a string literal to the primary stack
PushInt Integer
- Pushes an integer literal to the primary stack
PushFloat Float
- Pushes a floating point number to the primary stack
PushName String
- Pushes a string to the name stack
PushType String
- Pushes a refrence to a type to the type stack
Execution
Instruction can be executed one by one in a for loop, since it currently uses only recursion for loops, meaning the state is only the three stacks, the variables, the types, the functions, the function mode bool, and the if mode bool (could potentially both be replaced by an instruction buffer and an instruction pointer + navigation instructions).
Configuration
The Language is configured in itself, as its behaviour can be changed for ease of use.
The most important Settings are:
- auto_name_to_type, which pushes names that corespond to a type to the typestack automatically (pretty important for good typechecking tbh)
- auto_type_bottom, which lets the bottom of the type_stack act like a primary type coresponding to the primary stack value.
Examples
These Examples have both important settings enabled, because they're pretty helpful.
Hello, World!
A simple Hello World Program:
"Hello World" print
Cat
Takes a filename from stdin, reads the file and prints it.
// gets stdin and calls String.split $stdin get String.split call // creates a buffer of strings as a variable stdin let // indexes into the first element, to put it onto the stack stdin 0 index // reads and prints it read print
Truth Machine
Takes a number from stdin and if its 0 it prints 0 and exits else it'll print one indefinitely.
$stdin get String.split call
stdin let
stdin 1 index
String.parse_int call
pop
loop_1 0 None fn
1 print
loop_1 call
;
2 else
loop_1 call