Commit Graph

154 Commits

Author SHA1 Message Date
Thakee Nathees
776ea0ab87 builtin types added.
This commit adds the builtin types to the VM's builtin classes
buffer (however no methods were added to those classes) and a super
class parameter introduced while creating a new class.
2022-04-20 15:35:33 +05:30
Thakee Nathees
4d46930d1b instance and class type cleaned
this is a part of the class implementation. In this commit classes
and instances type were completely cleaned and prepared for a new
implementation. Native class registering mechanism were fully refactored
and made it much simpler.
2022-04-20 14:40:08 +05:30
Thakee Nathees
29be68fc86 classes were removed temproarly
to implement classes properly and support methods I had to remove
the older class syntax temproarly.
2022-04-20 13:54:45 +05:30
Thakee Nathees
1f8a71fe0a dlfcn removed and minor code cleanups 2022-04-20 13:08:14 +05:30
Thakee Nathees
88c45cccac function and else if keywords are changed.
- `func` keyword has change to `function`.
- `elsif` changed to `else if`
2022-04-17 07:33:40 +05:30
Thakee Nathees
c67572d552
names buffer merged with constant pool (#202)
a buffer of classes for primitive types added to PKVM, but they'll
not be initialized in this commit.

names buffer and constant pool of a module are now merged (just like
java's constant pool).

VM's core libraries and scirpt modules are merged into a single
map name modules.

creating a new module doesn't register it automatically anymore,
you need to call pkRegisterModule(...) each time.

newModule() function refactored with a simpler interface, we're not
setting path or registering globals anymore, the caller is
responsible for that.
2022-04-17 06:47:27 +05:30
Thakee Nathees
d8d229b0fb tcc build supported.
inorder to support tcc, I need to remove some math functions that
tcc on windows doesn't support (v language is using openlibm).
This is temproarly and the math functions should be moved to it's
own math script module once the import system is refactored.

TCC build tested with the binary downloaded from --
https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27-win64-bin.zip
(download link from the https://bellard.org/tcc/ website), and this
should be added to the CI workflow.
2022-04-16 09:37:38 +05:30
Thakee Nathees
5aee9616c1 modules were moved to cli/modules
now it's easier to re-use cli modules into another hosting
application and a little python script have added to generate
native api to support native extension library.
2022-04-15 19:30:26 +05:30
Thakee Nathees
ddc8bd8197 yet another refactor.
This commit doesn't change any behavior, just moving the code
around cleaning things.
2022-04-15 09:58:02 +05:30
Thakee Nathees
b285336895 fiber stored as register variable
and the benchmark script refactored, and now it will generate an
html report
2022-04-14 08:01:16 +05:30
Thakee Nathees
8d062e38b8 closures were completely added. 2022-04-13 14:31:57 +05:30
Thakee Nathees
2e1d8d89dd lexical scoping support using upvalues 2022-04-13 09:20:56 +05:30
Thakee Nathees
e0852139b9 exprName re-defined
The exprName function re-defined into a cleanner way, and now it's
possible to override builtin functions, this will come in handy
to introduce upvalues.
2022-04-13 08:40:37 +05:30
Thakee Nathees
227be9aab5 local variable miss-calculation bug fix
for nested functions the count of locals and the required stack size
are miss-calculated, ie. No new count wasn't started for inner functions
it makes the required stack size greater than or equal to it's enclosing
functions stack size.
2022-04-12 16:29:20 +05:30
Thakee Nathees
3feb9ac723 functions are replaced with clsoures
Every occurrence of function as first classes citizen is replaced
with closures yet upvalues are still to do.
2022-04-12 07:28:33 +05:30
Thakee Nathees
20b99c60b3 script renamed to modules
The name script is missleading as it only refering to the scripts
(the files that contain the statements) where as it could also
be the native module objects containing collection of native
functions.

After this commit, native functions can also have set owner module
and it won't be as confusing as before.
2022-04-11 14:08:00 +05:30
Thakee Nathees
8c039b5d77 fn, cls moved to constants buffer
functions and classes are moved to constant buffer, and forward
names are resolved for globals.
2022-04-11 00:02:21 +05:30
Thakee Nathees
05a516d47d literals renamed to constants
Since the functions and classes will be moved to the constants buffer
rather than having their own (function buffer and class buffer) the
rename is essential, and to make the refactoring process easier all the
intermediate steps are done with its own pr.
2022-04-10 06:11:50 +05:30
Thakee Nathees
9dade8313f closure, upvalue type were added.
It's just the types that were added and only object creation
and garbage collection of that types are implemented, the
reset of the implementation is not part of this commit.
2022-04-09 00:40:50 +05:30
Thakee Nathees
c1d36c666c debug dump are now directly prints to stdout 2022-04-07 23:09:30 +05:30
Thakee Nathees
c89db94256 parsing context are moved to struct Parser 2022-04-07 08:58:51 +05:30
Thakee Nathees
9b7ad74a7c pk_var changed to pk_value and some minor changes 2022-04-07 06:13:29 +05:30
Thakee Nathees
dfd1c5a612 false positive assertion crash -- fixed 2022-04-06 19:08:07 +05:30
Thakee Nathees
2bc09f41e5 Stack miss calculation bug fix & minor changes 2022-04-06 08:56:51 +05:30
Thakee Nathees
967cf3a0ed name interpolation implemented
The below is a valid syntax:
  name = "World"
  print("Hello $name!")
2022-04-05 10:22:23 +05:30
Thakee Nathees
0d87403f6b string interpolation implemented (1/2)
expression interpolation have implemented (ie. "a${b}c")
name interpolation yet to do (ie. "a $b c")
2022-04-05 08:27:46 +05:30
Thakee Nathees
168edb5e4c
tco last call check were changed to a cleaner method (#177) 2022-04-04 20:37:29 +05:30
Thakee Nathees
cda9cc75ca
un used functions were removed (#174)
In addition tail call is not enabled for functions that
doesn't return the last call (caused a bug).
2022-04-03 21:03:12 +05:30
Thakee Nathees
5e67403a9d
Compile time stack size wrong calculation fixed. (#173)
* and / or logic refactored

* and / or opcodes added and stack size bug fixed

- and / or keywords were added.
- class construction function not poping the class instance
  from the stack (fixed).
2022-04-03 16:59:03 +05:30
Thakee Nathees
42883eb783
copyright notice updated for 2022 (#172) 2022-04-03 00:09:57 +05:30
Thakee Nathees
f3b220106c
Function type validation was always passed - fixed (#170) 2022-03-31 22:57:53 +05:30
Thakee Nathees
6e02e021bc
some comments were added (#169) 2022-03-30 23:43:18 +05:30
Tim Gates
bcfa4de706
docs: Fix a few typos (#167)
There are small typos in:
- README.md
- cli/modules.c
- src/pk_compiler.c
- src/pk_core.c
- src/pk_opcodes.h
- src/pk_vm.h
- tests/benchmarks/benchmarks.py

Fixes:
- Should read `temporary` rather than `temproary`.
- Should read `stdout` rather than `stdour`.
- Should read `sprintf` rather than `spritnf`.
- Should read `splitted` rather than `splited`.
- Should read `script` rather than `scirpt`.
- Should read `reported` rather than `repored`.
- Should read `reduce` rather than `recude`.
- Should read `performance` rather than `preformance`.
- Should read `instead` rather than `insted`.
- Should read `default` rather than `defalt`.
2022-03-30 23:20:44 +05:30
Victor Akpan
9635c223b1
Added new Math functions (#160)
* Added log and round functions to math module

* Added log and round functions to math module

* Added a few math functions

* Static checks

* Maybe this will fix linux

* Fixed errors with styles and tests
2022-03-30 23:14:01 +05:30
Thakee Nathees
025ede86a4
Fix: Main function of native modules were NULL (#161)
This is handled and the crash were fixed
2021-07-03 21:54:36 +05:30
Thakee Nathees
c9ec704c13 repl crash after core-module refactor fixed 2021-07-03 20:46:01 +05:30
Thakee Nathees
89f8b77bb6
imported scripts were initialized (#158) 2021-07-02 21:32:30 +05:30
Thakee Nathees
3ef213b170 native api refactored (#157) 2021-07-01 14:55:53 +05:30
Thakee Nathees
6ad5dfe9f7
native api function improvements (#153) 2021-06-30 12:09:17 +05:30
Victor Akpan
b35b7a48cc
Log and Round Functions (#154)
* Added log and round functions to math module

* Added log and round functions to math module
2021-06-30 11:55:25 +05:30
Derick Alangi
f1bbafaa28
Introduce support for substring function - str_sub() (#152)
This function takes in 3 arguments: the string, the position and the
length (of the substring). As a quick example, a call to the function

`str_sub('c programming', 3, 11)`

will return the string 'programming' as the substring to the string
that is provisioned to the function call.
2021-06-29 18:18:41 +05:30
Thakee Nathees
273a31e588 native types initialization & attribute getters. (#147)
getters/setters native api functions added to the
vm's configurations and native types were initialized.
2021-06-29 00:30:41 +05:30
Jordan Ellis Coppard
794c789fca
add exit() function (#138)
* add exit() function

* add integer range function

* add pr request

squash

* add pr changes
2021-06-26 21:42:54 +05:30
Derick Alangi
e74e209b7c
Add support for hyperbolic & arc trigonometric functions (#126)
Functions added are: `sinh(x)`, `cosh(x)`, `tanh(x)`, `asin(x)`,
`acos(x)`, and `atan(x)`.

In addition, basic tests added in core.pk for these functions.
2021-06-26 18:13:29 +05:30
Derick Alangi
c1cde4c69b
Yet another fix of typos (#128) 2021-06-24 16:47:54 +05:30
Derick Alangi
273fbafa09
Add IS_NUM_BYTE validator to check if number is a byte (#127)
In conjunction with the ASCII char set, a byte should be any valid
character mapping to an integer between -128 to 127 (that is signed
integers as well).

Anything beyond can't fit into a byte hence this can't be a character
but 2 characters.
2021-06-24 16:47:30 +05:30
Thakee Nathees
beaff939bb benchmarks script refactored (#134) 2021-06-24 11:16:51 +05:30
Jordan Ellis Coppard
39c5fba9d9
add elem in map (#121) 2021-06-23 21:03:26 +05:30
Tiago Cavalcante Trindade
6d434db0cb
Add <<= and >>= operators (#119)
* Add <<= and >>=
2021-06-23 19:54:20 +05:30
Thakee Nathees
64bf27674a
in test (ie. elem in container) implemented. (#117)
in keyword will invoke varContains(), the for now the list contains
implemented.
2021-06-23 15:51:59 +05:30