Code Monkey home page Code Monkey logo

feral's Introduction

About

Build Status

Feral is a dynamically typed, imperative, interpreted language which revolves (to most extent) around the idea of minimalism.

The primary example being that the language syntax itself does not contain anything related to imports, structure, or enums. Instead, there are libraries/functions that allow the user to import modules, and create structures as well as enums.

For feral, all imports, structures, enums, and functions are variables. This makes all of them a first class citizen. One can pass and modify all of those around in functions, etc, just like a normal variable.

Do note that Feral is not an object oriented programming language, but does support one primary construct - the dot operator.

variable.inside = 10;
let x = variable.func();

This makes the code a bit cleaner and easier to understand. See examples to understand its usage.

There is also a (WIP) book/guide for Feral available here: https://feral-lang.github.io/Book/ (source)

Examples

Hello World

let io = import('std/io');
io.println('Hello World');

Hello greeting using a function

let io = import('std/io');

let hello_fn = fn(name) {
	io.println('Hello ', name);
};

hello_fn('Electrux'); # prints 'Hello Electrux`

Simple factorial of 5 using a function

let io = import('std/io');

let facto = fn(num) {
	let fact = 1;
	for i in range(num, 1, -1) {
		fact *= i;
	}
	return fact;
};

io.println('factorial of 5 is: ', facto(5));

Creating an empty struct

let lang = import('std/lang');
let struct_t = lang.struct(); # empty structure type (struct with no fields)

Creating a struct with fields

# fields `a` and `b` of type integers having default values `10`, and `20` respectively
let lang = import('std/lang');

let struct_t = lang.struct(a = 10, b = 20);

To create objects of this structure:

# default values for struct fields
let struct_obj1 = struct_t(); # a = 10, b = 20

# overwrite first field's value (a)
let struct_obj2 = struct_t(30); # a = 30, b = 20

# overwrite using assigned argument
let struct_obj3 = struct_t(b = 30); # a = 10, b = 30

Installation

Prerequisites

To install Feral, the following packages are required:

  • CMake (build system - for compiling the project)
  • LibGMP (large integers)
  • LibMPFR (large floating point numbers)

Note: Feral doesn't yet support Windows.

Automated Build

You can automatically build Feral and its standard library by downloading and running build.sh. It requires Git and the packages listed under Prerequisites.

# Download the script (example using wget:)
wget https://raw.githubusercontent.com/Feral-Lang/Feral/master/build.sh
# Run it!
sh build.sh

Manual Build

Once the prerequisites have been met, clone this repository:

git clone https://github.com/Feral-Lang/Feral.git

Inside the repository, create a directory (say build), cd in it and run the commands for building and installing Feral:

cd Feral && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release # optionally PREFIX_DIR=<dir> can be set before this
make -j<cpu cores on your system> install

By default, PREFIX_DIR=$HOME/.feral. Once installation is done, execute the installed feral binary ($PREFIX_DIR/bin/feral) to use the Feral language.

Post Installation

After installation is done, you'd probably also like to use the feral init command to initialize the $FERAL_HOME directory, which currently is $HOME/.feral. This directory is where external packages shall be installed.

Syntax Highlighting Extensions

As of right now, there are Feral language's syntax highlighting extensions available for Visual Studio Code and Vim editors. Installation steps can be found on their repositories.

Visual Studio Code: Feral-Lang/Feral-VSCode

Vim: Feral-Lang/Feral-Vim

For Developers

The .clang-format style file is present in the repository: https://github.com/Electrux/cpp-format

Communication

Join us on Discord: https://discord.gg/zMAjSXn

feral's People

Contributors

benjaminnavarro avatar electrux avatar immaax avatar vitkarpov 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  avatar

feral's Issues

Make nearest_mult8 concise

I'd like to work on this just to dip my toes into the project.
Here is the current implementation of nearest_mult8 function โ†’

size_t nearest_mult8( size_t sz )

I'd like to shorten it to sz = (sz + 7) & ~7 and build & run tests along the way.

Possible `enum` improvements

After playing a bit with enums I can see two possible improvements:

  1. The str() function on an enumerator returns its numerical value instead of its name, which would be less confusing
  2. Numerical values different from the enum's enumerators can be assigned, leading to an inconsistent state

Examples:

let colors = lang.enum(.red, .green, .blue);
let color = colors.green;
io.println(color);       # prints 1
io.println(color.str()); # prints 1
color = 10;              # no errors
io.println(color);       # print 10, which is not a possible color

I still don't know enough about the internals of the language to know how to fix this, so I prefer create an issue

Add my installer script to README.md

Hi :)
Even though building Feral isn't too hard, I've created an installer script that builds Feral and its standard library automatically.
I thought it may be a good idea to add it to README.md as an alternative installation option, especially for people who just want to get started real quick.

Test cases for Feral Core (VM) and Standard Library

Need to make test cases for the Compiler and VM to verify their correct functioning, as well as make adding features/modifications easy to test for any breakage in existing system.

The tests must consist of the following components:

  • Nil
  • Integers
  • Floating point numbers
  • Strings
  • Modules (tests/builtin/mod.fer)
  • Language Constructs
    • Conditionals
    • Loops
      • For (tests/multi_loops.fer)
      • Foreach (tests/multi_loops_range.fer)
      • While
    • Continue (tests/multi_loops*.fer)
    • Break (tests/multi_loops*.fer)
    • Functions (tests/facto_*.fer)
    • Return (tests/facto_*.fer)

Standard Library:

  • IO
  • Vectors
  • Maps
  • FS
  • Lang
  • OS
  • Ptr
  • Runtime
  • String
  • Sys

Tests will be run using the assert function, as well as using valgrind for memory leak checks.

Also:

  • Write a Feral script to execute all the tests in one command (test runner script)
  • Add valgrind capabilities in the test runner script

Work on Book/Documentation

The following things are yet to be implemented in the Feral Book.

  • Implement more chapters
    • 7 - Loops
    • 8 - "Member" Functions
      • For
      • While
      • Foreach
    • 9 - "Member" Functions
    • 10 - Modules/Imports
    • 11 - Scopes and Variable Assignment vs Copy
    • 12 - Standard Library
      • 1 - IO
      • 2 - Lang
      • 3 - Strings
      • 4 - Vectors
      • 5 - Maps
      • 6 - FS
      • 7 - OS
      • 8 - Runtime
      • 9 - Ptr
      • 10 - Sys
      • 11 - Builder
  • Review existing chapters
  • Implement highlighting for Feral code blocks (Highlight.js)

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.