Wednesday, 23 July 2008

Assembler

To get a diversion from the "core" Topaz code, I started working on an assembler. It is progressing really fast, and can convert :class MyClass :func MyFunc PUSH 1 PUSH 2 THISCALL __add PEEK tmp PUSH "The result is %d" THISCALL format PUSHG io STACALL writeln PUSH 3 THISCALL __eq :branch .When true PUSH "Result == 3" PUSHG io STACALL writeln .End .When false PUSH "Result != 3" PUSHG io STACALL writeln .End .End into MyClass = { -- :class MyClass MyFunc = { -- :func MyFunc {0x11, 1}, -- PUSH 1 {0x11, 2}, -- PUSH 2 {0x41, "__add"}, -- THISCALL __add {0x31, "tmp"}, -- PEEK tmp {0x11, "\"The result is %d\""}, -- PUSH "The result is %d" {0x41, "format"}, -- THISCALL format {0xFFFFFFFF, "io"}, -- PUSHG io {0x42, "writeln"}, -- STACALL writeln {0x11, 3}, -- PUSH 3 {0x41, "__eq"}, -- THISCALL __eq {0x61, nil} -- :branch { -- :branch [true] = { -- .When true {0x11, "\"Result == 3\""}, -- PUSH "Result == 3" {0xFFFFFFFF, "io"}, -- PUSHG io {0x42, "writeln"}, -- STACALL writeln }, [false] = { -- .When false {0x11, "\"Result != 3\""}, -- PUSH "Result != 3" {0xFFFFFFFF, "io"}, -- PUSHG io {0x42, "writeln"}, -- STACALL writeln }, }, } } Of course, this is completely useless as long as the VM doesn't work, but it's nice to relax(?) with some simpler code.

Tuesday, 22 July 2008

Out with opcodes, in with functions

OK, time for my second post. I was on a vacation last week, without my computer, therefore I haven't been able to get any further. However, I was able to think(!), and I decided to do a change in the inner workings of Topaz. At first, I had many opcodes, e.g. 0x21, ADD. Now I've decided to instead use functions, and only create the opcodes necessary to invoke a function (which still is a lot). For example, this 0x11, {topaz.vm.T_LOCALREF, 'VAL'}, {topaz.vm.T_FLOAT, 1}, -- MOV eax, 1 0x21, {topaz.vm.T_LOCALREF, 'VAL'}, {topaz.vm.T_FLOAT, 2}, -- ADD eax, 2 0x23, {topaz.vm.T_LOCALREF, 'VAL'}, {topaz.vm.T_FLOAT, 3}, -- MUL eax, 3 0xF1, {topaz.vm.T_LOCALREF, 'VAL'}, {0, 0}, -- PRINT eax becomes 0x11, {'INT', 1}, nil, -- PUSH (INT)1 0x11, {'INT', 2}, nil, -- PUSH (INT)2 0x22, '__add', nil, -- THISCALL __add 0x22, '__mul', nil -- THISCALL __mul 0x11, 'print', nil -- PRINT But the details are far from finished, and I would like some feedback.

Wednesday, 16 July 2008

Introduction

Hello, and welcome to my blog where I will talk about Topaz. I'm creating this blog for two reasons: First, so you can get more detailed information about the project.Currently the only things that exists is a broken early VM (virtual machine, the thing that actually executes the program), supporting only a small subset of the features I want Topaz to have.

So, what exactly is Topaz?

Topaz is (going to be) a high-level scripting language, supporting classes, inheritance, polymorphism, delegates, etc...

What does Topaz look like?

The exact syntax of Topaz is not finished yet, but I'm imagining something like this:

// A simple class that holds a value, // using only one instance per value class ExampleClass{ private exampleMember; private function exampleClass(arg){ exampleMember = arg; } private static _instances; public static function getInstance(arg){ if(!_instances) _instances = new Hash(Any, ExampleClass); return ( _instances.hasKey(arg) ? _instances[arg] : _instances[arg] = new ExampleClass(arg) ); } }

But the syntax / supported features are still not decided. The second reason for creating this blog is to get feedback. I want to know how YOU want it to be!