Giter Site home page Giter Site logo

ellipse0934 / cont Goto Github PK

View Code? Open in Web Editor NEW

This project forked from farkon00/cont

0.0 0.0 0.0 1.08 MB

Cont is a compiled statically-typed object oriented concatenative programming language written in Python

License: MIT License

JavaScript 3.23% Python 95.52% TypeScript 1.24%

cont's Introduction

Cont

Cont is a compiled statically-typed concatenative programming language, that has elements of OOP, is written in Python and is inspired by Porth.

Where did the name come from

From word concatinative. How have I come up with that specific word? I just mixed beginning of that word and tried to come up with something, that sounds good.

Quick Start

You can learn the language by using the "Learn cont" manual

$ python3 -V
 Python >=3.10

$ git clone https://github.com/farkon00/cont.git
$ cd cont

# Install fasm with your package manager, nodejs and wabt (https://github.com/WebAssembly/wabt) for testing wasm
$ sudo apt install fasm nodejs wabt
$ python3 -m pip install pytest
$ pytest test.py

$ python3 cont.py <source_code>.cn -r

Examples

You can find more examples in tests or examples folders or in the standard library source, which can be found in std.

Hello world

include std.cn

"Hello, world!" println

Fibonacci Numbers

include std.cn

0 print 1 print

0 1 48 
while dup 0 > do
  bind prev2 prev num:
    prev
    prev2 prev +
    dup print
    num 1 -
  end
end

Memories

Memories aren't recommended to use, because they don't have type safety in most cases you will want to use variables.

include std.cn

memory a 16 // Global memory of size 16 bytes

12 a ! // Write 12 to first 8 bytes a
a @ print // Read value of first 8 bytes of a
76 a 8 ptr+ !8 // Write 76 to 9th byte of a
a 8 ptr+ @ print // Read 8 bytes from a+8

proc local:
  memory b 8 // Local memory of size 8 bytes
  2123 b !8 // Write 2123 to first byte of b(there will be overflow)
  b @ print // Read first 8 bytes of b
end

Arrays

include std.cn

const coords_len 69 end

struct Vector2
  int x
  int y
end

init var coords [coords_len] Vector2 // Create array of Vector2 with size coodrs_len and init all of the pointers to the structure 

42 68 coords [] !.x // Write 42 into x of 69th element of array
420 12 coords [] !.x // Write 420 into x of 13th element of array
68 coords [] .x print // Read x of 69th element of array
12 coords [] .x print // Read x of 13th element of array
4 2 Vector2 23 coords *[] ! // Writes new Vector in 24th array element

Structures

Structures technically support OOP in cont. It doesn't have some really advanced features like interfaces or generics, but there is movement in that direction like dunder methods or static methods.

struct Vector2
  int x
  int y
end

struct (Vector2) Vector3
  int z
end

// If you use named procedure owner of the method will be binded to self
nproc [Vector2] 3diffy -> Vector3:
  self.x self.y 0
  Vector3
end

42 69 Vector2 .3diffy // Call a 3diffy on newly created vector
.x print // Print x field of return value of 3diffy
// Btw you can call 3diffy on Vector3

cont's People

Contributors

farkon00 avatar ellipse0934 avatar datawater avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.