Commit Graph

63 Commits

Author SHA1 Message Date
Thakee Nathees
67ab2057c0 method buffer added to classes
and also allocation/de-allocation callbacks were added to newClass
function and yet registering attribute getters and setters is to do.
2022-04-20 16:41:57 +05:30
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
1f8a71fe0a dlfcn removed and minor code cleanups 2022-04-20 13:08:14 +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
andrea321123
f980e91b60
Handle Ctrl+D, Ctrl+Z properly
* Fix #105

* Check if last char is EOF
2022-04-16 15:24:55 +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
2e1d8d89dd lexical scoping support using upvalues 2022-04-13 09:20:56 +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
9b7ad74a7c pk_var changed to pk_value and some minor changes 2022-04-07 06:13:29 +05:30
Thakee Nathees
42883eb783
copyright notice updated for 2022 (#172) 2022-04-03 00:09:57 +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
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
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
Derick Alangi
44f836bf69
Fix gcc warning thrown to STDOUT about argv qualifier (#144)
Fix gcc warning 'char **' to parameter of type 'const char **' as
the library requires a 'const char**' instead of 'char**'.
2021-06-26 18:44:26 +05:30
Thakee Nathees
a22c4cb90d
CLI argparse implementation. (#136)
* argparse library added to third parth.

We're using argparse (https://github.com/cofyc/argparse) repo to parse
cli args.

* parsed arguments applied to the cli.

Co-authored-by: Derick Alangi <alangiderick@gmail.com>
2021-06-24 23:08:44 +05:30
Thakee Nathees
600f972927 Native types & File object implementations. 2021-06-22 13:31:21 +05:30
Thakee Nathees
41ed7dd991 class implemented 2021-06-21 12:13:37 +05:30
Thakee Nathees
258b64948e yet another minor refactor 2021-06-20 15:53:21 +05:30
Thakee Nathees
4ba3ee2e28 __file__ added and some todos were completed 2021-06-20 09:29:26 +05:30
Thakee Nathees
d0229a9744 minor refactors for internal documenting. 2021-06-17 01:05:37 +05:30
Derick Alangi
c7a6bdec49 Improve REPL to use a byte buffer with fgetc() to read line
Introduced a new function `readLine()` that utilizes the byte buffer
together with `fgetc()` to read input from the STDIN. This enables
the REPL to read characters one at a time for validation & in a
safer manner where the buffer gets to be resized if it's full.
2021-06-16 12:14:23 +01:00
Thakee Nathees
6992f54ef3 Tail call optimization implemented 2021-06-13 21:57:54 +05:30
Thakee Nathees
17df5eb1e4 disassemble implemented 2021-06-12 16:34:10 +05:30
Thakee Nathees
749456e215 some (minor) code cleanups 2021-06-11 13:16:55 +05:30
Thakee Nathees
9fdab23a94 core attributes refactored and added tests 2021-06-10 23:12:04 +05:30
Derick Alangi
3a7ffc7cf1
Cleanup more typos from cli/ source files (#50) 2021-06-10 07:53:16 +05:30
Derick Alangi
fd6d2412ee
Fix more typos in cli/common.h (#49) 2021-06-10 04:27:28 +05:30
Derick Alangi
04c333a15e
Set pointer to first byte of mem block when realloc()'d (#48)
* While reading various files in the repo, just going ahead to
clean up some typos (for clarity of text).

* When calling `realloc()`, let the pointer be returned to the
first byte of the memory block after resize. Compiler warns against
not doing this too.

* In addition, rename the file uitls.c to "utils.c" which seems to
be the correct name in this case.

NOTE: I recompiled and tested the `./pocket` intepreter and it still
works as expected.
2021-06-10 04:10:24 +05:30
Thakee Nathees
49c1fec85f
REPL implementation. (#47) 2021-06-09 16:12:26 +05:30
Derick Alangi
1a60646e38
Fix minor typos, while reading codebase (#46)
* Fix minor typos, while reading codebase

* Fix typo in common.h comment

* Fix typo in src/common.h
2021-06-08 22:19:58 +05:30
Thakee Nathees
9901d4d441 REPL refactor [3/3] 2021-06-08 19:32:43 +05:30
Thakee Nathees
fdf685731d refactor for repl support [2/3] 2021-06-07 20:00:35 +05:30
Thakee Nathees
3092118008 Merge pull request #42 from ThakeeNathees/fiber-docs
fiber documentations
2021-06-07 07:20:06 +05:30
Thakee Nathees
e1711b1c9d fiber implemented. 2021-06-06 03:10:58 +05:30
Thakee Nathees
284232c8c6 minor parser refactor for repl 2021-06-05 18:50:53 +05:30
Thakee Nathees
0bebeaafdf some style guides were enforcde.
- according to https://github.com/mcinglis/c-style
2021-06-04 13:26:50 +05:30
Thakee Nathees
f9bf0c1b9c more comments written throught out the source 2021-06-03 07:40:07 +05:30
Thakee Nathees
2c1468f0e8 Merge pull request #37 from ThakeeNathees/bug-fixes
controlflow bugs fixed
2021-06-02 19:53:04 +05:30
Thakee Nathees
0e450bc7b1 path library implemented 2021-05-30 05:46:04 +05:30
Thakee Nathees
185a71914a Iterations were heavily optimized 2021-05-27 15:38:33 +05:30
Thakee Nathees
df93b2c1ec gc bugs fixed
- popping operands from the stack was too early -fixed
- some temproary string objects weren't pushed to the vm's temp root
  -fixed
- and some minor bug fixed
2021-05-23 23:25:04 +05:30
Thakee Nathees
8738ccfe64 Native function api implemented 2021-05-23 02:29:32 +05:30
Thakee Nathees
deda294326 a small test script added 2021-05-22 18:57:40 +05:30
Thakee Nathees
994baea600 function name resolve implemented 2021-05-20 19:35:57 +05:30