• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

vrJASS

Status
Not open for further replies.
Level 10
Joined
Sep 19, 2011
Messages
527
Beginning with generics ^^:

JASS:
struct List<E>
	
	E array elements
	integer count
	
	public method add takes E element
		set this.elements[this.count] = element
		set this.count += 1
	end
	
	static method onInit
		local List<integer> li = cast 1 to List
		call li.add(42)
		call li.add(24)
		call li.add("1") // CompileException: Element <element> must have/return a value of type <integer> but given <string>
	end
	
end
 
Level 13
Joined
Nov 7, 2014
Messages
571
// CompileException: Element <element> must have/return a value of type <integer> but given <string>

This error message seems horrible... =)
"CompileException", seriously? Seriously!?
What the hell is "Element <element>", did you meant argument?

Instead, maybe you could point to the argument with the '^' thingy and say something like: "mismatched types, expected <integer> found/got <string>",
or "incorrect signature: method add(<integer>) called with add(<string>)


Implemented modulo: 2 % 1 -> ModuloReal(2,1)

Shouldn't that be ModuloInteger instead?

Also, using '%', is confusing, does it mean 'rem'/remainder or 'mod'/modulo?

Regardless, you can save the function call and inline it:

integer A = 3
integer B = 2
integer result

A rem B =>
JASS:
set result = A - trunc_0(A, B) * B
// trunct_0 => A / B (i.e integer division in Jass),
// integer division truncated towards 0

A mod B =>
JASS:
set result = A - floor_div(A, B) * B

// integer division truncated towards -∞
function floor_div takes integer A, integer B returns integer
    local real r = I2R(A) / I2R(B)
    local integer i = R2I(r)

    if r >= i then
        return i
    endif
    return i - 1 // if r < 0 then
endfunction

Note that if A and B > 0 and A < B then you don't have to compute anything, i.e result = A =)
 
Level 10
Joined
Sep 19, 2011
Messages
527
This error message seems horrible... =)
"CompileException", seriously? Seriously!?
What the hell is "Element <element>", did you meant argument?

Instead, maybe you could point to the argument with the '^' thingy and say something like: "mismatched types, expected <integer> found/got <string>",
or "incorrect signature: method add(<integer>) called with add(<string>)

Agree, some of the error messages are a little confusing (specially regarding to params/args). Will work on this after I finish the generics feature.
Element <element>... the last element refers to the name of the param.
"CompileException" doesn't appear.

Shouldn't that be ModuloInteger instead?

Also, using '%', is confusing, does it mean 'rem'/remainder or 'mod'/modulo?

Thought it as well, but isn't the same?
About using '%', dunno, I mean I have seen this same operand for a lot of languages. What would you suggest instead?.

Regardless, you can save the function call and inline it:

Yep, but right now I'm not into optimization (leaving this for later).
 
Level 13
Joined
Nov 7, 2014
Messages
571
After the param/args error message improvement I think I should jump into textmacros, what do you say?.

Aren't textmacros poor man's generics?

JASS:
function min<T extends ComparableOrSomething> takes T a, T b returns T
    if a < b then
        return a
    endif
    return b
endfuncion

// vs

//! textmacro FUNC_MIN takes T
function min_$T$ takes $T$ a, $T$ b returns $T$
    if a < b then
        return a
    endif
    return b
endfunction
//! endtextmacro
//! runtextmacro FUNC_MIN("integer")
//! runtextmacro FUNC_MIN("real")



function use_min takes nothing returns nothing
    local integer i = min(1, 2)
    // => local integer i = min_integer(1, 2)

    local real r = min(6.28, 3.14)
    // => local real r = min_real(6.28, 3.14)

    local integer i2 = min(6.28, 2)
    // => mismatched types: expected <integer> got <real>

    local real r2 = min(6.28, 2)
    // => mismatched types: expected <real> got <integer>
endfunction

// vs

function use_min takes nothing returns nothing
    // local integer i = min(1, 2) // function not found, duh... =)
    local integer i = min_integer(1, 2)
    local real r = min_real(6.28, 3.14)
endfunction

Although, the compiler must know what "Comparable" is... it could be an interface or just
compiler magic for integer/reals =).


Now what would a generic save/load/has/remove functions look like for wrapping the hashtable/gamecache
natives look like? I don't know... I guess they could just be overloaded functions, maybe?
 
Level 10
Joined
Sep 19, 2011
Messages
527
I was actually thinking more of like a C define rather than what we currently have in vJASS.
Overload functions, could be interesting to implement ^^, but after macros.

EDIT: Thanks Aniki, changed the error message for args/params to "Mismatched type, expected <X> but found <Y>"
 
Last edited:
Level 10
Joined
Sep 19, 2011
Messages
527
Sorry, I forgot about method operators, I'm going to continue with that.

Quick but important announcement: There will be no method operator for raw names & the method keyword wont be used when declaring an operator:

JASS:
struct foo

    public method operator bar ... // vjass operator declaration, invalid
    end

    public operator [] takes integer index ... // valid, notice only operator keyword (no method)
    end

end

As you can see, raw names ("bar") wont be supported, since it isn't an operator and because you will have to check if a member is a property or an operator (doesn't make any sense).
 
Last edited:

Deleted member 219079

D

Deleted member 219079

I hope you keep working on this, here's my suggestions if you ever feel like not knowing what to work on next:

Could the syntax be more vJASS - permissive? So vrJASSers would have a gargantuan vJASS library from the very start. Also on the OP you state "vrJASS is An update to vJASS".
How's the inlining? With inline functions, you could actually pass by reference in JASS :D
Also, can you have an assignment expression returning the left operand? Would also be awesome.
Also comma that makes only the result of last operand considered would be amazing! (For if ... else if(dostuff,consider) ... else ...)
 
Level 10
Joined
Sep 19, 2011
Messages
527
I don't know really, not that many people seem to be interested in writing for W3 (that is one of the reasons I haven't contributed to Wurst @Cokemonkey11).

Although developing a compiler is really fun (got a lot of challenges) I have been thinking that perhaps, it would be really cool if you could write the vrJASS compiler in, wait for it... vrJASS. Kinda like C compiles C, well but for W3. I know that probably no body is going to contribute but man, compilers are fun (at least to me).

EDIT: Just letting you know, with this, you could write real programs with vrJASS.
 
Last edited:

Deleted member 219079

D

Deleted member 219079

Maybe the use of debugger makes the developing more pleasant?

Just recently got into Visual Studio and C++, VS lacks in text editing functionality (no horizontal scroll wtf kys devs) and is Windows - exclusive, but oh my god the debugging is amazing. You can halt the program in a break point, modify the code and apply the modification to the ongoing program. Also you can inspect variables in debugging mode (you don't need a debugger for that I know, but it's easier in debugger).

I dunno what options there are out there for Java, but I guess having anything at all makes a difference.
 

Deleted member 219079

D

Deleted member 219079

I'm double posting but whatever

I'm starting another project so it is now or ever if I'm to change syntax from vJASS.

It seems like there's no error window appearing when an error occurs. I know that it runs, because the map compiles. It would be one-line addition to the wehack.lua ("execprocess(notepad vrjass.txt)") but seems like you return 0 always, so the log file always appears..

Am I doing something wrong here
 
Level 10
Joined
Sep 19, 2011
Messages
527
Hi jondrean, in the latest version the log text won't open on error (we're working with @moyackx to get better integration on JNGP).

You're right, I'm always returning 0, gonna fix this. Thanks for letting me know ^^.

EDIT: Fixed now the compiler will return:

- 1 if compile error
- 2 if jmpq error
- 3 if io (couldn't find the file for example) error
- 4 other
 
Last edited:

Deleted member 219079

D

Deleted member 219079

I am by no means Java professional, I've done it for like, 10 minutes, but at least in C you have to close file to actually update its contents. I'm not getting input for vrjass.txt, could it be because you don't do logWriter.close(); before System.exit(...); ?
 
Level 10
Joined
Sep 19, 2011
Messages
527
I'm gonna be rewriting generics and method/function overwriting since right now, the implementation is really poor and fragile. Gonna add support for key,value generics as well (ex: Foo<integer, string>).

EDIT: Also, I would like to know if you guys would like the extend type feature. Ex:

JASS:
function integer.minutes returns integer
    return this * 60
end

// Use it
4.minutes

I'm proposing it because I have been using it in Ruby and it is really great to have something like this (Wurst also has it).
 
Last edited:

Deleted member 219079

D

Deleted member 219079

That extension thing looks cool. More suggestions:

Structs were one feature that I really wanted to improve. They work pretty similar as they do in vJASS, but do keep in mind that they use Hashtable instead of arrays (you can avoid this by using static).
Hmm, could you reconsider this?

So you already have abstract structs, what about final? I mean non-extendable.

Also I'd really much like to see textmacros implemented.

You say modules are deprecated in favor of abstract structs, but abstract structs connect its children together which might be unwanted behavior.

Also if you add modules, what about extending modules?

Example code with all of what I suggested (just another Table):
JASS:
// (...)

module TableMod
end

//! textmacro TABLE_OP takes TYPE, TABLEALIAS
    public final abstract struct $TYPE$Struct
        public method operator [] takes integer i returns $TYPE$
            return Load$TABLEALIAS$(TABLE_GLOBAL, this, i)
        end
        public method operator []= takes integer i, $TYPE$ t
            call Save$TABLEALIAS$(TABLE_GLOBAL, this, i, t)
        end
    end

    module TableMod$TYPE$ extends TableMod
        public method operator $TYPE$ returns $TYPE$Struct
            return this
        end
    end
//! endtextmacro

//! runtextmacro TABLE_OP ("unit", "UnitHandle")
//! runtextmacro TABLE_OP ("integer", "Integer")
//! runtextmacro TABLE_OP ("real", "Real")
//! runtextmacro TABLE_OP ("player", "PlayerHandle")
// (...)

public final struct Table
 
    implement TableMod
 
    // (...)
 
end
 
Last edited by a moderator:

Deleted member 219079

D

Deleted member 219079

Wut? Generics are already there mate.
 
Level 10
Joined
Sep 19, 2011
Messages
527
Hmm, could you reconsider this?
Yes, I was going to use arrays for extends array

So you already have abstract structs, what about final? I mean non-extendable.
I don't know if it is going to be a very useful feature.

Also I'd really much like to see textmacros implemented.
I was thinking more of a define feature (like in C or cJASS) (you could use them as hooks).

You say modules are deprecated in favor of abstract structs, but abstract structs connect its children together which might be unwanted behavior.

Also if you add modules, what about extending modules?
Perhaps I'd implement them just to provide compatibility to vJASS (although many use them just for the initialization stuff : \).
 

Deleted member 219079

D

Deleted member 219079

Generics are a class. C-like define is also cool.
 
Level 10
Joined
Sep 19, 2011
Messages
527
Just to let you guys know, I'm writing a clone of vJASS (in just a couple of hours I got something working ^^). For the moment, just that.

JASS:
function foo takes nothing returns foo
    local boolean b = true or 1 or "s"
endfunction

Throws:

Code:
Reference phase errors:
[2:35 - "s" is not a boolean expression
 2:30 - 1 is not a boolean expression
 1:35 - foo is not a valid type]
 
Last edited:
Level 10
Joined
Sep 19, 2011
Messages
527
dHtQNgW.png


The feedback will appear as you type WITHOUT any freeze.
 
Level 10
Joined
Sep 19, 2011
Messages
527
This is just awesome. The compiler is extremely fast, specially to answer requests (for example, what are the suggestions here?, or, what types do I have?).

I'm gonna keep working on it, in the meantime:

YTLB0dU.png


Yes, it is going to have easter eggs /m/ (I'm accepting suggestions!, let me know what secrets should I hide in the compiler - edit: only warcraft 3 related, obviously).
 

Deleted member 219079

D

Deleted member 219079

Do you have source code for that IDE extension uploaded somewhere?
 
Level 10
Joined
Sep 19, 2011
Messages
527
I haven't upload it yet since it is a mess (short, but a mess). The heavy lift is performed by the compiler (check the server package), the text editor extension only feeds the stdin with the code being written and asks questions (for example, do I have an error in this portion of the code?).

GitHub - Ruk33/vrJASS2

Edit: Since all the job is being done by the compiler, creating text editors extensions wont be hard (just ask questions through the stdin, listen the response and you are done ^^).
 
Last edited:

Deleted member 219079

D

Deleted member 219079

This is pleasant news. I'm interested in how you concluded my suggestions. Namely the one regarding the hash table for structs (scary results).

And I'm still interested in the code of IDE extension but I understand if you still want to keep it private.
 

Deleted member 219079

D

Deleted member 219079

That the fps is halved every time you use hash table native.
 

Deleted member 219079

D

Deleted member 219079

Oh I thought you were joking. I used [url=...]...[/url] BB code which was valid in Hive 1.0, XenForo is just a drag T.T

Here's the link again: Hashtable vs array

So basically the execution time for 5000 hash table native calls and 5000 array accesses were tested and the former was ~9.5x that of the latter one.

---------

What would be cool is a struct qualifier, e.g. long as in long struct MyStruct, which would enable the hash table storage.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Your url was correct also before. I know you are talking about the speed difference. Perspective is important in life. You need more of it.

I do agree that if an implementation for both ways already exists, it should be selectable, if only for the special snowflakes that can't think practically (but definitely not called "long", how is that related to anything other than integers?)
 

Deleted member 219079

D

Deleted member 219079

My first suggestion was big but then I remembered long int so I came up with long struct :D So in the end, long struct makes more sense than what I first had. Feel free to suggest your own if you got something better.
 
Level 10
Joined
Sep 19, 2011
Messages
527
I will use both, arrays and hashtables. Arrays when the struct has no array properties and no extends.

Regarding to the source code of the plugin for the text editor... right now I have a really poor conection but I will do my best to upload it as it is (later I will add some comments, clean, etc.).
 
Level 10
Joined
Sep 19, 2011
Messages
527
Ok today I finally pushed to the repository all the changes that I have been doing to vrJASS2. So far, I really like the new structure (again), it makes a lot more sense and it has been a pleasure to work with.

Some things worth mentioning:
- Structs will be translated using only arrays (for the moment, although I have been thinking about it and perhaps using Hashtables isn't necessary)
- The compatibility with vJASS must be a 100%
- The url of the repo is GitHub - Ruk33/vrJASS2
- I'm trying to keep things simple in the compiler (not over engineering it, avoid premature abstraction, etc.) so anyone can understand it

For the moment that's it. I will continue working on it, any news I will let you guys know ^^.
 
Status
Not open for further replies.
Top