Giter VIP home page Giter VIP logo

bike's Introduction

Interpreted language built on .NET/Mono

  • Dynamic and strong typing
  • Everything is an (expando) object
  • Prototypal inheritance
  • First-class functions
  • CLR interoperability
  • Cross-platform (Windows, OSX, Linux)

Examples

Fibonacci

func fib( n ) {
    n <= 2 ? n: fib( n - 1 ) + fib( n - 2 )
}
print( "n: " );
var n = readln();
println( fib( n.to_number() ) );
read();

Memoize

func memoize(f) {
  var cache = {
    member_missing: func() { null }
  };
  return func recur(n) {
    cache[n] || (cache[n] = f(recur, n));
  };
}
var m_fib = memoize(func(recur, n) {
  n < 2 ? 1 : recur(n-1) + recur(n-2);
});

Curry

Bike.Function.curry = func( *args ) {
	if ( args == null || args.size() == 0 ) return this;
	var me = this;
	return func( *more ) {
		if ( more != null )  
			args.add_all( more );
		me.call( this, *args );
	};
};
func add( a, b ) { a + b }
var addTo2 = add.curry( 2 );
println( addTo2( 3 ) );

Missing

obj = {
  member_missing: func(name) {
    if (name == "add") {
      return func(a, b) { a + b };
    } 
  }
};
println(obj.add(1, 2));

WinForms

load 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a';
load 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089';
var btn = System.Windows.Forms.Button();
btn.Text = "Click count: 0";
btn.Size = System.Drawing.Size( 100, 30 );
var count = 0;
btn.Click += func() {
	this.Text = "Click count: {0}".with( ++count );
};
var form = System.Windows.Forms.Form();
form.Text = "My Dialog Box";
form.Controls.Add( btn );
form.ShowDialog();

GTK

load 'gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f';
Gtk.Application.Init();
var lblHello = Gtk.Label();
var btnHello = Gtk.Button("Hello");
var count = 0;
btnHello.Clicked += func() {
	lblHello.Text = "Hello World ({0} {1})".with(
		++count, "time" + (count == 1 ? "" : "s"));
};
var btnQuit = Gtk.Button("Quit");
btnQuit.Clicked += func() {
	Gtk.Application.Quit();
};
var box = Gtk.VBox(false, 10);
box.PackStart(btnHello, true, true, 0);
box.PackStart(lblHello, true, true, 0);
box.PackStart(btnQuit, true, true, 0);
var win = Gtk.Window("Hello World");
win.DeleteEvent += func() {
	Gtk.Application.Quit();
};
win.Add(box);
win.Resize(300, 200);
win.ShowAll();
Gtk.Application.Run();

Run Bike

I don’t update the Mac OSX and Windows installers frequently, except for major releases. So to access latest features, you should follow these steps:

  • Fork or download code
  • Build (with VS.NET or MonoDevelop, if you’re on Mac OSX)
  • If you use Windows, run
    [code_folder]/src/Bike.Console/bin/Debug/bike.exe" -h="[code_folder]" bike_file.bk
  • If you use Mac OSX, run
    /usr/bin/mono "[code_folder]/src/Bike.Console/bin/Debug/bike.exe" -h="[code_folder]" bike_file.bk

Notes:
- You should configure NotePad++, TextMate or whatever code editor to run bike based on the above commands
- NotePad++ users can use this file to enable syntax highlighting (View > User-Defined Dialog > Import)
- I will upload a TextMate bundle later

Install Bike on Mac OSX

  • Prerequisite: Mono 2.10.2 (not tested yet with earlier versions)
  • Download bike.pkg in installers/osx
  • Run bike.pkg to install Bike
  • Open the Terminal and type the followings
    cat > hello.bk
    println('Hello World');
    Ctrl-D
    bike.sh hello.bk

Notes:
- If you didn’t install Mono or Bike to their default folders, modify /usr/local/bin/bike.sh to use correct paths
- If you want to double-click to execute a Bike file in Finder, associate the .bk extension to Applications/bike/bin/bike.app

Install Bike on Windows

  • Prerequisite: .NET 4.0
  • Download bike.exe in installers/win
  • Run bike.exe to extract and install Bike
  • Create a file named hello.bk with this content
    println('Hello World');
  • In the cmd, type bike hello.bk to execute it. Alternatively, you can double-click a Bike file in Windows Explorer.

The setup program also makes the following changes to your system:
- BIKE_HOME env variable pointing to the installation folder
- Append [installation_folder]bin/ to PATH env variable
- Associate .bk extension with bike.exe

Bike folder structure

In OSX, Bike is installed to Applications/bike. In Windows, Bike is installed to Program Files/bike. The structure of the Bike folder is as follows:

  • bin: binaries and dependencies and
    • bike.app (OSX only): the app you can used to associate with .bk files so that they are executable via Finder
    • bike.action (OSX only): the Automator action code used to create bike.app, feel free to customize
    • bike.sh (OSX only): the shell script used to run Bike (the same file also exists in /usr/local/bin)
  • lib
    • src
      • core: Library source code
      • test: Test for library
      • tools: Bike doc and unit tools
    • doc: API documentation
  • samples: Sample programs, most notable is spec.bk
  • resources (Windows only)
    • np.xml: Syntax highlighting file for NotePad++ (in NotePad++, select View > User-Defined Dialog > Import)
  • LICENSE

What’s next?

  • Want to learn more about Bike? Take a look at sample code in samples. The file spec.bk should give you a good overview.
  • Want to contribute? There are many things you can do to help:
    • Implement features (see Issues tab)
    • Suggest new features
    • Report or fix bugs
    • Document code or features
    • Add unit test cases

Contact

bike's People

Contributors

buunguyen avatar duylam 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bike's Issues

[Bug] seem to be interpreter bug

var ticks = 9000000;
var day = 10 , month = 10, year = 1000;
try {
var net_dt = System.DateTime( 9000000 );
println( 'done 1' );
var net_dt2 = System.DateTime( year, month, day ); # run time error, expect no error
println( 'done 2' );
} rescue e {
println( 'error' );
println( e.cause );
}

The error log

done 1
error
System.InvalidCastException: Specified cast is not valid.
at Bike.Interpreter.Interpreter.TypeCompatibilityRule.Convert(Type targetType, Object owner, Object& value)
at Bike.Interpreter.Interpreter.TryConvert(Type targetType, Object owner, Object& value)
at Fasterflect.TryInvokeWithValuesExtensions.TryCall(ParameterConverter converter, IEnumerable1 methodBases, Object obj, Object[] parameterValues) at Fasterflect.TryInvokeWithValuesExtensions.TryCreateInstanceWithValues(Type type, ParameterConverter converter, BindingFlags flags, Object[] parameterValues) at Bike.Interpreter.Interpreter.<>c__DisplayClass11.<CreateInstance>b__10(Object[] innerArgs) at Bike.Interpreter.Interpreter.PerformInvocation(Object target, String funcName, Object[] args, Func2[] invokers)
at Bike.Interpreter.Interpreter.CreateInstance(Type type, Object[] args)
at Bike.Interpreter.Interpreter.AccessOneByOne(Object currentTarget, Object previousTarget, List1 suffixes) at Bike.Interpreter.Interpreter.Call(CallExpression node, IEnumerable1 suffixes)
at Bike.Interpreter.Interpreter.Walk(CallExpression node)

at Bike.Ast.CallExpression.Accept(IWalker walker)

Lib - Socket

Objects to do socket-based programming (client and server). TCP first, then UDP.

Lib - Database Support

Objects to work with DB (wrapping ADO.NET). Besides the low-level API, somethings like ActiveRecords would be nice (need the runtime to support something member_missing).

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.