Repository: NerdLang/nerd
Branch: master
Commit: 400b367708c2
Files: 1067
Total size: 13.0 MB
Directory structure:
gitextract_918hrja8/
├── .gitignore
├── LICENSE
├── README.md
├── base/
│ ├── cli/
│ │ └── cliParser.js
│ ├── compiler/
│ │ └── target.js
│ └── util/
│ ├── copyDirSync.js
│ ├── copyRecursive.js
│ ├── flash.js
│ ├── getExt.js
│ └── getTips.js
├── compiler/
│ ├── native/
│ │ ├── compiler.js
│ │ ├── env/
│ │ │ ├── arduino.js
│ │ │ ├── js.js
│ │ │ ├── std.js
│ │ │ └── wasm.js
│ │ ├── nerdcore/
│ │ │ ├── src/
│ │ │ │ ├── class/
│ │ │ │ │ ├── _meta.h
│ │ │ │ │ ├── array.h
│ │ │ │ │ ├── array_header.h
│ │ │ │ │ ├── base_header.h
│ │ │ │ │ ├── fixed_array.h
│ │ │ │ │ ├── fixed_array_header.h
│ │ │ │ │ ├── function.h
│ │ │ │ │ ├── function_header.h
│ │ │ │ │ ├── native.h
│ │ │ │ │ ├── native_header.h
│ │ │ │ │ ├── native_tpl_header.h
│ │ │ │ │ ├── number.h
│ │ │ │ │ ├── number_header.h
│ │ │ │ │ ├── object.h
│ │ │ │ │ ├── object_header.h
│ │ │ │ │ ├── string.h
│ │ │ │ │ ├── string_header.h
│ │ │ │ │ ├── struct.h
│ │ │ │ │ └── struct_header.h
│ │ │ │ ├── classes.h
│ │ │ │ ├── classes_header.h
│ │ │ │ ├── enum.h
│ │ │ │ ├── functions.h
│ │ │ │ ├── functions_header.h
│ │ │ │ ├── macro.h
│ │ │ │ ├── native/
│ │ │ │ │ ├── double.h
│ │ │ │ │ ├── double_header.h
│ │ │ │ │ ├── int.h
│ │ │ │ │ └── int_header.h
│ │ │ │ ├── native.h
│ │ │ │ ├── native_header.h
│ │ │ │ ├── nerd.cpp
│ │ │ │ ├── nerd.hpp
│ │ │ │ ├── objmgmt.h
│ │ │ │ ├── objmgmt_header.h
│ │ │ │ ├── operator.h
│ │ │ │ ├── operator_header.h
│ │ │ │ ├── stdfn.h
│ │ │ │ ├── stdfn_header.h
│ │ │ │ ├── tsl/
│ │ │ │ │ ├── robin_growth_policy.h
│ │ │ │ │ ├── robin_hash.h
│ │ │ │ │ ├── robin_map.h
│ │ │ │ │ └── robin_set.h
│ │ │ │ ├── type_header.h
│ │ │ │ ├── values.h
│ │ │ │ ├── values_header.h
│ │ │ │ ├── var.h
│ │ │ │ └── var_header.h
│ │ │ └── test/
│ │ │ ├── array.cpp
│ │ │ ├── cast.cpp
│ │ │ ├── native.cpp
│ │ │ ├── object.cpp
│ │ │ └── operators.cpp
│ │ └── squel/
│ │ ├── arduino.cpp
│ │ ├── js.cpp
│ │ ├── std.cpp
│ │ └── wasm.cpp
│ └── self/
│ ├── base/
│ │ ├── cli/
│ │ │ └── cliParser.ng
│ │ ├── compiler/
│ │ │ └── target.js
│ │ └── util/
│ │ ├── copyDirSync.js
│ │ ├── copyRecursive.js
│ │ ├── flash.js
│ │ ├── getExt.js
│ │ ├── getTips.js
│ │ ├── httpUtils.js
│ │ └── rmdir.js
│ └── nerd.ng
├── example/
│ ├── arduino-lcd.ng
│ ├── arduino.ng
│ ├── args.ng
│ ├── circular_array.ng
│ ├── circular_fixed_array.ng
│ ├── circular_object.ng
│ ├── const.ng
│ ├── date.ng
│ ├── exec.ng
│ ├── exit.ng
│ ├── fibo.ng
│ ├── fiboit.ng
│ ├── functional.ng
│ ├── hello.ng
│ ├── http.ng
│ ├── http_post.ng
│ ├── json.ng
│ ├── loop.ng
│ ├── match.ng
│ ├── native.ng
│ ├── nested_object.ng
│ ├── new.ng
│ ├── object_keys.ng
│ ├── os.ng
│ ├── path.ng
│ ├── readfile.ng
│ ├── thread.ng
│ ├── throw.ng
│ ├── wasm.html
│ └── wasm_binding.ng
├── external/
│ ├── arduino/
│ │ ├── avr/
│ │ │ ├── LICENSE.txt
│ │ │ ├── boards.txt
│ │ │ ├── bootloaders/
│ │ │ │ ├── atmega/
│ │ │ │ │ ├── ATmegaBOOT_168.c
│ │ │ │ │ ├── ATmegaBOOT_168_atmega1280.hex
│ │ │ │ │ ├── ATmegaBOOT_168_atmega328.hex
│ │ │ │ │ ├── ATmegaBOOT_168_atmega328_pro_8MHz.hex
│ │ │ │ │ ├── ATmegaBOOT_168_diecimila.hex
│ │ │ │ │ ├── ATmegaBOOT_168_ng.hex
│ │ │ │ │ ├── ATmegaBOOT_168_pro_8MHz.hex
│ │ │ │ │ └── Makefile
│ │ │ │ ├── atmega8/
│ │ │ │ │ ├── ATmegaBOOT-prod-firmware-2009-11-07.hex
│ │ │ │ │ ├── ATmegaBOOT.c
│ │ │ │ │ ├── ATmegaBOOT.hex
│ │ │ │ │ ├── ATmegaBOOT.txt
│ │ │ │ │ └── Makefile
│ │ │ │ ├── bt/
│ │ │ │ │ ├── ATmegaBOOT_168.c
│ │ │ │ │ ├── ATmegaBOOT_168.hex
│ │ │ │ │ ├── ATmegaBOOT_168_atmega328_bt.hex
│ │ │ │ │ └── Makefile
│ │ │ │ ├── caterina/
│ │ │ │ │ ├── Caterina-Circuitplay32u4.hex
│ │ │ │ │ ├── Caterina-Esplora.hex
│ │ │ │ │ ├── Caterina-Esplora.txt
│ │ │ │ │ ├── Caterina-Industrial101.hex
│ │ │ │ │ ├── Caterina-Leonardo.hex
│ │ │ │ │ ├── Caterina-Leonardo.txt
│ │ │ │ │ ├── Caterina-LeonardoEthernet.hex
│ │ │ │ │ ├── Caterina-LininoOne.hex
│ │ │ │ │ ├── Caterina-Micro.hex
│ │ │ │ │ ├── Caterina-Micro.txt
│ │ │ │ │ ├── Caterina-Yun-noblink.hex
│ │ │ │ │ ├── Caterina-Yun.hex
│ │ │ │ │ ├── Caterina-YunMini.hex
│ │ │ │ │ ├── Caterina.c
│ │ │ │ │ ├── Caterina.h
│ │ │ │ │ ├── Descriptors.c
│ │ │ │ │ ├── Descriptors.h
│ │ │ │ │ ├── Esplora-prod-firmware-2012-12-10.hex
│ │ │ │ │ ├── Esplora-prod-firmware-2012-12-10.txt
│ │ │ │ │ ├── Leonardo-prod-firmware-2012-04-26.hex
│ │ │ │ │ ├── Leonardo-prod-firmware-2012-04-26.txt
│ │ │ │ │ ├── Leonardo-prod-firmware-2012-12-10.hex
│ │ │ │ │ ├── Leonardo-prod-firmware-2012-12-10.txt
│ │ │ │ │ ├── Makefile
│ │ │ │ │ ├── Micro-prod-firmware-2012-11-23.hex
│ │ │ │ │ ├── Micro-prod-firmware-2012-11-23.txt
│ │ │ │ │ ├── Micro-prod-firmware-2012-12-10.hex
│ │ │ │ │ └── Micro-prod-firmware-2012-12-10.txt
│ │ │ │ ├── caterina-Arduino_Robot/
│ │ │ │ │ ├── Caterina-Robot-Control.hex
│ │ │ │ │ ├── Caterina-Robot-Motor.hex
│ │ │ │ │ ├── Caterina-Robot.txt
│ │ │ │ │ ├── Caterina.c
│ │ │ │ │ ├── Caterina.h
│ │ │ │ │ ├── Descriptors.c
│ │ │ │ │ ├── Descriptors.h
│ │ │ │ │ ├── Makefile
│ │ │ │ │ └── README.md
│ │ │ │ ├── caterina-LilyPadUSB/
│ │ │ │ │ ├── Caterina-LilyPadUSB.hex
│ │ │ │ │ ├── Caterina.c
│ │ │ │ │ ├── Caterina.h
│ │ │ │ │ ├── Descriptors.c
│ │ │ │ │ ├── Descriptors.h
│ │ │ │ │ ├── Makefile
│ │ │ │ │ └── Readme.txt
│ │ │ │ ├── gemma/
│ │ │ │ │ ├── README.md
│ │ │ │ │ ├── avrdude.conf
│ │ │ │ │ ├── gemma_v1.hex
│ │ │ │ │ ├── usbconfig.h
│ │ │ │ │ └── usbconfig.patch
│ │ │ │ ├── lilypad/
│ │ │ │ │ ├── LilyPadBOOT_168.hex
│ │ │ │ │ └── src/
│ │ │ │ │ ├── ATmegaBOOT.c
│ │ │ │ │ └── Makefile
│ │ │ │ ├── optiboot/
│ │ │ │ │ ├── Makefile
│ │ │ │ │ ├── README.TXT
│ │ │ │ │ ├── boot.h
│ │ │ │ │ ├── makeall
│ │ │ │ │ ├── omake
│ │ │ │ │ ├── omake.bat
│ │ │ │ │ ├── optiboot.c
│ │ │ │ │ ├── optiboot_atmega168.hex
│ │ │ │ │ ├── optiboot_atmega168.lst
│ │ │ │ │ ├── optiboot_atmega328-Mini.hex
│ │ │ │ │ ├── optiboot_atmega328.hex
│ │ │ │ │ ├── optiboot_atmega328.lst
│ │ │ │ │ ├── optiboot_atmega8.hex
│ │ │ │ │ ├── optiboot_atmega8.lst
│ │ │ │ │ ├── pin_defs.h
│ │ │ │ │ └── stk500.h
│ │ │ │ └── stk500v2/
│ │ │ │ ├── License.txt
│ │ │ │ ├── Makefile
│ │ │ │ ├── Mega2560-prod-firmware-2011-06-29.hex
│ │ │ │ ├── STK500V2.pnproj
│ │ │ │ ├── STK500V2.pnps
│ │ │ │ ├── avr_cpunames.h
│ │ │ │ ├── avrinterruptnames.h
│ │ │ │ ├── command.h
│ │ │ │ ├── stk500boot.c
│ │ │ │ ├── stk500boot.ppg
│ │ │ │ └── stk500boot_v2_mega2560.hex
│ │ │ ├── cores/
│ │ │ │ └── arduino/
│ │ │ │ ├── Arduino.h
│ │ │ │ ├── CDC.cpp
│ │ │ │ ├── Client.h
│ │ │ │ ├── HardwareSerial.cpp
│ │ │ │ ├── HardwareSerial.h
│ │ │ │ ├── HardwareSerial0.cpp
│ │ │ │ ├── HardwareSerial1.cpp
│ │ │ │ ├── HardwareSerial2.cpp
│ │ │ │ ├── HardwareSerial3.cpp
│ │ │ │ ├── HardwareSerial_private.h
│ │ │ │ ├── IPAddress.cpp
│ │ │ │ ├── IPAddress.h
│ │ │ │ ├── PluggableUSB.cpp
│ │ │ │ ├── PluggableUSB.h
│ │ │ │ ├── Print.cpp
│ │ │ │ ├── Print.h
│ │ │ │ ├── Printable.h
│ │ │ │ ├── Server.h
│ │ │ │ ├── Stream.cpp
│ │ │ │ ├── Stream.h
│ │ │ │ ├── Tone.cpp
│ │ │ │ ├── USBAPI.h
│ │ │ │ ├── USBCore.cpp
│ │ │ │ ├── USBCore.h
│ │ │ │ ├── USBDesc.h
│ │ │ │ ├── Udp.h
│ │ │ │ ├── WCharacter.h
│ │ │ │ ├── WInterrupts.c
│ │ │ │ ├── WMath.cpp
│ │ │ │ ├── WString.cpp
│ │ │ │ ├── WString.h
│ │ │ │ ├── abi.cpp
│ │ │ │ ├── binary.h
│ │ │ │ ├── hooks.c
│ │ │ │ ├── main.cpp
│ │ │ │ ├── new.cpp
│ │ │ │ ├── new.h
│ │ │ │ ├── wiring.c
│ │ │ │ ├── wiring_analog.c
│ │ │ │ ├── wiring_digital.c
│ │ │ │ ├── wiring_private.h
│ │ │ │ ├── wiring_pulse.S
│ │ │ │ ├── wiring_pulse.c
│ │ │ │ └── wiring_shift.c
│ │ │ ├── extras/
│ │ │ │ ├── pack.hourlybuild.bash
│ │ │ │ ├── pack.pullrequest.bash
│ │ │ │ ├── pack.release.bash
│ │ │ │ ├── package_index.json.Hourly.template
│ │ │ │ └── package_index.json.PR.template
│ │ │ ├── firmwares/
│ │ │ │ ├── arduinoISP/
│ │ │ │ │ └── readme.txt
│ │ │ │ ├── atmegaxxu2/
│ │ │ │ │ ├── Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex
│ │ │ │ │ ├── Arduino-COMBINED-dfu-usbserial-atmega16u2-MegaADK-Rev3.hex
│ │ │ │ │ ├── Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex
│ │ │ │ │ ├── Genuino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-R3.hex
│ │ │ │ │ ├── Genuino-COMBINED-dfu-usbserial-atmega16u2-Uno-R3.hex
│ │ │ │ │ ├── MEGA-dfu_and_usbserial_combined.hex
│ │ │ │ │ ├── README.txt
│ │ │ │ │ ├── UNO-dfu_and_usbserial_combined.hex
│ │ │ │ │ ├── arduino-usbdfu/
│ │ │ │ │ │ ├── Arduino-usbdfu.c
│ │ │ │ │ │ ├── Arduino-usbdfu.h
│ │ │ │ │ │ ├── Board/
│ │ │ │ │ │ │ └── LEDs.h
│ │ │ │ │ │ ├── Descriptors.c
│ │ │ │ │ │ ├── Descriptors.h
│ │ │ │ │ │ ├── makefile
│ │ │ │ │ │ └── readme.txt
│ │ │ │ │ └── arduino-usbserial/
│ │ │ │ │ ├── Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex
│ │ │ │ │ ├── Arduino-usbserial-atmega16u2-MegaADK-Rev3.hex
│ │ │ │ │ ├── Arduino-usbserial-atmega16u2-Uno-Rev3.hex
│ │ │ │ │ ├── Arduino-usbserial-mega.hex
│ │ │ │ │ ├── Arduino-usbserial-uno.hex
│ │ │ │ │ ├── Arduino-usbserial.c
│ │ │ │ │ ├── Arduino-usbserial.h
│ │ │ │ │ ├── Board/
│ │ │ │ │ │ └── LEDs.h
│ │ │ │ │ ├── Descriptors.c
│ │ │ │ │ ├── Descriptors.h
│ │ │ │ │ ├── Genuino-usbserial-atmega16u2-Mega2560-R3.hex
│ │ │ │ │ ├── Genuino-usbserial-atmega16u2-Uno-R3.hex
│ │ │ │ │ ├── Lib/
│ │ │ │ │ │ └── LightweightRingBuff.h
│ │ │ │ │ ├── makefile
│ │ │ │ │ └── readme.txt
│ │ │ │ └── wifishield/
│ │ │ │ ├── binary/
│ │ │ │ │ ├── wifiHD.elf
│ │ │ │ │ ├── wifiHD.hex
│ │ │ │ │ ├── wifiHD_2_1.elf
│ │ │ │ │ ├── wifi_dnld.elf
│ │ │ │ │ ├── wifi_dnld.hex
│ │ │ │ │ └── wifi_dnld_2_1.elf
│ │ │ │ ├── scripts/
│ │ │ │ │ ├── ArduinoWifiShield_upgrade.sh
│ │ │ │ │ └── ArduinoWifiShield_upgrade_mac.sh
│ │ │ │ ├── wifiHD/
│ │ │ │ │ ├── .cproject
│ │ │ │ │ ├── .project
│ │ │ │ │ ├── Release/
│ │ │ │ │ │ ├── wifiHD.elf
│ │ │ │ │ │ └── wifiHD.hex
│ │ │ │ │ ├── src/
│ │ │ │ │ │ ├── CONFIG/
│ │ │ │ │ │ │ ├── conf_access.h
│ │ │ │ │ │ │ ├── conf_at45dbx.h
│ │ │ │ │ │ │ ├── conf_ebi.h
│ │ │ │ │ │ │ └── conf_sd_mmc_spi.h
│ │ │ │ │ │ ├── SOFTWARE_FRAMEWORK/
│ │ │ │ │ │ │ ├── ASM/
│ │ │ │ │ │ │ │ └── trampoline.x
│ │ │ │ │ │ │ ├── BOARDS/
│ │ │ │ │ │ │ │ ├── ARDUINO/
│ │ │ │ │ │ │ │ │ ├── arduino.h
│ │ │ │ │ │ │ │ │ ├── led.c
│ │ │ │ │ │ │ │ │ └── led.h
│ │ │ │ │ │ │ │ ├── EVK1105/
│ │ │ │ │ │ │ │ │ ├── evk1105.h
│ │ │ │ │ │ │ │ │ ├── led.c
│ │ │ │ │ │ │ │ │ └── led.h
│ │ │ │ │ │ │ │ ├── board.h
│ │ │ │ │ │ │ │ └── board.h.my
│ │ │ │ │ │ │ ├── COMPONENTS/
│ │ │ │ │ │ │ │ ├── MEMORY/
│ │ │ │ │ │ │ │ │ └── DATA_FLASH/
│ │ │ │ │ │ │ │ │ └── AT45DBX/
│ │ │ │ │ │ │ │ │ ├── at45dbx.c
│ │ │ │ │ │ │ │ │ ├── at45dbx.h
│ │ │ │ │ │ │ │ │ ├── at45dbx_mem.c
│ │ │ │ │ │ │ │ │ └── at45dbx_mem.h
│ │ │ │ │ │ │ │ └── WIFI/
│ │ │ │ │ │ │ │ └── HD/
│ │ │ │ │ │ │ │ ├── v2.7.0/
│ │ │ │ │ │ │ │ │ ├── UCR1/
│ │ │ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ │ │ ├── lib_ucr1_hd_sdio_v2.7.0.a
│ │ │ │ │ │ │ │ │ │ ├── lib_ucr1_hd_spi_v2.7.0.a
│ │ │ │ │ │ │ │ │ │ └── lib_ucr1_hd_wl_sta_intwpa_v2.7.0.a
│ │ │ │ │ │ │ │ │ ├── UCR2/
│ │ │ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ │ │ ├── lib_ucr2_hd_sdio_v2.7.0.a
│ │ │ │ │ │ │ │ │ │ ├── lib_ucr2_hd_spi_v2.7.0.a
│ │ │ │ │ │ │ │ │ │ └── lib_ucr2_hd_wl_sta_intwpa_v2.7.0.a
│ │ │ │ │ │ │ │ │ └── revision.txt
│ │ │ │ │ │ │ │ ├── wl_api.h
│ │ │ │ │ │ │ │ ├── wl_fw.h
│ │ │ │ │ │ │ │ ├── wl_os.h
│ │ │ │ │ │ │ │ ├── wl_sdio.h
│ │ │ │ │ │ │ │ ├── wl_spi.h
│ │ │ │ │ │ │ │ └── wlap_api.h
│ │ │ │ │ │ │ ├── DRIVERS/
│ │ │ │ │ │ │ │ ├── CPU/
│ │ │ │ │ │ │ │ │ └── CYCLE_COUNTER/
│ │ │ │ │ │ │ │ │ └── cycle_counter.h
│ │ │ │ │ │ │ │ ├── EBI/
│ │ │ │ │ │ │ │ │ └── SMC/
│ │ │ │ │ │ │ │ │ ├── smc.c
│ │ │ │ │ │ │ │ │ └── smc.h
│ │ │ │ │ │ │ │ ├── EIC/
│ │ │ │ │ │ │ │ │ ├── eic.c
│ │ │ │ │ │ │ │ │ └── eic.h
│ │ │ │ │ │ │ │ ├── FLASHC/
│ │ │ │ │ │ │ │ │ ├── flashc.c
│ │ │ │ │ │ │ │ │ └── flashc.h
│ │ │ │ │ │ │ │ ├── GPIO/
│ │ │ │ │ │ │ │ │ ├── gpio.c
│ │ │ │ │ │ │ │ │ └── gpio.h
│ │ │ │ │ │ │ │ ├── INTC/
│ │ │ │ │ │ │ │ │ ├── exception.x
│ │ │ │ │ │ │ │ │ ├── intc.c
│ │ │ │ │ │ │ │ │ └── intc.h
│ │ │ │ │ │ │ │ ├── PDCA/
│ │ │ │ │ │ │ │ │ ├── pdca.c
│ │ │ │ │ │ │ │ │ └── pdca.h
│ │ │ │ │ │ │ │ ├── PM/
│ │ │ │ │ │ │ │ │ ├── pm.c
│ │ │ │ │ │ │ │ │ ├── pm.h
│ │ │ │ │ │ │ │ │ ├── pm_conf_clocks.c
│ │ │ │ │ │ │ │ │ ├── power_clocks_lib.c
│ │ │ │ │ │ │ │ │ └── power_clocks_lib.h
│ │ │ │ │ │ │ │ ├── RTC/
│ │ │ │ │ │ │ │ │ ├── rtc.c
│ │ │ │ │ │ │ │ │ └── rtc.h
│ │ │ │ │ │ │ │ ├── SPI/
│ │ │ │ │ │ │ │ │ ├── spi.c
│ │ │ │ │ │ │ │ │ └── spi.h
│ │ │ │ │ │ │ │ ├── TC/
│ │ │ │ │ │ │ │ │ ├── tc.c
│ │ │ │ │ │ │ │ │ └── tc.h
│ │ │ │ │ │ │ │ └── USART/
│ │ │ │ │ │ │ │ ├── usart.c
│ │ │ │ │ │ │ │ └── usart.h
│ │ │ │ │ │ │ ├── SERVICES/
│ │ │ │ │ │ │ │ ├── DELAY/
│ │ │ │ │ │ │ │ │ ├── delay.c
│ │ │ │ │ │ │ │ │ └── delay.h
│ │ │ │ │ │ │ │ ├── LWIP/
│ │ │ │ │ │ │ │ │ ├── lwip-1.3.2/
│ │ │ │ │ │ │ │ │ │ └── src/
│ │ │ │ │ │ │ │ │ │ ├── core/
│ │ │ │ │ │ │ │ │ │ │ ├── dhcp.c
│ │ │ │ │ │ │ │ │ │ │ ├── dns.c
│ │ │ │ │ │ │ │ │ │ │ ├── init.c
│ │ │ │ │ │ │ │ │ │ │ ├── ipv4/
│ │ │ │ │ │ │ │ │ │ │ │ ├── autoip.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── icmp.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── igmp.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── inet.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── inet_chksum.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── ip.c
│ │ │ │ │ │ │ │ │ │ │ │ ├── ip_addr.c
│ │ │ │ │ │ │ │ │ │ │ │ └── ip_frag.c
│ │ │ │ │ │ │ │ │ │ │ ├── mem.c
│ │ │ │ │ │ │ │ │ │ │ ├── memp.c
│ │ │ │ │ │ │ │ │ │ │ ├── netif.c
│ │ │ │ │ │ │ │ │ │ │ ├── pbuf.c
│ │ │ │ │ │ │ │ │ │ │ ├── raw.c
│ │ │ │ │ │ │ │ │ │ │ ├── stats.c
│ │ │ │ │ │ │ │ │ │ │ ├── tcp.c
│ │ │ │ │ │ │ │ │ │ │ ├── tcp_in.c
│ │ │ │ │ │ │ │ │ │ │ ├── tcp_out.c
│ │ │ │ │ │ │ │ │ │ │ └── udp.c
│ │ │ │ │ │ │ │ │ │ ├── include/
│ │ │ │ │ │ │ │ │ │ │ ├── ipv4/
│ │ │ │ │ │ │ │ │ │ │ │ └── lwip/
│ │ │ │ │ │ │ │ │ │ │ │ ├── autoip.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── icmp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── igmp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── inet.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── inet_chksum.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── ip.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── ip_addr.h
│ │ │ │ │ │ │ │ │ │ │ │ └── ip_frag.h
│ │ │ │ │ │ │ │ │ │ │ ├── lwip/
│ │ │ │ │ │ │ │ │ │ │ │ ├── api.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── api_msg.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── arch.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── debug.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── def.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── dhcp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── dns.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── err.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── init.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── mem.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── memp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── memp_std.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── netbuf.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── netdb.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── netif.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── netifapi.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── opt.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── pbuf.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── raw.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── sio.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── snmp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── snmp_asn1.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── snmp_msg.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── snmp_structs.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── sockets.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── stats.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── sys.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── tcp.h
│ │ │ │ │ │ │ │ │ │ │ │ ├── tcpip.h
│ │ │ │ │ │ │ │ │ │ │ │ └── udp.h
│ │ │ │ │ │ │ │ │ │ │ └── netif/
│ │ │ │ │ │ │ │ │ │ │ ├── etharp.h
│ │ │ │ │ │ │ │ │ │ │ ├── loopif.h
│ │ │ │ │ │ │ │ │ │ │ ├── ppp_oe.h
│ │ │ │ │ │ │ │ │ │ │ └── slipif.h
│ │ │ │ │ │ │ │ │ │ └── netif/
│ │ │ │ │ │ │ │ │ │ ├── etharp.c
│ │ │ │ │ │ │ │ │ │ └── loopif.c
│ │ │ │ │ │ │ │ │ └── lwip-port-1.3.2/
│ │ │ │ │ │ │ │ │ └── HD/
│ │ │ │ │ │ │ │ │ ├── if/
│ │ │ │ │ │ │ │ │ │ ├── include/
│ │ │ │ │ │ │ │ │ │ │ ├── arch/
│ │ │ │ │ │ │ │ │ │ │ │ ├── cc.h
│ │ │ │ │ │ │ │ │ │ │ │ └── perf.h
│ │ │ │ │ │ │ │ │ │ │ ├── lwipopts.h
│ │ │ │ │ │ │ │ │ │ │ └── netif/
│ │ │ │ │ │ │ │ │ │ │ └── wlif.h
│ │ │ │ │ │ │ │ │ │ └── netif/
│ │ │ │ │ │ │ │ │ │ └── wlif.c
│ │ │ │ │ │ │ │ │ └── readme.txt
│ │ │ │ │ │ │ │ └── MEMORY/
│ │ │ │ │ │ │ │ └── CTRL_ACCESS/
│ │ │ │ │ │ │ │ ├── ctrl_access.c
│ │ │ │ │ │ │ │ └── ctrl_access.h
│ │ │ │ │ │ │ └── UTILS/
│ │ │ │ │ │ │ ├── DEBUG/
│ │ │ │ │ │ │ │ ├── debug.c
│ │ │ │ │ │ │ │ ├── debug.h
│ │ │ │ │ │ │ │ ├── print_funcs.c
│ │ │ │ │ │ │ │ └── print_funcs.h
│ │ │ │ │ │ │ ├── LIBS/
│ │ │ │ │ │ │ │ └── NEWLIB_ADDONS/
│ │ │ │ │ │ │ │ ├── INCLUDE/
│ │ │ │ │ │ │ │ │ ├── nlao_cpu.h
│ │ │ │ │ │ │ │ │ ├── nlao_exceptions.h
│ │ │ │ │ │ │ │ │ ├── nlao_interrupts.h
│ │ │ │ │ │ │ │ │ ├── nlao_io.h
│ │ │ │ │ │ │ │ │ └── nlao_usart.h
│ │ │ │ │ │ │ │ └── libnewlib_addons-at32ucr2-speed_opt.a
│ │ │ │ │ │ │ ├── LINKER_SCRIPTS/
│ │ │ │ │ │ │ │ └── AT32UC3A/
│ │ │ │ │ │ │ │ ├── 0512/
│ │ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ │ └── link_uc3a0512.lds
│ │ │ │ │ │ │ │ └── 1256/
│ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ └── link_uc3a1256.lds
│ │ │ │ │ │ │ ├── PREPROCESSOR/
│ │ │ │ │ │ │ │ ├── mrepeat.h
│ │ │ │ │ │ │ │ ├── preprocessor.h
│ │ │ │ │ │ │ │ ├── stringz.h
│ │ │ │ │ │ │ │ └── tpaste.h
│ │ │ │ │ │ │ ├── STARTUP_FILES/
│ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ └── crt0.x
│ │ │ │ │ │ │ ├── compiler.h
│ │ │ │ │ │ │ ├── conf_isp.h
│ │ │ │ │ │ │ └── parts.h
│ │ │ │ │ │ ├── ard_spi.c
│ │ │ │ │ │ ├── ard_spi.h
│ │ │ │ │ │ ├── ard_tcp.c
│ │ │ │ │ │ ├── ard_tcp.h
│ │ │ │ │ │ ├── ard_utils.c
│ │ │ │ │ │ ├── ard_utils.h
│ │ │ │ │ │ ├── avr32_spi.c
│ │ │ │ │ │ ├── board_init.c
│ │ │ │ │ │ ├── board_init.h
│ │ │ │ │ │ ├── cmd_wl.c
│ │ │ │ │ │ ├── cmd_wl.h
│ │ │ │ │ │ ├── console.c
│ │ │ │ │ │ ├── console.h
│ │ │ │ │ │ ├── debug.h
│ │ │ │ │ │ ├── fw_download.h
│ │ │ │ │ │ ├── fw_download_extflash.c
│ │ │ │ │ │ ├── license.txt
│ │ │ │ │ │ ├── lwip_setup.c
│ │ │ │ │ │ ├── lwip_setup.h
│ │ │ │ │ │ ├── lwipopts.h
│ │ │ │ │ │ ├── main.c
│ │ │ │ │ │ ├── nvram.c
│ │ │ │ │ │ ├── nvram.h
│ │ │ │ │ │ ├── owl_os.c
│ │ │ │ │ │ ├── ping.c
│ │ │ │ │ │ ├── ping.h
│ │ │ │ │ │ ├── printf-stdarg.c
│ │ │ │ │ │ ├── printf-stdarg.h
│ │ │ │ │ │ ├── timer.c
│ │ │ │ │ │ ├── timer.h
│ │ │ │ │ │ ├── top_defs.h
│ │ │ │ │ │ ├── trace.h
│ │ │ │ │ │ ├── util.c
│ │ │ │ │ │ ├── util.h
│ │ │ │ │ │ ├── wifi_spi.h
│ │ │ │ │ │ ├── wl_cm.c
│ │ │ │ │ │ ├── wl_cm.h
│ │ │ │ │ │ └── wl_definitions.h
│ │ │ │ │ └── wifiHD.cproj
│ │ │ │ ├── wifi_dnld/
│ │ │ │ │ ├── .cproject
│ │ │ │ │ ├── .project
│ │ │ │ │ ├── Release/
│ │ │ │ │ │ └── wifi_dnld.elf
│ │ │ │ │ ├── src/
│ │ │ │ │ │ ├── CONFIG/
│ │ │ │ │ │ │ ├── conf_access.h
│ │ │ │ │ │ │ └── conf_at45dbx.h
│ │ │ │ │ │ ├── SOFTWARE_FRAMEWORK/
│ │ │ │ │ │ │ ├── ASM/
│ │ │ │ │ │ │ │ └── trampoline.x
│ │ │ │ │ │ │ ├── BOARDS/
│ │ │ │ │ │ │ │ ├── ARDUINO/
│ │ │ │ │ │ │ │ │ ├── arduino.h
│ │ │ │ │ │ │ │ │ ├── led.c
│ │ │ │ │ │ │ │ │ └── led.h
│ │ │ │ │ │ │ │ ├── EVK1105/
│ │ │ │ │ │ │ │ │ ├── evk1105.h
│ │ │ │ │ │ │ │ │ ├── led.c
│ │ │ │ │ │ │ │ │ └── led.h
│ │ │ │ │ │ │ │ ├── board.h
│ │ │ │ │ │ │ │ └── board.h.ori
│ │ │ │ │ │ │ ├── COMPONENTS/
│ │ │ │ │ │ │ │ └── MEMORY/
│ │ │ │ │ │ │ │ └── DATA_FLASH/
│ │ │ │ │ │ │ │ └── AT45DBX/
│ │ │ │ │ │ │ │ ├── at45dbx.c
│ │ │ │ │ │ │ │ ├── at45dbx.h
│ │ │ │ │ │ │ │ ├── at45dbx_mem.c
│ │ │ │ │ │ │ │ └── at45dbx_mem.h
│ │ │ │ │ │ │ ├── DRIVERS/
│ │ │ │ │ │ │ │ ├── FLASHC/
│ │ │ │ │ │ │ │ │ ├── flashc.c
│ │ │ │ │ │ │ │ │ └── flashc.h
│ │ │ │ │ │ │ │ ├── GPIO/
│ │ │ │ │ │ │ │ │ ├── gpio.c
│ │ │ │ │ │ │ │ │ └── gpio.h
│ │ │ │ │ │ │ │ ├── INTC/
│ │ │ │ │ │ │ │ │ ├── exception.x
│ │ │ │ │ │ │ │ │ ├── intc.c
│ │ │ │ │ │ │ │ │ └── intc.h
│ │ │ │ │ │ │ │ ├── PM/
│ │ │ │ │ │ │ │ │ ├── pm.c
│ │ │ │ │ │ │ │ │ ├── pm.h
│ │ │ │ │ │ │ │ │ ├── pm_conf_clocks.c
│ │ │ │ │ │ │ │ │ ├── power_clocks_lib.c
│ │ │ │ │ │ │ │ │ └── power_clocks_lib.h
│ │ │ │ │ │ │ │ ├── SPI/
│ │ │ │ │ │ │ │ │ ├── spi.c
│ │ │ │ │ │ │ │ │ └── spi.h
│ │ │ │ │ │ │ │ └── USART/
│ │ │ │ │ │ │ │ ├── usart.c
│ │ │ │ │ │ │ │ └── usart.h
│ │ │ │ │ │ │ ├── SERVICES/
│ │ │ │ │ │ │ │ └── MEMORY/
│ │ │ │ │ │ │ │ └── CTRL_ACCESS/
│ │ │ │ │ │ │ │ ├── ctrl_access.c
│ │ │ │ │ │ │ │ └── ctrl_access.h
│ │ │ │ │ │ │ └── UTILS/
│ │ │ │ │ │ │ ├── DEBUG/
│ │ │ │ │ │ │ │ ├── debug.c
│ │ │ │ │ │ │ │ ├── debug.h
│ │ │ │ │ │ │ │ ├── print_funcs.c
│ │ │ │ │ │ │ │ └── print_funcs.h
│ │ │ │ │ │ │ ├── LIBS/
│ │ │ │ │ │ │ │ └── NEWLIB_ADDONS/
│ │ │ │ │ │ │ │ ├── INCLUDE/
│ │ │ │ │ │ │ │ │ ├── nlao_cpu.h
│ │ │ │ │ │ │ │ │ ├── nlao_exceptions.h
│ │ │ │ │ │ │ │ │ ├── nlao_interrupts.h
│ │ │ │ │ │ │ │ │ ├── nlao_io.h
│ │ │ │ │ │ │ │ │ └── nlao_usart.h
│ │ │ │ │ │ │ │ └── libnewlib_addons-at32ucr2-speed_opt.a
│ │ │ │ │ │ │ ├── LINKER_SCRIPTS/
│ │ │ │ │ │ │ │ └── AT32UC3A/
│ │ │ │ │ │ │ │ ├── 0512/
│ │ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ │ └── link_uc3a0512.lds
│ │ │ │ │ │ │ │ └── 1256/
│ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ └── link_uc3a1256.lds
│ │ │ │ │ │ │ ├── PREPROCESSOR/
│ │ │ │ │ │ │ │ ├── mrepeat.h
│ │ │ │ │ │ │ │ ├── preprocessor.h
│ │ │ │ │ │ │ │ ├── stringz.h
│ │ │ │ │ │ │ │ └── tpaste.h
│ │ │ │ │ │ │ ├── STARTUP_FILES/
│ │ │ │ │ │ │ │ └── GCC/
│ │ │ │ │ │ │ │ └── crt0.x
│ │ │ │ │ │ │ ├── compiler.h
│ │ │ │ │ │ │ ├── conf_isp.h
│ │ │ │ │ │ │ └── parts.h
│ │ │ │ │ │ ├── clocks.c
│ │ │ │ │ │ ├── clocks.h
│ │ │ │ │ │ ├── flash_fw.c
│ │ │ │ │ │ ├── license.txt
│ │ │ │ │ │ ├── nor_flash.c
│ │ │ │ │ │ ├── nor_flash.h
│ │ │ │ │ │ ├── printf-stdarg.c
│ │ │ │ │ │ ├── printf-stdarg.h
│ │ │ │ │ │ ├── startup.c
│ │ │ │ │ │ ├── startup.h
│ │ │ │ │ │ └── wl_fw.h
│ │ │ │ │ └── wifi_dnld.cproj
│ │ │ │ └── wifishield.atsln
│ │ │ ├── libraries/
│ │ │ │ ├── EEPROM/
│ │ │ │ │ ├── README.md
│ │ │ │ │ ├── examples/
│ │ │ │ │ │ ├── eeprom_clear/
│ │ │ │ │ │ │ └── eeprom_clear.ino
│ │ │ │ │ │ ├── eeprom_crc/
│ │ │ │ │ │ │ └── eeprom_crc.ino
│ │ │ │ │ │ ├── eeprom_get/
│ │ │ │ │ │ │ └── eeprom_get.ino
│ │ │ │ │ │ ├── eeprom_iteration/
│ │ │ │ │ │ │ └── eeprom_iteration.ino
│ │ │ │ │ │ ├── eeprom_put/
│ │ │ │ │ │ │ └── eeprom_put.ino
│ │ │ │ │ │ ├── eeprom_read/
│ │ │ │ │ │ │ └── eeprom_read.ino
│ │ │ │ │ │ ├── eeprom_update/
│ │ │ │ │ │ │ └── eeprom_update.ino
│ │ │ │ │ │ └── eeprom_write/
│ │ │ │ │ │ └── eeprom_write.ino
│ │ │ │ │ ├── keywords.txt
│ │ │ │ │ ├── library.properties
│ │ │ │ │ └── src/
│ │ │ │ │ └── EEPROM.h
│ │ │ │ ├── HID/
│ │ │ │ │ ├── keywords.txt
│ │ │ │ │ ├── library.properties
│ │ │ │ │ └── src/
│ │ │ │ │ ├── HID.cpp
│ │ │ │ │ └── HID.h
│ │ │ │ ├── SPI/
│ │ │ │ │ ├── examples/
│ │ │ │ │ │ ├── BarometricPressureSensor/
│ │ │ │ │ │ │ └── BarometricPressureSensor.ino
│ │ │ │ │ │ └── DigitalPotControl/
│ │ │ │ │ │ └── DigitalPotControl.ino
│ │ │ │ │ ├── keywords.txt
│ │ │ │ │ ├── library.properties
│ │ │ │ │ └── src/
│ │ │ │ │ ├── SPI.cpp
│ │ │ │ │ └── SPI.h
│ │ │ │ ├── SoftwareSerial/
│ │ │ │ │ ├── examples/
│ │ │ │ │ │ ├── SoftwareSerialExample/
│ │ │ │ │ │ │ └── SoftwareSerialExample.ino
│ │ │ │ │ │ └── TwoPortReceive/
│ │ │ │ │ │ └── TwoPortReceive.ino
│ │ │ │ │ ├── keywords.txt
│ │ │ │ │ ├── library.properties
│ │ │ │ │ └── src/
│ │ │ │ │ ├── SoftwareSerial.cpp
│ │ │ │ │ └── SoftwareSerial.h
│ │ │ │ └── Wire/
│ │ │ │ ├── examples/
│ │ │ │ │ ├── SFRRanger_reader/
│ │ │ │ │ │ └── SFRRanger_reader.ino
│ │ │ │ │ ├── digital_potentiometer/
│ │ │ │ │ │ └── digital_potentiometer.ino
│ │ │ │ │ ├── i2c_scanner/
│ │ │ │ │ │ └── i2c_scanner.ino
│ │ │ │ │ ├── master_reader/
│ │ │ │ │ │ └── master_reader.ino
│ │ │ │ │ ├── master_writer/
│ │ │ │ │ │ └── master_writer.ino
│ │ │ │ │ ├── slave_receiver/
│ │ │ │ │ │ └── slave_receiver.ino
│ │ │ │ │ └── slave_sender/
│ │ │ │ │ └── slave_sender.ino
│ │ │ │ ├── keywords.txt
│ │ │ │ ├── library.properties
│ │ │ │ └── src/
│ │ │ │ ├── Wire.cpp
│ │ │ │ ├── Wire.h
│ │ │ │ └── utility/
│ │ │ │ ├── twi.c
│ │ │ │ └── twi.h
│ │ │ ├── platform.txt
│ │ │ ├── programmers.txt
│ │ │ └── variants/
│ │ │ ├── circuitplay32u4/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── eightanaloginputs/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── ethernet/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── gemma/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── leonardo/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── mega/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── micro/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── robot_control/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── robot_motor/
│ │ │ │ └── pins_arduino.h
│ │ │ ├── standard/
│ │ │ │ └── pins_arduino.h
│ │ │ └── yun/
│ │ │ └── pins_arduino.h
│ │ └── stlarduino/
│ │ ├── ArduinoSTL.cpp
│ │ ├── ArduinoSTL.h
│ │ ├── LICENSE
│ │ ├── abi/
│ │ │ ├── abi.cpp
│ │ │ ├── libgcc_eh/
│ │ │ │ ├── Makefile
│ │ │ │ └── Makefile.in
│ │ │ └── libsupc/
│ │ │ ├── Makefile
│ │ │ └── Makefile.in
│ │ ├── algorithm
│ │ ├── algorithm.cpp
│ │ ├── associative_base
│ │ ├── associative_base.cpp
│ │ ├── basic_definitions
│ │ ├── bitset
│ │ ├── bitset.cpp
│ │ ├── cassert
│ │ ├── cctype
│ │ ├── cerrno
│ │ ├── cfloat
│ │ ├── char_traits
│ │ ├── char_traits.cpp
│ │ ├── climits
│ │ ├── clocale
│ │ ├── cmath
│ │ ├── complex
│ │ ├── complex.cpp
│ │ ├── csetjmp
│ │ ├── csignal
│ │ ├── cstdarg
│ │ ├── cstddef
│ │ ├── cstdio
│ │ ├── cstdlib
│ │ ├── cstring
│ │ ├── ctime
│ │ ├── cwchar
│ │ ├── cwctype
│ │ ├── del_op.cpp
│ │ ├── del_opnt.cpp
│ │ ├── del_ops.cpp
│ │ ├── del_opv.cpp
│ │ ├── del_opvnt.cpp
│ │ ├── del_opvs.cpp
│ │ ├── deque
│ │ ├── deque.cpp
│ │ ├── eh_alloc.cpp
│ │ ├── eh_globals.cpp
│ │ ├── exception
│ │ ├── exception.cpp
│ │ ├── func_exception
│ │ ├── func_exception.cpp
│ │ ├── functional
│ │ ├── initializer_list
│ │ ├── iomanip
│ │ ├── iomanip.cpp
│ │ ├── ios
│ │ ├── ios.cpp
│ │ ├── iosfwd
│ │ ├── iostream
│ │ ├── iostream.cpp
│ │ ├── istream
│ │ ├── istream.cpp
│ │ ├── istream_helpers
│ │ ├── iterator
│ │ ├── iterator.cpp
│ │ ├── iterator_base
│ │ ├── limits
│ │ ├── limits.cpp
│ │ ├── list
│ │ ├── list.cpp
│ │ ├── locale
│ │ ├── locale.cpp
│ │ ├── map
│ │ ├── map.cpp
│ │ ├── memory
│ │ ├── new
│ │ ├── new_handler.cpp
│ │ ├── new_op.cpp
│ │ ├── new_opnt.cpp
│ │ ├── new_opv.cpp
│ │ ├── new_opvnt.cpp
│ │ ├── nonstd-function.h
│ │ ├── numeric
│ │ ├── numeric.cpp
│ │ ├── ostream
│ │ ├── ostream.cpp
│ │ ├── ostream_helpers
│ │ ├── ostream_helpers.cpp
│ │ ├── queue
│ │ ├── queue.cpp
│ │ ├── serstream
│ │ ├── set
│ │ ├── set.cpp
│ │ ├── sstream
│ │ ├── sstream.cpp
│ │ ├── stack
│ │ ├── stack.cpp
│ │ ├── stdexcept
│ │ ├── stdexcept.cpp
│ │ ├── streambuf
│ │ ├── streambuf.cpp
│ │ ├── string
│ │ ├── string.cpp
│ │ ├── string_iostream
│ │ ├── string_view
│ │ ├── support
│ │ ├── support.cpp
│ │ ├── system_configuration.h
│ │ ├── tuple
│ │ ├── type_traits
│ │ ├── typeinfo
│ │ ├── typeinfo.cpp
│ │ ├── unwind-cxx.h
│ │ ├── utility
│ │ ├── utility.cpp
│ │ ├── valarray
│ │ ├── valarray.cpp
│ │ ├── vector
│ │ └── vector.cpp
│ └── libuv/
│ ├── LICENSE
│ ├── include/
│ │ ├── uv/
│ │ │ ├── aix.h
│ │ │ ├── android-ifaddrs.h
│ │ │ ├── bsd.h
│ │ │ ├── darwin.h
│ │ │ ├── errno.h
│ │ │ ├── linux.h
│ │ │ ├── os390.h
│ │ │ ├── posix.h
│ │ │ ├── stdint-msvc2008.h
│ │ │ ├── sunos.h
│ │ │ ├── threadpool.h
│ │ │ ├── tree.h
│ │ │ ├── unix.h
│ │ │ ├── version.h
│ │ │ └── win.h
│ │ └── uv.h
│ └── src/
│ ├── fs-poll.c
│ ├── heap-inl.h
│ ├── idna.c
│ ├── idna.h
│ ├── inet.c
│ ├── queue.h
│ ├── random.c
│ ├── strscpy.c
│ ├── strscpy.h
│ ├── threadpool.c
│ ├── timer.c
│ ├── unix/
│ │ ├── aix-common.c
│ │ ├── aix.c
│ │ ├── android-ifaddrs.c
│ │ ├── async.c
│ │ ├── atomic-ops.h
│ │ ├── bsd-ifaddrs.c
│ │ ├── bsd-proctitle.c
│ │ ├── core.c
│ │ ├── cygwin.c
│ │ ├── darwin-proctitle.c
│ │ ├── darwin-stub.h
│ │ ├── darwin.c
│ │ ├── dl.c
│ │ ├── freebsd.c
│ │ ├── fs.c
│ │ ├── fsevents.c
│ │ ├── getaddrinfo.c
│ │ ├── getnameinfo.c
│ │ ├── haiku.c
│ │ ├── ibmi.c
│ │ ├── internal.h
│ │ ├── kqueue.c
│ │ ├── linux-core.c
│ │ ├── linux-inotify.c
│ │ ├── linux-syscalls.c
│ │ ├── linux-syscalls.h
│ │ ├── loop-watcher.c
│ │ ├── loop.c
│ │ ├── netbsd.c
│ │ ├── no-fsevents.c
│ │ ├── no-proctitle.c
│ │ ├── openbsd.c
│ │ ├── os390-syscalls.c
│ │ ├── os390-syscalls.h
│ │ ├── os390.c
│ │ ├── pipe.c
│ │ ├── poll.c
│ │ ├── posix-hrtime.c
│ │ ├── posix-poll.c
│ │ ├── process.c
│ │ ├── procfs-exepath.c
│ │ ├── proctitle.c
│ │ ├── pthread-fixes.c
│ │ ├── random-devurandom.c
│ │ ├── random-getentropy.c
│ │ ├── random-getrandom.c
│ │ ├── random-sysctl-linux.c
│ │ ├── signal.c
│ │ ├── spinlock.h
│ │ ├── stream.c
│ │ ├── sunos.c
│ │ ├── sysinfo-loadavg.c
│ │ ├── sysinfo-memory.c
│ │ ├── tcp.c
│ │ ├── thread.c
│ │ ├── tty.c
│ │ └── udp.c
│ ├── uv-common.c
│ ├── uv-common.h
│ ├── uv-data-getter-setters.c
│ ├── version.c
│ └── win/
│ ├── async.c
│ ├── atomicops-inl.h
│ ├── core.c
│ ├── detect-wakeup.c
│ ├── dl.c
│ ├── error.c
│ ├── fs-event.c
│ ├── fs-fd-hash-inl.h
│ ├── fs.c
│ ├── getaddrinfo.c
│ ├── getnameinfo.c
│ ├── handle-inl.h
│ ├── handle.c
│ ├── internal.h
│ ├── loop-watcher.c
│ ├── pipe.c
│ ├── poll.c
│ ├── process-stdio.c
│ ├── process.c
│ ├── req-inl.h
│ ├── signal.c
│ ├── snprintf.c
│ ├── stream-inl.h
│ ├── stream.c
│ ├── tcp.c
│ ├── thread.c
│ ├── tty.c
│ ├── udp.c
│ ├── util.c
│ ├── winapi.c
│ ├── winapi.h
│ ├── winsock.c
│ └── winsock.h
├── lib/
│ ├── check/
│ │ ├── isAssignment.js
│ │ ├── isBoolean.js
│ │ ├── isDelimiter.js
│ │ ├── isIncrement.js
│ │ ├── isInitOperator.js
│ │ ├── isKeyword.js
│ │ ├── isNative.js
│ │ ├── isNumber.js
│ │ ├── isObjectOperator.js
│ │ ├── isOperator.js
│ │ ├── isRegExp.js
│ │ ├── isSemi.js
│ │ ├── isString.js
│ │ ├── isUnary.js
│ │ └── isVariable.js
│ ├── env.js
│ ├── include.js
│ ├── package.js
│ ├── parser.js
│ ├── require.js
│ └── verify.js
├── nerd.js
├── nerd_modules/
│ ├── JSON/
│ │ ├── index.ng
│ │ ├── lib/
│ │ │ ├── jsmn.h
│ │ │ └── json.h
│ │ └── package.json
│ ├── Module/
│ │ └── index.ng
│ ├── RegExp/
│ │ └── index.ng
│ ├── String/
│ │ └── index.ng
│ ├── arduino/
│ │ └── index.ng
│ ├── arduino-lcd/
│ │ ├── index.ng
│ │ ├── lib/
│ │ │ ├── LiquidCrystal.cpp
│ │ │ └── LiquidCrystal.h
│ │ └── package.json
│ ├── child_process/
│ │ ├── index.ng
│ │ └── package.json
│ ├── console/
│ │ └── index.ng
│ ├── date/
│ │ └── index.ng
│ ├── error/
│ │ └── index.ng
│ ├── fs/
│ │ ├── index.ng
│ │ └── package.json
│ ├── http/
│ │ ├── httpStruct.h
│ │ ├── httplib/
│ │ │ ├── uSockets/
│ │ │ │ ├── LICENSE
│ │ │ │ ├── bsd.c
│ │ │ │ ├── context.c
│ │ │ │ ├── crypto/
│ │ │ │ │ ├── openssl.c
│ │ │ │ │ ├── sni_tree.cpp
│ │ │ │ │ └── wolfssl.c
│ │ │ │ ├── eventing/
│ │ │ │ │ ├── epoll_kqueue.c
│ │ │ │ │ ├── gcd.c
│ │ │ │ │ └── libuv.c
│ │ │ │ ├── internal/
│ │ │ │ │ ├── eventing/
│ │ │ │ │ │ ├── epoll_kqueue.h
│ │ │ │ │ │ ├── gcd.h
│ │ │ │ │ │ └── libuv.h
│ │ │ │ │ ├── internal.h
│ │ │ │ │ ├── loop_data.h
│ │ │ │ │ └── networking/
│ │ │ │ │ └── bsd.h
│ │ │ │ ├── libusockets.h
│ │ │ │ ├── loop.c
│ │ │ │ └── socket.c
│ │ │ └── uWS/
│ │ │ ├── App.h
│ │ │ ├── AsyncSocket.h
│ │ │ ├── AsyncSocketData.h
│ │ │ ├── BloomFilter.h
│ │ │ ├── HttpContext.h
│ │ │ ├── HttpContextData.h
│ │ │ ├── HttpParser.h
│ │ │ ├── HttpResponse.h
│ │ │ ├── HttpResponseData.h
│ │ │ ├── HttpRouter.h
│ │ │ ├── LICENSE
│ │ │ ├── Loop.h
│ │ │ ├── LoopData.h
│ │ │ ├── MessageParser.h
│ │ │ ├── MoveOnlyFunction.h
│ │ │ ├── Multipart.h
│ │ │ ├── PerMessageDeflate.h
│ │ │ ├── ProxyParser.h
│ │ │ ├── QueryParser.h
│ │ │ ├── TopicTree.h
│ │ │ ├── Utilities.h
│ │ │ ├── WebSocket.h
│ │ │ ├── WebSocketContext.h
│ │ │ ├── WebSocketContextData.h
│ │ │ ├── WebSocketData.h
│ │ │ ├── WebSocketExtensions.h
│ │ │ ├── WebSocketHandshake.h
│ │ │ └── WebSocketProtocol.h
│ │ ├── index.ng
│ │ └── package.json
│ ├── math/
│ │ └── index.ng
│ ├── object/
│ │ └── index.ng
│ ├── os/
│ │ └── index.ng
│ ├── path/
│ │ └── index.ng
│ ├── process/
│ │ └── index.ng
│ ├── querystring/
│ │ └── index.ng
│ ├── thread/
│ │ └── index.ng
│ └── wasm/
│ ├── index.ng
│ ├── lib/
│ │ └── wasm.hpp
│ └── package.json
├── package.json
├── self/
│ ├── base/
│ │ ├── cli/
│ │ │ └── cliParser.js
│ │ ├── compiler/
│ │ │ └── target.js
│ │ └── util/
│ │ ├── copyDirSync.js
│ │ ├── copyRecursive.js
│ │ ├── flash.js
│ │ ├── getExt.js
│ │ ├── getTips.js
│ │ └── rmdir.js
│ ├── compiler/
│ │ ├── native/
│ │ │ ├── compiler.js
│ │ │ ├── env/
│ │ │ │ ├── arduino.js
│ │ │ │ ├── js.js
│ │ │ │ ├── std.js
│ │ │ │ └── wasm.js
│ │ │ ├── nerdcore/
│ │ │ │ ├── src/
│ │ │ │ │ ├── class/
│ │ │ │ │ │ ├── _meta.h
│ │ │ │ │ │ ├── array.h
│ │ │ │ │ │ ├── array_header.h
│ │ │ │ │ │ ├── base_header.h
│ │ │ │ │ │ ├── fixed_array.h
│ │ │ │ │ │ ├── fixed_array_header.h
│ │ │ │ │ │ ├── function.h
│ │ │ │ │ │ ├── function_header.h
│ │ │ │ │ │ ├── native.h
│ │ │ │ │ │ ├── native_header.h
│ │ │ │ │ │ ├── native_tpl_header.h
│ │ │ │ │ │ ├── number.h
│ │ │ │ │ │ ├── number_header.h
│ │ │ │ │ │ ├── object.h
│ │ │ │ │ │ ├── object_header.h
│ │ │ │ │ │ ├── string.h
│ │ │ │ │ │ ├── string_header.h
│ │ │ │ │ │ ├── struct.h
│ │ │ │ │ │ └── struct_header.h
│ │ │ │ │ ├── classes.h
│ │ │ │ │ ├── classes_header.h
│ │ │ │ │ ├── enum.h
│ │ │ │ │ ├── functions.h
│ │ │ │ │ ├── functions_header.h
│ │ │ │ │ ├── macro.h
│ │ │ │ │ ├── native/
│ │ │ │ │ │ ├── double.h
│ │ │ │ │ │ ├── double_header.h
│ │ │ │ │ │ ├── int.h
│ │ │ │ │ │ └── int_header.h
│ │ │ │ │ ├── native.h
│ │ │ │ │ ├── native_header.h
│ │ │ │ │ ├── nerd.cpp
│ │ │ │ │ ├── nerd.hpp
│ │ │ │ │ ├── objmgmt.h
│ │ │ │ │ ├── objmgmt_header.h
│ │ │ │ │ ├── operator.h
│ │ │ │ │ ├── operator_header.h
│ │ │ │ │ ├── stdfn.h
│ │ │ │ │ ├── stdfn_header.h
│ │ │ │ │ ├── tsl/
│ │ │ │ │ │ ├── robin_growth_policy.h
│ │ │ │ │ │ ├── robin_hash.h
│ │ │ │ │ │ ├── robin_map.h
│ │ │ │ │ │ └── robin_set.h
│ │ │ │ │ ├── type_header.h
│ │ │ │ │ ├── values.h
│ │ │ │ │ ├── values_header.h
│ │ │ │ │ ├── var.h
│ │ │ │ │ └── var_header.h
│ │ │ │ └── test/
│ │ │ │ ├── array.cpp
│ │ │ │ ├── cast.cpp
│ │ │ │ ├── native.cpp
│ │ │ │ ├── object.cpp
│ │ │ │ └── operators.cpp
│ │ │ └── squel/
│ │ │ ├── arduino.cpp
│ │ │ ├── js.cpp
│ │ │ ├── std.cpp
│ │ │ └── wasm.cpp
│ │ └── self/
│ │ ├── base/
│ │ │ ├── cli/
│ │ │ │ └── cliParser.ng
│ │ │ ├── compiler/
│ │ │ │ └── target.js
│ │ │ └── util/
│ │ │ ├── copyDirSync.js
│ │ │ ├── copyRecursive.js
│ │ │ ├── flash.js
│ │ │ ├── getExt.js
│ │ │ ├── getTips.js
│ │ │ ├── httpUtils.js
│ │ │ └── rmdir.js
│ │ └── nerd.ng
│ ├── lib/
│ │ ├── check/
│ │ │ ├── isAssignment.js
│ │ │ ├── isBoolean.js
│ │ │ ├── isDelimiter.js
│ │ │ ├── isIncrement.js
│ │ │ ├── isInitOperator.js
│ │ │ ├── isKeyword.js
│ │ │ ├── isNative.js
│ │ │ ├── isNumber.js
│ │ │ ├── isObjectOperator.js
│ │ │ ├── isOperator.js
│ │ │ ├── isSemi.js
│ │ │ ├── isString.js
│ │ │ ├── isUnary.js
│ │ │ └── isVariable.js
│ │ ├── env.js
│ │ ├── include.js
│ │ ├── package.js
│ │ ├── parser.js
│ │ ├── require.js
│ │ └── verify.js
│ ├── nerd.js
│ └── package.json
└── test/
├── accessor.ng
├── builtin.ng
├── comments.ng
├── conditionals.ng
├── function.ng
├── loop.ng
├── native.ng
└── var.ng
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.nerd
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
No VM. No Bytecode. No packaging. No Garbage Collector. Fully compiled to native binaries.
# NectarJS becomes Nerd
Compile JavaScript and NerdLang in native binaries.
# What is NerdLang
NerdLang is a substract of JS with some additions, focus on efficiency.
**Nerd** is a **JavaScript native compiler** aiming to make JavaScript universal, Nerd is able to compile native apps for Windows, Mac, Linux, iOS, Android, Raspberry, STM32 and more.
> **Nerd** is in active development, join us on [Discord](https://discord.gg/cpe2UuN) if you need more information.
- [Roadmap on Trello](https://trello.com/invite/b/6F4rvEj2/ATTI8842296bacc92724fa8b4114fe1dc80aA9FA431B/nerd)
## Main objectives
* Supporting EcmaScript 3 standard (then 5, 6 ...)
* Supporting NodeJS and NPM ecosystem
* Supporting a maximum of platforms (Windows, Mac, Linux, Android, Arduino, ...)
* Being secure
* Embeding debuging tools
* Compile everything that can be transpiled in JS: Ruby (Opal), Python (Transcript, Brython, JavaScrypthon), TypeScript ...
# Get started
## Installation
### Install GCC/CLang for your platform
- Windows
Install Mingw and Clang for Windows here: http://winlibs.com/ or Clang here: https://releases.llvm.org/
You can also install Linux for Windows and use a linux system on Windows
You need MinGW with POSIX threads
- Linux / FreeBSD
Install it with your distro (apt install gcc, yum install gcc, ...).
You can use GCC, CLANG, as well as any derivative of those compilers (arm-gcc ...)
- Apple iOS
Install xCode and you are ready.
You can check your installation with `npm start njs_test`
## Usage
Simplest way to use Nerd:
```
nerd file.js / file.ng
```
The output file name will be automatically chosen regarding the target. You can specify another output with `-o something.out`
You can select a preset
```
nerd file.js --preset [none|speed|size]
```
You can also run the compiled executable just after compilation using --run:
```
nerd file.js --run
```
You can enable the quiet mode with --quiet:
```
nerd file.js --quiet
```
Changing the stack size (useful on Windows):
```
nerd --stack 10000000 flood.js
```
For more informations about compilation output, use `--verbose`
For help, use `--help`
# Benchmarks
* _Need update_
Compiled with GCC v10.2.0 on Windows
| | NodeJS v12.8.1 | QuickJS 2020-07-05 | Nerd v0.6.104 |
|-----------|----------------|--------------------|-------------------|
| sort(1e6) [No preset] |
| - Time: | 0.33s | - | **0.33s** |
| - Memory: | 7.0Mb | - | **1.0Mb** |
|- Filesize:| 28.6Mb | - | **424Kb** |
| sort(1e6) [+Size preset] |
|- Filesize:| 28.6Mb | - | **260Kb** |
| sort(1e6) [+Speed preset] |
| - Time: | 0.33s | - | **0.20s** |
| matrix(256) [No preset] |
| - Time: | 0.33s | - | **0.21s** |
| - Memory: | 7.0Mb | - | **1.0Mb** |
|- Filesize:| 28.6Mb | - | **405Kb** |
| matrix(256) [+Size preset] |
|- Filesize:| 28.6Mb | - | **251Kb** |
| matrix(1e6) [+Speed preset] |
| - Time: | 0.33s | - | **0.11s** |
* _Some code can be evaluated compile-time_
# Supported platforms
Actively tested for
- Windows
* - win-x86-32
* - win-x86-64
- Linux
* - linux-x86-32
* - linux-x86-64
* - linux-arm32v7
- Arduino
* - arduino-nano
* - arduino-uno
* - arduino-mega1280
* - arduino-mega2560
- STM32 Nucleo
* - nucleo-l152re
* - nucleo-l432kc
* - nucleo-f446re
- Mobile
* - android
- Web
* - wasm
* - wast
* - asm-js
- macOS
- Sun OS
# Development
This project is in heavy development and a lot features are not implemented yet.
## ECMAScript Support
Nerd already supports more than 80% of ES3.
Prototype
* .call()
* .bind()
Array
* .length
* .push(value)
Class
* constructor
* methods
* static methods
Console
* .log(variadic)
JSON
* .parse(str)
* .stringify(obj)
Math **(DONE)**
* [All static methods and constants]
Object
* .keys
performance
* timeOrigin
* .now()
String
* .length
* .toString()
* .indexOf(needle)
* .lastIndexOf(needle)
* .search(needle)
* .slice(start, end)
* .substring(start, end)
* .substr(start, end)
* .replace(needle, str)
Syntax
* for
* while / do while
* if / else if / else
* try / catch / finally
* function / lambda
* class
* new
* typeof
* instanceof
* undefined
* null
* Infinite
* NaN / isNaN
* true / false
================================================
FILE: base/cli/cliParser.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var parseCLI = function(args)
{
var result = {error: false, msg: "", cli:{}, stack: [], useless: []};
var useless = [0];
if(!global["__NERD__"])
{
useless.push(1);
}
var withArgs = ["--target", "--spec", "--env", "--stack", "-o", "--preset", "--flash", "--compiler", "-c", "--build", "-b", "--option", "--register", "-r", "--setauthor", "--setid", "--setkey", "--setapi", "--setport", "--sethash", "--setsdk", "--setndk", "--setwin_inc_ucrt", "--setwin_lib_ucrt", "--setwin_lib_um", "--setxcode"];
var noArgs = ["--install_external", "--debug", "--conserve", "--generate", "--config", "--reinit", "--example", "--examples" , "--prepare", "--project", "--run", "--clean", "--purge", "--check", "--no-check", "--verbose", "-v", "--tips", "--version", "--help", "-h", "--release", "--no-object-hashmap"];
for(var i = 0; i < args.length; i++)
{
if( useless.indexOf(i) > -1 )
{
result.useless.push(args[i]);
}
else if( withArgs.indexOf(args[i]) > -1)
{
if(args[i+1])
{
result.cli[args[i]] =
{
state: true,
argument: args[i+1],
};
i++;
}
else
{
result.error = true;
result.msg = "[!] Missing argument for " + args[i];
break;
}
}
else if(noArgs.indexOf(args[i]) > -1)
{
result.cli[args[i]] =
{
state: true,
};
}
else if(args[i].length > 0 && args[i][0] == "-")
{
if(withArgs.indexOf(args[i]) < 0 && noArgs.indexOf(args[i]) < 0)
{
result.error = true;
result.msg = "[!] Unknown parameter : " + args[i];
break;
}
}
else
{
result.stack.push(args[i]);
}
}
return result;
}
module.exports = parseCLI;
================================================
FILE: base/compiler/target.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var target = ["win-x86-32", "win-x86-64", "linux-x86-32", "linux-x86-64", "linux-arm32v7",
"arduino-uno", "arduino-mega1280", "arduino-mega2560",
"wasm", "wast", "asm-js",
"mac-osx",
"nucleo-l152re", "nucleo-l432kc"
];
module.exports = target;
================================================
FILE: base/util/copyDirSync.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var fs = require("fs");
var path = require("path");
var copyDirSync = function( source, target )
{
var targetFile = target;
if ( fs.existsSync( target ) )
{
if ( fs.lstatSync( target ).isDirectory() )
{
targetFile = path.join( target, path.basename( source ) );
}
}
fs.copyFileSync(source, targetFile);
}
var copyFolderRecursiveSync = function( source, target, _root )
{
var files = [];
var targetFolder = path.join( target, path.basename( source ) );
if(_root)
{
targetFolder = target;
}
if ( !fs.existsSync( targetFolder ) )
{
fs.mkdirSync( targetFolder );
}
if ( fs.lstatSync( source ).isDirectory() )
{
files = fs.readdirSync( source );
for(var i = 0; i < files.length; i++)
{
var curSource = path.join( source, files[i] );
if ( fs.lstatSync( curSource ).isDirectory() )
{
copyFolderRecursiveSync( curSource, targetFolder );
}
else
{
copyDirSync( curSource, targetFolder );
}
}
}
}
module.exports = copyFolderRecursiveSync;
================================================
FILE: base/util/copyRecursive.js
================================================
var fs = require("fs");
var path = require("path");
var copyRecursiveSync = function(src, dest)
{
if(!fs.existsSync(src))
{
console.log("[!] Warning: " + src + " doesn't exist");
return;
}
if(fs.lstatSync( src ).isDirectory())
{
var _newDest = path.dirname(dest);
global.copyDirSync(src, _newDest, true);
}
else
{
var _path = [];
var _newDest = path.dirname(dest);
_path.push(_newDest);
while(path.dirname(_newDest) != _newDest)
{
_newDest = path.dirname(_newDest);
if(_newDest.indexOf(global.NERD_PATH) == 0)
{
_path.push(_newDest);
}
}
for(var i = _path.length; i > -1; i--)
{
try
{
fs.mkdirSync(_path[i]);
}
catch(e){}
}
fs.copyFileSync(src, dest);
}
};
module.exports = copyRecursiveSync;
================================================
FILE: base/util/flash.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var fs = require("fs");
var path = require("path");
var execFlashArduino = function(from, to, model, driver, bauds, verb)
{
var spawn = require("child_process").spawn;
var _flash = spawn("avrdude", ["-p", model, "-c", driver, "-P", to, "-b", bauds, "-F", "-U", "flash:w:"+from]);
_flash.stdout.on("data", function(data)
{
if(verb) process.stdout.write(data.toString());
});
_flash.stderr.on("data", function(data)
{
if(verb) process.stdout.write(data.toString());
});
_flash.on("error", function(err)
{
console.log("[!] Error :");
console.log(err);
});
_flash.on("close", function(code)
{
console.log("[+] Flashed");
});
}
var execFlashSTM32 = function(from, to)
{
try
{
fs.writeFileSync(path.join(to, from), fs.readFileSync(from));
console.log("[+ Flashed]");
}
catch(e)
{
console.log("[!] Your file is compiled, but an error occured while flashing, please try again.");
}
}
var Flash = function(from, to, target, verb)
{
switch(target)
{
case "uno":
execFlashArduino(from, to, "ATMEGA328P", "arduino", "19200", verb);
break;
case "mega1280":
execFlashArduino(from, to, "m1280", "arduino", "57600", verb);
break;
case "mega2560":
execFlashArduino(from, to, "m2560", "wiring", "115200", verb);
break;
case "nucleo-l152re":
case "nucleo-l432kc":
execFlashSTM32(from, to);
break;
default:
console.log("Nothing to do for target : " + target);
break;
}
}
module.exports = Flash;
================================================
FILE: base/util/getExt.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var getExt = function(target)
{
switch(target)
{
case "wasm":
return ".wasm";
break;
case "asm-js":
return ".asm.js";
break;
case "wast":
return ".wast";
break;
case "win-x86-32":
case "win-x86-64":
return "-" + target + ".exe";
break;
case "nucleo-l432kc":
case "nucleo-l152re":
case "mac-osx":
case "linux-x86-32":
case "linux-x86-64":
case "linux-arm32v7":
return "-" + target + ".bin";
break;
case "arduino-uno":
return "-" + target + ".hex";
break;
case "arduino-mega1280":
return "-" + target + ".hex";
break;
case "arduino-mega2560":
return "-" + target + ".hex";
break;
default:
return ".bin";
break;
}
}
module.exports = getExt;
================================================
FILE: base/util/getTips.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var getTips = function(target, file)
{
switch(target)
{
case "wasm":
return "";
break;
case "asm-js":
return "[*] Tips : run this file with node : 'node " + file + "', or embed it in a .html page with ";
break;
case "wast":
return "";
break;
case "win-x86-32":
case "win-x86-64":
return "[*] Tips : on Linux, you can run this .exe with Wine : 'wine " + file + "'";
break;
case "linux-x86-32":
case "linux-x86-64":
case "linux-arm32v7":
return "[*] Tips : on Linux, don't forget to : 'chmod +x " + file + "'.";
break;
case "arduino-uno":
return "[*] Tips : avrdude -p ATMEGA328P -c arduino -P [COMPORT] -b 19200 -F -U flash:w:" + file;
break;
case "arduino-mega1280":
return "[*] Tips : avrdude -p m1280 -c arduino -P [COMPORT] -b 57600 -F -U flash:w:" + file;
break;
case "arduino-mega2560":
return "[*] Tips : avrdude -p m2560 -c wiring -P [COMPORT] -b 115200 -F -U flash:w:" + file;
break;
case "nucleo-l152re":
case "nucleo-l432kc":
return "[*] Connect your nucleo on your computer, and symple copy/paste " + file + " on the nucleo drive";
default:
return "";
break;
}
}
module.exports = getTips;
================================================
FILE: compiler/native/compiler.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
global.ENV = loadEnv();
function loadEnv()
{
var _res = {};
var _folder = path.join(__dirname, "/env/");
var _list = fs.readdirSync(_folder);
for(var _el in _list)
{
var _name = _list[_el].substring(0, _list[_el].length-3);
var _e = require(path.join(_folder, _list[_el]));
_res[_name] = _e;
}
return _res;
}
function Compiler()
{
var _handler = this;
this.MAIN_PATH = __dirname;
this.TARGET = "standard";
this.SPEC;
this.EXPOSE = "";
this.STD = "";
this.GEN = "";
this.PATH = "";
this.LIBS = "";
this.STATE = "";
this.PACK = [];
this.DIR = [];
if(CLI.stack[0]) this.PATH = path.dirname(CLI.stack[0]) + path.sep;
this.ENV = ENV["std"];
if(CLI.cli["--env"])
{
var _env = CLI.cli["--env"].argument;
if(ENV[_env])
{
this.ENV = ENV[_env];
}
else
{
console.log("[!] ENV: " + _env + " does not exist, please select one of [" + Object.keys(ENV).toString() + "]");
process.exit(1);
}
}
this.COMPILER = this.ENV.compiler;
this.PRESET = "none";
this.MAIN = fs.readFileSync(path.join(__dirname, "squel", this.ENV.main)).toString();
this.IN = "";
this.OUT = "";
this.TMP_FOLDER = "";
this.OPTION = "";
this.INIT = "";
this.DECL = "";
this.REQUIRE = "";
this.INCLUDE = "";
this.INFO =
{
FUNCTION: [],
CACHE: {},
VALUE: [],
CALL: {},
SCOPE: {},
HOISTING: [],
};
if(this.ENV.stdlib)
{
for(var _s in this.ENV.stdlib)
{
if(typeof this.ENV.stdlib[_s] == "string")
{
this.DECL += "var " + this.ENV.stdlib[_s] + ";";
this.STD += this.ENV.stdlib[_s] + " = require(\"" + this.ENV.stdlib[_s] + "\");";
}
else if(typeof this.ENV.stdlib[_s] == "object")
{
this.DECL += "var " + this.ENV.stdlib[_s].bind + ";";
this.STD += this.ENV.stdlib[_s].bind + " = require(\"" + this.ENV.stdlib[_s].module + "\");";
}
}
}
this.CODE = "";
this.FOOTER = "";
/*** METHODS ***/
this.Parse = function(code, _file)
{
var _env = createEnv(_handler.PATH, _file);
code = this.STD + code;
parseCode(code, 0, _env);
parseAST(_env);
var _generated = generateCode(_env);
_handler.MAIN = _handler.MAIN.replace("{CODE}", _generated);
_handler.MAIN = _handler.MAIN.replace("{INIT}", COMPILER.INIT);
_handler.MAIN = _handler.MAIN.replace("{DECL}", COMPILER.DECL);
_handler.MAIN = _handler.MAIN.replace("{INCLUDE}", COMPILER.INCLUDE);
_handler.MAIN = _handler.MAIN.replace("{{__PLATFORM__}}", os.platform());
}
this.Prepare = function(_folder)
{
if((!CLI.cli["--profile"]) || CLI.cli["--profile"].argument != "use")
{
copyDirSync(path.join(__dirname, "nerdcore"), _folder, false);
}
};
this.Out = function(_name)
{
if(os.platform() == "win32" && path.extname(_name) != ".exe") _handler.OUT = _name + ".exe";
else _handler.OUT = _name;
if(COMPILER.ENV.out && typeof COMPILER.ENV.out == "function")
{
_handler.OUT = COMPILER.ENV.out(_name);
}
return _handler.OUT;
}
this.CLI = function(compiler, out, _in, option)
{
return this.ENV.cli(compiler, this.preset, out, _in, option, this.TARGET, this.SPEC);
}
this.Compile = function(_folder, _file)
{
fs.writeFileSync(_file, _handler.MAIN);
process.chdir(_folder);
var _exec = _handler.CLI(_handler.COMPILER, _handler.OUT, _file, _handler.OPTION);
execSync(_exec);
}
this.Package = function()
{
if(this.PACK && this.PACK.length)
{
for(var i = 0; i < this.PACK.length; i++)
{
copyRecursiveSync(this.PACK[i], this.OUT);
}
}
}
/*** END METHODS ***/
}
module.exports = new Compiler();
================================================
FILE: compiler/native/env/arduino.js
================================================
var OPTIONS =
{
"mega": { preset: "-DF_CPU=16000000UL -mmcu=atmega2560", variant: "mega"},
"mega2560": { preset: "-DF_CPU=16000000UL -mmcu=atmega2560", variant: "mega"},
"mega1280": { preset: "-DF_CPU=16000000UL -mmcu=atmega1280", variant: "mega"},
"mega328p": { preset: "-DF_CPU=16000000UL -mmcu=atmega328p", variant: "standard"},
"uno": { preset: "-DF_CPU=16000000UL -mmcu=atmega328p", variant: "standard"},
"nano": { preset: "-DF_CPU=16000000UL -mmcu=atmega328p", variant: "standard"},
"nano2": { preset: "-DF_CPU=16000000UL -mmcu=atmega168", variant: "standard"},
"nano3": { preset: "-DF_CPU=16000000UL -mmcu=atmega328p", variant: "standard"}
}
function getOptions()
{
var OPT =
{
elf: false,
cli: false,
};
if(CLI.cli["--option"] && CLI.cli["--option"].argument)
{
var _args = CLI.cli["--option"].argument.split(",");
for(var i = 0; i < _args.length; i++)
{
OPT[_args[i]] = true;
}
}
return OPT;
}
var ARDUINO =
{
name: "arduino",
main: "arduino.cpp",
cli: function(compiler, preset, out, _in, option, target, spec)
{
var OPT = getOptions();
var _cliOption = "";
if(CLI.cli["--option"]) _cliOption = CLI.cli["--option"].argument;
if(!target || !OPTIONS[target])
{
console.log("[!] No target or bad target selected, switching to 'uno'");
target = "uno";
}
var _cli = `${compiler} ${OPTIONS[target].preset} -D__NERD__OBJECT_VECTOR -DARDUINO_ARCH_AVR -w -Os -fno-exceptions -fno-rtti -fno-stack-protector -fomit-frame-pointer -ffunction-sections -fdata-sections -Wl,--gc-sections \
-I ${extern}/arduino/avr -I ${extern}/arduino/avr/variants/${OPTIONS[target].variant}/ -I ${extern}/arduino/avr/cores/arduino -I ${extern}/arduino/stlarduino ${extern}/arduino/stlarduino/ios.cpp ${extern}/arduino/avr/cores/arduino/abi.cpp ${extern}/arduino/stlarduino/new*.cpp ${extern}/arduino/stlarduino/char_traits.cpp ${extern}/arduino/stlarduino/del*.cpp ${extern}/arduino/stlarduino/stdexcept.cpp ${extern}/arduino/stlarduino/func_exception.cpp ${extern}/arduino/stlarduino/ostream_helpers.cpp -fno-threadsafe-statics -lm ${COMPILER.LIBS} -o ${out} ${_in} ${_cliOption}`;
if(!OPT.elf) _cli += `&& avr-objcopy -O ihex -R .eeprom ${out}`;
if(OPT.cli) console.log("[*]" + _cli);
return _cli;
},
compiler: "avr-g++ -std=c++17",
stdlib:[],
out: function(_name)
{
var OPT = getOptions();
if(OPT.elf) _name += ".elf";
else _name += ".hex";
return _name;
},
}
module.exports = ARDUINO;
================================================
FILE: compiler/native/env/js.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var _debug = " -g ";
var JS =
{
name: "js",
main: "js.cpp",
compiler: "g++",
stdlib: ["console", "JSON", "Module", "process", "RegExp", "Math"],
cli: function(compiler, preset, out, _in, option)
{
var _cachePath = path.join(process.cwd(), "..", "cached_" + COMPILER.ENV.name + "_" + os.platform + "_" + VERSION);
var _precompiled = path.join(_cachePath, "nerd.o");
var _stack = 0;
if(CLI.cli["--stack"])
{
try
{
_stack = parseInt(CLI.cli["--stack"].argument);
}
catch(e)
{
console.log("[!] Error: --stack flags required a number, received -> " + CLI.cli["--stack"].argument);
process.exit(1);
}
}
if(!fs.existsSync(_precompiled))
{
var _args = " -flto -Ofast ";
if(preset == "debug")
{
console.log("Building core with debug");
_args = _debug;
}
console.log(`[+] Creating Nerd binary lib for ${COMPILER.ENV.name + "_" + os.platform + "_" + VERSION}`);
console.log(`${compiler} -std=c++17 ${_args} -c nerdcore/src/nerd.cpp -o "${_precompiled}"`);
try { fs.mkdirSync(_cachePath); } catch(e){};
execSync(`${compiler} -std=c++17 ${_args} -c nerdcore/src/nerd.cpp -o "${_precompiled}"`);
console.log("[+] Compiling with precompiled Nerd lib");
}
if(compiler == "cl" || compiler.indexOf("cl ") == 0)
{
console.log("[!] cl is not supported, please use g++, clang++, em++ or avr-g++");
process.exit(1);
}
var _hashmap = "";
if(CLI.cli['--no-object-hashmap']) _hashmap = "-D__NERD__OBJECT_VECTOR";
if(_stack) _stack = "-Wl,--stack," + _stack;
else _stack = "";
var _sysVNetLibs = "";
if(os.platform() == "sunos") _sysVNetLibs = "-lsocket -lnsl";
var _cliOption = "";
if(CLI.cli["--option"]) _cliOption = CLI.cli["--option"].argument;
if(CLI.cli["--profile"])
{
if(!CLI.cli["--conserve"]) CLI.cli["--conserve"] = true;
if(CLI.cli["--profile"].argument == "gen")
{
_cliOption += " -fprofile-generate";
console.log("[*] Profiling data will be stored in: " + COMPILER.TMP_FOLDER);
}
else if(CLI.cli["--profile"].argument == "use")
{
_cliOption += " -fprofile-use";
console.log("[*] Using profile data from: " + COMPILER.TMP_FOLDER);
}
else
{
console.log("[!] Please use --profile with gen or use");
}
}
var _files = `"${_precompiled}" "${_in}"`;
if(os.platform == "win32") _files = `"${_in}" "${_precompiled}"`;
if(preset == "none")
{
return `${compiler} ${_stack} -std=c++17 ${_files} -g -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else if(preset == "debug")
{
console.log(`${compiler} ${_stack} -std=c++17 ${_files} ${_debug} -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`);
return `${compiler} ${_stack} -std=c++17 ${_files} ${_debug} -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else if(preset == "size")
{
return `${compiler} ${_stack} -std=c++17 ${_files} -pthread -Os -fno-rtti -fno-stack-protector -fomit-frame-pointer -s ${COMPILER.LIBS} -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else
{
var _opt = "-O";
if(os.platform() == "darwin" || compiler.indexOf("clang") > -1) _opt += "3";
else _opt += "fast";
_opt += " -flto";
return `${compiler} ${_stack} -std=c++17 ${_files} ${_opt} -pthread -s ${COMPILER.LIBS} -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
},
write: function(_content, _in)
{
if(CLI.cli["--profile"] && CLI.cli["--profile"].argument == "use")
{
return;
}
fs.writeFileSync(_in, _content);
}
}
module.exports = JS;
================================================
FILE: compiler/native/env/std.js
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var _debug = " -g ";
var STD =
{
name: "std",
main: "std.cpp",
compiler: "g++",
stdlib: [],
cli: function(compiler, preset, out, _in, option)
{
var _cachePath = path.join(process.cwd(), "..", "cached_" + COMPILER.ENV.name + "_" + os.platform + "_" + VERSION);
var _precompiled = path.join(_cachePath, "nerd.o");
var _stack = 0;
if(CLI.cli["--stack"])
{
try
{
_stack = parseInt(CLI.cli["--stack"].argument);
}
catch(e)
{
console.log("[!] Error: --stack flags required a number, received -> " + CLI.cli["--stack"].argument);
process.exit(1);
}
}
if(!fs.existsSync(_precompiled))
{
var _args = " -flto -Ofast ";
if(preset == "debug")
{
console.log("Building core with debug");
_args = _debug;
}
console.log(`[+] Creating Nerd binary lib for ${COMPILER.ENV.name + "_" + os.platform + "_" + VERSION}`);
console.log(`${compiler} -std=c++17 ${_args} -c nerdcore/src/nerd.cpp -o "${_precompiled}"`);
try { fs.mkdirSync(_cachePath); } catch(e){};
execSync(`${compiler} -std=c++17 ${_args} -c nerdcore/src/nerd.cpp -o "${_precompiled}"`);
console.log("[+] Compiling with precompiled Nerd lib");
}
if(compiler == "cl" || compiler.indexOf("cl ") == 0)
{
console.log("[!] cl is not supported, please use g++, clang++, em++ or avr-g++");
process.exit(1);
}
var _hashmap = "";
if(CLI.cli['--no-object-hashmap']) _hashmap = "-D__NERD__OBJECT_VECTOR";
if(_stack) _stack = "-Wl,--stack," + _stack;
else _stack = "";
var _sysVNetLibs = "";
if(os.platform() == "sunos") _sysVNetLibs = "-lsocket -lnsl";
var _cliOption = "";
if(CLI.cli["--option"]) _cliOption = CLI.cli["--option"].argument;
if(CLI.cli["--profile"])
{
if(!CLI.cli["--conserve"]) CLI.cli["--conserve"] = true;
if(CLI.cli["--profile"].argument == "gen")
{
_cliOption += " -fprofile-generate";
console.log("[*] Profiling data will be stored in: " + COMPILER.TMP_FOLDER);
}
else if(CLI.cli["--profile"].argument == "use")
{
_cliOption += " -fprofile-use";
console.log("[*] Using profile data from: " + COMPILER.TMP_FOLDER);
}
else
{
console.log("[!] Please use --profile with gen or use");
}
}
var _files = `"${_precompiled}" "${_in}"`;
if(os.platform == "win32") _files = `"${_in}" "${_precompiled}"`;
if(preset == "none")
{
return `${compiler} ${_stack} -std=c++17 ${_files} -g -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else if(preset == "debug")
{
console.log(`${compiler} ${_stack} -std=c++17 ${_files} ${_debug} -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`);
return `${compiler} ${_stack} -std=c++17 ${_files} ${_debug} -s ${COMPILER.LIBS} -pthread -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else if(preset == "size")
{
return `${compiler} ${_stack} -std=c++17 ${_files} -pthread -Os -fno-rtti -fno-stack-protector -fomit-frame-pointer -s ${COMPILER.LIBS} -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
else
{
var _opt = "-O";
if(os.platform() == "darwin" || compiler.indexOf("clang") > -1) _opt += "3";
else _opt += "fast";
_opt += " -flto";
return `${compiler} ${_stack} -std=c++17 ${_files} ${_opt} -pthread -s ${COMPILER.LIBS} -o "${out}" ${_sysVNetLibs} ${_cliOption}`;
}
},
write: function(_content, _in)
{
if(CLI.cli["--profile"] && CLI.cli["--profile"].argument == "use")
{
return;
}
fs.writeFileSync(_in, _content);
}
}
module.exports = STD;
================================================
FILE: compiler/native/env/wasm.js
================================================
var WASM =
{
name: "wasm",
main: "wasm.cpp",
compiler: "em++",
out: function(_name)
{
if(CLI.cli["--target"])
{
if(CLI.cli["--target"].argument == "js") return _name + ".asm.js";
else if(CLI.cli["--target"].argument == "wasm") return _name + ".wasm";
else if(CLI.cli["--target"].argument == "html") return _name + ".html";
else
{
console.log("[!] Invalid target, expected js, wasm, html");
process.exit(1);
}
}
return _name + ".wasm";
},
cli: function(compiler, preset, out, _in, option)
{
/*
var _cachePath = path.join(process.cwd(), "..", "cached_" + COMPILER.ENV.name + "_" + VERSION);
var _precompiled = path.join(_cachePath, "nerd.o");
if(!fs.existsSync(_precompiled))
{
console.log(`[+] Creating Nerd binary lib for ${COMPILER.ENV.name + "_" + VERSION}`);
try { fs.mkdirSync(_cachePath); } catch(e){};
execSync(`${compiler} -std=c++17 -c nerd.cpp -O3 -o "${_precompiled}"`);
console.log("[+] Compiling with precompiled Nerd lib");
}
*/
var _cliOption = "";
if(CLI.cli["--option"]) _cliOption = CLI.cli["--option"].argument;
if(preset == "none")
{
return `${compiler} nerdcore/src/nerd.cpp -D__NJS_REGISTER_SIZE=${COMPILER.REGISTER} ${_in} -O1 -w -s TOTAL_MEMORY=33554432 ${COMPILER.LIBS} -o ${out} ${_cliOption}`;
}
else if(preset == "size")
{
return `${compiler} nerdcore/src/nerd.cpp -D__NJS_REGISTER_SIZE=${COMPILER.REGISTER} ${_in} -Os -fno-rtti -fno-stack-protector -fomit-frame-pointer -w -s TOTAL_MEMORY=33554432 ${COMPILER.LIBS} -o ${out} ${_cliOption}`;
}
else
{
return `${compiler} nerdcore/src/nerd.cpp -D__NJS_REGISTER_SIZE=${COMPILER.REGISTER} ${_in} -O3 -w -s TOTAL_MEMORY=33554432 ${COMPILER.LIBS} -o ${out} ${_cliOption}`;
}
}
}
module.exports = WASM;
================================================
FILE: compiler/native/nerdcore/src/class/_meta.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include
namespace NerdCore::Class
{
#ifdef __NERD_ENV_ARDUINO
typedef uint16_t count_t;
#else
typedef int count_t;
#endif
class InvalidTypeException : public std::exception
{
};
#ifdef __NERD_ENV_ARDUINO
const int SMI_MAX = 32767;
const int SMI_MIN = -32768;
#else
const int SMI_MAX = 1073741823;
const int SMI_MIN = -1073741824;
#endif
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/array.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "array_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
Array::Array()
{
object["__proto__"] = NerdCore::Global::Array["prototype"];
}
Array::Array(NerdCore::Type::vector_t vec)
{
object["__proto__"] = NerdCore::Global::Array["prototype"];
value = vec;
}
Array::Array(std::initializer_list l) : value(l)
{
object["__proto__"] = NerdCore::Global::Array["prototype"];
}
// Methods
inline void Array::Delete() noexcept
{
if (--counter == 0)
{
delete this;
}
}
double Array::Size()
{
return value.size();
}
inline void Array::jsDelete(NerdCore::VAR _key) noexcept
{
if(_key.type == NerdCore::Enum::Type::String)
{
// TODO: if string is a number, convert to number and erase
}
else if(_key.type == NerdCore::Enum::Type::Number)
{
value[(double)_key] = NerdCore::Global::null;
}
}
inline void* Array::Copy() noexcept
{
counter++;
return this;
}
// Native cast
Array::operator bool() const noexcept { return true; }
Array::operator double() const noexcept
{
if (value.size() == 1)
{
return (double)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
Array::operator int() const noexcept
{
if (value.size() == 1)
{
return (int)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
Array::operator long long() const noexcept
{
if (value.size() == 1)
{
return (long long)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
Array::operator std::string() const noexcept
{
auto l = value.size();
if (l == 0)
return "";
std::stringstream stream;
stream << (std::string)value[0];
for (auto i = 1; i < l; i++)
{
stream << "," << (std::string)value[i];
}
return stream.str();
}
NerdCore::VAR &Array::GetSet(std::string key)
{
#ifndef __NERD__OBJECT_VECTOR
// if current object[key] is null, we look for the prototypal chain
if(object[key].type == NerdCore::Enum::Type::Null)
{
NerdCore::VAR __proto = object["__proto__"];
while(__proto.type != NerdCore::Enum::Type::Null)
{
if(__proto[key].type != NerdCore::Enum::Type::Null)
{
object[key] = __proto[key];
break;
}
__proto = __proto["__proto__"];
}
}
/*
if(object[key].type == NerdCore::Enum::Type::Function)
{
(__NERD_FUNCTION(object[key]))->object["this"] = NerdCore::VAR(this);
__NERD_FUNCTION(object[key])->bind = bind;
}
*/
return object[key];
#else
for (auto & search : object)
{
if (key.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(key, NerdCore::Global::null));
return object[object.size() - 1].second;
#endif
}
// Main operators
NerdCore::VAR const Array::operator[](int key) const
{
if (key >= 0 && key <= value.size())
{
return value.at(key);
}
return NerdCore::Global::null;
}
NerdCore::VAR &Array::operator[](NerdCore::VAR key)
{
if (key.type == NerdCore::Enum::Type::Number)
{
auto i = (int)key;
if (i < 0)
{
return NerdCore::Global::null;
}
else
{
if (i >= value.size())
{
value.resize(i + 1);
}
}
return value[i];
}
else
{
return GetSet(key);
}
return NerdCore::Global::null;
}
NerdCore::VAR &Array::operator[](int key)
{
if (key < 0)
{
return NerdCore::Global::null;
}
else
{
if (key >= value.size())
{
value.resize(key + 1);
}
}
return value[key];
}
NerdCore::VAR &Array::operator[](double key)
{
if (key < 0)
{
return NerdCore::Global::null;
}
else
{
if (key >= value.size())
{
value.resize(key + 1);
}
}
return value[key];
}
NerdCore::VAR &Array::operator[](const char* key)
{
return GetSet(key);
}
// Comparation operators
Array Array::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
// Numeric operators
Array Array::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator+(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator+=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator-(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator-=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator*(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator*=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
// TODO: "**" and "**=" operators
Array Array::operator/(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator/=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator%(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator%=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator&(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator|(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator^(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator>>(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator<<(const Array &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator&=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator|=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator^=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator>>=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
Array Array::operator<<=(const Array &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Array();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/array_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Array : public virtual Base
{
public:
// Constructors
Array();
Array(NerdCore::Type::vector_t vec);
template
Array(Args ... args)
{
NerdCore::Type::vector_t _vec = {args...};
value = _vec;
}
Array(std::initializer_list l);
// Properties
count_t counter = 0;
NerdCore::Type::vector_t value;
NerdCore::Type::object_t object;
NerdCore::VAR length;
// Methods
double Size();
inline void Delete() noexcept;
inline void jsDelete(const NerdCore::VAR _key) noexcept;
inline void* Copy() noexcept;
// Native cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
NerdCore::VAR &GetSet(std::string key);
NerdCore::VAR const operator[](int key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
Array operator!() const;
template
bool operator==(const t &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
template
bool operator!=(const t &_v1) const { return true; }
template
bool operator<(const t &_v1) const { return (*this)[0] < _v1;}
template
bool operator<=(const t &_v1) const { return (*this)[0] <= _v1; }
template
bool operator>(const t &_v1) const { return (*this)[0] > _v1; }
template
bool operator>=(const t &_v1) const { return (*this)[0] >= _v1; }
// Numeric operators
Array operator+() const;
Array operator-() const;
Array operator++(const int _v1);
Array operator--(const int _v1);
Array operator+(const Array &_v1) const;
Array operator+=(const Array &_v1);
Array operator-(const Array &_v1) const;
Array operator-=(const Array &_v1);
Array operator*(const Array &_v1) const;
Array operator*=(const Array &_v1);
// TODO: "**" and "**=" operators
Array operator/(const Array &_v1) const;
Array operator/=(const Array &_v1);
Array operator%(const Array &_v1) const;
Array operator%=(const Array &_v1);
Array operator&(const Array &_v1) const;
Array operator|(const Array &_v1) const;
Array operator^(const Array &_v1) const;
Array operator~() const;
Array operator>>(const Array &_v1) const;
Array operator<<(const Array &_v1) const;
Array operator&=(const Array &_v1);
Array operator|=(const Array &_v1);
Array operator^=(const Array &_v1);
Array operator>>=(const Array &_v1);
Array operator<<=(const Array &_v1);
// TODO: ">>>" and ">>>=" operators
NerdCore::VAR __iterator(NerdCore::VAR* args, int _length) const;
NerdCore::VAR __unscopables(NerdCore::VAR* args, int _length) const;
NerdCore::VAR concat(NerdCore::VAR* args, int _length) const;
NerdCore::VAR copyWithin(NerdCore::VAR* args, int _length);
NerdCore::VAR entries(NerdCore::VAR* args, int _length) const;
NerdCore::VAR every(NerdCore::VAR* args, int _length) const;
NerdCore::VAR fill(NerdCore::VAR* args, int _length) const;
NerdCore::VAR filter(NerdCore::VAR* args, int _length) const;
NerdCore::VAR find(NerdCore::VAR* args, int _length) const;
NerdCore::VAR findIndex(NerdCore::VAR* args, int _length) const;
NerdCore::VAR flat(NerdCore::VAR* args, int _length) const;
NerdCore::VAR flatMap(NerdCore::VAR* args, int _length) const;
NerdCore::VAR forEach(NerdCore::VAR* args, int _length) const;
NerdCore::VAR includes(NerdCore::VAR* args, int _length) const;
NerdCore::VAR indexOf(NerdCore::VAR* args, int _length) const;
NerdCore::VAR join(NerdCore::VAR* args, int _length) const;
NerdCore::VAR keys(NerdCore::VAR* args, int _length) const;
NerdCore::VAR lastIndexOf(NerdCore::VAR* args, int _length) const;
NerdCore::VAR map(NerdCore::VAR* args, int _length) const;
NerdCore::VAR pop(NerdCore::VAR* args, int _length);
NerdCore::VAR push(NerdCore::VAR* args, int _length);
NerdCore::VAR reduce(NerdCore::VAR* args, int _length) const;
NerdCore::VAR reduceRight(NerdCore::VAR* args, int _length) const;
NerdCore::VAR reverse(NerdCore::VAR* args, int _length);
NerdCore::VAR shift(NerdCore::VAR* args, int _length);
NerdCore::VAR slice(NerdCore::VAR* args, int _length) const;
NerdCore::VAR some(NerdCore::VAR* args, int _length) const;
NerdCore::VAR sort(NerdCore::VAR* args, int _length) const;
NerdCore::VAR splice(NerdCore::VAR* args, int _length);
NerdCore::VAR toLocaleString(NerdCore::VAR* args, int _length) const;
NerdCore::VAR toString(NerdCore::VAR* args, int _length) const;
NerdCore::VAR unshift(NerdCore::VAR* args, int _length);
NerdCore::VAR values(NerdCore::VAR* args, int _length) const;
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/base_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Base
{
public:
#ifdef __NERD_ENV_ESP32
virtual ~Base() { }
#endif
virtual void Delete() noexcept{};
virtual void* Copy() noexcept{ return nullptr; };
virtual explicit operator bool() const noexcept{ return true;};
virtual explicit operator std::string() const noexcept{ return "";};
virtual explicit operator int() const noexcept {return 0;};
virtual explicit operator double() const noexcept {return 0.0;};
virtual explicit operator long long() const noexcept {return 0;};
virtual NerdCore::VAR &operator[](NerdCore::VAR key){ return NerdCore::Global::null; };
virtual NerdCore::VAR &operator[](int key){ return NerdCore::Global::null; };
virtual NerdCore::VAR &operator[](double key){ return NerdCore::Global::null; };
virtual NerdCore::VAR &operator[](const char* key){ return NerdCore::Global::null; };
};
}
================================================
FILE: compiler/native/nerdcore/src/class/fixed_array.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "array_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
FixedArray::FixedArray()
{
length = 8;
value = new NerdCore::VAR[8];
}
FixedArray::FixedArray(NerdCore::VAR _length)
{
length = _length;
value = new NerdCore::VAR[(int)_length];
}
FixedArray::FixedArray(int _length)
{
length = _length;
value = new NerdCore::VAR[_length];
}
FixedArray::FixedArray(NerdCore::VAR* _var, int _length)
{
length = _length;
value = new NerdCore::VAR[_length];
for(int i = 0; i < _length; i++)
{
value[i] = _var[i];
}
}
// Methods
inline void FixedArray::Delete() noexcept
{
if (--counter == 0)
{
delete[] value;
delete this;
}
}
inline void* FixedArray::Copy() noexcept
{
counter++;
return this;
}
// Native cast
FixedArray::operator bool() const noexcept { return true; }
FixedArray::operator double() const noexcept
{
if ((int)length == 1)
{
return (double)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
FixedArray::operator int() const noexcept
{
if ((int)length == 1)
{
return (int)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
FixedArray::operator long long() const noexcept
{
if ((int)length == 1)
{
return (long long)value[0];
}
else
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
}
FixedArray::operator std::string() const noexcept
{
auto l = (int)length;
std::stringstream stream;
stream << (std::string)value[0];
for (auto i = 1; i < l; i++)
{
stream << "," << (std::string)value[i];
}
return stream.str();
}
// Main operators
NerdCore::VAR const FixedArray::operator[](NerdCore::VAR key) const
{
if (key.type == NerdCore::Enum::Type::Number)
{
auto i = (int)key;
if (i >= 0 && i <= (int)length)
{
return value[i];
}
}
return NerdCore::Global::null;
}
NerdCore::VAR const FixedArray::operator[](int key) const
{
if (key >= 0 && key <= (int)length)
{
return value[key];
}
return NerdCore::Global::null;
}
NerdCore::VAR &FixedArray::operator[](NerdCore::VAR key)
{
if (key.type == NerdCore::Enum::Type::Number)
{
auto i = (int)key;
if (i < 0)
{
return NerdCore::Global::null;
}
else
{
if (i >= (int)length)
{
return NerdCore::Global::null;
}
}
return value[i];
}
return NerdCore::Global::null;
}
NerdCore::VAR &FixedArray::operator[](int key)
{
if (key < 0)
{
return NerdCore::Global::null;
}
else
{
if (key >= (int)length)
{
return NerdCore::Global::null;
}
}
return value[key];
}
NerdCore::VAR &FixedArray::operator[](double key)
{
if (key < 0)
{
return NerdCore::Global::null;
}
else
{
if (key >= (int)length)
{
return NerdCore::Global::null;
}
}
return value[(int)key];
}
NerdCore::VAR &FixedArray::operator[](const char* key)
{
return NerdCore::Global::null;
}
// Comparation operators
FixedArray FixedArray::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
// Numeric operators
FixedArray FixedArray::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator+(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator+=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator-(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator-=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator*(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator*=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
// TODO: "**" and "**=" operators
FixedArray FixedArray::operator/(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator/=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator%(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator%=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator&(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator|(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator^(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator>>(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator<<(const FixedArray &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator&=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator|=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator^=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator>>=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
FixedArray FixedArray::operator<<=(const FixedArray &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return FixedArray();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/fixed_array_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class FixedArray : public virtual Base
{
public:
// Constructors
FixedArray();
FixedArray(NerdCore::VAR length);
FixedArray(int length);
FixedArray(NerdCore::VAR* value, int length);
// Properties
count_t counter = 0;
NerdCore::VAR length;
NerdCore::VAR* value;
// Methods
inline void Delete() noexcept;
inline void* Copy() noexcept;
// Native cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR const operator[](int key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
FixedArray operator!() const;
template
bool operator==(const t &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
template
bool operator!=(const t &_v1) const { return true; }
template
bool operator<(const t &_v1) const { return (*this)[0] < _v1;}
template
bool operator<=(const t &_v1) const { return (*this)[0] <= _v1; }
template
bool operator>(const t &_v1) const { return (*this)[0] > _v1; }
template
bool operator>=(const t &_v1) const { return (*this)[0] >= _v1; }
// Numeric operators
FixedArray operator+() const;
FixedArray operator-() const;
FixedArray operator++(const int _v1);
FixedArray operator--(const int _v1);
FixedArray operator+(const FixedArray &_v1) const;
FixedArray operator+=(const FixedArray &_v1);
FixedArray operator-(const FixedArray &_v1) const;
FixedArray operator-=(const FixedArray &_v1);
FixedArray operator*(const FixedArray &_v1) const;
FixedArray operator*=(const FixedArray &_v1);
// TODO: "**" and "**=" operators
FixedArray operator/(const FixedArray &_v1) const;
FixedArray operator/=(const FixedArray &_v1);
FixedArray operator%(const FixedArray &_v1) const;
FixedArray operator%=(const FixedArray &_v1);
FixedArray operator&(const FixedArray &_v1) const;
FixedArray operator|(const FixedArray &_v1) const;
FixedArray operator^(const FixedArray &_v1) const;
FixedArray operator~() const;
FixedArray operator>>(const FixedArray &_v1) const;
FixedArray operator<<(const FixedArray &_v1) const;
FixedArray operator&=(const FixedArray &_v1);
FixedArray operator|=(const FixedArray &_v1);
FixedArray operator^=(const FixedArray &_v1);
FixedArray operator>>=(const FixedArray &_v1);
FixedArray operator<<=(const FixedArray &_v1);
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/function.h
================================================
/*
Copyright (c) 2022 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "function_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
Function::Function()
{
(*this)["prototype"] = new NerdCore::Class::Object();
}
Function::Function(void *val)
{
counter++;
value = (NerdCore::Type::function_t*)val;
if((*this)["prototype"].type == NerdCore::Enum::Type::Null)
{
(*this)["prototype"] = new NerdCore::Class::Object();
}
}
Function::Function(void *val, NerdCore::VAR __this)
{
counter++;
(*this)["this"] = __this;
value = (NerdCore::Type::function_t*)val;
if((*this)["prototype"].type == NerdCore::Enum::Type::Null)
{
(*this)["prototype"] = new NerdCore::Class::Object();
}
}
// Methods
inline void Function::Delete() noexcept
{
if (--counter < 1)
{
delete (NerdCore::Type::function_t*)value;
delete this;
}
}
inline void Function::jsDelete(const std::string _key) noexcept
{
}
inline void* Function::Copy() noexcept
{
counter++;
return this;
}
// Main operators
NerdCore::VAR const Function::operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
#ifndef __NERD__OBJECT_VECTOR
NerdCore::VAR &Function::operator[](NerdCore::VAR key)
{
/*
if(hasLazy && LazyRTM.count(key) && !object.count(key))
{
object[key] = LazyRTM[key];
}
*/
return object[key];
}
#else
NerdCore::VAR &Function::operator[](NerdCore::VAR key)
{
std::string _str = ((std::string)key);
NerdCore::Type::StringView _sview = _str;
if (key.type == NerdCore::Enum::Type::Number)
{
auto i = (int)key;
if (i < 0)
{
return NerdCore::Global::null;
}
else
{
if (i >= object.size())
{
object.reserve(i + 1);
object.resize(i + 1);
}
}
return object[i].second;
}
for (auto & search : object)
{
if (_sview.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::Global::null));
return object[object.size() - 1].second;
}
#endif
#ifndef __NERD__OBJECT_VECTOR
NerdCore::VAR &Function::operator[](int key)
{
std::string _str = std::to_string(key);
NerdCore::Type::StringView _sview = _str;
return object[_str];
}
#else
NerdCore::VAR &Function::operator[](int key)
{
std::string _str = std::to_string(key);
NerdCore::Type::StringView _sview = _str;
for (auto & search : object)
{
if (_sview.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::Global::null));
return object[object.size() - 1].second;
}
#endif
#ifndef __NERD__OBJECT_VECTOR
NerdCore::VAR &Function::operator[](double key)
{
std::string _str = std::to_string(key);
NerdCore::Type::StringView _sview = _str;
return object[_str];
}
#else
NerdCore::VAR &Function::operator[](double key)
{
std::string _str = std::to_string(key);
NerdCore::Type::StringView _sview = _str;
for (auto & search : object)
{
if (_sview.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::Global::null));
return object[object.size() - 1].second;
}
#endif
#ifndef __NERD__OBJECT_VECTOR
NerdCore::VAR &Function::operator[](const char* key)
{
/*
if(hasLazy && LazyRTM.count(key) && !object.count(key))
{
object[key] = LazyRTM[key];
}
*/
return object[key];
}
#else
NerdCore::VAR &Function::operator[](const char* key)
{
std::string _str = key;
NerdCore::Type::StringView _sview = _str;
for (auto & search : object)
{
if (_sview.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::Global::null));
return object[object.size() - 1].second;
}
#endif
// Comparation operators
NerdCore::VAR Function::operator!() const
{
return __NERD_Boolean_FALSE;
}
bool Function::operator==(const Function &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool Function::operator!=(const Function &_v1) const { return true; }
bool Function::operator<(const Function &_v1) const { return false; }
bool Function::operator<=(const Function &_v1) const { return true; }
bool Function::operator>(const Function &_v1) const { return false; }
bool Function::operator>=(const Function &_v1) const { return true; }
// Numeric operators
Function Function::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator+(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator+=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator-(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator-=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator*(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator*=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
// TODO: "**" and "**=" operators
Function Function::operator/(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator/=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator%(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator%=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator&(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator|(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator^(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator>>(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator<<(const Function &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator&=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator|=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator^=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator>>=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
Function Function::operator<<=(const Function &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Function();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/function_header.h
================================================
/*
Copyright (c) 2022 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Function : public virtual Base
{
public:
// Constructors
Function();
Function(void* val);
Function(void* val, NerdCore::VAR __this);
// Properties
count_t counter = 0;
NerdCore::Type::function_t* value = nullptr;
NerdCore::Type::object_t object;
NerdCore::VAR This;
//void* bind = nullptr;
// Methods
inline void Delete() noexcept;
inline void jsDelete(std::string _key) noexcept;
inline void* Copy() noexcept;
inline NerdCore::VAR Call(NerdCore::VAR __NERD_THIS, NerdCore::VAR* _args, int i)
{
#ifndef __NERD__OBJECT_VECTOR
if(__NERD_THIS.type == NerdCore::Enum::Type::Null)
{
return std::invoke((*static_cast(value)), This, _args, i);
}
else
{
return std::invoke((*static_cast(value)), __NERD_THIS, _args, i);
}
#else
return (*static_cast(value))(__NERD_THIS, _args, i);
#endif
}
template
NerdCore::VAR operator()(NerdCore::VAR __NERD_THIS, Args... args)
{
NerdCore::VAR _args[] = {args...};
int i = sizeof...(args);
#ifndef __NERD__OBJECT_VECTOR
if(__NERD_THIS.type == NerdCore::Enum::Type::Null)
{
return std::invoke((*static_cast(value)), This, _args, i);
}
else
{
return std::invoke((*static_cast(value)), __NERD_THIS, _args, i);
}
#else
return (*static_cast(value))(__NERD_THIS, _args, i);
#endif
}
template
NerdCore::VAR New(NerdCore::VAR __NERD_THIS, Args... args)
{
NerdCore::VAR _args[] = {args...};
int i = sizeof...(args);
NerdCore::VAR _this = new NerdCore::Class::Object(); //__NERD_Object_Clone((*this)["this"]);
if(_this.type == NerdCore::Enum::Type::Null) _this = new NerdCore::Class::Object();
//((NerdCore::Class::Object*)_this.data.ptr)->bind = bind;
NerdCore::VAR _return = this->Call(_this, _args, i);
if(_return.type == NerdCore::Enum::Type::Object)
{
_this = _return;
}
_this["__proto__"] = object["prototype"];
return _this;
}
// Main operators
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
NerdCore::VAR operator!() const;
bool operator==(const Function &_v1) const;
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const Function &_v1) const;
bool operator<(const Function &_v1) const;
bool operator<=(const Function &_v1) const;
bool operator>(const Function &_v1) const;
bool operator>=(const Function &_v1) const;
// Numeric operators
Function operator+() const;
Function operator-() const;
Function operator++(const int _v1);
Function operator--(const int _v1);
Function operator+(const Function &_v1) const;
Function operator+=(const Function &_v1);
Function operator-(const Function &_v1) const;
Function operator-=(const Function &_v1);
Function operator*(const Function &_v1) const;
Function operator*=(const Function &_v1);
// TODO: "**" and "**=" operators
Function operator/(const Function &_v1) const;
Function operator/=(const Function &_v1);
Function operator%(const Function &_v1) const;
Function operator%=(const Function &_v1);
Function operator&(const Function &_v1) const;
Function operator|(const Function &_v1) const;
Function operator^(const Function &_v1) const;
Function operator~() const;
Function operator>>(const Function &_v1) const;
Function operator<<(const Function &_v1) const;
Function operator&=(const Function &_v1);
Function operator|=(const Function &_v1);
Function operator^=(const Function &_v1);
Function operator>>=(const Function &_v1);
Function operator<<=(const Function &_v1);
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/native.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "native_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
Native::Native() {}
Native::Native(void *val)
{
value = val;
}
// Methods
inline void Native::Delete() noexcept
{
if (--counter < 1)
{
if((*this)["__NERD_On_Destroy"]) (*this)["__NERD_On_Destroy"](NerdCore::Global::null);
delete this;
}
}
inline void* Native::Copy() noexcept
{
counter++;
return this;
}
// Native cast
Native::operator bool() const noexcept { return true; }
Native::operator double() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Native::operator int() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Native::operator long long() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Native::operator std::string() const noexcept
{
return "[native code]";
}
// Main operators
NerdCore::VAR const Native::operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
NerdCore::VAR &Native::operator[](NerdCore::VAR key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &Native::operator[](int key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &Native::operator[](double key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &Native::operator[](const char* key)
{
return NerdCore::Global::null;
}
// Comparation operators
Native Native::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
bool Native::operator==(const Native &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool Native::operator!=(const Native &_v1) const { return true; }
bool Native::operator<(const Native &_v1) const { return false; }
bool Native::operator<=(const Native &_v1) const { return true; }
bool Native::operator>(const Native &_v1) const { return false; }
bool Native::operator>=(const Native &_v1) const { return true; }
// Numeric operators
Native Native::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator+(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator+=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator-(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator-=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator*(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator*=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
// TODO: "**" and "**=" operators
Native Native::operator/(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator/=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator%(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator%=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator&(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator|(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator^(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator>>(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator<<(const Native &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator&=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator|=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator^=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator>>=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
Native Native::operator<<=(const Native &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Native();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/native_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Native : public virtual Base
{
public:
// Constructors
Native();
Native(void* val);
// Properties
count_t counter = 1;
int length = 0;
void* value = nullptr;
// Methods
inline void Delete() noexcept;
inline void* Copy() noexcept;
// Native cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
Native operator!() const;
bool operator==(const Native &_v1) const;
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const Native &_v1) const;
bool operator<(const Native &_v1) const;
bool operator<=(const Native &_v1) const;
bool operator>(const Native &_v1) const;
bool operator>=(const Native &_v1) const;
// Numeric operators
Native operator+() const;
Native operator-() const;
Native operator++(const int _v1);
Native operator--(const int _v1);
Native operator+(const Native &_v1) const;
Native operator+=(const Native &_v1);
Native operator-(const Native &_v1) const;
Native operator-=(const Native &_v1);
Native operator*(const Native &_v1) const;
Native operator*=(const Native &_v1);
// TODO: "**" and "**=" operators
Native operator/(const Native &_v1) const;
Native operator/=(const Native &_v1);
Native operator%(const Native &_v1) const;
Native operator%=(const Native &_v1);
Native operator&(const Native &_v1) const;
Native operator|(const Native &_v1) const;
Native operator^(const Native &_v1) const;
Native operator~() const;
Native operator>>(const Native &_v1) const;
Native operator<<(const Native &_v1) const;
Native operator&=(const Native &_v1);
Native operator|=(const Native &_v1);
Native operator^=(const Native &_v1);
Native operator>>=(const Native &_v1);
Native operator<<=(const Native &_v1);
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/native_tpl_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
template
class NativeTPL : public virtual Base
{
private:
inline void internalDelete()
{
if(is_ptr)
{
delete value;
}
}
public:
// Constructors
bool is_ptr = true;
int length = 0;
std::string type;
NativeTPL(T val)
{
is_ptr = true;
value = val;
type = "undef";
}
NativeTPL(T val, const char str[])
{
is_ptr = true;
type = str;
value = val;
}
NativeTPL(T val, bool isPtr)
{
is_ptr = isPtr;
value = val;
type = "undef";
}
NativeTPL(T val, const char str[], bool isPtr)
{
is_ptr = isPtr;
value = val;
type = str;
}
// Properties
count_t counter = 1;
T value;
NerdCore::Type::object_t object;
// Methods
inline void Delete() noexcept
{
if (--counter == 0)
{
internalDelete();
delete this;
}
}
inline void* Copy() noexcept
{
counter++;
return this;
}
template
const inline T operator()(Cast& c) const
{
static_assert(std::is_same::value, "Casting must be same as NativeType");
return value;
}
inline T operator()() const
{
return value;
}
operator bool() const noexcept { return true; }
operator double() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
operator int() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
operator long long() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
operator std::string() const noexcept
{
return std::string("[native ") + type + std::string("]");
}
// Main operators
NerdCore::VAR const operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
NerdCore::VAR &operator[](NerdCore::VAR key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &operator[](int key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &operator[](double key)
{
return NerdCore::Global::null;
}
NerdCore::VAR &operator[](const char* key)
{
return NerdCore::Global::null;
}
// Comparation operators
NativeTPL operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
bool operator==(const NativeTPL &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const NativeTPL &_v1) const { return true; }
bool operator<(const NativeTPL &_v1) const { return false; }
bool operator<=(const NativeTPL &_v1) const { return true; }
bool operator>(const NativeTPL &_v1) const { return false; }
bool operator>=(const NativeTPL &_v1) const { return true; }
// Numeric operators
NativeTPL operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator+(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator+=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator-(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator-=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator*(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator*=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
// TODO: "**" and "**=" operators
NativeTPL operator/(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator/=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator%(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator%=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator&(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator|(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator^(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator>>(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator<<(const NativeTPL &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator&=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator|=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator^=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator>>=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
NativeTPL operator<<=(const NativeTPL &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NativeTPL();
}
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/number.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace NerdCore::Class::NUMBER
{
}
================================================
FILE: compiler/native/nerdcore/src/class/number_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace NerdCore::Class::NUMBER
{
}
================================================
FILE: compiler/native/nerdcore/src/class/object.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "object_header.h"
#include
namespace NerdCore::Class
{
NerdCore::VAR __proxy;
// Constructors
Object::Object() { }
/*
Object::Object(const char* _key, NerdCore::VAR _value)
{
object[_key] = _value;
}
*/
/*
Object::Object(NerdCore::VAR _obj)
{
object = ((NerdCore::Class::Object*)_obj.data.ptr)->object;
}
*/
Object::Object(NerdCore::Type::object_t obj)
{
object = obj;
}
Object::Object(std::initializer_list obj)
{
for (NerdCore::Type::pair_t p : obj)
{
object[p.first] = p.second;
}
}
// Methods
double Object::Size()
{
return object.size();
}
inline void Object::Delete() noexcept
{
if (--counter < 1)
{
delete this;
}
}
inline void Object::jsDelete(const std::string _key) noexcept
{
#ifndef __NERD__OBJECT_VECTOR
object.erase(_key);
#else
for (NerdCore::Type::object_t::iterator it = object.begin() ; it != object.end(); ++it)
{
if (_key.compare(it->first) == 0)
{
object.erase(it);
return;
}
}
#endif
}
inline void* Object::Copy() noexcept
{
counter++;
return this;
}
// Native cast
Object::operator bool() const noexcept { return true; }
Object::operator double() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Object::operator int() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Object::operator long long() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Object::operator std::string() const noexcept
{
return "[object Object]";
}
// Main operators
NerdCore::VAR const Object::operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
NerdCore::VAR &Object::GetSet(std::string key)
{
#ifndef __NERD__OBJECT_VECTOR
// if current object[key] is null, we look for the prototypal chain
if(object[key].type == NerdCore::Enum::Type::Null)
{
NerdCore::VAR __proto = object["__proto__"];
while(__proto.type != NerdCore::Enum::Type::Null)
{
if(__proto[key].type != NerdCore::Enum::Type::Null)
{
object[key] = __proto[key];
break;
}
__proto = __proto["__proto__"];
}
}
/*
if(object[key].type == NerdCore::Enum::Type::Function)
{
(__NERD_FUNCTION(object[key]))->object["this"] = NerdCore::VAR(this);
__NERD_FUNCTION(object[key])->bind = bind;
}
*/
return object[key];
#else
for (auto & search : object)
{
if (key.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(key, NerdCore::Global::null));
return object[object.size() - 1].second;
#endif
}
NerdCore::VAR &Object::operator[](NerdCore::VAR key)
{
return Object::GetSet(key);
}
NerdCore::VAR &Object::operator[](int key)
{
std::string _str = std::to_string(key);
return Object::GetSet(_str);
}
NerdCore::VAR &Object::operator[](double key)
{
std::string _str = std::to_string(key);
return Object::GetSet(_str);
}
NerdCore::VAR &Object::operator[](const char* key)
{
return Object::GetSet(key);
}
// Comparation operators
Object Object::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
bool Object::operator==(const Object &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool Object::operator!=(const Object &_v1) const { return true; }
bool Object::operator<(const Object &_v1) const { return false; }
bool Object::operator<=(const Object &_v1) const { return true; }
bool Object::operator>(const Object &_v1) const { return false; }
bool Object::operator>=(const Object &_v1) const { return true; }
// Numeric operators
Object Object::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator+(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator+=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator-(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator-=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator*(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator*=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
// TODO: "**" and "**=" operators
Object Object::operator/(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator/=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator%(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator%=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator&(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator|(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator^(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator>>(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator<<(const Object &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator&=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator|=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator^=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator>>=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
Object Object::operator<<=(const Object &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return Object();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/object_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Object : public virtual Base
{
public:
// Constructors
Object();
Object(NerdCore::Type::object_t obj);
Object(std::initializer_list);
//Object(NerdCore::VAR _obj);
// Properties
count_t counter = 0;
bool deleted = false;
//bool hasLazy = false;
NerdCore::Type::object_t object;
void* bind = nullptr;
// Methods
double Size();
inline void Delete() noexcept;
inline void jsDelete(const std::string _key) noexcept;
inline void* Copy() noexcept;
// Native cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
inline NerdCore::VAR& GetSet(std::string key);
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
Object operator!() const;
bool operator==(const Object &_v1) const;
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const Object &_v1) const;
bool operator<(const Object &_v1) const;
bool operator<=(const Object &_v1) const;
bool operator>(const Object &_v1) const;
bool operator>=(const Object &_v1) const;
// Numeric operators
Object operator+() const;
Object operator-() const;
Object operator++(const int _v1);
Object operator--(const int _v1);
Object operator+(const Object &_v1) const;
Object operator+=(const Object &_v1);
Object operator-(const Object &_v1) const;
Object operator-=(const Object &_v1);
Object operator*(const Object &_v1) const;
Object operator*=(const Object &_v1);
// TODO: "**" and "**=" operators
Object operator/(const Object &_v1) const;
Object operator/=(const Object &_v1);
Object operator%(const Object &_v1) const;
Object operator%=(const Object &_v1);
Object operator&(const Object &_v1) const;
Object operator|(const Object &_v1) const;
Object operator^(const Object &_v1) const;
Object operator~() const;
Object operator>>(const Object &_v1) const;
Object operator<<(const Object &_v1) const;
Object operator&=(const Object &_v1);
Object operator|=(const Object &_v1);
Object operator^=(const Object &_v1);
Object operator>>=(const Object &_v1);
Object operator<<=(const Object &_v1);
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/string.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "string_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
String::String()
{
object["__proto__"] = NerdCore::Global::String["prototype"];
}
String::String(std::string val)
{
object["__proto__"] = NerdCore::Global::String["prototype"];
value = val;
}
String::String(const char* val)
{
object["__proto__"] = NerdCore::Global::String["prototype"];
value = val;
}
// Methods
inline void String::Delete() noexcept
{
if (--counter < 1)
{
delete this;
}
}
inline void* String::Copy() noexcept
{
return new String(value);
}
// Native cast
String::operator bool() const noexcept { return value.size() > 0; }
String::operator double() const noexcept
{
std::string::size_type end;
double res;
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
try
{
res = std::stod(value, &end);
}catch(...){}
#else
res = std::stod(value, &end);
#endif
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return end == value.size() ? res : std::numeric_limits::quiet_NaN();
#endif
}
String::operator int() const noexcept
{
std::string::size_type end;
int res;
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
try
{
res = std::stoi(value, &end, 10);
}catch(...){}
#else
res = std::stoi(value, &end, 10);
#endif
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return end == value.size() ? res : std::numeric_limits::quiet_NaN();
#endif
}
String::operator long long() const noexcept
{
std::string::size_type end;
long long res;
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
try
{
res = std::stoll(value, &end, 10);
}catch(...){}
#else
res = std::stoll(value, &end, 10);
#endif
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return end == value.size() ? res : std::numeric_limits::quiet_NaN();
#endif
}
String::operator std::string() const noexcept { return value; }
// Main operators
NerdCore::VAR const String::operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
static NerdCore::Global::var _char = "";
NerdCore::VAR &String::GetSet(NerdCore::VAR keyVar)
{
if(keyVar.type == NerdCore::Enum::Type::Number)
{
int key = (int)keyVar;
if(key > value.size() - 1)
{
return NerdCore::Global::null;
}
else
{
_char = std::string(1, value[key]);
return _char;
}
}
else if(keyVar.type == NerdCore::Enum::Type::String)
{
std::string key = ((NerdCore::Class::String*)(keyVar.data.ptr))->value;
#ifndef __NERD__OBJECT_VECTOR
// if current object[key] is null, we look for the prototypal chain
if(object[key].type == NerdCore::Enum::Type::Null)
{
NerdCore::VAR __proto = object["__proto__"];
while(__proto.type != NerdCore::Enum::Type::Null)
{
if(__proto[key].type != NerdCore::Enum::Type::Null)
{
object[key] = __proto[key];
break;
}
__proto = __proto["__proto__"];
}
}
/*
if(object[key].type == NerdCore::Enum::Type::Function)
{
value.copy((char*)__NERD_FUNCTION(object[key])->bind, value.length());
}
*/
return object[key];
#else
for (auto & search : object)
{
if (key.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(key, NerdCore::Global::null));
return object[object.size() - 1].second;
#endif
}
else
{
return NerdCore::Global::null;
}
}
NerdCore::VAR &String::operator[](NerdCore::VAR key)
{
return String::GetSet(key);
}
NerdCore::VAR &String::operator[](int key)
{
return String::GetSet(key);
}
NerdCore::VAR &String::operator[](double key)
{
return String::GetSet(key);
}
NerdCore::VAR &String::operator[](const char* key)
{
#ifndef __NERD__OBJECT_VECTOR
// if current object[key] is null, we look for the prototypal chain
if(object[key].type == NerdCore::Enum::Type::Null)
{
NerdCore::VAR __proto = object["__proto__"];
while(__proto.type != NerdCore::Enum::Type::Null)
{
if(__proto[key].type != NerdCore::Enum::Type::Null)
{
object[key] = __proto[key];
break;
}
__proto = __proto["__proto__"];
}
}
/*
if(object[key].type == NerdCore::Enum::Type::Function)
{
//__NERD_FUNCTION(object[key])->bind = value.data();
//value.copy((char*)__NERD_FUNCTION(object[key])->bind, value.length());
}
*/
return object[key];
#else
for (auto & search : object)
{
if (key.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(key, NerdCore::Global::null));
return object[object.size() - 1].second;
#endif
}
// Comparation operators
String String::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
bool String::operator==(const String &_v1) const { return value.compare(_v1.value) == 0; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool String::operator!=(const String &_v1) const { return value.compare(_v1.value) != 0; }
bool String::operator<(const String &_v1) const { return value.at(0) < _v1.value.at(0); }
bool String::operator<=(const String &_v1) const { return value.at(0) <= _v1.value.at(0); }
bool String::operator>(const String &_v1) const { return value.at(0) > _v1.value.at(0); }
bool String::operator>=(const String &_v1) const { return value.at(0) >= _v1.value.at(0); }
// Numeric operators
String String::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator+(const String &_v1) const { return value + _v1.value; }
String String::operator+=(const String &_v1) { value += _v1.value; return *this; }
String String::operator-(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator-=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator*(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator*=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
// TODO: "**" and "**=" operators
String String::operator/(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator/=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator%(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator%=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator&(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator|(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator^(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator>>(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator<<(const String &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator&=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator|=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator^=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator>>=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
String String::operator<<=(const String &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return String();
}
// TODO: ">>>" and ">>>=" operators
/*** STRING METHODS ***/
NerdCore::VAR String::toString(NerdCore::VAR* _args, int _length) const
{
return value;
}
NerdCore::VAR String::split(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _needle;
if (_length > 0)
_needle = _args[0];
else
return NerdCore::VAR(this->value);
NerdCore::VAR _arr = new NerdCore::Class::Array();
char *_v = (char *)malloc(strlen(this->value.c_str()) + 1);
strcpy(_v, this->value.c_str());
char *delim = (char *)malloc(strlen(((std::string)_needle).c_str()) + 1);
strcpy(delim, ((std::string)_needle).c_str());
char *ptr = strtok(_v, delim);
int i = 0;
char *_new;
while (ptr != NULL)
{
_new = (char *)malloc(strlen(ptr) + 1);
strcpy(_new, ptr);
__NERD_Object_Set(i, _new, _arr);
free(_new);
ptr = strtok(NULL, delim);
i++;
}
free(delim);
return _arr;
}
NerdCore::VAR String::indexOf(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _needle;
if (_length > 0)
_needle = _args[0];
else
return NerdCore::VAR(-1);
std::string::size_type loc = this->value.find((std::string)_needle, 0);
if (loc != std::string::npos)
{
return NerdCore::VAR((int)loc);
}
return NerdCore::VAR(-1);
}
NerdCore::VAR String::lastIndexOf(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _needle;
if (_length > 0)
_needle = _args[0];
else
return NerdCore::VAR(-1);
std::string::size_type loc = this->value.find_last_of((std::string)_needle, 0);
if (loc != std::string::npos)
{
return NerdCore::VAR((int)loc);
}
return NerdCore::VAR(-1);
}
NerdCore::VAR String::search(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _needle;
if (_length > 0)
_needle = _args[0];
else
return NerdCore::VAR(-1);
std::string::size_type loc = this->value.find((std::string)_needle, 0);
if (loc != std::string::npos)
{
return NerdCore::VAR((int)loc);
}
return NerdCore::VAR(-1);
}
NerdCore::VAR String::slice(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _start;
NerdCore::VAR _end;
if (_length > 0)
_start = _args[0];
else
return NerdCore::VAR(this->value);
if (_length > 1)
_end = _args[1];
if (_end.type == NerdCore::Enum::Type::Null)
return NerdCore::VAR(this->value.substr((int)_start, std::string::npos));
int _endIndex = (int)_end - (int)_start;
return NerdCore::VAR(this->value.substr((int)_start, _endIndex));
}
NerdCore::VAR String::substr(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _start;
NerdCore::VAR _end;
if (_length > 0)
_start = _args[0];
else
return NerdCore::VAR(this->value);
if (_length > 1)
_end = _args[1];
if (_end.type == NerdCore::Enum::Type::Null)
return NerdCore::VAR(this->value.substr((int)_start, std::string::npos));
return NerdCore::VAR(this->value.substr((int)_start, (int)_end));
}
NerdCore::VAR String::replace(NerdCore::VAR* _args, int _length) const
{
NerdCore::VAR _search;
NerdCore::VAR _replace;
if (_length > 0)
_search = _args[0];
else
return NerdCore::VAR(this->value);
if (_length > 1)
_replace = _args[1];
size_t start_pos = this->value.find((std::string)_search);
if (start_pos == std::string::npos)
{
return NerdCore::VAR(value);
}
std::string _new = value;
return NerdCore::VAR(_new.replace(start_pos, ((std::string)_search).length(), (std::string)_replace));
}
/* END STRING METHODS */
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/string_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class String : public virtual Base
{
public:
// Constructors
String();
String(std::string val);
String(const char* val);
// Properties
std::string value;
NerdCore::Type::object_t object;
NerdCore::VAR length;
void* bind = nullptr;
count_t counter = 1;
// Methods
inline void Delete() noexcept;
inline void* Copy() noexcept;
// Native cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
inline NerdCore::VAR& GetSet(NerdCore::VAR keyVar);
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
// Comparation operators
template
NerdCore::VAR operator() (Args... args)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::Global::null;
}
String operator!() const;
bool operator==(const String &_v1) const;
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const String &_v1) const;
bool operator<(const String &_v1) const;
bool operator<=(const String &_v1) const;
bool operator>(const String &_v1) const;
bool operator>=(const String &_v1) const;
// Numeric operators
String operator+() const;
String operator-() const;
String operator++(const int _v1);
String operator--(const int _v1);
String operator+(const String &_v1) const;
String operator+=(const String &_v1);
String operator-(const String &_v1) const;
String operator-=(const String &_v1);
String operator*(const String &_v1) const;
String operator*=(const String &_v1);
// TODO: "**" and "**=" operators
String operator/(const String &_v1) const;
String operator/=(const String &_v1);
String operator%(const String &_v1) const;
String operator%=(const String &_v1);
String operator&(const String &_v1) const;
String operator|(const String &_v1) const;
String operator^(const String &_v1) const;
String operator~() const;
String operator>>(const String &_v1) const;
String operator<<(const String &_v1) const;
String operator&=(const String &_v1);
String operator|=(const String &_v1);
String operator^=(const String &_v1);
String operator>>=(const String &_v1);
String operator<<=(const String &_v1);
// TODO: ">>>" and ">>>=" operators
/*** STRING METHODS ***/
NerdCore::VAR toString(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR split(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR indexOf(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR lastIndexOf(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR search(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR slice(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR substr(NerdCore::VAR* _args, int _length) const;
NerdCore::VAR replace(NerdCore::VAR* _args, int _length) const;
/* END STRING METHODS */
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/struct.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "struct_header.h"
#include
#include
namespace NerdCore::Class
{
// Constructors
Struct::Struct() {}
Struct::Struct(void *val)
{
value = val;
}
Struct::Struct(void *val, void* fn)
{
value = val;
Clean = (NerdCore::Type::clean_struct*)fn;
}
// Methods
inline void Struct::Delete() noexcept
{
if (--counter == 0)
{
(*static_cast(Clean))(value);
delete Clean;
delete this;
}
}
inline void* Struct::Copy() noexcept
{
counter++;
return this;
}
// Native cast
Struct::operator bool() const noexcept { return true; }
Struct::operator double() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Struct::operator int() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Struct::operator long long() const noexcept
{
#ifdef __NERD_ENV_ARDUINO
return 0;
#else
return std::numeric_limits::quiet_NaN();
#endif
}
Struct::operator std::string() const noexcept
{
return "[native struct]";
}
// Main operators
NerdCore::VAR const Struct::operator[](NerdCore::VAR key) const
{
return NerdCore::Global::null;
}
NerdCore::VAR &Struct::operator[](NerdCore::VAR key)
{
#ifndef __NERD__OBJECT_VECTOR
return object[(std::string)key];
#else
for (auto & search : object)
{
if (((std::string)key).compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t((std::string)key, NerdCore::VAR()));
return object[object.size() - 1].second;
#endif
}
NerdCore::VAR &Struct::operator[](int key)
{
#ifndef __NERD__OBJECT_VECTOR
return object[std::to_string(key)];
#else
std::string _str = std::to_string(key);
for (auto & search : object)
{
if (_str.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::VAR()));
return object[object.size() - 1].second;
#endif
}
NerdCore::VAR &Struct::operator[](double key)
{
#ifndef __NERD__OBJECT_VECTOR
return object[std::to_string(key)];
#else
std::string _str = std::to_string(key);
for (auto & search : object)
{
if (_str.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(_str, NerdCore::VAR()));
return object[object.size() - 1].second;
#endif
}
NerdCore::VAR &Struct::operator[](const char* key)
{
std::string str = key;
#ifndef __NERD__OBJECT_VECTOR
return object[str];
#else
for (auto & search : object)
{
if (str.compare(search.first) == 0)
{
return search.second;
}
}
object.push_back(NerdCore::Type::pair_t(str, NerdCore::VAR()));
return object[object.size() - 1].second;
#endif
}
// Comparation operators
NerdCore::VAR Struct::operator!() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
bool Struct::operator==(const NerdCore::VAR &_v1) const { return false; }
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool Struct::operator!=(const NerdCore::VAR &_v1) const { return true; }
bool Struct::operator<(const NerdCore::VAR &_v1) const { return false; }
bool Struct::operator<=(const NerdCore::VAR &_v1) const { return true; }
bool Struct::operator>(const NerdCore::VAR &_v1) const { return false; }
bool Struct::operator>=(const NerdCore::VAR &_v1) const { return true; }
// Numeric operators
NerdCore::VAR Struct::operator+() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator-() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator++(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator--(const int _v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator+(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator+=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator-(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator-=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator*(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator*=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
// TODO: "**" and "**=" operators
NerdCore::VAR Struct::operator/(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator/=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator%(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator%=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator&(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator|(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator^(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator~() const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator>>(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator<<(const NerdCore::VAR &_v1) const
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator&=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator|=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator^=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator>>=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
NerdCore::VAR Struct::operator<<=(const NerdCore::VAR &_v1)
{
#if !defined(__NERD_ENV_ARDUINO) && !defined(__NERD_ENV_ESP32)
throw InvalidTypeException();
#endif
return NerdCore::VAR();
}
// TODO: ">>>" and ">>>=" operators
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/class/struct_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "_meta.h"
namespace NerdCore::Class
{
class Struct : public virtual Base
{
public:
// Constructors
Struct();
Struct(void* val);
Struct(void* val, void* fn);
// Properties
count_t counter = 1;
void* value = nullptr;
NerdCore::Type::object_t object;
NerdCore::Type::clean_struct* Clean;
// Methods
inline void Delete() noexcept;
inline void StructDelete() noexcept;
inline void* Copy() noexcept;
// Struct cast
explicit operator bool() const noexcept;
explicit operator double() const noexcept;
explicit operator int() const noexcept;
explicit operator long long() const noexcept;
explicit operator std::string() const noexcept;
// Main operators
NerdCore::VAR const operator[](NerdCore::VAR key) const;
NerdCore::VAR &operator[](NerdCore::VAR key);
NerdCore::VAR &operator[](int key);
NerdCore::VAR &operator[](double key);
NerdCore::VAR &operator[](const char* key);
template
NerdCore::VAR operator()(Args... args) const
{
auto _args = NerdCore::Type::vector_t{(NerdCore::VAR)args...};
return (*static_cast *>(value))(_args);
}
// Comparation operators
NerdCore::VAR operator!() const;
bool operator==(const NerdCore::VAR &_v1) const;
// === emulated with __NERD_EQUAL_VALUE_AND_TYPE
// !== emulated with __NERD_NOT_EQUAL_VALUE_AND_TYPE
bool operator!=(const NerdCore::VAR &_v1) const;
bool operator<(const NerdCore::VAR &_v1) const;
bool operator<=(const NerdCore::VAR &_v1) const;
bool operator>(const NerdCore::VAR &_v1) const;
bool operator>=(const NerdCore::VAR &_v1) const;
// Numeric operators
NerdCore::VAR operator+() const;
NerdCore::VAR operator-() const;
NerdCore::VAR operator++(const int _v1);
NerdCore::VAR operator--(const int _v1);
NerdCore::VAR operator+(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator+=(const NerdCore::VAR &_v1);
NerdCore::VAR operator-(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator-=(const NerdCore::VAR &_v1);
NerdCore::VAR operator*(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator*=(const NerdCore::VAR &_v1);
// TODO: "**" and "**=" operators
NerdCore::VAR operator/(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator/=(const NerdCore::VAR &_v1);
NerdCore::VAR operator%(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator%=(const NerdCore::VAR &_v1);
NerdCore::VAR operator&(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator|(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator^(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator~() const;
NerdCore::VAR operator>>(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator<<(const NerdCore::VAR &_v1) const;
NerdCore::VAR operator&=(const NerdCore::VAR &_v1);
NerdCore::VAR operator|=(const NerdCore::VAR &_v1);
NerdCore::VAR operator^=(const NerdCore::VAR &_v1);
NerdCore::VAR operator>>=(const NerdCore::VAR &_v1);
NerdCore::VAR operator<<=(const NerdCore::VAR &_v1);
// TODO: ">>>" and ">>>=" operators
};
} // namespace NerdCore::Class
================================================
FILE: compiler/native/nerdcore/src/classes.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "./class/array.h"
#include "./class/function.h"
#include "./class/native.h"
#include "./class/struct.h"
#include "./class/fixed_array.h"
#include "./class/object.h"
#include "./class/string.h"
================================================
FILE: compiler/native/nerdcore/src/classes_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#define __INC_Nerd_CLASSES_HEADER
#include "./class/base_header.h"
#include "./class/array_header.h"
#include "./class/object_header.h"
#include "./class/function_header.h"
#include "./class/native_header.h"
//#include "./class/native_tpl_header.h"
#include "./class/struct_header.h"
#include "./class/fixed_array_header.h"
#include "./class/string_header.h"
================================================
FILE: compiler/native/nerdcore/src/enum.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace NerdCore::Enum
{
enum Type
{
Null,
Boolean,
Number,
String,
Native,
NativeTPL,
Struct,
FixedArray,
Array,
Object,
Function,
};
}
================================================
FILE: compiler/native/nerdcore/src/functions.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR getArguments(int argc, char** argv)
{
NerdCore::VAR __NJS_ARGS = new NerdCore::Class::Array();
for( int i = 0; i < argc; i++)
{
__NJS_ARGS[i] = argv[i];
}
return __NJS_ARGS;
}
================================================
FILE: compiler/native/nerdcore/src/functions_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR __NERD_Log_Console(NerdCore::VAR _var);
NerdCore::VAR __NERD_Object_Keys(NerdCore::VAR _var);
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var);
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var, bool _bracket);
NerdCore::VAR __NERD_Object_Clone(NerdCore::VAR& _var);
NerdCore::VAR __NERD_Object_Set(std::string _index, NerdCore::VAR _value, NerdCore::Type::object_t *_obj);
std::string __NERD_DOUBLE_TO_STRING(double _var);
/*** String MANIPULATION ***/
#ifdef __NERD_ENV_ARDUINO
namespace std
{
template
string to_string(m _var)
{
std::stringstream output;
output << _var;
return output.str();
}
int isnan(double __x)
{
return ::isnan(__x);
}
inline int isfinite(double __x)
{
return ::isfinite(__x);
}
inline int signbit(double __x)
{
return ::signbit(__x);
}
inline double stod(std::string _str, std::string::size_type* sz)
{
*sz = _str.length();
return String(_str.c_str()).toFloat();
}
inline int stoi(std::string _str, std::string::size_type* sz, int _base)
{
*sz = _str.length();
return String(_str.c_str()).toInt();
}
inline long long stoll(std::string _str, std::string::size_type* sz, int _base)
{
*sz = _str.length();
return atol(_str.c_str());
}
}
template
m remainder(m _dividend, n _divisor)
{
m quotient = (int)_dividend / (int)_divisor;
m remainder = (int)_dividend % (int)_divisor;
return remainder;
}
#endif
template
std::string __NERD_Concat_To_Str(m _left, n _right)
{
std::stringstream output;
output << _left << _right;
return output.str();
}
/* END String MANIPULATION */
/*** Number MANIPULATION ***/
template
int __NERD_Str_To_Int(m _left)
{
int out;
std::stringstream output;
output << _left;
output >> out;
return out;
}
template
double __NERD_Str_To_Double(m _left)
{
double out;
std::stringstream output;
output << _left;
output >> out;
return out;
}
/* END Number MANIPULATION */
NerdCore::VAR getArguments(int argc, char** argv);
================================================
FILE: compiler/native/nerdcore/src/macro.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*** HELPERS ***/
#define __NERD_GET_String(_var) _var.get().s->value
#define __NERD_Create_Boolean(_value) NerdCore::VAR(NerdCore::Enum::Type::Boolean, _value)
#define __NERD_Create_Number(_value) NerdCore::VAR(_value)
#define __NERD_Create_Function(_value) NerdCore::VAR(NerdCore::Enum::Type::Function, _value)
#define __NERD_Create_Undefined() NerdCore::VAR()
#define __NERD_Create_String(_value) NerdCore::VAR(_value)
#define __NERD_Create_Infinity() NerdCore::VAR(std::numeric_limits::infinity)
#define __NERD_Create_Null() NerdCore::VAR(NerdCore::Enum::Type::Null, 0)
#define __NERD_Create_Struct(_value) NerdCore::VAR(new _value(), new NerdCore::Type::clean_struct([](void* _ptr){ delete (_value*)_ptr;}))
#define __NERD_Create_FixedArray(_length) NerdCore::VAR(new NerdCore::Class::FixedArray(_length))
#define __NERD_Create_Lambda(name) NerdCore::Type::function_t* name = new NerdCore::Type::function_t([](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH)
#define __NERD_Create_Ptr_Scoped_Anon(__CONTENT__) new NerdCore::Type::function_t([&](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH) mutable -> NerdCore::Global::var { __CONTENT__ })
#define __NERD_Create_Ptr_Scoped_Copy_Anon(__CONTENT__) new NerdCore::Type::function_t([=](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH) mutable -> NerdCore::Global::var { __CONTENT__ })
#define __NERD_Create_Ptr_Scoped_Copy_Anon_With_Ref(__FN__, __CONTENT__) new NerdCore::Type::function_t([=, &__FN__](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH) mutable -> NerdCore::Global::var { __CONTENT__ })
#define __NERD_Create_Ptr_Unscoped_With_Copy(__FN__, __CONTENT__) new NerdCore::Type::function_t([__FN__](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH) mutable -> NerdCore::Global::var { __CONTENT__ })
#define __NERD_Create_Ptr_Unscoped_Anon(__CONTENT__) new NerdCore::Type::function_t([](NerdCore::VAR& __NERD_THIS, NerdCore::VAR* __NERD_VARARGS, int __NERD_VARLENGTH) -> NerdCore::Global::var{ __CONTENT__ })
#define __NERD_Create_Var_Scoped_Anon(__CONTENT__) NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_Create_Ptr_Scoped_Anon(__CONTENT__))
#define __NERD_Create_Var_Unscoped_Anon(__CONTENT__) NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_Create_Ptr_Unscoped_Anon(__CONTENT__))
#define __NERD_Create_Var_Scoped_Copy_Anon(__CONTENT__) NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_Create_Ptr_Scoped_Copy_Anon(__CONTENT__))
#define __NERD_Create_Var_Unscoped_With_Copy(__FN__, __CONTENT__) NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_Create_Ptr_Unscoped_With_Copy(__FN__, __CONTENT__))
#define __NERD_Create_Var_Scoped_Copy_Anon_With_Ref(__FN__, __CONTENT__) NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_Create_Ptr_Scoped_Copy_Anon_With_Ref(__FN__, __CONTENT__))
#define __NERD_Init_Int(_name, _value) int _name = _value
#define __NERD_Init_Double(_name, _value) double _name = _value
#define __NERD_Init_String(_name, _value) std::string _name = _value
#define __NERD_EXCEPTION_PARAMETER NerdCore::VAR &e
#define finally ;
#define __NERD_Throw_Error(_err) NerdCore::VAR(NerdCore::VAR(_err) + NerdCore::VAR(", line: ") + std::to_string(__LINE__) + NerdCore::VAR(", file: ") + NerdCore::VAR(__FILE__))
#define __NERD_Boolean_TRUE __NERD_Create_Boolean(true)
#define __NERD_Boolean_FALSE __NERD_Create_Boolean(false)
#define __NERD_FAST_INT double
#define __NERD_CreateMethodToClass(_name, _fn) __NERD_Object_Set(_name, __NERD_Create_Var_Scoped_Anon( return _fn(NerdCore::VAR& __NERD_THIS, __NERD_VARARGS, __NERD_VARLENGTH); ), &object);
#define __NERD_NEW(_fn) ((NerdCore::Class::Function*)_fn.data.ptr)->New
#define __NERD_Access_Struct(_exp, _name) (*(_name*)((NerdCore::Class::Struct*)_exp.data.ptr)->value)
#define arguments() new NerdCore::Class::FixedArray(__NERD_VARARGS, __NERD_VARLENGTH);
//#define __NERD_Native_Ptr(_var, _type) ((_type)((NerdCore::Class::NativeTPL<_type>*)_var.data.ptr)->value)
#define __NERD_OBJECT(_var) ((NerdCore::Class::Object*)_var.data.ptr)
#define __NERD_ARRAY(_var) ((NerdCore::Class::Array*)_var.data.ptr)
#define __NERD_FUNCTION(_var) ((NerdCore::Class::Function*)_var.data.ptr)
#define __NERD_BIND(_var, _function, _bind) _var = _function;((NerdCore::Class::Function*)_var.data.ptr)->bind = _bind;
#define Prototype() __NERD_Create_Var_Scoped_Copy_Anon( return __NERD_THIS; )
================================================
FILE: compiler/native/nerdcore/src/native/double.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR operator+(double _i, NerdCore::VAR _v)
{
if(_v.type == NerdCore::Enum::Type::String) return __NERD_DOUBLE_TO_STRING(_i) + (std::string)_v;
else return _i + (double)_v;
}
void operator+=(double& _i, NerdCore::VAR _v)
{
_i += (double)_v;
}
double operator-(double _i, NerdCore::VAR _v)
{
if(_v.type == NerdCore::Enum::Type::String) return std::numeric_limits::quiet_NaN();
return _i - (double)_v;
}
void operator-=(double& _i, NerdCore::VAR _v)
{
_i -= (double)_v;
}
double operator*(double _i, NerdCore::VAR _v)
{
if(_v.type == NerdCore::Enum::Type::String) return std::numeric_limits::quiet_NaN();
return _i * (double)_v;
}
void operator*=(double& _i, NerdCore::VAR _v)
{
_i *= (double)_v;
}
double operator/(double _i, NerdCore::VAR _v)
{
if(_v.type == NerdCore::Enum::Type::String) return std::numeric_limits::quiet_NaN();
return _i / (double)_v;
}
void operator/=(double& _i, NerdCore::VAR _v)
{
_i /= _v;
}
double operator%(double _i, NerdCore::VAR _v)
{
return (int)_i % (int)_v;
}
void operator%=(double& _i, NerdCore::VAR _v)
{
_i %= _v;
}
double operator==(double _i, NerdCore::VAR _v)
{
return _i == (double)_v;
}
double operator!=(double _i, NerdCore::VAR _v)
{
return _i != (double)_v;
}
double operator>(double _i, NerdCore::VAR _v)
{
return _i > (double)_v;
}
double operator>=(double _i, NerdCore::VAR _v)
{
return _i >= (double)_v;
}
double operator<(double _i, NerdCore::VAR _v)
{
return _i < (double)_v;
}
double operator<=(double _i, NerdCore::VAR _v)
{
return _i <= (double)_v;
}
================================================
FILE: compiler/native/nerdcore/src/native/double_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR operator+(double _i, NerdCore::VAR _v);
void operator+=(double& _i, NerdCore::VAR _v);
double operator-(double _i, NerdCore::VAR _v);
void operator-=(double& _i, NerdCore::VAR _v);
double operator*(double _i, NerdCore::VAR _v);
void operator*=(double& _i, NerdCore::VAR _v);
double operator/(double _i, NerdCore::VAR _v);
void operator/=(double& _i, NerdCore::VAR _v);
double operator%(double _i, NerdCore::VAR _v);
void operator%=(double& _i, NerdCore::VAR _v);
double operator==(double _i, NerdCore::VAR _v);
double operator!=(double _i, NerdCore::VAR _v);
double operator>(double _i, NerdCore::VAR _v);
double operator>=(double _i, NerdCore::VAR _v);
double operator<(double _i, NerdCore::VAR _v);
double operator<=(double _i, NerdCore::VAR _v);
================================================
FILE: compiler/native/nerdcore/src/native/int.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR operator+(int _i, NerdCore::VAR _v)
{
if(_v.type == NerdCore::Enum::Type::String) return __NERD_DOUBLE_TO_STRING(_i) + (std::string)_v;
else return _i + (double)_v;
}
void operator+=(int& _i, NerdCore::VAR _v)
{
_i += (double)_v;
}
double operator-(int _i, NerdCore::VAR _v)
{
return _i - (double)_v;
}
void operator-=(int& _i, NerdCore::VAR _v)
{
_i -= (double)_v;
}
double operator*(int _i, NerdCore::VAR _v)
{
return _i * (double)_v;
}
void operator*=(int& _i, NerdCore::VAR _v)
{
_i *= _v;
}
double operator/(int _i, NerdCore::VAR _v)
{
return _i / (double)_v;
}
void operator/=(int& _i, NerdCore::VAR _v)
{
_i /= _v;
}
double operator%(int _i, NerdCore::VAR _v)
{
return (int)_i % (int)_v;
}
void operator%=(int& _i, NerdCore::VAR _v)
{
_i %= _v;
}
double operator==(int _i, NerdCore::VAR _v)
{
return _i == (double)_v;
}
double operator!=(int _i, NerdCore::VAR _v)
{
return _i != (double)_v;
}
double operator>(int _i, NerdCore::VAR _v)
{
return _i > (double)_v;
}
double operator>=(int _i, NerdCore::VAR _v)
{
return _i >= (double)_v;
}
double operator<(int _i, NerdCore::VAR _v)
{
return _i < (double)_v;
}
double operator<=(int _i, NerdCore::VAR _v)
{
return _i <= (double)_v;
}
================================================
FILE: compiler/native/nerdcore/src/native/int_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR operator+(int _i, NerdCore::VAR _v);
void operator+=(int& _i, NerdCore::VAR _v);
double operator-(int _i, NerdCore::VAR _v);
void operator-=(int& _i, NerdCore::VAR _v);
double operator*(int _i, NerdCore::VAR _v);
void operator*=(int& _i, NerdCore::VAR _v);
double operator/(int _i, NerdCore::VAR _v);
void operator/=(int& _i, NerdCore::VAR _v);
double operator%(int _i, NerdCore::VAR _v);
void operator%=(int& _i, NerdCore::VAR _v);
double operator==(int _i, NerdCore::VAR _v);
double operator!=(int _i, NerdCore::VAR _v);
double operator>(int _i, NerdCore::VAR _v);
double operator>=(int _i, NerdCore::VAR _v);
double operator<(int _i, NerdCore::VAR _v);
double operator<=(int _i, NerdCore::VAR _v);
================================================
FILE: compiler/native/nerdcore/src/native.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "native/int.h"
#include "native/double.h"
================================================
FILE: compiler/native/nerdcore/src/native_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "native/int_header.h"
#include "native/double_header.h"
================================================
FILE: compiler/native/nerdcore/src/nerd.cpp
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "nerd.hpp"
#include "functions.h"
#include "native.h"
#include "values.h"
#include "class/number.h"
#include "var.h"
#include "objmgmt.h"
#include "classes.h"
#include "operator.h"
#include "stdfn.h"
================================================
FILE: compiler/native/nerdcore/src/nerd.hpp
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define _USE_MATH_DEFINES
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define _USE_MATH_DEFINES
#include
#include
#include
#ifdef __NERD_ENV_ARDUINO
#include
#include
#include
#include
#include
#include
#include
#undef max
#undef min
#include
#else
#include
#include
#include
#include
#include
#include
#endif
#include "enum.h"
#include "macro.h"
namespace NerdCore
{
struct VAR;
namespace Class
{
class Base;
class Undefined;
class Boolean;
class String;
class Array;
class Object;
class Function;
class Native;
class Struct;
class FixedArray;
//template
//class NativeTPL;
}
} // namespace NerdCore
#include "type_header.h"
#include "var_header.h"
#include "values_header.h"
#include "functions_header.h"
#include "classes_header.h"
#include "native_header.h"
#include "class/number_header.h"
#include "objmgmt_header.h"
#include "operator_header.h"
#include "stdfn_header.h"
================================================
FILE: compiler/native/nerdcore/src/objmgmt.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR __NERD_delete(NerdCore::VAR _left, NerdCore::VAR _right)
{
if(_left.type == NerdCore::Enum::Type::Object)
{
((NerdCore::Class::Object*)_left.data.ptr)->jsDelete(_right);
return __NERD_Boolean_TRUE;
}
else if(_left.type == NerdCore::Enum::Type::Array)
{
((NerdCore::Class::Array*)_left.data.ptr)->jsDelete(_right);
return __NERD_Boolean_TRUE;
}
else if(_left.type == NerdCore::Enum::Type::Function)
{
((NerdCore::Class::Function*)_left.data.ptr)->jsDelete(_right);
return __NERD_Boolean_TRUE;
}
return __NERD_Boolean_FALSE;
}
/*** ***/
#ifndef __NERD__OBJECT_VECTOR
NerdCore::VAR __NERD_Object_Set(std::string _index, NerdCore::VAR _value, NerdCore::Type::object_t *_obj)
{
if (_value.type == NerdCore::Enum::Type::String)
{
(*_obj)[_index] = new NerdCore::Class::String((std::string)_value);
}
else
{
(*_obj)[_index].data.ptr = _value.data.ptr;
}
return NerdCore::Global::null;
}
#else
NerdCore::VAR __NERD_Object_Set(std::string _index, NerdCore::VAR _value, NerdCore::Type::object_t *_obj)
{
int _j = (*_obj).size();
for (int _i = 0; _i < _j; _i++)
{
if (_index.compare((*_obj)[_i].first) == 0)
{
if (_value.type == NerdCore::Enum::Type::String)
{
(*_obj)[_i].second = new NerdCore::Class::String((std::string)_value);
}
else
{
(*_obj)[_i].second.data.ptr = _value.data.ptr;
}
return NerdCore::Global::null;
}
}
(*_obj).push_back(NerdCore::Type::pair_t(_index, _value));
return NerdCore::Global::null;
}
#endif
/**/
NerdCore::VAR __NERD_Object_Set(NerdCore::VAR _index, NerdCore::VAR _value, NerdCore::VAR _array)
{
if (_array.type == NerdCore::Enum::Type::Array && _index.type == NerdCore::Enum::Type::Number)
{
if (((NerdCore::Class::Array*)_array.data.ptr)->value.size() <= (int)_index.data.number)
{
((NerdCore::Class::Array*)_array.data.ptr)->value.resize( (int)_index.data.number + 1);
}
((NerdCore::Class::Array*)_array.data.ptr)->value.at( (int)_index.data.number ) = _value;
return NerdCore::Global::null;
}
else if (_array.type == NerdCore::Enum::Type::Object || _array.type == NerdCore::Enum::Type::String || _array.type == NerdCore::Enum::Type::Function || _array.type == NerdCore::Enum::Type::Array || _array.type == NerdCore::Enum::Type::Native)
{
NerdCore::Type::object_t *_obj;
if (_array.type == NerdCore::Enum::Type::Object)
_obj = &((NerdCore::Class::Object*)_array.data.ptr)->object;
else
return NerdCore::Global::null;
return __NERD_Object_Set((std::string)_index, _value, _obj);
}
return NerdCore::Global::null;
}
/* typeof */
const std::string _array[] = {"null", "boolean", "number", "string", "native", "native", "struct", "fixed_array", "array", "object", "function" };
std::string type_of(NerdCore::Global::var _var)
{
return _array[_var.type];
}
std::string typeof(NerdCore::Global::var _var)
{
return _array[_var.type];
}
================================================
FILE: compiler/native/nerdcore/src/objmgmt_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR __NERD_delete(NerdCore::VAR _left, NerdCore::VAR _right);
NerdCore::VAR __NERD_Object_Set(std::string _index, NerdCore::VAR _value, NerdCore::Type::object_t *_obj);
NerdCore::VAR __NERD_Object_Set(NerdCore::VAR _index, NerdCore::VAR _value, NerdCore::VAR _array);
std::string type_of(NerdCore::Global::var _var);
std::string typeof(NerdCore::Global::var _var);
/*
inline NerdCore::Global::var Object()
{
return NerdCore::VAR((NerdCore::Class::Object *)new NerdCore::Class::Object());
}
*/
/*
inline NerdCore::Global::var Object(NerdCore::Type::object_t _obj)
{
return new NerdCore::Class::Object(_obj);
}
*/
inline NerdCore::Global::var NewArray()
{
return new NerdCore::Class::Array();
}
inline NerdCore::Global::var FixedArray()
{
return new NerdCore::Class::FixedArray();
}
inline NerdCore::Global::var FixedArray(NerdCore::Global::var _length)
{
return new NerdCore::Class::FixedArray(_length);
}
inline NerdCore::Global::var FixedArray(int _length)
{
return new NerdCore::Class::FixedArray(_length);
}
================================================
FILE: compiler/native/nerdcore/src/operator.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
NerdCore::VAR operator+ (const char* _left, const NerdCore::VAR &_right)
{
return NerdCore::VAR(_left) + _right;
}
NerdCore::VAR operator+ (std::string _left, const NerdCore::VAR &_right)
{
return NerdCore::VAR(_left) + _right;
}
NerdCore::VAR operator* (const char* _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
NerdCore::VAR operator* (std::string _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
NerdCore::VAR operator- (const char* _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
NerdCore::VAR operator- (std::string _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
NerdCore::VAR operator/ (const char* _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
NerdCore::VAR operator/ (std::string _left, const NerdCore::VAR &_right)
{
return NerdCore::Global::NaN;
}
/*** operator== ***/
NerdCore::VAR operator== (NerdCore::VAR _left, int right)
{
return (double)_left == right;
}
NerdCore::VAR operator== (NerdCore::VAR _left, double right)
{
return (double)_left == right;
}
NerdCore::VAR operator== (NerdCore::VAR _left, std::string right)
{
return (std::string)_left == right;
}
NerdCore::VAR operator== (NerdCore::VAR _left, const char* right)
{
return (std::string)_left == std::string(right);
}
/* end operator== */
/*** operator!= ***/
NerdCore::VAR operator!= (NerdCore::VAR _left, int right)
{
return (double)_left != right;
}
NerdCore::VAR operator!= (NerdCore::VAR _left, double right)
{
return (double)_left != right;
}
NerdCore::VAR operator!= (NerdCore::VAR _left, std::string right)
{
return (std::string)_left != right;
}
NerdCore::VAR operator!= (NerdCore::VAR _left, const char* right)
{
return (std::string)_left != std::string(right);
}
/* end operator!= */
/*** operator| ***/
NerdCore::VAR operator| (NerdCore::VAR _left, int right)
{
return (int)_left | right;
}
NerdCore::VAR operator| (NerdCore::VAR _left, double right)
{
return (int)_left | (int)right;
}
NerdCore::VAR operator| (NerdCore::VAR _left, std::string right)
{
return (double)_left;
}
NerdCore::VAR operator| (NerdCore::VAR _left, const char* right)
{
return (double)_left;
}
/* end operator| */
/*** operator^ ***/
NerdCore::VAR operator^ (NerdCore::VAR _left, int right)
{
return (int)_left ^ right;
}
NerdCore::VAR operator^ (NerdCore::VAR _left, double right)
{
return (int)_left ^ (int)right;
}
NerdCore::VAR operator^ (NerdCore::VAR _left, std::string right)
{
return (double)_left;
}
NerdCore::VAR operator^ (NerdCore::VAR _left, const char* right)
{
return (double)_left;
}
/* end operator^ */
/*** operator& ***/
NerdCore::VAR operator& (NerdCore::VAR _left, int right)
{
return (int)_left & right;
}
NerdCore::VAR operator& (NerdCore::VAR _left, double right)
{
return (int)_left & (int)right;
}
NerdCore::VAR operator& (NerdCore::VAR _left, std::string right)
{
return (double)_left;
}
NerdCore::VAR operator& (NerdCore::VAR _left, const char* right)
{
return (double)_left;
}
/* end operator& */
/*** operator< **
inline NerdCore::VAR operator< (NerdCore::VAR _left, int right)
{
return _left.data.number < right;
}
inline NerdCore::VAR operator< (NerdCore::VAR _left, double right)
{
return _left.data.number < right;
}
*/
NerdCore::VAR operator< (NerdCore::VAR _left, std::string right)
{
return (std::string)_left < right;
}
NerdCore::VAR operator< (NerdCore::VAR _left, const char* right)
{
return (std::string)_left < std::string(right);
}
/* end operator< */
/*** operator<< ***/
NerdCore::VAR operator<< (NerdCore::VAR _left, int right)
{
return (int)_left << right;
}
NerdCore::VAR operator<< (NerdCore::VAR _left, double right)
{
return (int)_left << (int)right;
}
NerdCore::VAR operator<< (NerdCore::VAR _left, std::string right)
{
return (std::string)_left << right;
}
NerdCore::VAR operator<< (NerdCore::VAR _left, const char* right)
{
return (std::string)_left << std::string(right);
}
/* end operator<< */
/*** operator>= ***/
NerdCore::VAR operator<= (NerdCore::VAR _left, std::string right)
{
return (std::string)_left <= right;
}
NerdCore::VAR operator<= (NerdCore::VAR _left, const char* right)
{
return (std::string)_left < std::string(right);
}
/* end operator<= */
/*** operator> ***/
NerdCore::VAR operator> (NerdCore::VAR _left, std::string right)
{
return (std::string)_left > right;
}
NerdCore::VAR operator> (NerdCore::VAR _left, const char* right)
{
return (std::string)_left > std::string(right);
}
/* end operator> */
/*** operator>> ***/
NerdCore::VAR operator>> (NerdCore::VAR _left, int right)
{
return (int)_left >> right;
}
NerdCore::VAR operator>> (NerdCore::VAR _left, double right)
{
return (int)_left >> (int)right;
}
NerdCore::VAR operator>> (NerdCore::VAR _left, std::string right)
{
return (std::string)_left >> right;
}
NerdCore::VAR operator>> (NerdCore::VAR _left, const char* right)
{
return (std::string)_left >> std::string(right);
}
/* end operator>> */
/*** operator>= ***/
NerdCore::VAR operator>= (NerdCore::VAR _left, std::string right)
{
return (std::string)_left >= right;
}
NerdCore::VAR operator>= (NerdCore::VAR _left, const char* right)
{
return (std::string)_left > std::string(right);
}
/* end operator>= */
NerdCore::VAR __NERD_Boolean_Result(NerdCore::VAR _v)
{
if (_v.type == NerdCore::Enum::Type::Number)
return _v.data.number;
else if (_v.type == NerdCore::Enum::Type::Boolean)
return _v.data.number;
else if (_v.type == NerdCore::Enum::Type::String)
{
if (strlen(((NerdCore::Class::String*)_v.data.ptr)->value.c_str()) > 0)
return true;
else
return false;
}
else if (_v.type == NerdCore::Enum::Type::Array)
return true;
else
return false;
}
std::string __NERD_DOUBLE_TO_STRING(double _var)
{
std::ostringstream strout ;
strout << std::fixed << std::setprecision(14) << _var;
std::string str = strout.str() ;
size_t end = str.find_last_not_of( '0' ) + 1 ;
str = str.erase( end ) ;
end = str.find_last_not_of( '.' ) + 1 ;
str = str.erase( end ) ;
int exp = str.length();
if(exp > 21)
{
std::string first = str.substr(0, 1);
std::string second = str.substr(1, 15);
str = first + "." + second + "e+" + std::to_string(exp-1);
}
return str;
}
std::ostream &operator<<(std::ostream &os, const NerdCore::VAR &_v)
{
switch (_v.type)
{
case NerdCore::Enum::Type::Boolean:
if(_v.data.number) os << "true";
else os << "false";
break;
case NerdCore::Enum::Type::Number:
os << std::setprecision(14) << _v.data.number;
break;
case NerdCore::Enum::Type::String:
os << (std::string)(*(NerdCore::Class::String*)_v.data.ptr);
break;
case NerdCore::Enum::Type::Object:
os << __NERD_Object_Stringify(_v);
break;
case NerdCore::Enum::Type::FixedArray:
os << __NERD_Object_Stringify(_v);
break;
case NerdCore::Enum::Type::Array:
os << __NERD_Object_Stringify(_v);
break;
case NerdCore::Enum::Type::Struct:
os << (std::string)(*(NerdCore::Class::Struct*)_v.data.ptr);
break;
case NerdCore::Enum::Type::Native:
os << (std::string)(*(NerdCore::Class::Native*)_v.data.ptr);
break;
case NerdCore::Enum::Type::Function:
os << (std::string)(*(NerdCore::Class::Function*)_v.data.ptr);
break;
case NerdCore::Enum::Type::Null:
os << "null";
break;
default:
os << "null";
break;
}
return os;
}
NerdCore::VAR parseInt(NerdCore::VAR _str)
{
if (_str.type == NerdCore::Enum::Type::String)
{
#ifdef __NERD_ENV_ARDUINO
return NerdCore::Global::null;
#else
return __NERD_Create_Number((double)(*(NerdCore::Class::String*)_str.data.ptr));
#endif
}
else
return NerdCore::Global::null;
}
NerdCore::VAR __NERD_Log_Console(NerdCore::VAR _var)
{
#ifdef __NERD_ENV_ARDUINO
#else
std::cout << _var;
std::cout << std::endl;
#endif
return NerdCore::Global::null;
}
NerdCore::VAR __NERD_Log_Console(NerdCore::VAR* _var, int _length)
{
#ifdef __NERD_ENV_ARDUINO
#else
bool first = false;
for(int i = 0; i < _length; i++)
{
if(first) std::cout << " ";
std::cout << _var[i];
if(!first) first = true;
}
std::cout << std::endl;
#endif
return NerdCore::Global::null;
}
NerdCore::VAR __NERD_Object_Keys(NerdCore::VAR _var)
{
NerdCore::VAR _res = new NerdCore::Class::Array();
if (_var.type != NerdCore::Enum::Type::Object && _var.type != NerdCore::Enum::Type::Array)
{
return _res;
}
if(_var.type == NerdCore::Enum::Type::Array)
{
NerdCore::Type::vector_t *_arr = &((NerdCore::Class::Array*)_var.data.ptr)->value;
int _j = (*_arr).size();
for (int _i = 0; _i < _j; _i++)
{
_res[_i] = std::to_string(_i);
}
}
else
{
NerdCore::Type::object_t *_obj;
if(_var.type == NerdCore::Enum::Type::Object) _obj = &((NerdCore::Class::Object*)_var.data.ptr)->object;
#ifndef __NERD__OBJECT_VECTOR
int _k = 0;
for (auto _el: *_obj)
{
_res[_k] = _el.first;
_k++;
}
#else
int _j = (*_obj).size();
for (int _k = 0; _k < _j; _k++)
{
_res[_k] = (*_obj)[_k].first;
}
#endif
}
return _res;
}
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var)
{
return __NERD_Object_Stringify(_var, true);
}
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var, bool _bracket)
{
NerdCore::Enum::Type _t = _var.type;
if (_t == NerdCore::Enum::Type::Number)
{
return "\e[33m" + _var + "\e[0m";
}
else if (_t == NerdCore::Enum::Type::String)
{
return "\e[32m'" + ((NerdCore::Class::String*)_var.data.ptr)->value + "'\e[0m";
}
else if (_t == NerdCore::Enum::Type::Function)
{
return "'" + (std::string)(*(NerdCore::Class::Function*)_var.data.ptr) + "'";
}
else if (_t == NerdCore::Enum::Type::FixedArray)
{
NerdCore::VAR _res = "";
NerdCore::VAR *_arr = ((NerdCore::Class::FixedArray*)_var.data.ptr)->value;
if(_bracket) _res += " [ ";
int j = ((NerdCore::Class::FixedArray*)_var.data.ptr)->length;
int k = 0;
int l = 0;
for (int i = 0; i < j; i++)
{
if (l > 0) _res += ", ";
if(k > 0)
{
if(k == 1)
_res += "\e[90m<1 empty item>\e[0m, ";
else
_res += "\e[90m<" + std::to_string(k) + " empty items>\e[0m, ";
k = 0;
}
_res += __NERD_Object_Stringify((*_arr)[i], _bracket);
l++;
}
if(k > 0)
{
if (l > 0) _res += ", ";
if(k == 1)
_res += "\e[90m<1 empty item>\e[0m";
else
_res += "\e[90m<" + std::to_string(k) + " empty items>\e[0m";
l++;
}
if(_bracket) _res += " ] ";
return _res;
}
else if (_t == NerdCore::Enum::Type::Array)
{
NerdCore::VAR _res = NerdCore::Global::var("");
NerdCore::Type::vector_t *_arr = &((NerdCore::Class::Array*)_var.data.ptr)->value;
if(_bracket) _res += " [ ";
int j = (*_arr).size();
int k = 0;
int l = 0;
for (int i = 0; i < j; i++)
{
if (l > 0) _res += ", ";
if(k > 0)
{
if(k == 1)
_res += "\e[90m<1 empty item>\e[0m, ";
else
_res += "\e[90m<" + std::to_string(k) + " empty items>\e[0m, ";
k = 0;
}
NerdCore::Global::var test =
_res += __NERD_Object_Stringify((*_arr)[i], _bracket);
l++;
}
if(k > 0)
{
if (l > 0) _res += ", ";
if(k == 1)
_res += "\e[90m<1 empty item>\e[0m";
else
_res += "\e[90m<" + std::to_string(k) + " empty items>\e[0m";
l++;
}
if(_bracket) _res += " ] ";
return _res;
}
else if (_t == NerdCore::Enum::Type::Object)
{
NerdCore::VAR _res = "";
NerdCore::Type::object_t *_obj = &((NerdCore::Class::Object*)_var.data.ptr)->object;
_res = "{";
#ifndef __NERD__OBJECT_VECTOR
int _i = 0;
int _comma = 0;
for (auto _el: *_obj)
{
if(_el.second.type != NerdCore::Enum::Type::Null && _el.first != "__proto__" && _el.first != "prototype")
{
if (_comma > 0) _res += ", ";
_res += NerdCore::VAR("\"") + _el.first + "\"";
_res += ":";
_res += __NERD_Object_Stringify(_el.second);
_comma++;
}
_i++;
}
#else
int j = (*_obj).size();
for (int _i = 0; _i < j; _i++)
{
if (_i > 0) _res += ", ";
_res += NerdCore::VAR("\"") + (*_obj)[_i].first + "\"";
_res += ":";
_res += __NERD_Object_Stringify((*_obj)[_i].second);
}
#endif
_res += "}";
return _res;
}
else
return "";
}
NerdCore::VAR __NERD_Object_Clone(NerdCore::VAR& _var)
{
NerdCore::Enum::Type _t = _var.type;
switch(_t)
{
case NerdCore::Enum::Type::Null:
case NerdCore::Enum::Type::Number:
case NerdCore::Enum::Type::String:
case NerdCore::Enum::Type::Function:
return _var;
case NerdCore::Enum::Type::Array:
{
NerdCore::VAR _res = new NerdCore::Class::Array();
std::vector *_arr = &((NerdCore::Class::Array*)_var.data.ptr)->value;
int j = (*_arr).size();
for (int i = 0; i < j; i++)
{
_res[i] = __NERD_Object_Clone((*_arr)[i]);
}
return _res;
}
case NerdCore::Enum::Type::Object:
{
const NerdCore::VAR _res = new NerdCore::Class::Object();
NerdCore::Type::object_t *_obj = &((NerdCore::Class::Object*)_var.data.ptr)->object;
#ifndef __NERD__OBJECT_VECTOR
for (auto _el: *_obj)
{
_res[_el.first] = __NERD_Object_Clone(_el.second);
}
#else
int j = (*_obj).size();
for (int _i = 0; _i < j; _i++)
{
_res[(*_obj)[_i].first] = __NERD_Object_Clone((*_obj)[_i].second);
}
#endif
return _res;
}
default:
return NerdCore::Global::null;
}
}
void __NERD_Object_Construct(NerdCore::VAR _this, NerdCore::VAR _prototype)
{
if(_this.type == NerdCore::Enum::Type::Object && _prototype.type == NerdCore::Enum::Type::Object)
{
NerdCore::Type::object_t *_obj = &((NerdCore::Class::Object*)_prototype.data.ptr)->object;
#ifndef __NERD__OBJECT_VECTOR
for (auto _el: *_obj)
{
NerdCore::VAR _tmp = _this[_el.first];
if(_tmp.type == NerdCore::Enum::Type::Null)
{
_this[_el.first] = _el.second;
}
}
#else
int j = (*_obj).size();
for (int _i = 0; _i < j; _i++)
{
NerdCore::VAR _tmp = _this[(*_obj)[_i].first];
if(_tmp.type == NerdCore::Enum::Type::Null)
{
_this[(*_obj)[_i].first] = (*_obj)[_i].second;
}
}
#endif
}
}
NerdCore::VAR __NERD_CREATE_Function(void *_fn)
{
return NerdCore::VAR(NerdCore::Enum::Type::Function, _fn);
}
NerdCore::VAR __NERD_Create_Native(void *_native)
{
return NerdCore::VAR(NerdCore::Enum::Type::Null, _native);
}
void *__NERD_Get_Native(NerdCore::VAR _native)
{
return ((NerdCore::Class::Function*)_native.data.ptr);
}
__NERD_Create_Lambda(__IMPL_EVAL)
{
__NERD_Log_Console("eval not implemented, return NerdCore::Global::null");
return NerdCore::VAR();
});
NerdCore::VAR eval = __NERD_Create_Function(__IMPL_EVAL);
std::function *__NERD_IS_NAN = new std::function([](NerdCore::Type::vector_t _Nerd_VARARGS) {
NerdCore::VAR _test;
if (_Nerd_VARARGS.size() > 0)
_test = _Nerd_VARARGS[0];
else
return __NERD_Create_Boolean(0);
if (_test.type == NerdCore::Enum::Type::Number)
{
return __NERD_Create_Boolean(1);
}
return __NERD_Create_Boolean(0);
});
NerdCore::VAR isNaN = NerdCore::VAR(NerdCore::Enum::Type::Function, __NERD_IS_NAN);
NerdCore::VAR __NERD_EQUAL_VALUE_AND_TYPE(NerdCore::VAR _left, NerdCore::VAR _right)
{
if (_left.type == _right.type && (NerdCore::VAR)_left == (NerdCore::VAR)_right)
{
return __NERD_Create_Boolean(1);
}
return __NERD_Create_Boolean(0);
}
NerdCore::VAR __NERD_NOT_EQUAL_VALUE_AND_TYPE(NerdCore::VAR _left, NerdCore::VAR _right)
{
if (_left.type != _right.type || (bool)(_left != _right))
{
return __NERD_Create_Boolean(1);
}
return __NERD_Create_Boolean(0);
}
NerdCore::VAR operator+ (NerdCore::VAR _left, int right)
{
if (_left.type == NerdCore::Enum::Type::String) return (std::string)_left + __NERD_DOUBLE_TO_STRING(right);
else return (double)_left + right;
}
NerdCore::VAR operator+ (NerdCore::VAR _left, double right)
{
if (_left.type == NerdCore::Enum::Type::String) return (std::string)_left + __NERD_DOUBLE_TO_STRING(right);
else return (double)_left + right;
}
NerdCore::VAR operator+ (NerdCore::VAR _left, const char* right)
{
return (std::string)_left + std::string(right);
}
void operator+= (NerdCore::VAR& _left, std::string right)
{
std::string _str = (std::string)_left;
_str += right;
_left = _str;
}
void operator+= (NerdCore::VAR& _left, const char* right)
{
std::string _str = (std::string)_left;
_str += right;
_left = _str;
}
void operator+= (NerdCore::VAR& _left, int right)
{
if(_left.type == NerdCore::Enum::Type::Number) _left.data.number += right;
else
{
std::string _str = (std::string)_left;
_str += right;
_left = _str;
}
}
void operator+= (NerdCore::VAR& _left, double right)
{
if(_left.type == NerdCore::Enum::Type::Number) _left.data.number += right;
else
{
std::string _str = (std::string)_left;
_str += right;
_left.data.ptr = new NerdCore::Class::String(_str);
_left.type = NerdCore::Enum::Type::String;
}
}
NerdCore::VAR operator|| (NerdCore::VAR _left, int right)
{
if(_left.type != NerdCore::Enum::Type::Null) return _left;
else return right;
}
NerdCore::VAR operator|| (NerdCore::VAR _left, double right)
{
if(_left.type != NerdCore::Enum::Type::Null) return _left;
else return right;
}
NerdCore::VAR operator|| (NerdCore::VAR _left, std::string right)
{
if(_left.type != NerdCore::Enum::Type::Null) return _left;
else return right;
}
NerdCore::VAR operator|| (NerdCore::VAR _left, const char* right)
{
if(_left.type != NerdCore::Enum::Type::Null) return _left;
else return right;
}
/*** op* ***/
NerdCore::VAR operator* (NerdCore::VAR _left, int right)
{
return (double)_left * right;
}
NerdCore::VAR operator* (NerdCore::VAR _left, double right)
{
return (double)_left * right;
}
NerdCore::VAR operator* (NerdCore::VAR _left, std::string right)
{
return (double)_left * (double)(NerdCore::VAR(right));
}
NerdCore::VAR operator* (NerdCore::VAR _left, const char* right)
{
return (double)_left * (double)(NerdCore::VAR(right));
}
/* end op* */
/*** op- ***/
NerdCore::VAR operator- (NerdCore::VAR _left, int right)
{
return (double)_left - right;
}
NerdCore::VAR operator- (NerdCore::VAR _left, double right)
{
return (double)_left - right;
}
NerdCore::VAR operator- (NerdCore::VAR _left, std::string right)
{
return (double)_left - (double)(NerdCore::VAR(right));
}
NerdCore::VAR operator- (NerdCore::VAR _left, const char* right)
{
return (double)_left - (double)(NerdCore::VAR(right));
}
/* end op- */
/*** op/ ***/
NerdCore::VAR operator/ (NerdCore::VAR _left, int right)
{
return (double)_left / right;
}
NerdCore::VAR operator/ (NerdCore::VAR _left, double right)
{
return (double)_left / right;
}
NerdCore::VAR operator/ (NerdCore::VAR _left, std::string right)
{
return (double)_left / (double)(NerdCore::VAR(right));
}
NerdCore::VAR operator/ (NerdCore::VAR _left, const char* right)
{
return (double)_left / (double)(NerdCore::VAR(right));
}
/* end op/ */
/*** op% ***/
NerdCore::VAR operator% (NerdCore::VAR _left, int right)
{
return (int)_left % right;
}
NerdCore::VAR operator% (NerdCore::VAR _left, double right)
{
return (int)_left % (int)right;
}
NerdCore::VAR operator% (NerdCore::VAR _left, std::string right)
{
return (int)_left % (int)(NerdCore::VAR(right));
}
NerdCore::VAR operator% (NerdCore::VAR _left, const char* right)
{
return (int)_left % (int)(NerdCore::VAR(right));
}
/* end op% */
================================================
FILE: compiler/native/nerdcore/src/operator_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifdef __NERD_ENV_ARDUINO
bool operator==(std::string_view sw, const char* c)
{
return sw == std::string_view(c);
}
bool operator!=(std::string_view sw, const char* c)
{
return sw != std::string_view(c);
}
#else
constexpr bool operator==(std::string_view sw, const char* c)
{
return sw == std::string_view(c);
}
constexpr bool operator!=(std::string_view sw, const char* c)
{
return sw != std::string_view(c);
}
#endif
NerdCore::VAR __NERD_Boolean_Result(NerdCore::VAR _v);
std::string __NERD_DOUBLE_TO_STRING(double _var);
std::ostream &operator<<(std::ostream &os, const NerdCore::VAR &_v);
NerdCore::VAR parseInt(NerdCore::VAR _str);
NerdCore::VAR __NERD_Log_Console(NerdCore::VAR _var);
NerdCore::VAR __NERD_Log_Console(NerdCore::VAR* _var, int _length);
NerdCore::VAR __NERD_Object_Keys(NerdCore::VAR _var);
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var);
NerdCore::VAR __NERD_Object_Stringify(NerdCore::VAR _var, bool _bracket);
NerdCore::VAR __NERD_Object_Clone(NerdCore::VAR& _var);
void __NERD_Object_Construct(NerdCore::VAR _this, NerdCore::VAR _prototype);
NerdCore::VAR __NERD_CREATE_Function(void *_fn);
NerdCore::VAR __NERD_Create_Native(void *_native);
void *__NERD_Get_Native(NerdCore::VAR _native);
/*** REDIFINING STD OPERATORS ***/
NerdCore::VAR operator+ (const char* _left, const NerdCore::VAR &_right);
NerdCore::VAR operator+ (std::string _left, const NerdCore::VAR &_right);
NerdCore::VAR operator- (const char* _left, const NerdCore::VAR &_right);
NerdCore::VAR operator- (std::string _left, const NerdCore::VAR &_right);
NerdCore::VAR operator* (const char* _left, const NerdCore::VAR &_right);
NerdCore::VAR operator* (std::string _left, const NerdCore::VAR &_right);
NerdCore::VAR operator/ (const char* _left, const NerdCore::VAR &_right);
NerdCore::VAR operator/ (std::string _left, const NerdCore::VAR &_right);
inline bool operator< (NerdCore::VAR _left, const int right) noexcept
{
return _left.data.number < right;
}
inline bool operator< (NerdCore::VAR _left, const long long int right) noexcept
{
return _left.data.number < right;
}
inline bool operator< (NerdCore::VAR _left, const double right) noexcept
{
return _left.data.number < right;
}
NerdCore::VAR operator< (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator< (NerdCore::VAR _left, const char* right);
inline bool operator<= (NerdCore::VAR _left, const int right) noexcept
{
return _left.data.number <= right;
}
inline bool operator<= (NerdCore::VAR _left, const long long int right) noexcept
{
return _left.data.number <= right;
}
inline bool operator<= (NerdCore::VAR _left, const double right) noexcept
{
return _left.data.number <= right;
}
NerdCore::VAR operator<= (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator<= (NerdCore::VAR _left, const char* right);
inline bool operator> (NerdCore::VAR _left, const int right) noexcept
{
return _left.data.number > right;
}
inline bool operator> (NerdCore::VAR _left, const long long int right) noexcept
{
return _left.data.number > right;
}
inline bool operator> (NerdCore::VAR _left, const double right) noexcept
{
return _left.data.number > right;
}
NerdCore::VAR operator> (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator> (NerdCore::VAR _left, const char* right);
inline const bool operator>= (NerdCore::VAR _left, const int right) noexcept
{
return _left.data.number >= right;
}
inline bool operator>= (NerdCore::VAR _left, const long long int right) noexcept
{
return _left.data.number >= right;
}
inline bool operator>= (NerdCore::VAR _left, const double right) noexcept
{
return _left.data.number >= right;
}
NerdCore::VAR operator>= (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator>= (NerdCore::VAR _left, const char* right);
/*** END REDIFINING STD OPERATORS ***/
extern NerdCore::VAR eval;
extern std::function *__NERD_IS_NAN;
extern NerdCore::VAR isNaN;
NerdCore::VAR __NERD_EQUAL_VALUE_AND_TYPE(NerdCore::VAR _left, NerdCore::VAR _right);
NerdCore::VAR __NERD_NOT_EQUAL_VALUE_AND_TYPE(NerdCore::VAR _left, NerdCore::VAR _right);
NerdCore::VAR operator+ (NerdCore::VAR _left, int right);
NerdCore::VAR operator+ (NerdCore::VAR _left, double right);
void operator+= (NerdCore::VAR& _left, std::string right);
void operator+= (NerdCore::VAR& _left, const char* right);
void operator+= (NerdCore::VAR& _left, int right);
void operator+= (NerdCore::VAR& _left, double right);
NerdCore::VAR operator* (NerdCore::VAR _left, int right);
NerdCore::VAR operator* (NerdCore::VAR _left, double right);
NerdCore::VAR operator* (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator* (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator- (NerdCore::VAR _left, int right);
NerdCore::VAR operator- (NerdCore::VAR _left, double right);
NerdCore::VAR operator- (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator- (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator/ (NerdCore::VAR _left, int right);
NerdCore::VAR operator/ (NerdCore::VAR _left, double right);
NerdCore::VAR operator/ (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator/ (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator% (NerdCore::VAR _left, int right);
NerdCore::VAR operator% (NerdCore::VAR _left, double right);
NerdCore::VAR operator% (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator% (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator|| (NerdCore::VAR _left, int right);
NerdCore::VAR operator|| (NerdCore::VAR _left, double right);
NerdCore::VAR operator|| (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator|| (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator== (NerdCore::VAR _left, int right);
NerdCore::VAR operator== (NerdCore::VAR _left, double right);
NerdCore::VAR operator== (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator== (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator!= (NerdCore::VAR _left, int right);
NerdCore::VAR operator!= (NerdCore::VAR _left, double right);
NerdCore::VAR operator!= (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator!= (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator| (NerdCore::VAR _left, int right);
NerdCore::VAR operator| (NerdCore::VAR _left, double right);
NerdCore::VAR operator| (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator| (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator^ (NerdCore::VAR _left, int right);
NerdCore::VAR operator^ (NerdCore::VAR _left, double right);
NerdCore::VAR operator^ (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator^ (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator& (NerdCore::VAR _left, int right);
NerdCore::VAR operator& (NerdCore::VAR _left, double right);
NerdCore::VAR operator& (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator& (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator<< (NerdCore::VAR _left, int right);
NerdCore::VAR operator<< (NerdCore::VAR _left, double right);
NerdCore::VAR operator<< (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator<< (NerdCore::VAR _left, const char* right);
NerdCore::VAR operator>> (NerdCore::VAR _left, int right);
NerdCore::VAR operator>> (NerdCore::VAR _left, double right);
NerdCore::VAR operator>> (NerdCore::VAR _left, std::string right);
NerdCore::VAR operator>> (NerdCore::VAR _left, const char* right);
================================================
FILE: compiler/native/nerdcore/src/stdfn.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace NerdCore::Functions
{
NerdCore::VAR println()
{
#ifndef __NERD_ENV_ARDUINO
std::cout << std::endl;
#endif
return NerdCore::Global::null;
}
NerdCore::VAR println(NerdCore::VAR _var)
{
#ifndef __NERD_ENV_ARDUINO
std::cout << _var << std::endl;
#endif
return NerdCore::Global::null;
}
NerdCore::VAR print()
{
return NerdCore::Global::null;
}
NerdCore::VAR print(NerdCore::VAR _var)
{
#ifndef __NERD_ENV_ARDUINO
std::cout << _var;
#endif
return NerdCore::Global::null;
}
}
// no namespace
NerdCore::VAR length_of(NerdCore::VAR _var)
{
switch( _var.type)
{
case NerdCore::Enum::Type::Null:
return 0;
break;
case NerdCore::Enum::Type::Boolean:
return 1;
break;
case NerdCore::Enum::Type::Number:
return 1;
break;
case NerdCore::Enum::Type::String:
return (double)((std::string)_var).size();
break;
case NerdCore::Enum::Type::Array:
return (double)((NerdCore::Class::Array*)_var.data.ptr)->Size();
break;
case NerdCore::Enum::Type::FixedArray:
return (double)((NerdCore::Class::FixedArray*)_var.data.ptr)->length;
break;
case NerdCore::Enum::Type::Object:
return (double)((NerdCore::Class::Object*)_var.data.ptr)->Size();
break;
case NerdCore::Enum::Type::Native:
return (double)((NerdCore::Class::Native*)_var.data.ptr)->length;
break;
default:
return 0;
break;
}
return 0;
}
NerdCore::VAR size_of(NerdCore::VAR _var)
{
return (double)sizeof(_var);
}
================================================
FILE: compiler/native/nerdcore/src/stdfn_header.h
================================================
/*
Copyright (c) 2021 NerdLang - Adrien THIERRY and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace NerdCore::Functions
{
NerdCore::VAR println();
NerdCore::VAR println(NerdCore::VAR _var);
NerdCore::VAR print();
NerdCore::VAR print(NerdCore::VAR _var);
}
// no namespace
NerdCore::VAR length_of(NerdCore::VAR _var);
NerdCore::VAR size_of(NerdCore::VAR _var);
================================================
FILE: compiler/native/nerdcore/src/tsl/robin_growth_policy.h
================================================
/**
* MIT License
*
* Copyright (c) 2017 Thibaut Goetghebuer-Planchon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TSL_ROBIN_GROWTH_POLICY_H
#define TSL_ROBIN_GROWTH_POLICY_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef TSL_DEBUG
#define tsl_rh_assert(expr) assert(expr)
#else
#define tsl_rh_assert(expr) (static_cast(0))
#endif
/**
* If exceptions are enabled, throw the exception passed in parameter, otherwise
* call std::terminate.
*/
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \
(defined(_MSC_VER) && defined(_CPPUNWIND))) && \
!defined(TSL_NO_EXCEPTIONS)
#define TSL_RH_THROW_OR_TERMINATE(ex, msg) throw ex(msg)
#else
#define TSL_RH_NO_EXCEPTIONS
#ifdef TSL_DEBUG
#include
#define TSL_RH_THROW_OR_TERMINATE(ex, msg) \
do { \
std::cerr << msg << std::endl; \
std::terminate(); \
} while (0)
#else
#define TSL_RH_THROW_OR_TERMINATE(ex, msg) std::terminate()
#endif
#endif
#if defined(__GNUC__) || defined(__clang__)
#define TSL_RH_LIKELY(exp) (__builtin_expect(!!(exp), true))
#else
#define TSL_RH_LIKELY(exp) (exp)
#endif
#define TSL_RH_UNUSED(x) static_cast(x)
namespace tsl {
namespace rh {
/**
* Grow the hash table by a factor of GrowthFactor keeping the bucket count to a
* power of two. It allows the table to use a mask operation instead of a modulo
* operation to map a hash to a bucket.
*
* GrowthFactor must be a power of two >= 2.
*/
template
class power_of_two_growth_policy {
public:
/**
* Called on the hash table creation and on rehash. The number of buckets for
* the table is passed in parameter. This number is a minimum, the policy may
* update this value with a higher value if needed (but not lower).
*
* If 0 is given, min_bucket_count_in_out must still be 0 after the policy
* creation and bucket_for_hash must always return 0 in this case.
*/
explicit power_of_two_growth_policy(std::size_t& min_bucket_count_in_out) {
if (min_bucket_count_in_out > max_bucket_count()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
if (min_bucket_count_in_out > 0) {
min_bucket_count_in_out =
round_up_to_power_of_two(min_bucket_count_in_out);
m_mask = min_bucket_count_in_out - 1;
} else {
m_mask = 0;
}
}
/**
* Return the bucket [0, bucket_count()) to which the hash belongs.
* If bucket_count() is 0, it must always return 0.
*/
std::size_t bucket_for_hash(std::size_t hash) const noexcept {
return hash & m_mask;
}
/**
* Return the number of buckets that should be used on next growth.
*/
std::size_t next_bucket_count() const {
if ((m_mask + 1) > max_bucket_count() / GrowthFactor) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
return (m_mask + 1) * GrowthFactor;
}
/**
* Return the maximum number of buckets supported by the policy.
*/
std::size_t max_bucket_count() const {
// Largest power of two.
return (std::numeric_limits::max() / 2) + 1;
}
/**
* Reset the growth policy as if it was created with a bucket count of 0.
* After a clear, the policy must always return 0 when bucket_for_hash is
* called.
*/
void clear() noexcept { m_mask = 0; }
private:
static std::size_t round_up_to_power_of_two(std::size_t value) {
if (is_power_of_two(value)) {
return value;
}
if (value == 0) {
return 1;
}
--value;
for (std::size_t i = 1; i < sizeof(std::size_t) * CHAR_BIT; i *= 2) {
value |= value >> i;
}
return value + 1;
}
static constexpr bool is_power_of_two(std::size_t value) {
return value != 0 && (value & (value - 1)) == 0;
}
protected:
static_assert(is_power_of_two(GrowthFactor) && GrowthFactor >= 2,
"GrowthFactor must be a power of two >= 2.");
std::size_t m_mask;
};
/**
* Grow the hash table by GrowthFactor::num / GrowthFactor::den and use a modulo
* to map a hash to a bucket. Slower but it can be useful if you want a slower
* growth.
*/
template >
class mod_growth_policy {
public:
explicit mod_growth_policy(std::size_t& min_bucket_count_in_out) {
if (min_bucket_count_in_out > max_bucket_count()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
if (min_bucket_count_in_out > 0) {
m_mod = min_bucket_count_in_out;
} else {
m_mod = 1;
}
}
std::size_t bucket_for_hash(std::size_t hash) const noexcept {
return hash % m_mod;
}
std::size_t next_bucket_count() const {
if (m_mod == max_bucket_count()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
const double next_bucket_count =
std::ceil(double(m_mod) * REHASH_SIZE_MULTIPLICATION_FACTOR);
if (!std::isnormal(next_bucket_count)) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
if (next_bucket_count > double(max_bucket_count())) {
return max_bucket_count();
} else {
return std::size_t(next_bucket_count);
}
}
std::size_t max_bucket_count() const { return MAX_BUCKET_COUNT; }
void clear() noexcept { m_mod = 1; }
private:
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR =
1.0 * GrowthFactor::num / GrowthFactor::den;
static const std::size_t MAX_BUCKET_COUNT =
std::size_t(double(std::numeric_limits::max() /
REHASH_SIZE_MULTIPLICATION_FACTOR));
static_assert(REHASH_SIZE_MULTIPLICATION_FACTOR >= 1.1,
"Growth factor should be >= 1.1.");
std::size_t m_mod;
};
namespace detail {
#if SIZE_MAX >= ULLONG_MAX
#define TSL_RH_NB_PRIMES 51
#elif SIZE_MAX >= ULONG_MAX
#define TSL_RH_NB_PRIMES 40
#else
#define TSL_RH_NB_PRIMES 23
#endif
static constexpr const std::array PRIMES = {{
1u,
5u,
17u,
29u,
37u,
53u,
67u,
79u,
97u,
131u,
193u,
257u,
389u,
521u,
769u,
1031u,
1543u,
2053u,
3079u,
6151u,
12289u,
24593u,
49157u,
#if SIZE_MAX >= ULONG_MAX
98317ul,
196613ul,
393241ul,
786433ul,
1572869ul,
3145739ul,
6291469ul,
12582917ul,
25165843ul,
50331653ul,
100663319ul,
201326611ul,
402653189ul,
805306457ul,
1610612741ul,
3221225473ul,
4294967291ul,
#endif
#if SIZE_MAX >= ULLONG_MAX
6442450939ull,
12884901893ull,
25769803751ull,
51539607551ull,
103079215111ull,
206158430209ull,
412316860441ull,
824633720831ull,
1649267441651ull,
3298534883309ull,
6597069766657ull,
#endif
}};
template
static constexpr std::size_t mod(std::size_t hash) {
return hash % PRIMES[IPrime];
}
// MOD_PRIME[iprime](hash) returns hash % PRIMES[iprime]. This table allows for
// faster modulo as the compiler can optimize the modulo code better with a
// constant known at the compilation.
static constexpr const std::array
MOD_PRIME = {{
&mod<0>, &mod<1>, &mod<2>, &mod<3>, &mod<4>, &mod<5>,
&mod<6>, &mod<7>, &mod<8>, &mod<9>, &mod<10>, &mod<11>,
&mod<12>, &mod<13>, &mod<14>, &mod<15>, &mod<16>, &mod<17>,
&mod<18>, &mod<19>, &mod<20>, &mod<21>, &mod<22>,
#if SIZE_MAX >= ULONG_MAX
&mod<23>, &mod<24>, &mod<25>, &mod<26>, &mod<27>, &mod<28>,
&mod<29>, &mod<30>, &mod<31>, &mod<32>, &mod<33>, &mod<34>,
&mod<35>, &mod<36>, &mod<37>, &mod<38>, &mod<39>,
#endif
#if SIZE_MAX >= ULLONG_MAX
&mod<40>, &mod<41>, &mod<42>, &mod<43>, &mod<44>, &mod<45>,
&mod<46>, &mod<47>, &mod<48>, &mod<49>, &mod<50>,
#endif
}};
} // namespace detail
/**
* Grow the hash table by using prime numbers as bucket count. Slower than
* tsl::rh::power_of_two_growth_policy in general but will probably distribute
* the values around better in the buckets with a poor hash function.
*
* To allow the compiler to optimize the modulo operation, a lookup table is
* used with constant primes numbers.
*
* With a switch the code would look like:
* \code
* switch(iprime) { // iprime is the current prime of the hash table
* case 0: hash % 5ul;
* break;
* case 1: hash % 17ul;
* break;
* case 2: hash % 29ul;
* break;
* ...
* }
* \endcode
*
* Due to the constant variable in the modulo the compiler is able to optimize
* the operation by a series of multiplications, substractions and shifts.
*
* The 'hash % 5' could become something like 'hash - (hash * 0xCCCCCCCD) >> 34)
* * 5' in a 64 bits environment.
*/
class prime_growth_policy {
public:
explicit prime_growth_policy(std::size_t& min_bucket_count_in_out) {
auto it_prime = std::lower_bound(
detail::PRIMES.begin(), detail::PRIMES.end(), min_bucket_count_in_out);
if (it_prime == detail::PRIMES.end()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
m_iprime = static_cast(
std::distance(detail::PRIMES.begin(), it_prime));
if (min_bucket_count_in_out > 0) {
min_bucket_count_in_out = *it_prime;
} else {
min_bucket_count_in_out = 0;
}
}
std::size_t bucket_for_hash(std::size_t hash) const noexcept {
return detail::MOD_PRIME[m_iprime](hash);
}
std::size_t next_bucket_count() const {
if (m_iprime + 1 >= detail::PRIMES.size()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The hash table exceeds its maximum size.");
}
return detail::PRIMES[m_iprime + 1];
}
std::size_t max_bucket_count() const { return detail::PRIMES.back(); }
void clear() noexcept { m_iprime = 0; }
private:
unsigned int m_iprime;
static_assert(std::numeric_limits::max() >=
detail::PRIMES.size(),
"The type of m_iprime is not big enough.");
};
} // namespace rh
} // namespace tsl
#endif
================================================
FILE: compiler/native/nerdcore/src/tsl/robin_hash.h
================================================
/**
* MIT License
*
* Copyright (c) 2017 Thibaut Goetghebuer-Planchon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TSL_ROBIN_HASH_H
#define TSL_ROBIN_HASH_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "robin_growth_policy.h"
namespace tsl {
namespace detail_robin_hash {
template
struct make_void {
using type = void;
};
template
struct has_is_transparent : std::false_type {};
template
struct has_is_transparent::type>
: std::true_type {};
template
struct is_power_of_two_policy : std::false_type {};
template
struct is_power_of_two_policy>
: std::true_type {};
// Only available in C++17, we need to be compatible with C++11
template
const T& clamp(const T& v, const T& lo, const T& hi) {
return std::min(hi, std::max(lo, v));
}
template
static T numeric_cast(U value,
const char* error_message = "numeric_cast() failed.") {
T ret = static_cast(value);
if (static_cast(ret) != value) {
TSL_RH_THROW_OR_TERMINATE(std::runtime_error, error_message);
}
const bool is_same_signedness =
(std::is_unsigned::value && std::is_unsigned::value) ||
(std::is_signed::value && std::is_signed::value);
if (!is_same_signedness && (ret < T{}) != (value < U{})) {
TSL_RH_THROW_OR_TERMINATE(std::runtime_error, error_message);
}
return ret;
}
template
static T deserialize_value(Deserializer& deserializer) {
// MSVC < 2017 is not conformant, circumvent the problem by removing the
// template keyword
#if defined(_MSC_VER) && _MSC_VER < 1910
return deserializer.Deserializer::operator()();
#else
return deserializer.Deserializer::template operator()();
#endif
}
/**
* Fixed size type used to represent size_type values on serialization. Need to
* be big enough to represent a std::size_t on 32 and 64 bits platforms, and
* must be the same size on both platforms.
*/
using slz_size_type = std::uint64_t;
static_assert(std::numeric_limits::max() >=
std::numeric_limits::max(),
"slz_size_type must be >= std::size_t");
using truncated_hash_type = std::uint32_t;
/**
* Helper class that stores a truncated hash if StoreHash is true and nothing
* otherwise.
*/
template
class bucket_entry_hash {
public:
bool bucket_hash_equal(std::size_t /*hash*/) const noexcept { return true; }
truncated_hash_type truncated_hash() const noexcept { return 0; }
protected:
void set_hash(truncated_hash_type /*hash*/) noexcept {}
};
template <>
class bucket_entry_hash {
public:
bool bucket_hash_equal(std::size_t hash) const noexcept {
return m_hash == truncated_hash_type(hash);
}
truncated_hash_type truncated_hash() const noexcept { return m_hash; }
protected:
void set_hash(truncated_hash_type hash) noexcept {
m_hash = truncated_hash_type(hash);
}
private:
truncated_hash_type m_hash;
};
/**
* Each bucket entry has:
* - A value of type `ValueType`.
* - An integer to store how far the value of the bucket, if any, is from its
* ideal bucket (ex: if the current bucket 5 has the value 'foo' and
* `hash('foo') % nb_buckets` == 3, `dist_from_ideal_bucket()` will return 2 as
* the current value of the bucket is two buckets away from its ideal bucket) If
* there is no value in the bucket (i.e. `empty()` is true)
* `dist_from_ideal_bucket()` will be < 0.
* - A marker which tells us if the bucket is the last bucket of the bucket
* array (useful for the iterator of the hash table).
* - If `StoreHash` is true, 32 bits of the hash of the value, if any, are also
* stored in the bucket. If the size of the hash is more than 32 bits, it is
* truncated. We don't store the full hash as storing the hash is a potential
* opportunity to use the unused space due to the alignment of the bucket_entry
* structure. We can thus potentially store the hash without any extra space
* (which would not be possible with 64 bits of the hash).
*/
template
class bucket_entry : public bucket_entry_hash {
using bucket_hash = bucket_entry_hash;
public:
using value_type = ValueType;
using distance_type = std::int16_t;
bucket_entry() noexcept
: bucket_hash(),
m_dist_from_ideal_bucket(EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET),
m_last_bucket(false) {
tsl_rh_assert(empty());
}
bucket_entry(bool last_bucket) noexcept
: bucket_hash(),
m_dist_from_ideal_bucket(EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET),
m_last_bucket(last_bucket) {
tsl_rh_assert(empty());
}
bucket_entry(const bucket_entry& other) noexcept(
std::is_nothrow_copy_constructible::value)
: bucket_hash(other),
m_dist_from_ideal_bucket(EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET),
m_last_bucket(other.m_last_bucket) {
if (!other.empty()) {
::new (static_cast(std::addressof(m_value)))
value_type(other.value());
m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
}
tsl_rh_assert(empty() == other.empty());
}
/**
* Never really used, but still necessary as we must call resize on an empty
* `std::vector`. and we need to support move-only types. See
* robin_hash constructor for details.
*/
bucket_entry(bucket_entry&& other) noexcept(
std::is_nothrow_move_constructible::value)
: bucket_hash(std::move(other)),
m_dist_from_ideal_bucket(EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET),
m_last_bucket(other.m_last_bucket) {
if (!other.empty()) {
::new (static_cast(std::addressof(m_value)))
value_type(std::move(other.value()));
m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
}
tsl_rh_assert(empty() == other.empty());
}
bucket_entry& operator=(const bucket_entry& other) noexcept(
std::is_nothrow_copy_constructible::value) {
if (this != &other) {
clear();
bucket_hash::operator=(other);
if (!other.empty()) {
::new (static_cast(std::addressof(m_value)))
value_type(other.value());
}
m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
m_last_bucket = other.m_last_bucket;
}
return *this;
}
bucket_entry& operator=(bucket_entry&&) = delete;
~bucket_entry() noexcept { clear(); }
void clear() noexcept {
if (!empty()) {
destroy_value();
m_dist_from_ideal_bucket = EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET;
}
}
bool empty() const noexcept {
return m_dist_from_ideal_bucket == EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET;
}
value_type& value() noexcept {
tsl_rh_assert(!empty());
#if defined(__cplusplus) && __cplusplus >= 201703L
return *std::launder(
reinterpret_cast(std::addressof(m_value)));
#else
return *reinterpret_cast(std::addressof(m_value));
#endif
}
const value_type& value() const noexcept {
tsl_rh_assert(!empty());
#if defined(__cplusplus) && __cplusplus >= 201703L
return *std::launder(
reinterpret_cast(std::addressof(m_value)));
#else
return *reinterpret_cast(std::addressof(m_value));
#endif
}
distance_type dist_from_ideal_bucket() const noexcept {
return m_dist_from_ideal_bucket;
}
bool last_bucket() const noexcept { return m_last_bucket; }
void set_as_last_bucket() noexcept { m_last_bucket = true; }
template
void set_value_of_empty_bucket(distance_type dist_from_ideal_bucket,
truncated_hash_type hash,
Args&&... value_type_args) {
tsl_rh_assert(dist_from_ideal_bucket >= 0);
tsl_rh_assert(empty());
::new (static_cast(std::addressof(m_value)))
value_type(std::forward(value_type_args)...);
this->set_hash(hash);
m_dist_from_ideal_bucket = dist_from_ideal_bucket;
tsl_rh_assert(!empty());
}
void swap_with_value_in_bucket(distance_type& dist_from_ideal_bucket,
truncated_hash_type& hash, value_type& value) {
tsl_rh_assert(!empty());
tsl_rh_assert(dist_from_ideal_bucket > m_dist_from_ideal_bucket);
using std::swap;
swap(value, this->value());
swap(dist_from_ideal_bucket, m_dist_from_ideal_bucket);
if (StoreHash) {
const truncated_hash_type tmp_hash = this->truncated_hash();
this->set_hash(hash);
hash = tmp_hash;
} else {
// Avoid warning of unused variable if StoreHash is false
TSL_RH_UNUSED(hash);
}
}
static truncated_hash_type truncate_hash(std::size_t hash) noexcept {
return truncated_hash_type(hash);
}
private:
void destroy_value() noexcept {
tsl_rh_assert(!empty());
value().~value_type();
}
public:
static const distance_type EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET = -1;
static const distance_type DIST_FROM_IDEAL_BUCKET_LIMIT = 4096;
static_assert(DIST_FROM_IDEAL_BUCKET_LIMIT <=
std::numeric_limits::max() - 1,
"DIST_FROM_IDEAL_BUCKET_LIMIT must be <= "
"std::numeric_limits::max() - 1.");
private:
using storage = typename std::aligned_storage::type;
distance_type m_dist_from_ideal_bucket;
bool m_last_bucket;
storage m_value;
};
/**
* Internal common class used by `robin_map` and `robin_set`.
*
* ValueType is what will be stored by `robin_hash` (usually `std::pair`
* for map and `Key` for set).
*
* `KeySelect` should be a `FunctionObject` which takes a `ValueType` in
* parameter and returns a reference to the key.
*
* `ValueSelect` should be a `FunctionObject` which takes a `ValueType` in
* parameter and returns a reference to the value. `ValueSelect` should be void
* if there is no value (in a set for example).
*
* The strong exception guarantee only holds if the expression
* `std::is_nothrow_swappable::value &&
* std::is_nothrow_move_constructible::value` is true.
*
* Behaviour is undefined if the destructor of `ValueType` throws.
*/
template
class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
private:
template
using has_mapped_type =
typename std::integral_constant::value>;
static_assert(
noexcept(std::declval().bucket_for_hash(std::size_t(0))),
"GrowthPolicy::bucket_for_hash must be noexcept.");
static_assert(noexcept(std::declval().clear()),
"GrowthPolicy::clear must be noexcept.");
public:
template
class robin_iterator;
using key_type = typename KeySelect::key_type;
using value_type = ValueType;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using hasher = Hash;
using key_equal = KeyEqual;
using allocator_type = Allocator;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = robin_iterator;
using const_iterator = robin_iterator;
private:
/**
* Either store the hash because we are asked by the `StoreHash` template
* parameter or store the hash because it doesn't cost us anything in size and
* can be used to speed up rehash.
*/
static constexpr bool STORE_HASH =
StoreHash ||
((sizeof(tsl::detail_robin_hash::bucket_entry) ==
sizeof(tsl::detail_robin_hash::bucket_entry)) &&
(sizeof(std::size_t) == sizeof(truncated_hash_type) ||
is_power_of_two_policy::value) &&
// Don't store the hash for primitive types with default hash.
(!std::is_arithmetic::value ||
!std::is_same>::value));
/**
* Only use the stored hash on lookup if we are explicitly asked. We are not
* sure how slow the KeyEqual operation is. An extra comparison may slow
* things down with a fast KeyEqual.
*/
static constexpr bool USE_STORED_HASH_ON_LOOKUP = StoreHash;
/**
* We can only use the hash on rehash if the size of the hash type is the same
* as the stored one or if we use a power of two modulo. In the case of the
* power of two modulo, we just mask the least significant bytes, we just have
* to check that the truncated_hash_type didn't truncated more bytes.
*/
static bool USE_STORED_HASH_ON_REHASH(size_type bucket_count) {
if (STORE_HASH && sizeof(std::size_t) == sizeof(truncated_hash_type)) {
TSL_RH_UNUSED(bucket_count);
return true;
} else if (STORE_HASH && is_power_of_two_policy::value) {
return bucket_count == 0 ||
(bucket_count - 1) <=
std::numeric_limits::max();
} else {
TSL_RH_UNUSED(bucket_count);
return false;
}
}
using bucket_entry =
tsl::detail_robin_hash::bucket_entry;
using distance_type = typename bucket_entry::distance_type;
using buckets_allocator = typename std::allocator_traits<
allocator_type>::template rebind_alloc;
using buckets_container_type = std::vector;
public:
/**
* The 'operator*()' and 'operator->()' methods return a const reference and
* const pointer respectively to the stored value type.
*
* In case of a map, to get a mutable reference to the value associated to a
* key (the '.second' in the stored pair), you have to call 'value()'.
*
* The main reason for this is that if we returned a `std::pair&`
* instead of a `const std::pair&`, the user may modify the key which
* will put the map in a undefined state.
*/
template
class robin_iterator {
friend class robin_hash;
private:
using bucket_entry_ptr =
typename std::conditional::type;
robin_iterator(bucket_entry_ptr bucket) noexcept : m_bucket(bucket) {}
public:
using iterator_category = std::forward_iterator_tag;
using value_type = const typename robin_hash::value_type;
using difference_type = std::ptrdiff_t;
using reference = value_type&;
using pointer = value_type*;
robin_iterator() noexcept {}
// Copy constructor from iterator to const_iterator.
template ::type* = nullptr>
robin_iterator(const robin_iterator& other) noexcept
: m_bucket(other.m_bucket) {}
robin_iterator(const robin_iterator& other) = default;
robin_iterator(robin_iterator&& other) = default;
robin_iterator& operator=(const robin_iterator& other) = default;
robin_iterator& operator=(robin_iterator&& other) = default;
const typename robin_hash::key_type& key() const {
return KeySelect()(m_bucket->value());
}
template ::value &&
IsConst>::type* = nullptr>
const typename U::value_type& value() const {
return U()(m_bucket->value());
}
template ::value &&
!IsConst>::type* = nullptr>
typename U::value_type& value() const {
return U()(m_bucket->value());
}
reference operator*() const { return m_bucket->value(); }
pointer operator->() const { return std::addressof(m_bucket->value()); }
robin_iterator& operator++() {
while (true) {
if (m_bucket->last_bucket()) {
++m_bucket;
return *this;
}
++m_bucket;
if (!m_bucket->empty()) {
return *this;
}
}
}
robin_iterator operator++(int) {
robin_iterator tmp(*this);
++*this;
return tmp;
}
friend bool operator==(const robin_iterator& lhs,
const robin_iterator& rhs) {
return lhs.m_bucket == rhs.m_bucket;
}
friend bool operator!=(const robin_iterator& lhs,
const robin_iterator& rhs) {
return !(lhs == rhs);
}
private:
bucket_entry_ptr m_bucket;
};
public:
#if defined(__cplusplus) && __cplusplus >= 201402L
robin_hash(size_type bucket_count, const Hash& hash, const KeyEqual& equal,
const Allocator& alloc,
float min_load_factor = DEFAULT_MIN_LOAD_FACTOR,
float max_load_factor = DEFAULT_MAX_LOAD_FACTOR)
: Hash(hash),
KeyEqual(equal),
GrowthPolicy(bucket_count),
m_buckets_data(bucket_count, alloc),
m_buckets(m_buckets_data.empty() ? static_empty_bucket_ptr()
: m_buckets_data.data()),
m_bucket_count(bucket_count),
m_nb_elements(0),
m_grow_on_next_insert(false),
m_try_shrink_on_next_insert(false) {
if (bucket_count > max_bucket_count()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The map exceeds its maximum bucket count.");
}
if (m_bucket_count > 0) {
tsl_rh_assert(!m_buckets_data.empty());
m_buckets_data.back().set_as_last_bucket();
}
this->min_load_factor(min_load_factor);
this->max_load_factor(max_load_factor);
}
#else
/**
* C++11 doesn't support the creation of a std::vector with a custom allocator
* and 'count' default-inserted elements. The needed contructor `explicit
* vector(size_type count, const Allocator& alloc = Allocator());` is only
* available in C++14 and later. We thus must resize after using the
* `vector(const Allocator& alloc)` constructor.
*
* We can't use `vector(size_type count, const T& value, const Allocator&
* alloc)` as it requires the value T to be copyable.
*/
robin_hash(size_type bucket_count, const Hash& hash, const KeyEqual& equal,
const Allocator& alloc,
float min_load_factor = DEFAULT_MIN_LOAD_FACTOR,
float max_load_factor = DEFAULT_MAX_LOAD_FACTOR)
: Hash(hash),
KeyEqual(equal),
GrowthPolicy(bucket_count),
m_buckets_data(alloc),
m_buckets(static_empty_bucket_ptr()),
m_bucket_count(bucket_count),
m_nb_elements(0),
m_grow_on_next_insert(false),
m_try_shrink_on_next_insert(false) {
if (bucket_count > max_bucket_count()) {
TSL_RH_THROW_OR_TERMINATE(std::length_error,
"The map exceeds its maximum bucket count.");
}
if (m_bucket_count > 0) {
m_buckets_data.resize(m_bucket_count);
m_buckets = m_buckets_data.data();
tsl_rh_assert(!m_buckets_data.empty());
m_buckets_data.back().set_as_last_bucket();
}
this->min_load_factor(min_load_factor);
this->max_load_factor(max_load_factor);
}
#endif
robin_hash(const robin_hash& other)
: Hash(other),
KeyEqual(other),
GrowthPolicy(other),
m_buckets_data(other.m_buckets_data),
m_buckets(m_buckets_data.empty() ? static_empty_bucket_ptr()
: m_buckets_data.data()),
m_bucket_count(other.m_bucket_count),
m_nb_elements(other.m_nb_elements),
m_load_threshold(other.m_load_threshold),
m_min_load_factor(other.m_min_load_factor),
m_max_load_factor(other.m_max_load_factor),
m_grow_on_next_insert(other.m_grow_on_next_insert),
m_try_shrink_on_next_insert(other.m_try_shrink_on_next_insert) {}
robin_hash(robin_hash&& other) noexcept(
std::is_nothrow_move_constructible<
Hash>::value&& std::is_nothrow_move_constructible::value&&
std::is_nothrow_move_constructible::value&&
std::is_nothrow_move_constructible::value)
: Hash(std::move(static_cast(other))),
KeyEqual(std::move(static_cast(other))),
GrowthPolicy(std::move(static_cast(other))),
m_buckets_data(std::move(other.m_buckets_data)),
m_buckets(m_buckets_data.empty() ? static_empty_bucket_ptr()
: m_buckets_data.data()),
m_bucket_count(other.m_bucket_count),
m_nb_elements(other.m_nb_elements),
m_load_threshold(other.m_load_threshold),
m_min_load_factor(other.m_min_load_factor),
m_max_load_factor(other.m_max_load_factor),
m_grow_on_next_insert(other.m_grow_on_next_insert),
m_try_shrink_on_next_insert(other.m_try_shrink_on_next_insert) {
other.clear_and_shrink();
}
robin_hash& operator=(const robin_hash& other) {
if (&other != this) {
Hash::operator=(other);
KeyEqual::operator=(other);
GrowthPolicy::operator=(other);
m_buckets_data = other.m_buckets_data;
m_buckets = m_buckets_data.empty() ? static_empty_bucket_ptr()
: m_buckets_data.data();
m_bucket_count = other.m_bucket_count;
m_nb_elements = other.m_nb_elements;
m_load_threshold = other.m_load_threshold;
m_min_load_factor = other.m_min_load_factor;
m_max_load_factor = other.m_max_load_factor;
m_grow_on_next_insert = other.m_grow_on_next_insert;
m_try_shrink_on_next_insert = other.m_try_shrink_on_next_insert;
}
return *this;
}
robin_hash& operator=(robin_hash&& other) {
other.swap(*this);
other.clear_and_shrink();
return *this;
}
allocator_type get_allocator() const {
return m_buckets_data.get_allocator();
}
/*
* Iterators
*/
iterator begin() noexcept {
std::size_t i = 0;
while (i < m_bucket_count && m_buckets[i].empty()) {
i++;
}
return iterator(m_buckets + i);
}
const_iterator begin() const noexcept { return cbegin(); }
const_iterator cbegin() const noexcept {
std::size_t i = 0;
while (i < m_bucket_count && m_buckets[i].empty()) {
i++;
}
return const_iterator(m_buckets + i);
}
iterator end() noexcept { return iterator(m_buckets + m_bucket_count); }
const_iterator end() const noexcept { return cend(); }
const_iterator cend() const noexcept {
return const_iterator(m_buckets + m_bucket_count);
}
/*
* Capacity
*/
bool empty() const noexcept { return m_nb_elements == 0; }
size_type size() const noexcept { return m_nb_elements; }
size_type max_size() const noexcept { return m_buckets_data.max_size(); }
/*
* Modifiers
*/
void clear() noexcept {
if (m_min_load_factor > 0.0f) {
clear_and_shrink();
} else {
for (auto& bucket : m_buckets_data) {
bucket.clear();
}
m_nb_elements = 0;
m_grow_on_next_insert = false;
}
}
template
std::pair insert(P&& value) {
return insert_impl(KeySelect()(value), std::forward(value));
}
template