Jump to content




Programming Language JaC - Compiler


49 replies to this topic

#41 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 26 November 2015 - 09:59 AM

Lambdas are coming:
var lambda = x -> x+100;
lambda(1);
And some other neat stuff:
var str = "String";
for(i=#str,1,--) {// -- : -1 | ++ : +1
   print(str:sub(i,i));
}
//or
var = 1;
i++;
print(i); //2
i--;
print(i); //1

JaC Updated!

JaC supports Lambdas! See tutorial section for more info!

Added: "i++" and "i--"

Download: pastebin get exSCtn9q JaC



#42 Awe2K

  • Members
  • 38 posts
  • LocationSomewhere near keyboard

Posted 27 November 2015 - 08:08 PM

What's about specifying when should increment/decrement be done in loop:
// Here, decrement will be performed before checking loop condition
for (i=#str,1,--i) // Or maybe something like that
Also, if I want to help, do you have an GitHub page (or maybe other way to collaborate)?

#43 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 27 November 2015 - 08:14 PM

View PostAwe2K, on 27 November 2015 - 08:08 PM, said:

What's about specifying when should increment/decrement be done in loop:
// Here, decrement will be performed before checking loop condition
for (i=#str,1,--i) // Or maybe something like that
Also, if I want to help, do you have an GitHub page (or maybe other way to collaborate)?
For loops:
for(i=#str,1,--) //Subtract by one
-
for(i=#str,1,++) //Add by one
-
for(i=#str,1,anyNumber or -anyNumber)
And GitHub, I will make one, but tomorrow.

#44 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 27 November 2015 - 10:25 PM

There is a (in my opinion) big bug that forces you to use "bad" indenting. Somehow this throws a "no colon found." error
class Main {
  public function Main(args) {
	print(args[1]);
  }
}

but this doesn't
class Main {
public function Main(args) {
  print(args[1]);
}
}

//Edit:
Also it looks like it doesn't like lines without any whitespaces at the beginning too.
class Game {
var t = false;
public function Game(test) {
t = test;
}

public function print() {
print(t);
}
}

class Main {
public function Main(args) {
var game = new Game(args[1]);
game.print();
}
}
This throws an ArrayIndexOutOfBoundsException. Is it possible that my build script is the reason?
if not fs.exists"src" then fs.makeDir"src" end
if not fs.exists"out" then fs.makeDir"out" end
local m = fs.open("out/raw.jac","w")
local function recursive(loc)
  local list = fs.list(loc)
  for k,v in pairs(list) do
    if(v ~= "main.jac") then
	  if(not fs.isDir(fs.combine(loc,v))) then
	    print("adding "..fs.combine(loc,v))
	    local h = fs.open(fs.combine(loc,v),"r")
	    for line in h.readLine do
		  if(line:sub(1,1) == " ") then
		    m.write(line:sub((line:find("%S"))))
		  else
		    m.write(line)
		  end
		  m.write("\n")
	    end
	    m.write("\n")
	    h.close()
	  else
	    recursive(fs.combine(loc,v))
	  end
    end
  end
end
recursive("src")
print("adding src/main.jac")
local h = fs.open("src/main.jac","r")
for line in h.readLine do
  if(line:sub(1,1) == " ") then
    m.write(line:sub((line:find("%S"))))
  else
    m.write(line)
  end
  m.write("\n")
end
m.close()
shell.run("jac -f out/raw.jac -o out/main.lua")
--fs.delete"out/raw.jac"
It basically takes every file inside "src" and puts them into one file which then is compiled with JaC.

Also, it seems like you messed some terms and that stuff up. Extending, for example, doesn't mean adding the class to the environment. When Class2 extends Class1, Class2 will inherit everything (methods and fields) from Class1. Also, a method isn't a namespace/package/whatever. A method "is" a function.

Now, after complaining (sorry for that); here are some ideas:
  • Add interfaces
  • Don't make "var <something>;" evaluate to "<something> = nil" because that's basically like not setting it at all.
  • Maybe static typing?
  • (not sure if that's already possible) function overloading
  • The ability to load not-compiled files at runtime (that would allow you to load plug-ins, or stuff like that, without restarting)
  • Maybe annotations (like in java)?
  • Something like Reflection maybe?

Edited by H4X0RZ, 27 November 2015 - 11:02 PM.


#45 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 28 November 2015 - 11:46 AM

View PostH4X0RZ, on 27 November 2015 - 10:25 PM, said:

There is a (in my opinion) big bug that forces you to use "bad" indenting. Somehow this throws a "no colon found." error
class Main {
  public function Main(args) {
	print(args[1]);
  }
}

but this doesn't
class Main {
public function Main(args) {
  print(args[1]);
}
}
Fixed!

View PostH4X0RZ, on 27 November 2015 - 10:25 PM, said:

//Edit:
Also it looks like it doesn't like lines without any whitespaces at the beginning too.
class Game {
var t = false;
public function Game(test) {
t = test;
}

public function print() {
print(t);
}
}

class Main {
public function Main(args) {
var game = new Game(args[1]);
game.print();
}
}
This is a bug with print, print is global so it errors because you call print within itself ex:
function print(...)
   print(...) --VM error
end

View PostH4X0RZ, on 27 November 2015 - 10:25 PM, said:

Also, it seems like you messed some terms and that stuff up. Extending, for example, doesn't mean adding the class to the environment. When Class2 extends Class1, Class2 will inherit everything (methods and fields) from Class1. Also, a method isn't a namespace/package/whatever. A method "is" a function.
Do you mean I should remove:
class Test extends TestGod {
   public function Test() {
      TestGod.print(); //This should be a normal print?
   }
}
And I will rename methods to packages then.

#46 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 28 November 2015 - 06:26 PM

(Not sure if it's just the tutorial not using it) but:
Are statics possible?
I really like the idea of making a compiler for a more advanced OOP language.

#47 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 28 November 2015 - 06:30 PM

Do you mean in this language? Like You make a language in JaC?

#48 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 28 November 2015 - 07:00 PM

View PostLeDark Lua, on 28 November 2015 - 11:46 AM, said:

Do you mean I should remove:
class Test extends TestGod {
   public function Test() {
	  TestGod.print(); //This should be a normal print?
   }
}
Umm... Not exactly. (I didn't read the whole compiler (or how a compiled program is structured) so I might be wrong sometimes)

Extending is nice and all, but it works different (atleast that's how it works in Java AFAIK):
class Human {
  var name = "";
  public function Human(n) {
    this.name = n;
  }
  public function sayHi() {
    print("Hi! My name is "..this.name);
  }
}

class ExtendedHuman extends Human {
  var age = 0;

  public function ExtendedHuman(name,age) {
    super(name); //Call the constructor of the class it extends.
    this.age = age; //Set new value not defined by Human.
  }

  public function sayHi(){
    super.sayHi(); //call .sayHi() from parent class on ExtendedHuman object. It HAS to work, because all the fields will be present thanks the inheritance.
    print("I am "..this.age.." years old."); //Add new print exclusively for ExtendedHuman.
  }
}

class Main {
  function Main(args) {
    eh = new ExtendedHuman("Deep Thought",42);
    eh.sayHi();
  }
}


#49 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 28 November 2015 - 07:13 PM

H4X0RZ I was trying to make a simpler language so thats why extending is like that

JaC Updated!

Fixed string declaration with " and '

Better error catching.

pastebin get exSCtn9q JaC


GitHub repo: here



#50 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 03 December 2015 - 03:46 PM

View PostH4X0RZ, on 27 November 2015 - 10:25 PM, said:

Now, after complaining (sorry for that); here are some ideas:
  • Add interfaces
  • Don't make "var <something>;" evaluate to "<something> = nil" because that's basically like not setting it at all.
  • Maybe static typing?
  • (not sure if that's already possible) function overloading
  • The ability to load not-compiled files at runtime (that would allow you to load plug-ins, or stuff like that, without restarting)
  • Maybe annotations (like in java)?
  • Something like Reflection maybe?
After reading this and having my mute away, I can say that I can add:
var num test = 15 || 15.5; //integers, floats, doubles, longs, ...
var string test = "Hello, world!" || 'Hello, world!'; //Strings
var table test = {}; //Tables
var Term term = new Term(); //Classes
Static typing as:
var num test = 15;
var string test = """; //Remove this line?
Ability to laod not compiled files like:
using file.jac; //or using file; | this would check files like: file, file.jac






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users