Code Monkey home page Code Monkey logo

pikt's People

Contributors

iamgio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pikt's Issues

Just a comment on the project!

Hi, I'm an esoteric language enthusiast, and just wanted to say that it's the most interesting one I've seen (haven't tried it yet thought).

Have a nice day!

Problem with struct typing

As of now, a struct (StructStatement) in Pikt is transpiled to a Kotlin data class, an improved kind of class that automatically generates some useful methods.

Referring to the wiki:

Generates the following Kotlin code:

data class `3600FF`(`30FF00`: Any = 0, `FF6C00`: Any = 0)
var `72F0FF` = `3600FF`()

For simplicity, let's use human-readable names:

data class MyStruct(first: Any = 0, second: Any = 0)
var struct = MyStruct()

Kotlin has automatic typing, so struct is a MyStruct at compile time. The problem arises when Pikt's dynamic typing comes: function parameters are Any at compile time (equivalent to Object in Java). A function in Pikt looks like this when converted to Kotlin:

fun myFunc(arg: Any) {
    // body
}

So arg has little to none information at compile time, but can be used with ease thanks to Pikt's Kotlin libraries that take only Any arguments. But what libraries cannot handle is what the . does. Take this:

data class MyStruct(first: Any = 0, second: Any = 0)
var struct = MyStruct()

fun myFunc(arg: Any) {
    print(arg.first)
}

myFunc(struct)

This leads to a compile error because arg is obviously not a MyStruct, yet we want it to be.

I'm currently considering multiple options:

  1. Structs could be converted to String-Any (hash)maps, with color names as keys.
    Pros: completely dynamic, no typing issues.
    Cons: slow during execution, slightly less readable output code.
var MyStruct = mapOf("first" to 0, "second" to 0)

fun myFunc(arg: Any) {
    print(arg["first"]) // 'get' can be overridden
}

myFunc(struct)
  1. Variables could be converted/cast to their real JVM type at the beginning of every context/scope.
    Pros: fast during execution, types are known at compile time.
    Cons: verbose output code, much more prone to errors, harder to debug Pikt sources.
fun myFunc(arg: Any) {
    arg as MyStruct // Similar to an assert
    print(arg.first)
}
  1. Like 2, but manual via a specific statement that casts the type of a variable to its struct class.
    Pros: same as 2.
    Cons: a new statement to put often in Pikt sources.

  2. Fields can be accessed via reflection: Pikt's dot operator could generate a function instead of a ., for example arg.dot(first) in order to retrieve the value via reflection.
    Pros: easy to implement, no typing issues.
    Cons: reflection should be avoided when possible, inline set wouldn't work.

Accept input from stdin during interpretation

Since 9b0584f eu.iamgio.pikt.compiler.AbstractCompiler exposes the handleInput(stdin) function that allows writing to the Kotlin compiler's stdin from Pikt's CLI.

The main implementation is handled by eu.iamgio.pikt.compiler.Interpreter. It lets the user interact with the Kotlin script interpreter via Pikt's standard input.
A common scenario would be calling Pikt's readInput() function (defined in the stdlib) and expecting some input from the command line.

The issue is that, on Pikt's side, the stream keeps looking for some new input and keeps the process alive, despite being in another thread. When it's fed with a line, the stream is already closed and leads to an IOException.

The stdin is being temporarily locked again (the function call from AbstractCompiler was commented out) until a solution is found. Any kind of help would be highly appreciated.

issuedemo.mov

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.