From 5ee9bcb7fb692b7dcbdcd71b38f4166f1ae56d3c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 28 Aug 2018 15:34:45 -0700 Subject: Upgraded version to 3.5.5.6, corresponding to Object Oriented changes. --- lib/object.nom | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/object.nom') diff --git a/lib/object.nom b/lib/object.nom index cad7b89..22321b3 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -1,17 +1,16 @@ -#!/usr/bin/env nomsu -V3 +#!/usr/bin/env nomsu -V3.5.5.6 # This file contains the implementation of an Object-Oriented programming system. test: object "Dog": (Dog).genus = "Canus" - my action [set up]: - %me.barks or= 0 + my action [set up]: %me.barks or= 0 my action [bark, woof]: %barks = ("Bark!" for % in 1 to %me.barks) return (%barks joined with " ") - my action [get pissed off]: - %me.barks += 1 + + my action [get pissed off]: %me.barks += 1 %d = (new Dog {barks:2}) assume (%d.barks == 2) @@ -26,14 +25,14 @@ test: assume (%d.barks == 3) %d2 = (new Dog) assume (%d2.barks == 0) or barf "Default initializer failed" - with {%d:new Dog {barks:1}}: assume ((%d::bark) == "Bark!") - + with {%d:new Dog {barks:1}}: + assume ((%d::bark) == "Bark!") object "Corgi" extends (Dog): my action [sploot] "splooted" my action [bark, woof]: %barks = ("Yip!" for % in 1 to %me.barks) return (%barks joined with " ") - + %corg = (new Corgi) assume (%corg.barks == 0) with {%d:new Corgi {barks:1}}: @@ -43,13 +42,14 @@ test: with {%d:new Dog {barks:2}}: assume ((%d::bark) == "Bark! Bark!") - compile [my action %actions %body] to: lua> ".." local fn_name = "A"..string.as_lua_id(\%actions[1].stub) local \%args = table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(a)) end) table.insert(\%args, \(\%me as lua id)) - local lua = LuaCode(tree.source, "class.", fn_name, " = ", \(compile as (%args -> %body))) + local lua = LuaCode(tree.source, "class.", fn_name, " = ", \(..) + compile as (%args -> %body) + ..) for i=2,#\%actions do local alias = \%actions[i] local alias_name = "A"..string.as_lua_id(alias.stub) @@ -94,7 +94,7 @@ compile [object %classname extends %parent %class_body] to: end \(%class_body as lua statements) - + local metamethod_map = {["as text"]="__tostring", ["clean up"]="__gc", ["+ 1"]="__add", ["- 1"]="__sub", ["* 1"]="__mul", ["/ 1"]="__div", ["-"]="__unm", ["// 1"]="__idiv", ["mod 1"]="__mod", ["^ 1"]="__pow", -- cgit v1.2.3