CASM

From Esolang
Jump to navigation Jump to search

CASM, meaning "C assembly" and pronounced like "chasm", is a partially-esoteric programming language with literally no type system. This is not to be confused with languages like brainfuck, which only have a single type—negating the need for a type checker of any sort—or with dynamically-typed languages like Python, which still have types that just aren't bound to variables, or even with Javascript which has been called "typeless" for whatever reason.

How does THAT work?

In CASM, you don't give a variable a type. Strictly speaking, you don't even need variables, but they are provided anyway as a convenience. In CASM, you must tell the program what type to interpret values as any time you work with them—basically, you are the typechecker.

Here's an example of CASM code:

def main(){
    init i = 5;
    init f = 2.9;
    result = i[+:int,float]f;
    return 0;
}

Notice two things here:

  1. The variables are never initialized with a type. They are still initialized—using the init keyword—but are not given a type. This is because the value that the variable is assigned to is converted at compile-time to the desired binary and is at no point checked for type; the program just rolls with it.
  2. The + operation is written weirdly. Heeeeeey you might be saying, if you have a keen enough eye. "That + operation is given types! You lied to us!". You're right—the + operation was passed types; however, before you storm away because this page said "no types", consider this: What would have happened if I told it that it is being given two ints? Or two floats? Or even two pointers to strings? You could do that, of course; the program won't yell at you, that would be a type checker. It would have, of course, yielded completely different and illogical results—specifically, the result where if you treat the literal storage as the wrong type. That is the beauty of CASM—there is no type system unless you discipline it to have one.

Operator Types

CASM supports a small set of "types" that operators can be told to interpret a variable as. These types correspond, in theory, directly to what you can do on the ASM that interprets it.

Type keyword Interpretation
int A 64-bit signed integer
nat A 64-bit unsigned integer
float An IEEE double-precision floating point number
arrptr A pointer to a string

These are fairly simple types, but the operators that use them can work in wildly unexpected ways—for example, you can call a nat, which will cause the program to work like a normal function call, but it CJMPs to the line which that number targets.

The Rest

Other than what you've seen, CASM is fairly similar to C, in theory. I haven't bothered to write a spec yet, but when I do it will be published here.