Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

ObjectScript: A new programming language

, 9 Oct 2012 MIT
The ObjectScript is a new programing language that mixes benefits of JavaScript, Lua, and PHP. The ObjectScript has syntax from JavaScript, multiple results from Lua, OOP from PHP and much more.
OS-0.98-rc-noexe.ZIP
OS
examples-os
add_user_module.os
bind.os
core.os
run_os_prog.os
test.os
proj.win32
add_user_module
add_user_module.vcxproj.filters
os
os.vcxproj.filters
osbind
osbind.vcxproj.filters
profile_benchmark
profile_benchmark.vcxproj.filters
scripts
test_fannkuch.lua
test_fannkuch.os
run_os_prog
run_os_prog.vcxproj.filters
stack_usage
stack_usage.vcxproj.filters
README.md
source
os-binder-FunctionClassImp.tpl
os-binder-FunctionImp.tpl
os-binder-FunctionImpVoid.tpl
OS-0.98-rc.ZIP
bin
os.exe
add_user_module.os
bind.os
core.os
run_os_prog.os
test.os
Makefile
add_user_module.vcxproj.filters
os.vcxproj.filters
osbind.vcxproj.filters
profile_benchmark.vcxproj.filters
test_fannkuch.lua
test_fannkuch.os
run_os_prog.vcxproj.filters
stack_usage.vcxproj.filters
README.md
os-binder-FunctionClassImp.tpl
os-binder-FunctionImp.tpl
os-binder-FunctionImpVoid.tpl
unitpoint-objectscript-86f30d7-noexe.zip
unitpoint-objectscript-86f30d7
.gitignore
README.md
bin
.gitignore
examples-os
add_user_module.os
bind.os
core.os
run_os_prog.os
test.os
proj.win32
.gitignore
add_user_module
.gitignore
os
.gitignore
test_fannkuch.osc
test_fannkuch.osd
osbind
.gitignore
profile_benchmark
.gitignore
scripts
test_fannkuch.lua
test_fannkuch.os
run_os_prog
.gitignore
stack_usage
.gitignore
source
.gitignore
os-binder-FunctionClassImp.tpl
os-binder-FunctionImp.tpl
os-binder-FunctionImpVoid.tpl
unitpoint-objectscript-86f30d7.zip
.gitignore
README.md
.gitignore
os.exe
add_user_module.os
bind.os
core.os
run_os_prog.os
test.os
.gitignore
.gitignore
.gitignore
test_fannkuch.osc
test_fannkuch.osd
.gitignore
.gitignore
test_fannkuch.lua
test_fannkuch.os
.gitignore
.gitignore
.gitignore
os-binder-FunctionClassImp.tpl
os-binder-FunctionImp.tpl
os-binder-FunctionImpVoid.tpl
#include "stdafx.h"
#include "windows.h"
#include "../../source/objectscript.h"

using namespace ObjectScript;

static double inv_frequency = 0.0;
static double start_time = 0.0;

struct __init_time__
{
	__init_time__()
	{
		LARGE_INTEGER largeInteger;

		if(inv_frequency == 0.0f){
			QueryPerformanceFrequency(&largeInteger);
			inv_frequency = double(largeInteger.QuadPart);
			if(inv_frequency > 0.0f){
				inv_frequency = 1.0f / inv_frequency;
			}
		}

		QueryPerformanceCounter(&largeInteger);
		start_time = double(largeInteger.QuadPart);
	}
} __init_time__;

OS::String getString(OS * os, const _TCHAR * str)
{
	OS_CHAR buf[1024*10];
	int i = 0;
	for(; str[i]; i++){
		buf[i] = (OS_CHAR)str[i];
	}
	buf[i] = 0;
	return OS::String(os, buf);
}

double getTimeSec()
{
	LARGE_INTEGER largeInteger;
	QueryPerformanceCounter(&largeInteger);
	double count = double(largeInteger.QuadPart);
	return inv_frequency * (count - start_time);
}

static int OS_getTimeSec(OS * os, int params, int upvalues, int, void*)
{
	os->pushNumber(getTimeSec());
	return 1;
}

int _tmain(int argc, _TCHAR* argv[])
{
	if(argc < 2){
		printf("ObjctScript " OS_VERSION " Copyright (C) 2012 Evgeniy Golovin (evgeniy.golovin@unitpoint.ru)\n");
		printf("Latest version and source code: https://github.com/unitpoint/objectscript\n");
		printf("\n");
		printf("Usage: %s script [args]\n", argv[0]);
		exit(1);
	}

	// craete ObjectScript instance
	OS * os = OS::create();
	// save allocated memory at start point
	int start_mem_usage = os->getAllocatedBytes();
	// set needed settings
	os->setSetting(OS_SETTING_CREATE_DEBUG_INFO, true);
	os->setSetting(OS_SETTING_CREATE_DEBUG_OPCODES, true);
	os->setSetting(OS_SETTING_CREATE_COMPILED_FILE, true);
	// create program arguments
	os->newObject();
	for(int i = 0; i < argc; i++){
		os->pushStackValue(-1);
		os->pushNumber(i-1);
		os->pushString(getString(os, argv[i]));
		os->setProperty();
	}
	// we can use the program arguments as global arg variable inside of our script
	os->setGlobal("arg");
	// set global getTimeSec function so we can check time inside of our script
	os->pushCFunction(OS_getTimeSec);
	os->setGlobal("getTimeSec");
	// run main stript
	os->require(getString(os, argv[1]));
	{
		int mem_allocated = os->getAllocatedBytes()/1024;
		int mem_cached = os->getCachedBytes()/1024;
		// run gc full step
		os->gcFull();
		int after_mem_allocated = os->getAllocatedBytes()/1024;
		int after_mem_cached = os->getCachedBytes()/1024;
		// output some debug memory usage info
		printf("\n\n[before GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n[after  GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n", 
			mem_allocated - mem_cached, 
			mem_cached, 
			mem_allocated, 
			after_mem_allocated - after_mem_cached,
			after_mem_cached,
			after_mem_allocated
			);
#ifdef OS_DEBUG
		printf("\nNotice: debug build uses much more memory than release build\n");
#endif
	}
	// release the ObjectScript instance
	os->release();
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

unitpoint

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Oct 2012
Article Copyright 2012 by unitpoint
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid