Commit Graph

13 Commits

Author SHA1 Message Date
Vinícius Garcia
2cfdf11e32 Improve float built-in function 2016-07-20 23:31:24 -03:00
Vinícius Garcia
9c0097d102 Add built-in functions: str(), float() and eval() 2016-07-20 19:37:01 -03:00
Vinícius Garcia
d5870affdc Add optional name attribute to Function class 2016-07-19 22:29:40 -03:00
Vinícius Garcia
92e2bd6221 Fix print() so that it will call print(None) 2016-07-18 11:15:11 -03:00
Vinícius Garcia
ab7be02878 Prevent bug called "static initialization order fiasco"
This bug is better explained here:

 - https://isocpp.org/wiki/faq/ctors#static-init-order

Short version:

It is caused when the compiler initializes static objects in
a random order. And one of these objects depend on the initialization
of another one.

In our project the singleton class Function::Startup depends
on the TokenMap_t Scope::default_global.

It might cause no bug if we are lucky with the init order the
compiler chooses. But might cause big problems otherwise.

This commit fix this problem so we don't need to depend on lucky.
2016-07-15 22:10:42 -03:00
Vinícius Garcia
3fb964195d Move Function::default_functions to Scope::default_global
The TokenMap_t Function::default_functions was used as base
map for all Scope instances, and represented the global scope.

It is more coherent to keep it with the name default_global
and defined as a static member of Scope class.

Now any other class that needs to add something to the global
scope can just use Scope::default_global.
2016-07-15 14:51:36 -03:00
Vinícius Garcia
61f00ecfb8 Update files to satisfy Travis CI rules 2016-07-15 01:28:15 -03:00
Vinícius Garcia
726182a8ec Set Function string argument to const char* 2016-07-15 01:04:36 -03:00
Brandon Amos
21eb0d7f99 Add abs to resolve #2. 2016-07-10 08:34:03 -04:00
Vinícius Garcia
f62d717479 Add <stdexcept> to functions.cpp 2016-07-10 01:56:29 -03:00
Vinícius Garcia
80f29955f5 Fix style to conform with Travis suggestions 2016-07-10 01:30:04 -03:00
Vinícius Garcia
9ea4e26f2c Add TUPLE type and functions with multiple arguments
The function implementation is not yet complete,
there are still some caveeats for example:

- Functions with no parameters will have an untested behavior.
- If a function receive a tuple as argument it will believe it
  has received a list of parameters.
- If there are more arguments than expected the extra ones
  can not be accessed.

One case that is already handled is the case when you have
less arguments than expected. In this case the remaining
arguments will be filled with packToken::None copies.
2016-07-09 17:45:18 -03:00
Vinícius Garcia
7b7e541d43 Add builtin function support
The builtin functions are defined in the file functions.cpp
Each function receive a Scope* as argument and must return
a packToken type.

The Function class inherits from TokenBase and its constructor
receive 3 arguments:
- A function pointer with signature: packToken (*func)(Scope*)
- The number of named arguments to expect.
- A std::string* list with the arguments name.

The number of named arguments must equal the length of the
string list.

The reason for the only argument be a Scope* is because a function
should also be able to access global variables. This scope is
created so that the arguments are inserted on its most
local TokenMap_t.

After the function execution this TokenMap_t is dellocated.

Builtin functions are now automatically added in the global
TokenMap_t of all scopes by the Scope constructor.
2016-07-09 13:04:47 -03:00