GithubHelp home page GithubHelp logo

mfichman / jogo Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 1.0 3.96 MB

High(er) performance compiled programming language with clean, powerful syntax

License: MIT License

C++ 69.83% Go 0.02% Lua 0.03% Ruby 0.06% C 17.29% Assembly 0.28% Python 2.34% Yacc 1.71% LLVM 0.69% Vim Script 7.75%

jogo's People

Contributors

mfichman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

duzhanyuan

jogo's Issues

Add union types

Similar to Haskell data structures. For example, a union type could be:

Json::Value = Bool | Int | Float | String | Array[Json::Value] | Map[Json::Value]

A union type is a subtype of any of the types in the union. Also, any type in the union is a subtype of the union type. Thus assignments such as this are legal:

val Json::Value = true
int Int = val

If 'val' is not the requested type, nil or the default value is used. Also, the is operator should be implemented:

if val is Bool {
    bool Bool = val
}

The is operator returns true if the tag is equal to the requested type. Every union has a tag that is equal to the vtable for the requested type:

struct Union {
    Ptr _vtable;
    Ptr _refcount;
    T _val ?
};

If the Union is a primitive or value, then the value is embedded directly into _val. If Union is a reference object, Union is just a pointer to the reference object. When packing/unpacking Unions, the _vtable field is examined to determine the type. So an assignment with a Union looks like this (in C):

int Int = (val._vtable == Int__vtable) ? val_.val : 0;
string String = (val._vtable == String__vtable) ? val : 0;

Union types are reference objects.

Add asynchronous I/O

Add asynchronous I/O using coroutines. Store the overlapped I/O structures in the coroutine structure.

Copy-on-write semantics for value params

Value parameters that are modified should automatically be copied once upon entry to the function. This may interact w/ the copier, but custom copiers are not yet allowed.

sample(vec Vec3) {
    vec.x = 10
    vec.mutate()
}

Possibility: Allow immutable types to be declared:

Vec3 < immutable Value {
    x Float
    y Float
    z Float
}

Escape analysis

Perform escape analysis to determine if heap allocations can be converted into stack allocations. A pointer 'escapes' a function if it is returned or assigned to a structure that is returned or passed into a function.

Windows/Linux

Make sure tests pass on Windows and Linux. Add calling convention for Windows.

Declarations vs. assignments

Some places should have declaration semantics rather than declaration-assignment semantics. For instance, let expressions:

let a = "hello" {
    ...
}

The above should always define a new variable a. This also arises with local functions:

test() {
   ...
}

This should always declare a new function variable.

Remove refcount and vtable fields from value types

These are not necessary for value types allocated on the stack. Boxed value types can be allocated such that they do use a refcount/vtable field when allocated on the heap; this is a special case.

Also, investigate allowing value types to be used for generics, but only if Boxed. That may be a possible compromise.

Coroutine cleanup/initial destructor work

Reserve a global (or thread-local) variable to store a pointer to the current exception. Analyze to determine if a function can throw an exception:

  1. Set can_throw = false initially (true if there is a throw statement)
  2. Compute can_throw for child functions
  3. If a child can throw, set can_throw = false
  4. Use an enum: can_throw = true | false | undef

If a function can_throw, then generate an if block after the call to check if current_exception is non-null. If it is, then cleanup, and jump to the finally or catch if there is one; otherwise, return garbage to rax and leave current_exception set.

Justification for this plan (vs. a table-driven exception handling scheme like C++ has):

  • C interoperability
  • Performance during exception throw/stack unwind (GCC has to do a binary search to find EH)
  • Cost slight code performance loss from error-checking if blocks (just 1 extra instruction)

To start, do not support try/throw/catch. Just mark yield as 'can_throw', and then perform can_throw analysis and add error-checking if blocks.

Package manager

Basically, the same a Gem; needs to pull from a URL down and install in a shared directory (which one?)

Very basic starting standard library

Should include: Strings, basic IO. Enough so that folks can start using the language. This won't include collection classes because that requires generics.

Segfault with boolean expressions

For example:

ret a < b

Since short-circuiting is used to eval boolean expressions, the result of an expression that has type "bool" needs to do special processing to get the boolean value into a register. This would also cause a problem:

func(a < b)

Private methods

Make sure private methods are not callable from outside the class.

Bootstrap the compiler

This involves rewriting the compiler (lexer, parser, semantic analysis, code generation), in Apollo. The basic standard library will still be implemented in C (I don't see a portable way around this that won't be extremely painful to implement).

Move subtype analysis out of Type and Class

The subtype analysis is complicated with generics. There needs to be an 'environment', i.e., a mapping between type parameters and their values. Right now, sub-typing doesn't work for generic interfaces.

When two types are being compared, a mapping between type parameters and their bound values need to be kept for each type. Since the structural type analysis is recursive, a stack must be used.

subtype(a, b)

Refcount incorrect on returned temporaries

Returned temporaries should have a refcount of 0 if just constructed. Temporaries also need to have refcount_inc called on them; right now, this doesn't happen for temporaries.

Fix up membership operator + function call operator

There are some problems here, not all cases are covered:

obj.func() # Normal dispatch
obj.func # Value of expression is a function value
obj.value # This is a call to an accessor, e.g., value?()

func() # Dispatch on local var
func() # Call free func
func() # Dispatch on self

Create a file format for libraries

Create a file format for Apollo libraries. Most likely, this will be a folder containing the interface file (.api file) and the library for linking. The interface file needs to have entries for all classes, function prototypes, etc. so they can be loaded into a parse tree. The code does not need to be serialized.

In fact, it may be most effective to output the prototype information in plain text, and just combine all the info into one .api file for the library. That way, the parser can still be used. The type checker doesn't need to be run on the body of functions that came from a .api file, so that should be ok.

Build failing mac os x 10.6.7

I have flex @2.5.35_0, bison @2.5_0, and the latest source but i get the following error on scons build. :P
(I just followed your instructions but didn't try to fix it) what do i do next Zeus?

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/compiler/BasicBlockGenerator.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/BasicBlockGenerator.cpp
g++ -o build/compiler/BasicBlockPrinter.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/BasicBlockPrinter.cpp
g++ -o build/compiler/Environment.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Environment.cpp
g++ -o build/compiler/Feature.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Feature.cpp
g++ -o build/compiler/File.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/File.cpp
g++ -o build/compiler/Intel64CodeGenerator.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Intel64CodeGenerator.cpp
g++ -o build/compiler/LivenessAnalyzer.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/LivenessAnalyzer.cpp
g++ -o build/compiler/Location.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Location.cpp
g++ -o build/compiler/Options.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Options.cpp
g++ -o build/compiler/Parser.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Parser.cpp
g++ -o build/compiler/RegisterAllocator.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/RegisterAllocator.cpp
g++ -o build/compiler/TreePrinter.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/TreePrinter.cpp
g++ -o build/compiler/Type.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/Type.cpp
g++ -o build/compiler/TypeChecker.o -c -g -Wall -Werror -pedantic -Wno-unused -Wno-sign-compare -Ibuild/compiler -Icompiler compiler/TypeChecker.cpp
bison --defines=build/compiler/Grammar.hpp --report=all -o build/compiler/Grammar.cc compiler/Grammar.yy
compiler/Grammar.yy:53.63-74: syntax error, unexpected type, expecting string or identifier
scons: *** [build/compiler/Grammar.cc] Error 1
scons: building terminated because of errors.

Functors

Basic idea:

  • Generate vtables in the final executable only (link)
  • Put operator functions in vtable
  • Direct jump to operator function using operator dispatch
  • Autogen for some operator funcs?
JsonOutput < Functor {
    @dispatch(obj Starship)
    @dispatch(obj Asteroid)
}

Render < Functor {
    @dispatch(obj Mesh)
    @dispatch(obj Particles)
    @dispatch(obj Quads)
    @dispatch(obj Material)
    @dispatch(obj Light)
}

Enums and Constants

Add enums, which are basically implemented as a set of integers inside a class scope. For example:

CarState < Enum {
    ON
    BROKEN
    OFF
}

Another alternative syntax is:

CarState = ON | BROKEN | OFF 

Similarly, union types have a similar syntax:

JsonValue = String | Int | Float

Or:

JsonValue < Union {
    String
    Int
    Float
}

Templates

Haven't decided what to do with this yet. Probably something better than Java's templates, more along the lines of Haskell. The final version will try to avoid annoying type decls, possibly by using a special symbol to mean a generic var.

map(list List[:a], op Function[:a, :b]) :b {
    out = List[:b]
    for out in list {
        ret.append(op(out))
    }
    ret out
}

Implement Mixins

Implement mixins, for interfaces and regular types. Mixins will basically just "paste" the mixin code into the body of the class. Debatable: Should mixins inherit from "Mixin?" I think yes, to make the compiler simpler and to distinguish between usable objects and Mixins, which are not standalone.

Conflict rules: victory goes to the method defined in the Object, or to the Mixin listed first in the mixin list.

Self: self-types should be usable in Mixins, and they should be bound to the type of the Object they are mixed into.

Implementation: just copy, or perform some kind of lookup? Should multiple functions be generated, or should the vtable forward to the mixin implementation? (need to worry about instance variables -- should they even be allowed in Mixins?)

Implement advanced standard library

Basically, this includes libraries that are essential for many tasks, but not core. Most likely this will include:

  • Net: Sockets and HTTP at least
  • Regex: Regular expressions (should this be core?)
  • JSON: Probably useful
  • XML: This will probably be a "minimal XML" implementation

Eventually there will also be 3D graphics bindings for OpenGL, and a game engine library :) but those are definitely not core.

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.