Code Monkey home page Code Monkey logo

maxlang's Introduction

MAXLANG

An expression based interpreted language

Files can be evaluated, and return a result - this is a “module system”. Data types are: bool, double, string, symbol, function, list, dict

true, false, “string”, $symbol,

Functions are defined like |a b c| body

where the next term is the body of the function.

A list is defined as [1, 2, 3, 4] A dict is defined as <a: b, c: d>

Code can be grouped by two block constructs:

{} <- introduces a new scope () <- doesn’t introduce a new scope The result of these blocks is either the last value, or nil if empty Expressions are separated inside the blocks with ;

Assignment:

A value can be assigned with “let”:

let x 2, y 3, z 4 multiple assignments can be done in a let statement, with the last one being the final result

Recursive assignment, where the expression being assigned to a variable has access to that variable can be defined with letrec fac |n| n `+ (fac n `- 1)

Function call

Functions are called by a symbol, then arguments: myfun 1 2 arg3

They are curried if less than the required number of arguments is given

Functions can be called infix by prepending with `: The sum function takes two things: + 2 3 = 5 This can be made infix with: 2 `+ 3 = 5

Symbols can be imported into the current scope using extract

extract a b c d e : dict

This binds the given symbols to the corresponding values of those symbols in the dictionary

Symbols can be called to extract stuff from dictionaries

{let d {a: 2}; $a d = 2} (or, with infix: d`$a = 2 )

Conditions are done like

cond { a ~ 3; b ~ 4; else 5 }

Call order

f x y! Should mean f x (y!)

f x `* y should mean f (* x y)

f x! `* y should mean f (* (x!) y)

(f `g) `h should mean h(g(f))

Boxes

Mutable values can be stored in a box, denoted with &value @dereferences the value

Contexts

Can pass down a context to the child. This is just a dict of symbols to values. Just like parameters in scheme

start a context expression with a “with”: Takes in the dictionary argument, which it merges with the above dict

Values inside the expression (dynamically, not lexically) can access the context with ^$a, ^$b, which access values belonging to the context.

with <$a: 2, $b: 3> { cond {let x %a => x, else 3} }

s

x, ya b!

Things to do

  • [X] Modify tail calls to recursive functions use the same stack frame?? (maybe not reasonable)
  • [ ] Add in a trait system (similar to rust/elixir behaviours)
  • [X] Add in native function calls (sum and stuff)
  • [ ] Add a module system Not totally sure how to do it yet. Have static modules and computed modules. A static module is like a struct - all things have their positions at compile time. Computed modules aren’t static, so they are a little slower to access, but dynamic
  • [ ] Add in structured coroutines Maybe do this in a way similar to kotlin, run by default in a tokio thread pool. Don’t have explicit await/async, just colour functions. Async functions can only be run inside other async functions or launch {} block. Normal functions can be run anywhere.
  • [X] Update expressions so that they can be given a register to put their result into When compiling an expression, give an optional register to put the result into. This register is not managed by the expression - it’s managed by whatever called the compilation of it. It doesn’t need to do anything to this slot. (Use the Local::Reserved struct from outside for this)
  • [X] Make all frames share the same underlying buffer, each one should have an index

maxlang's People

Contributors

maxastyler avatar

Watchers

 avatar  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.