Code Monkey home page Code Monkey logo

wendy's Introduction

WendyScript

WendyScript is a dynamically typed, imperative, bytecode-compiled programming language.

WendyScript supports first class functions and closures, structure based objects, easy list manipulation, and an easy to learn syntax.

Here is the code to print a list of odd numbers from 1 to 100:

for i in 1->100 if i % 2 == 1 i

or more clearly:

for i in 1->100 {
    if (i % 2 == 1) {
        i
    }
}

In fact, you can even use the short form keywords and it becomes:

#i:1->100?i%2==1i

The syntax for WendyScript can be found at wendy.felixguo.me.

WendyScript can be compiled and run online at wendy.felixguo.me/code.

Technical implementation details can be found at the wiki.

The source can be built by simply running:

make

wendy's People

Contributors

fg123 avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

timchenggu123

wendy's Issues

Prevent lingering items in stack / stack cleanup on return

In some cases a function could leave items on the stack, messing up argument parameters, eg:

map(#:(x) x * x, sort(A))

For some reason, I think sort(A) leaves items on the stack, since map retrieves A for the first parameter instead of the lambda function.

Implement l-value construct for assigning a range of values

Code like:

let a = [1, 2, 3, 4, 5];
a[0->2] = 0; // a = [0, 0, 3, 4, 5]
a[2->5] = [10, 20, 30]; // a = [0, 0, 10, 20, 30]

List based replacement should only work with lists and not all iterables, like the list concat vs append right now.

doesn't compile on macOS

hi,
doesn't compile on macOS
the problem is the in file ast.c
line 687 enum opcode code;
error variable 'code' is used uninitialized whenever switch default is taken
what is default value ?

OOP bug

struct posn => (x, y) [print];
posn.print  =>  () 10

posn.print

Support local recursive functions

Needs better identifier tracking to push local function to own call stack (top level is fine because it will search in global namespace)

Implement Release Safe_Malloc

Release builds should still perform checking to see if the system malloc returns a valid pointer. (just no memory leak check).

Resolve / assign local variables at compile time

Since we don't have dynamic naming of variables, codegen should know the names of all the variables (global and local), and in fact, optimizer already keeps track of these for optimization purposes. We could resolve the runtime stack into a simple index based lookup which would speed up the VM considerably both in time and space. Some work might need to be done for default function values or named arguments.

Prevent double imports

like if an import has an import, imports that have dependencies on other imports (how might that work after compile?)

Imports create invalid source lines

Because importing a file by include instead of by pre-compilation will change the original source, source line tracking needs to be updated.

Implement Spread Operator

Some syntax like ...iterable would expand to the elements in the surrounding context. This is easy to implement in codegen, just push each value of the iterable to the stack, but harder to do error checking in the AST. We probably need a "settings" struct to be passed around when recursive descending to set when we should match for these types of values.

Function calling overhaul

  • Function arguments can have default values
let fun => (a = 10, b = 20) ...
  • Function argument passing can pass by name of arg
fun(a = 10, b = 20)
  • Maybe look into multiple dispatch but that's more complicated

  • Implement var-args?

  • Safer function calling mechanism to prevent overflows.

Checking function arity during compile

Prevents a runtime error when function args don't match (also prevents pulling too many arguments from the stack thus corrupting the working stack)

alternative is to implement it like javascript

Native calls should do runtime type checking

static double native_to_numeric(data* t) {
	return t->value.number;
}

static char* native_to_string(data* t) {
	return t->value.string;
}

Should throw an error if the type is not numeric or string.

Overloading Negation

Can't overload negation on literal number because negation is done in parsing. If we move it to a full operator, then we need to add negating literals to optimizer.

Add Comments to Code Generation to help debug

Code generation comments in disassembly auto added if called with --disassemble.

Compiled version can have optional comments with -c -v.
New flag -v, --verbose. Will interleave comments in byte-code.

Memory Register Stack will Overflow

Function bodies that have ret will prevent closing of frm from:

		write_opcode(OP_FRM);
		codegen_statement_list(state->op.block_statement);
		write_opcode(OP_END);

The automatic frames are automatically closed when ret but the memory register stack will not be popped the correct amount.

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.